Class: Sinatra::ContentFor2::SlimHandler

Inherits:
BaseHandler show all
Defined in:
lib/sinatra/content_for2/slim_handler.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHandler

#template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

classes, register

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_bufferObject

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_slimObject



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.set_default_options(:buffer => '@_out_buf', :generator => Temple::Generators::StringBuffer)
    @slim_set = true
  end
end

Instance Method Details

#block_is_type?(block) ⇒ Boolean

Returns:

  • (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

#enginesObject



36
37
38
# File 'lib/sinatra/content_for2/slim_handler.rb', line 36

def engines
  @engines ||= [ :slim ]
end

#is_type?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sinatra/content_for2/slim_handler.rb', line 20

def is_type?
  ! self.output_buffer.nil?
end