Module: Rocketeer::Helpers::HTML

Defined in:
lib/rocketeer/helpers/html.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attributes(attributes) ⇒ String

Builds HTML attributes

Parameters:

  • attributes (Hash)

Returns:

  • (String)

Author:

  • Jack Polgar

Since:

  • 0.5



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rocketeer/helpers/html.rb', line 138

def self.attributes(attributes)
  html = []
  attributes.each do |k, v|
    next if v == nil
    html.push "#{k}=\"#{v}\""
  end
  if attributes.count > 0
    " #{html.join(' ')}"
  else
    ''
  end
end

Instance Method Details

Returns the code for linking CSS style sheets.

@example:

css_inc_tag '/assets/css/master.css'
css_inc_tag '/assets/css/print.css', 'screen'

Parameters:

  • url (String)

    The URL of the stylesheet

  • media (String) (defaults to: "screen")

    The media of the stylesheet

Author:

  • Jack Polgar

Since:

  • 0.1



110
111
112
# File 'lib/rocketeer/helpers/html.rb', line 110

def css_link_tag(url, media = "screen")
  "<link rel=\"stylesheet\" href=\"#{url}?#{Time.now.to_i}\" media=\"#{media}\" />"
end

#js_inc_tag(url) ⇒ Object

Returns the code for linking javascript files.

@example:

js_inc_tag '/assets/js/app.js'

Parameters:

  • url (String)

    The URL of the file

Author:

  • Jack Polgar

Since:

  • 0.1



124
125
126
# File 'lib/rocketeer/helpers/html.rb', line 124

def js_inc_tag(url)
  "<script src=\"#{url}\" type=\"text/javascript\"></script>"
end

Creates a link to the specified URL with the specified text

@example:

link_to 'Apple', 'http://apple.com/au'

Parameters:

  • text (String)

    The text for the link

  • the_url (String)

    The URL to link to

  • options (Hash) (defaults to: {})

    Options for the link

Author:

  • Jack Polgar

Since:

  • 0.1



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rocketeer/helpers/html.rb', line 35

def link_to(text, url, options = {})
  options = options.merge({
    :href => url ? url : request.path_info
  })
  if options[:confirm]
    options[:"data-confirm"] = options[:confirm]
    options[:confirm] = nil
  end
  if options[:remote]
    options[:"data-remote"] = options[:remote]
    options[:remote] = nil
  end
  
  html_options = []
  options.each do |k, v|
    pass if v === nil
    html_options.push "#{k.to_s}=\"#{v.to_s}\""
  end
  
  "<a #{html_options.join(' ')}>#{text}</a>"
end

Creates a link to the specified URL if the condition is met.

@example:

link_to_if Time.now.year == 2011, 'Google', 'http://google.com.au'

Parameters:

  • condition (Boolean)

    The condition to check

  • text (String)

    The text for the link

  • the_url (String)

    The URL to link to

  • options (Hash) (defaults to: {})

    Options for the link

Author:

  • Jack Polgar

Since:

  • 0.3



90
91
92
93
94
95
96
# File 'lib/rocketeer/helpers/html.rb', line 90

def link_to_if(condition, text, url, options = {})
  if condition
    link_to text, url, options = {}
  else
    text
  end
end

Creates a link to the specified URL unless the request matches the URL.

@example:

link_to_unless_current 'Google', 'http://google.com.au'

Parameters:

  • text (String)

    The text for the link

  • the_url (String)

    The URL to link to

  • options (Hash) (defaults to: {})

    Options for the link

Author:

  • Jack Polgar

Since:

  • 0.1



69
70
71
72
73
74
75
# File 'lib/rocketeer/helpers/html.rb', line 69

def link_to_unless_current(text, url, options = {})
  if request.path_info == url
    text
  else
    link_to text, url, options
  end
end