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.1.0"

Instance Method Summary collapse

Instance Method Details

#capture(*args) {|args| ... } ⇒ Object

Yields:

  • (args)

13
14
15
# File 'lib/cell/erb/template.rb', line 13

def capture(*args)
  yield(*args)
end

#concat(string) ⇒ Object


39
40
41
42
# File 'lib/cell/erb/template.rb', line 39

def concat(string)
  raise "[Cells-ERB] The #concat helper uses global state and is not supported anymore.
Please change your code to simple `+` String concatenation or tell the gem authors to remove #concat usage."
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.


20
21
22
# File 'lib/cell/erb/template.rb', line 20

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

#form_tag_html(html_options) ⇒ Object


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

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


30
31
32
# File 'lib/cell/erb/template.rb', line 30

def form_tag_with_body(html_options, content)
  "#{form_tag_html(html_options)}" << content.to_s << "</form>"
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).


26
27
28
# File 'lib/cell/erb/template.rb', line 26

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

#template_options_for(options) ⇒ Object


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

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