Module: Cell::Hamlit

Defined in:
lib/cell/hamlit.rb,
lib/cell/hamlit/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/cell/hamlit.rb', line 5

def self.included(base)
  begin
    require "hamlit/rails_helpers"
  rescue LoadError
  else
    base.include ::Hamlit::RailsHelpers
  end
end

Instance Method Details

#capture(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/cell/hamlit.rb', line 43

def capture(*args)
  value = nil
  buffer = with_output_buffer { value = yield(*args) }
  if buffer.size > 0
    buffer.to_s
  else
    value
  end
end

#content_tag(name, content_or_options_with_block = nil, options = nil, escape = false, &block) ⇒ Object

def form_for(*args, &block) # TODO: remove this once Haml 4.1 is out. the form_for_with_haml is buggy.

form_for_without_haml(*args, &block)

end



70
71
72
# File 'lib/cell/hamlit.rb', line 70

def (name, content_or_options_with_block=nil, options=nil, escape=false, &block)
  super
end

#form_tag_in_block(html_options, &block) ⇒ Object

From FormTagHelper. why do they escape every possible string? why?



26
27
28
29
# File 'lib/cell/hamlit.rb', line 26

def form_tag_in_block(html_options, &block)
  content = capture(&block)
  form_tag_with_body(html_options, content)
end

#form_tag_with_body(html_options, content) ⇒ Object



31
32
33
# File 'lib/cell/hamlit.rb', line 31

def form_tag_with_body(html_options, content)
  "#{form_tag_html(html_options)}" << content.to_s << "</form>"
end

#render_templateObject



53
54
55
56
57
58
59
# File 'lib/cell/hamlit.rb', line 53

def render_template(*)
  @output_buffer ||= nil # suppress uninitialized instance variable warning
  old_output_buffer = @output_buffer
  super
ensure
  @output_buffer = old_output_buffer
end

#template_options_for(options) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/cell/hamlit.rb', line 14

def template_options_for(options)
  {
    escape_html:    false,
    template_class: ::Hamlit::Template,
    suffix:         "haml",
    buffer:         '@output_buffer',
  }
end

#with_output_buffer(block_buffer = ViewModel::OutputBuffer.new) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/cell/hamlit.rb', line 35

def with_output_buffer(block_buffer=ViewModel::OutputBuffer.new)
  @output_buffer, old_buffer = block_buffer, @output_buffer
  yield
  block_buffer
ensure
  @output_buffer = old_buffer
end