Class: Sinatra::ContentFor2::SlimHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Sinatra::ContentFor2::SlimHandler
- Defined in:
- lib/sinatra/content_for2/slim_handler.rb
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
readonly
Returns the value of attribute output_buffer.
Attributes inherited from BaseHandler
Class Method Summary collapse
Instance Method Summary collapse
- #block_is_type?(block) ⇒ Boolean
- #capture_from_template(*args, &block) ⇒ Object
- #engines ⇒ Object
-
#initialize(template) ⇒ SlimHandler
constructor
A new instance of SlimHandler.
- #is_type? ⇒ Boolean
Methods inherited from BaseHandler
Constructor Details
#initialize(template) ⇒ SlimHandler
Returns a new instance of SlimHandler.
14 15 16 17 18 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 14 def initialize(template) super self.class.setup_slim @output_buffer = template.instance_variable_get(:@_out_buf) end |
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
12 13 14 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 12 def output_buffer @output_buffer end |
Class Method Details
.setup_slim ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 3 def setup_slim return if @slim_set if defined?(Slim) Slim::Engine.(:buffer => '@_out_buf', :generator => Temple::Generators::StringBuffer) @slim_set = true end end |
Instance Method Details
#block_is_type?(block) ⇒ Boolean
32 33 34 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 32 def block_is_type?(block) is_type? || (block && eval('defined? __in_erb_template', block.binding)) end |
#capture_from_template(*args, &block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 24 def capture_from_template(*args, &block) self.output_buffer, _buf_was = "", self.output_buffer block.call(*args) ret = eval("@_out_buf", block.binding) self.output_buffer = _buf_was ret end |
#engines ⇒ Object
36 37 38 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 36 def engines @engines ||= [ :slim ] end |
#is_type? ⇒ Boolean
20 21 22 |
# File 'lib/sinatra/content_for2/slim_handler.rb', line 20 def is_type? ! self.output_buffer.nil? end |