Module: Hamloft::Helpers

Included in:
Widget
Defined in:
lib/hamloft/helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset(url) ⇒ Object

styles



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

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

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



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

def block(identifier, variables={})
  haml_contents = File.read("src/themes/#{@_haml_locals[:theme]}/blocks/#{identifier}.haml")
  Hamloft.render(haml_contents, theme: @_haml_locals[:theme], base_path: @_haml_locals[:base_path], variables: variables)
end

#drop_containerObject

drop container



67
68
69
# File 'lib/hamloft/helpers.rb', line 67

def drop_container
  haml_tag :div, :class => "_typeloft_widget_drop_container"
end

#font(font_face, &block) ⇒ Object



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

def font(font_face, &block)
  haml_tag :font, :face => font_face do
    block.call if block
  end
end


37
38
39
40
41
42
43
44
# File 'lib/hamloft/helpers.rb', line 37

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



26
27
28
29
30
31
32
33
34
35
# File 'lib/hamloft/helpers.rb', line 26

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

#style(*args, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hamloft/helpers.rb', line 52

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
    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(options, *args, &block)
  Hamloft::StyleBuilder.new(options, args).process(block)
end

#var(key, default = nil) ⇒ Object



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

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

#variable(key, default = false) ⇒ Object



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

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

#widget_block(widget, &block) ⇒ Object

widgets



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

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