Module: Tiny::Buffering
- Included in:
- ActionViewAdditions, ErubisTemplating, HamlTemplating, Helpers
- Defined in:
- lib/tiny.rb
Overview
Buffering and capturing support.
Instance Method Summary collapse
-
#append(string) ⇒ String
(also: #text)
Appends sanitized text to the content.
-
#append!(content) ⇒ SafeString
(also: #text!)
Appends non HTML-escaped text to the content.
-
#raw(val) ⇒ SafeString
Returns content that won’t be HTML escaped when appended to content.
-
#with_buffer(*args) {|*args| ... } ⇒ String
Buffers calls to markup generating methods.
Instance Method Details
#append(string) ⇒ String Also known as: text
Appends sanitized text to the content.
html_tag(:p) do
text 'Foo &'
text 'Bar'
end
# => <p>
Foo &
Bar
</p>
181 182 183 184 185 186 187 188 |
# File 'lib/tiny.rb', line 181 def append(string) string = Helpers.sanitize(string) if working_buffer working_buffer << string.gsub(/(?<!^|\n)\z/, "\n") else string end end |
#append!(content) ⇒ SafeString Also known as: text!
Appends non HTML-escaped text to the content.
html_tag(:p) do
append! 'Foo & Bar'
append! '<evil>'
end
# => <p>
Foo & Bar
<evil>
</p>
Shortcut for
append raw(content)
208 209 210 |
# File 'lib/tiny.rb', line 208 def append!(content) append raw(content) end |
#raw(val) ⇒ SafeString
Returns content that won’t be HTML escaped when appended to content.
217 218 219 |
# File 'lib/tiny.rb', line 217 def raw(val) SafeString.new val.to_s end |
#with_buffer(*args) {|*args| ... } ⇒ String
Buffers calls to markup generating methods.
249 250 251 252 253 |
# File 'lib/tiny.rb', line 249 def with_buffer(*args) buffer_stack << '' yield(*args) buffer_stack.pop end |