Module: Railstar::Helper
- Defined in:
- lib/railstar/helper.rb
Instance Method Summary collapse
- #auto_discovery_rss(rss) ⇒ Object
- #br(str) ⇒ Object
- #hbr(str) ⇒ Object
- #javascript(*js) ⇒ Object
- #params_to_hidden_tag(object, options = {}) ⇒ Object
- #save_action(object, options = {}) ⇒ Object
- #stylesheet(*css) ⇒ Object
- #title(page_title) ⇒ Object
- #url2link(str) ⇒ Object
Instance Method Details
#auto_discovery_rss(rss) ⇒ Object
15 16 17 18 19 |
# File 'lib/railstar/helper.rb', line 15 def auto_discovery_rss(rss) content_for(:head) do %Q(<link rel="alternate" type="application/rss+xml" href="#{rss}" title="RSS 2.0" />) end end |
#br(str) ⇒ Object
26 27 28 |
# File 'lib/railstar/helper.rb', line 26 def br(str) str.gsub(/\r\n|\r|\n/, "<br />") end |
#hbr(str) ⇒ Object
21 22 23 24 |
# File 'lib/railstar/helper.rb', line 21 def hbr(str) str = html_escape(str) br(str) end |
#javascript(*js) ⇒ Object
11 12 13 |
# File 'lib/railstar/helper.rb', line 11 def javascript(*js) content_for(:head) { javascript_include_tag(*js) } end |
#params_to_hidden_tag(object, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/railstar/helper.rb', line 34 def params_to_hidden_tag(object, ={}) str = '' str << hidden_field_tag('back', 1) if [:back] attributes = params[object] return str unless attributes attributes.each do |method,value| next if [:except] && [:except].include?(method.to_sym) if value.is_a? Hash value.each do |k,v| if v.is_a? Hash v.each do |l,w| str << hidden_field_tag("#{object}[#{method}][#{k}][#{l}]", w) end else str << hidden_field_tag("#{object}[#{method}][#{k}]", v) end end else str << hidden_field(object, method, :value => attributes[method]) end end raw(str) end |
#save_action(object, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/railstar/helper.rb', line 58 def save_action(object, ={}) if object.new_record? {:action => "create"} else {:action => "update", :id => object} end.merge() end |
#stylesheet(*css) ⇒ Object
7 8 9 |
# File 'lib/railstar/helper.rb', line 7 def stylesheet(*css) content_for(:head) { stylesheet_link_tag(*css) } end |
#title(page_title) ⇒ Object
3 4 5 |
# File 'lib/railstar/helper.rb', line 3 def title(page_title) content_for(:title) { page_title } end |
#url2link(str) ⇒ Object
30 31 32 |
# File 'lib/railstar/helper.rb', line 30 def url2link(str) str.gsub(/(https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:@&=+$,%#]+)/){"<a href='#{$1}'>#{$1}</a>"} end |