Class: Slim::Embedded Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Temple filter which processes embedded engines

Defined Under Namespace

Classes: ERBEngine, Engine, InterpolateTiltEngine, JavaScriptEngine, PrecompiledTiltEngine, RubyEngine, SassEngine, StaticTiltEngine, TagEngine, TiltEngine

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_control, #on_slim_output, #on_slim_text

Constructor Details

#initialize(opts = {}) ⇒ Embedded

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Embedded.



89
90
91
92
93
94
# File 'lib/slim/embedded.rb', line 89

def initialize(opts = {})
  super
  @engines = {}
  @enabled = normalize_engine_list(options[:enable_engines])
  @disabled = normalize_engine_list(options[:disable_engines])
end

Class Method Details

.create(name, options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



82
83
84
85
# File 'lib/slim/embedded.rb', line 82

def self.create(name, options)
  constructor = @engines[name] || raise(Temple::FilterError, "Embedded engine #{name} not found")
  constructor.call(options)
end

.register(name, klass, *option_filter) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register embedded engine

Parameters:

  • name (String)

    Name of the engine

  • klass (Class)

    Engine class

  • option_filter

    List of options to pass to engine. Last argument can be default option hash.



72
73
74
75
76
77
78
79
80
# File 'lib/slim/embedded.rb', line 72

def self.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

Instance Method Details

#enabled?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/slim/embedded.rb', line 103

def enabled?(name)
  (!@enabled || @enabled.include?(name)) &&
    (!@disabled || !@disabled.include?(name))
end

#on_slim_embedded(name, body) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (Temple::FilterError)


96
97
98
99
100
101
# File 'lib/slim/embedded.rb', line 96

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