Module: Cell::Erb

Defined in:
lib/cell/erb/template.rb,
lib/cell/erb/version.rb

Overview

Erb contains helpers that are messed up in Rails and do escaping.

Defined Under Namespace

Classes: Template

Constant Summary collapse

VERSION =
"0.0.6"

Instance Method Summary collapse

Instance Method Details

#capture(*args) ⇒ Object

this is capture copied from AV:::CaptureHelper without doing escaping.



23
24
25
26
27
28
29
# File 'lib/cell/erb/template.rb', line 23

def capture(*args)
  value = nil
  buffer = with_output_buffer { value = yield(*args) }

  return buffer.to_s if buffer.size > 0
  value # this applies for "Beachparty" string-only statements.
end

#concat(string) ⇒ Object



61
62
63
# File 'lib/cell/erb/template.rb', line 61

def concat(string)
  @output_buffer << string
end

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

Below: Rails specific helper fixes. I hate that. I can’t tell you how much I hate those helpers, and their blind escaping for every possible string within the application.



42
43
44
# File 'lib/cell/erb/template.rb', line 42

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

#form_tag_html(html_options) ⇒ Object



56
57
58
59
# File 'lib/cell/erb/template.rb', line 56

def form_tag_html(html_options)
  extra_tags = extra_tags_for_form(html_options)
  "#{tag(:form, html_options, true) + extra_tags}"
end

#form_tag_with_body(html_options, content) ⇒ Object



52
53
54
# File 'lib/cell/erb/template.rb', line 52

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

#render_templateObject

This is to prevent multiple renders to share the same output_buffer. I am still trying to find a way to avoid output buffers.



8
9
10
11
12
13
# File 'lib/cell/erb/template.rb', line 8

def render_template(*)
  old_output_buffer = @output_buffer
  super
ensure
  @output_buffer = old_output_buffer
end

#tag_options(options, escape = true) ⇒ Object

We do statically set escape=true since attributes are double-quoted strings, so we have to escape (default in Rails).



48
49
50
# File 'lib/cell/erb/template.rb', line 48

def tag_options(options, escape = true)
  super(options, true)
end

#template_options_for(options) ⇒ Object



15
16
17
18
19
20
# File 'lib/cell/erb/template.rb', line 15

def template_options_for(options)
  {
    template_class: ::Cell::Erb::Template,
    suffix:         "erb"
  }
end

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



31
32
33
34
35
36
37
# File 'lib/cell/erb/template.rb', line 31

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

  block_buffer
end