Module: RatPack::HtmlHelpers
- Defined in:
- lib/ratpack/html_helpers.rb
Instance Method Summary collapse
- #css_link(name, options = {}) ⇒ Object
- #image_tag(file, attrs = {}) ⇒ Object
- #js_link(name, options = {}) ⇒ Object
- #link_to(name, url, options = {}) ⇒ Object
- #partial(template, opts = {}) ⇒ Object
- #pluralize(str, num) ⇒ Object
Instance Method Details
#css_link(name, options = {}) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ratpack/html_helpers.rb', line 18 def css_link(name, = {}) name = "/stylesheets/#{name}.css" unless remote_asset?(name) defaults = {:href => name, :media => "screen", :rel => "stylesheet", :type => "text/css"} self_closing_tag(:link,defaults.merge()) end |
#image_tag(file, attrs = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/ratpack/html_helpers.rb', line 12 def image_tag(file,attrs = {}) file = "/images/#{file}" unless remote_asset?(file) defaults = {:src => file } self_closing_tag(:img,defaults.merge()) end |
#js_link(name, options = {}) ⇒ Object
25 26 27 28 29 |
# File 'lib/ratpack/html_helpers.rb', line 25 def js_link(name, = {}) name = "/javascripts/#{name}.js" unless remote_asset?(name) defaults = {:src => name, :type => "text/javascript"} tag(:script,defaults.merge()) end |
#link_to(name, url, options = {}) ⇒ Object
7 8 9 10 |
# File 'lib/ratpack/html_helpers.rb', line 7 def link_to(name, url, = {}) defaults = {:href => url} tag(:a,name,defaults.merge()) end |
#partial(template, opts = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ratpack/html_helpers.rb', line 31 def partial(template, opts = {}) engine = opts.delete(:template) || :erb opts.merge!(:layout => false) path = :"partials/#{template}" if collection = opts.delete(:collection) then collection.map do |member| send(engine,path, opts.merge(:locals => {template.to_sym => member})) end.join("\n") else send(engine,path, opts) end end |
#pluralize(str, num) ⇒ Object
3 4 5 |
# File 'lib/ratpack/html_helpers.rb', line 3 def pluralize(str,num) num.to_i > 1 ? str.plural : str.singular end |