Module: Hamloft::Helpers

Included in:
Widget
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



71
72
73
# File 'lib/hamloft/helpers.rb', line 71

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

#font(font_face, &block) ⇒ Object



50
51
52
53
54
# File 'lib/hamloft/helpers.rb', line 50

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


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

def link(href, &block)
  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



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hamloft/helpers.rb', line 56

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_block(widget, &block) ⇒ Object

widgets



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

def widget_block(widget, &block)
  haml_tag :div, widget.typeloft_widget_options do
    yield(widget) if block
  end
end