Module: Tiny::Markup
- Included in:
- ActionViewAdditions, ErubisTemplating, HamlTemplating, Helpers
- Defined in:
- lib/tiny.rb
Overview
Provides basic markup generation support.
Instance Method Summary collapse
-
#cdata(content) ⇒ String
Appends a CDATA section to the content.
-
#comment(content) ⇒ SafeString
Appends an HTML coment to the content.
-
#doctype ⇒ String
Appends the doctype to the content.
-
#html_tag(name, attrs_or_content = {}, attrs = nil) { ... } ⇒ String
Generates an HTML tag or structured HTML markup.
Instance Method Details
#cdata(content) ⇒ String
Appends a CDATA section to the content.
div do
cdata 'foo'
end
# => <div>
<![CDATA[foo]]>
</div>
141 142 143 144 |
# File 'lib/tiny.rb', line 141 def cdata(content) content = content.to_s.gsub(']]>', ']]]]><![CDATA[>') append! "<![CDATA[#{content}]]>" end |
#comment(content) ⇒ SafeString
Appends an HTML coment to the content.
div do
comment 'foo'
end
# => <div>
<!-- foo -->
</div>
126 127 128 |
# File 'lib/tiny.rb', line 126 def comment(content) append! "<!-- #{content.to_s.gsub(/-(?=-)/, '- ')} -->" end |
#doctype ⇒ String
Appends the doctype to the content
with_buffer do
doctype
html_tag(:html) do
...
end
end
# => <!DOCTYPE html>
<html>
...
</html>
161 162 163 |
# File 'lib/tiny.rb', line 161 def doctype append! "<!DOCTYPE html>" end |
#html_tag(name, attrs_or_content = {}, attrs = nil) { ... } ⇒ String
Generates an HTML tag or structured HTML markup
This method is the basis for defining html helper functions or constructing html markup using pure ruby.
HTML attributes are HTML-escaped and tags are explicitly or self closed depeding on the tag name.
Calls to markup generating methods within the content block are appended to the tag’s content. See Tiny::Markup and HTML.
Content blocks originating from HAML or ERB templates are correctly captured and handled.
111 112 113 |
# File 'lib/tiny.rb', line 111 def html_tag(name, attrs_or_content = {}, attrs = nil, &block) append! Tag.new(name, attrs_or_content, attrs).render(&block) end |