Module: Hamloft::Helpers

Defined in:
lib/hamloft/helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset(url) ⇒ Object

styles



13
14
15
# File 'lib/hamloft/helpers.rb', line 13

def asset(url)
  "#{asset_uri}/themes/#{@_haml_locals[:theme]}/#{url}"
end

#asset_uriObject



21
22
23
# File 'lib/hamloft/helpers.rb', line 21

def asset_uri
  @_haml_locals[:asset_uri] || Hamloft.asset_uri
end

#block(identifier, variables = {}) ⇒ Object



7
8
9
10
# File 'lib/hamloft/helpers.rb', line 7

def block(identifier, variables = {})
  haml_contents = Hamloft.block_resolver.resolve(identifier, @_haml_locals)
  Hamloft.render(haml_contents, @_haml_locals.merge(variables))
end

#drop_containerObject

drop container



74
75
76
# File 'lib/hamloft/helpers.rb', line 74

def drop_container
  haml_tag :div, class: '_typeloft_widget_drop_container'
end

#font(font_face, &block) ⇒ Object



53
54
55
56
57
# File 'lib/hamloft/helpers.rb', line 53

def font(font_face, &block)
  haml_tag :font, face: font_face do
    yield if block
  end
end


44
45
46
47
48
49
50
51
# File 'lib/hamloft/helpers.rb', line 44

def link(href, referrer = 'Baker', &block)
  if referrer && !referrer.empty? && !href.include?('referrer=')
    href = "#{href}#{href.include?('?') ? '&' : '?'}referrer=#{referrer}"
  end
  haml_tag :a, href: href do
    yield if block
  end
end

#parse_html(key, type) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/hamloft/helpers.rb', line 33

def parse_html(key, type)
  if (html = @_haml_locals[key.to_sym]) && !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



17
18
19
# File 'lib/hamloft/helpers.rb', line 17

def root_asset(url)
  "#{asset_uri}/#{url}"
end

#style(*args, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hamloft/helpers.rb', line 59

def style(*args, &block)
  style = nil
  if args[-1].class.name == 'Hash'
    style_options = args.pop
    style = style_string(style_options, *style_options.keys)
  end

  classes = args.map { |a| "__#{a}" }
  haml_tag :span, class: classes.join(' '), style: style do
    yield if block
  end
end

#style_string(options, *args, &block) ⇒ Object



3
4
5
# File 'lib/hamloft/helpers.rb', line 3

def style_string(options, *args, &block)
  Hamloft::StyleBuilder.new(options, args).process(block)
end

#var(key, default = nil) ⇒ Object



25
26
27
# File 'lib/hamloft/helpers.rb', line 25

def var(key, default = nil)
  variable(:variables, {})[key.to_sym] || default
end

#variable(key, default = false) ⇒ Object



29
30
31
# File 'lib/hamloft/helpers.rb', line 29

def variable(key, default = false)
  @_haml_locals[key.to_sym] || default
end

#widget(identifier, options = {}, &block) ⇒ Object



78
79
80
81
82
83
# File 'lib/hamloft/helpers.rb', line 78

def widget(identifier, options={}, &block)
  widget = Hamloft.widgets[identifier].new(options, self)
  haml_tag "#{identifier}-widget", widget.widget_options do
    widget.template(&block)
  end
end