Module: Hamloft::Helpers
- Included in:
- Widget
- Defined in:
- lib/hamloft/helpers.rb
Instance Method Summary collapse
-
#asset(url) ⇒ Object
styles.
- #asset_uri ⇒ Object
- #block(identifier, variables = {}) ⇒ Object
-
#drop_container ⇒ Object
drop container.
- #font(font_face, &block) ⇒ Object
- #link(href, referrer = "Baker", &block) ⇒ Object
- #parse_html(key, type) ⇒ Object
- #root_asset(url) ⇒ Object
- #style(*args, &block) ⇒ Object
- #style_string(options, *args, &block) ⇒ Object
- #var(key, default = nil) ⇒ Object
- #variable(key, default = false) ⇒ Object
-
#widget_block(widget, &block) ⇒ Object
widgets.
Instance Method Details
#asset(url) ⇒ Object
styles
14 15 16 |
# File 'lib/hamloft/helpers.rb', line 14 def asset(url) "#{asset_uri}/themes/#{@_haml_locals[:theme]}/#{url}" end |
#asset_uri ⇒ Object
22 23 24 |
# File 'lib/hamloft/helpers.rb', line 22 def asset_uri @_haml_locals[:asset_uri] || Hamloft.asset_uri end |
#block(identifier, variables = {}) ⇒ Object
8 9 10 11 |
# File 'lib/hamloft/helpers.rb', line 8 def block(identifier, variables={}) haml_contents = Hamloft.block_resolver.resolve(identifier, @_haml_locals) Hamloft.render(haml_contents, @_haml_locals.merge(variables)) end |
#drop_container ⇒ Object
drop container
75 76 77 |
# File 'lib/hamloft/helpers.rb', line 75 def drop_container haml_tag :div, :class => "_typeloft_widget_drop_container" end |
#font(font_face, &block) ⇒ Object
54 55 56 57 58 |
# File 'lib/hamloft/helpers.rb', line 54 def font(font_face, &block) haml_tag :font, :face => font_face do block.call if block end end |
#link(href, referrer = "Baker", &block) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/hamloft/helpers.rb', line 45 def link(href, referrer="Baker", &block) if referrer and not referrer.empty? and not href.include?("referrer=") href = "#{href}#{href.include?("?") ? "&" : "?"}referrer=#{referrer}" end haml_tag :a, :href => href do block.call if block end end |
#parse_html(key, type) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hamloft/helpers.rb', line 34 def parse_html(key, type) if html = @_haml_locals[key.to_sym] and not Hamloft.template(type).nil? template = Hamloft.template(type).new(self, html) template.container do template.chunks.each do |chunk| template.process_chunk(chunk) end end end end |
#root_asset(url) ⇒ Object
18 19 20 |
# File 'lib/hamloft/helpers.rb', line 18 def root_asset(url) "#{asset_uri}/#{url}" end |
#style(*args, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hamloft/helpers.rb', line 60 def style(*args, &block) style = nil if args[-1].class.name == "Hash" = args.pop style = style_string(, *.keys) end classes = args.map{|a| "__#{a}"} haml_tag :span, :class => classes.join(" "), :style => style do block.call if block end end |
#style_string(options, *args, &block) ⇒ Object
4 5 6 |
# File 'lib/hamloft/helpers.rb', line 4 def style_string(, *args, &block) Hamloft::StyleBuilder.new(, args).process(block) end |
#var(key, default = nil) ⇒ Object
26 27 28 |
# File 'lib/hamloft/helpers.rb', line 26 def var(key, default=nil) variable(:variables, {})[key.to_sym] || default end |
#variable(key, default = false) ⇒ Object
30 31 32 |
# File 'lib/hamloft/helpers.rb', line 30 def variable(key, default=false) @_haml_locals[key.to_sym] || default end |
#widget_block(widget, &block) ⇒ Object
widgets
81 82 83 84 85 |
# File 'lib/hamloft/helpers.rb', line 81 def (, &block) haml_tag :div, . do block.call() if block end end |