Module: Voidtools::Sinatra::ViewHelpers

Includes:
Tracking
Defined in:
lib/voidtools/sinatra/sinatra.rb,
lib/voidtools/sinatra/view_helpers.rb

Instance Method Summary collapse

Methods included from Tracking

#analytics, #crazyegg, #gauges, #mixpanel, #track_run

Instance Method Details

#body_classObject



43
44
45
46
47
# File 'lib/voidtools/sinatra/view_helpers.rb', line 43

def body_class
  path = request.path.split("/")[1..2]
  path = path.join(" ") unless path.nil?
  request.path == "/" ? "home" : path
end

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



18
19
20
# File 'lib/voidtools/sinatra/view_helpers.rb', line 18

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

#include_assets(type, assets) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/voidtools/sinatra/view_helpers.rb', line 22

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



39
40
41
# File 'lib/voidtools/sinatra/view_helpers.rb', line 39

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

#include_js(assets) ⇒ Object



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

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

require ‘voidtools/sinatra/tracking’ include Voidtools::Tracking



8
9
10
11
12
13
14
15
16
# File 'lib/voidtools/sinatra/view_helpers.rb', line 8

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