Module: HtmlSlice
- Defined in:
- lib/html_slice.rb,
lib/html_slice/rails.rb,
lib/html_slice/version.rb
Defined Under Namespace
Modules: Rails
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 strong
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.6"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
32
33
34
35
|
# File 'lib/html_slice.rb', line 32
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
27
28
29
30
|
# File 'lib/html_slice.rb', line 27
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
77
78
79
|
# File 'lib/html_slice.rb', line 77
def _(text)
@html_slice[@html_slice_current_id] << text.to_s
end
|
#html_layout(slice_id = DEFAULT_SLICE, &block) ⇒ Object
37
38
39
|
# File 'lib/html_slice.rb', line 37
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/html_slice.rb', line 41
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
72
73
74
75
|
# File 'lib/html_slice.rb', line 72
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
|