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_class ⇒ Object
37
38
39
40
41
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 37
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
12
13
14
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 12
def image_tag(url, options={})
haml_tag :img, options.merge(src: url)
end
|
#include_assets(type, assets) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 16
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
33
34
35
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 33
def include_css(assets)
include_assets "css", assets
end
|
#include_js(assets) ⇒ Object
29
30
31
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 29
def include_js(assets)
include_assets "js", assets
end
|
#link_to(label, path = "javascript:void(0)", options = {}) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/voidtools/sinatra/view_helpers.rb', line 5
def link_to(label, path="javascript:void(0)", options={})
options = options.map do |key, value|
" #{key}='#{value}'"
end.join(" ")
haml_concat "<a href='#{path}'#{options}>#{label}</a>"
end
|