Class: Tony::Slim::Env
- Inherits:
-
Object
- Object
- Tony::Slim::Env
- Includes:
- AssetTagHelper, ContentFor, Tony::ScriptHelper
- Defined in:
- lib/tony/slim.rb
Instance Method Summary collapse
-
#initialize(partials:, options:, **locals) ⇒ Env
constructor
A new instance of Env.
- #method_missing(method, *args, &block) ⇒ Object
- #partial(file, **locals, &block) ⇒ Object
- #respond_to_missing?(method, include_all) ⇒ Boolean
Methods included from ContentFor
Methods included from Tony::ScriptHelper
Methods included from AssetTagHelper
#favicon_link_tag, #font_awesome, #google_fonts, #image_tag, #javascript_include_tag, #preconnect_link_tag, #stylesheet_link_tag
Constructor Details
#initialize(partials:, options:, **locals) ⇒ Env
Returns a new instance of Env.
33 34 35 36 37 |
# File 'lib/tony/slim.rb', line 33 def initialize(partials:, options:, **locals) @partials = partials @options = @locals = locals end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
47 48 49 |
# File 'lib/tony/slim.rb', line 47 def method_missing(method, *args, &block) return @locals.key?(method) ? @locals.fetch(method) : super end |
Instance Method Details
#partial(file, **locals, &block) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/tony/slim.rb', line 39 def partial(file, **locals, &block) file = File.join(@partials, "#{file}.slim") env = Env.new(partials: @partials, options: @options, **@locals.merge(locals)) return ::Slim::Template.new(file, @options).render(env, &block) end |
#respond_to_missing?(method, include_all) ⇒ Boolean
51 52 53 |
# File 'lib/tony/slim.rb', line 51 def respond_to_missing?(method, include_all) return @locals.key?(method) || super end |