Module: RatPack::HtmlHelpers

Defined in:
lib/ratpack/html_helpers.rb

Instance Method Summary collapse

Instance Method Details



18
19
20
21
22
23
# File 'lib/ratpack/html_helpers.rb', line 18

def css_link(name, options = {})
  name = "/stylesheets/#{name}.css" unless remote_asset?(name)
  defaults = {:href => name, :media => "screen",
    :rel => "stylesheet", :type => "text/css"}
  self_closing_tag(:link,defaults.merge(options))
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(options))
end


25
26
27
28
29
# File 'lib/ratpack/html_helpers.rb', line 25

def js_link(name, options = {})
  name = "/javascripts/#{name}.js" unless remote_asset?(name)
  defaults = {:src => name, :type => "text/javascript"}
  tag(:script,defaults.merge(options))
end


7
8
9
10
# File 'lib/ratpack/html_helpers.rb', line 7

def link_to(name, url, options = {})
  defaults = {:href => url}
  tag(:a,name,defaults.merge(options))
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