Module: HtmlSlice
- Defined in:
- lib/html_slice.rb,
lib/html_slice/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- TAGS =
%i[ div title embed meta br a em b i ul ol li img table tbody thead tr th td form input button link h1 h2 h3 h4 h5 h6 hr span label iframe template main footer aside source section small nav area ].freeze
- EMPTY_TAGS =
%i[ area br embed hr img input link meta source ].freeze
- TAGS_WITHOUT_HTML_ESCAPE =
%i[ style script ].freeze
- DEFAULT_SLICE =
:default- ATTRIBUTE_CACHE =
{}
- VERSION =
"0.2.5"
Class Method Summary collapse
- .layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
- .slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) ⇒ Object
Instance Method Summary collapse
- #_(text) ⇒ Object
- #html_layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
- #html_slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) ⇒ Object
- #tag(tag_name, *args, &block) ⇒ Object
Class Method Details
.layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
31 32 33 34 |
# File 'lib/html_slice.rb', line 31 def self.layout(slice_id = DEFAULT_SLICE, &block) @class ||= Class.new { include HtmlSlice }.new @class.html_layout(slice_id, &block) end |
.slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) ⇒ Object
26 27 28 29 |
# File 'lib/html_slice.rb', line 26 def self.slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) @class ||= Class.new { include HtmlSlice }.new @class.html_slice(slice_id, wrap: wrap, &block) end |
Instance Method Details
#_(text) ⇒ Object
76 77 78 |
# File 'lib/html_slice.rb', line 76 def _(text) @html_slice[@html_slice_current_id] << text.to_s end |
#html_layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
36 37 38 |
# File 'lib/html_slice.rb', line 36 def html_layout(slice_id = DEFAULT_SLICE, &block) html_slice(slice_id, wrap: ["<!DOCTYPE html><html>", "</html>"], &block) end |
#html_slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/html_slice.rb', line 40 def html_slice(slice_id = DEFAULT_SLICE, wrap: ["", ""], &block) @html_slice_current_id = slice_id @html_slice ||= {} if block_given? buffer = +"" buffer << wrap[0] @html_slice[slice_id] = buffer instance_eval(&block) buffer << wrap[1] end @html_slice[slice_id].to_s end |
#tag(tag_name, *args, &block) ⇒ Object
71 72 73 74 |
# File 'lib/html_slice.rb', line 71 def tag(tag_name, *args, &block) content, attrs = parse_args(args, escape: true) render_tag(tag_name.to_s, tag_name, content, attrs, &block) end |