Module: Rocketeer::Helpers::HTML
- Defined in:
- lib/rocketeer/helpers/html.rb
Class Method Summary collapse
-
.attributes(attributes) ⇒ String
Builds HTML attributes.
Instance Method Summary collapse
-
#css_link_tag(url, media = "screen") ⇒ Object
Returns the code for linking CSS style sheets.
-
#js_inc_tag(url) ⇒ Object
Returns the code for linking javascript files.
-
#link_to(text, url, options = {}) ⇒ Object
Creates a link to the specified URL with the specified text.
-
#link_to_if(condition, text, url, options = {}) ⇒ Object
Creates a link to the specified URL if the condition is met.
-
#link_to_unless_current(text, url, options = {}) ⇒ Object
Creates a link to the specified URL unless the request matches the URL.
Class Method Details
.attributes(attributes) ⇒ String
Builds HTML attributes
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
#css_link_tag(url, media = "screen") ⇒ Object
Returns the code for linking CSS style sheets.
@example:
css_inc_tag '/assets/css/master.css'
css_inc_tag '/assets/css/print.css', 'screen'
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'
124 125 126 |
# File 'lib/rocketeer/helpers/html.rb', line 124 def js_inc_tag(url) "<script src=\"#{url}\" type=\"text/javascript\"></script>" end |
#link_to(text, url, options = {}) ⇒ Object
Creates a link to the specified URL with the specified text
@example:
link_to 'Apple', 'http://apple.com/au'
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, = {}) = .merge({ :href => url ? url : request.path_info }) if [:confirm] [:"data-confirm"] = [:confirm] [:confirm] = nil end if [:remote] [:"data-remote"] = [:remote] [:remote] = nil end = [] .each do |k, v| pass if v === nil .push "#{k.to_s}=\"#{v.to_s}\"" end "<a #{.join(' ')}>#{text}</a>" end |
#link_to_if(condition, text, url, options = {}) ⇒ Object
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'
90 91 92 93 94 95 96 |
# File 'lib/rocketeer/helpers/html.rb', line 90 def link_to_if(condition, text, url, = {}) if condition link_to text, url, = {} else text end end |
#link_to_unless_current(text, url, options = {}) ⇒ Object
Creates a link to the specified URL unless the request matches the URL.
@example:
link_to_unless_current 'Google', 'http://google.com.au'
69 70 71 72 73 74 75 |
# File 'lib/rocketeer/helpers/html.rb', line 69 def link_to_unless_current(text, url, = {}) if request.path_info == url text else link_to text, url, end end |