Module: Voidtools::Sinatra::ViewHelpers

Defined in:
lib/voidtools/sinatra/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#image_tag(url, options = {}) ⇒ Object



14
15
16
# File 'lib/voidtools/sinatra/view_helpers.rb', line 14

def image_tag(url, options={})
  haml_tag :img, options.merge(src: url)
end

#include_assets(type, assets) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/voidtools/sinatra/view_helpers.rb', line 18

def include_assets(type, assets)
  type_js = type == "js"
  tag = type_js ?  "script" : "link"
  [assets].flatten.each do |asset|
    options = if type_js
      { type: "text/javascript", src: "/js/#{asset}.js"  }
    else
      { rel: "stylesheet", href: "/css/#{asset}.css" }
    end
    haml_tag tag, options
  end
end

#include_css(assets) ⇒ Object



35
36
37
# File 'lib/voidtools/sinatra/view_helpers.rb', line 35

def include_css(assets)
  include_assets "css", assets
end

#include_js(assets) ⇒ Object



31
32
33
# File 'lib/voidtools/sinatra/view_helpers.rb', line 31

def include_js(assets)
  include_assets "js", assets
end


4
5
6
7
8
9
10
11
12
# File 'lib/voidtools/sinatra/view_helpers.rb', line 4

def link_to(label, path="javascript:void(0)", options={})
  # haml_tag :a, { href: path } do
  #   haml_concat label
  # end
  options = options.map do |key, value|
    " #{key}='#{value}'"
  end.join(" ")
  haml_concat "<a href='#{path}'#{options}>#{label}</a>"
end