Module: Voidtools::Sinatra::ViewHelpers
- Defined in:
- lib/voidtools/sinatra/view_helpers.rb
Instance Method Summary collapse
- #image_tag(url, options = {}) ⇒ Object
- #include_assets(type, assets) ⇒ Object
- #include_css(assets) ⇒ Object
- #include_js(assets) ⇒ Object
- #link_to(label, path = "javascript:void(0)", options = {}) ⇒ Object
Instance Method Details
#image_tag(url, options = {}) ⇒ Object
14 15 16 |
# File 'lib/voidtools/sinatra/view_helpers.rb', line 14 def image_tag(url, ={}) haml_tag :img, .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| = if type_js { type: "text/javascript", src: "/js/#{asset}.js" } else { rel: "stylesheet", href: "/css/#{asset}.css" } end haml_tag tag, 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 |
#link_to(label, path = "javascript:void(0)", options = {}) ⇒ Object
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)", ={}) # haml_tag :a, { href: path } do # haml_concat label # end = .map do |key, value| " #{key}='#{value}'" end.join(" ") haml_concat "<a href='#{path}'#{}>#{label}</a>" end |