Class: Tony::Slim
- Inherits:
-
Object
- Object
- Tony::Slim
- Defined in:
- lib/tony/slim.rb
Defined Under Namespace
Classes: Env
Instance Attribute Summary collapse
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
-
#initialize(views: 'views', layout: nil, partials: 'views/partials', options: {}) ⇒ Slim
constructor
A new instance of Slim.
- #render(file, **locals) ⇒ Object
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 = @layout = if layout ::Slim::Template.new("#{layout}.slim", @options) else ::Slim::Template.new(@options) { '==yield' } end end |
Instance Attribute Details
#layout ⇒ Object
Returns the value of attribute layout.
5 6 7 |
# File 'lib/tony/slim.rb', line 5 def layout @layout end |
#views ⇒ Object
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 |