Class: Tony::Slim

Inherits:
Object
  • Object
show all
Defined in:
lib/tony/slim.rb

Defined Under Namespace

Classes: Env

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(views: 'views', layout: nil, partials: 'views/partials', options: {}) ⇒ Slim

Returns a new instance of Slim.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tony/slim.rb', line 7

def initialize(views: 'views',
               layout: nil,
               partials: 'views/partials',
               options: {})
  @views = views
  @partials = partials
  @options = options
  @layout = if layout
              ::Slim::Template.new("#{layout}.slim", @options)
            else
              ::Slim::Template.new(@options) { '==yield' }
            end
end

Instance Attribute Details

#layoutObject

Returns the value of attribute layout.



5
6
7
# File 'lib/tony/slim.rb', line 5

def layout
  @layout
end

#viewsObject

Returns the value of attribute views.



5
6
7
# File 'lib/tony/slim.rb', line 5

def views
  @views
end

Instance Method Details

#render(file, **locals) ⇒ Object



21
22
23
24
25
26
# File 'lib/tony/slim.rb', line 21

def render(file, **locals)
  file = File.join(@views, "#{file}.slim")
  env = Env.new(partials: @partials, options: @options, **locals)
  view = ::Slim::Template.new(file, @options).render(env)
  return @layout.render(env) { view }
end