class Slim::Embedded
Temple filter which processes embedded engines @api private
Attributes
engines[R]
Public Class Methods
create(name, options)
click to toggle source
# File lib/slim/embedded.rb, line 84 def create(name, options) constructor = engines[name] || raise(Temple::FilterError, "Embedded engine #{name} not found") constructor.call(options) end
new(opts = {})
click to toggle source
Calls superclass method
# File lib/slim/embedded.rb, line 92 def initialize(opts = {}) super @engines = {} @enabled = normalize_engine_list(options[:enable_engines]) @disabled = normalize_engine_list(options[:disable_engines]) end
register(name, klass, *option_filter)
click to toggle source
Register embedded engine
@param [String] name Name of the engine @param [Class] klass Engine class @param option_filter List of options to pass to engine.
Last argument can be default option hash.
# File lib/slim/embedded.rb, line 74 def register(name, klass, *option_filter) name = name.to_sym local_options = option_filter.last.respond_to?(:to_hash) ? option_filter.pop.to_hash : {} define_options(name, *option_filter) klass.define_options(name) engines[name.to_sym] = proc do |options| klass.new({}.update(options).delete_if {|k,v| !option_filter.include?(k) && k != name }.update(local_options)) end end
Public Instance Methods
enabled?(name)
click to toggle source
# File lib/slim/embedded.rb, line 106 def enabled?(name) (!@enabled || @enabled.include?(name)) && (!@disabled || !@disabled.include?(name)) end
on_slim_embedded(name, body)
click to toggle source
# File lib/slim/embedded.rb, line 99 def on_slim_embedded(name, body) name = name.to_sym raise(Temple::FilterError, "Embedded engine #{name} is disabled") unless enabled?(name) @engines[name] ||= self.class.create(name, options) @engines[name].on_slim_embedded(name, body) end
Protected Instance Methods
normalize_engine_list(list)
click to toggle source
# File lib/slim/embedded.rb, line 113 def normalize_engine_list(list) raise(ArgumentError, "Option :enable_engines/:disable_engines must be String or Symbol list") unless !list || Array === list list && list.map(&:to_sym) end