Class: Slim::LogicLess Private

Inherits:
Filter
  • Object
show all
Defined in:
lib/slim/logic_less/filter.rb,
lib/slim/logic_less/context.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.

Handle logic less mode This filter can be activated with the option "logic_less"

Defined Under Namespace

Classes: Context

Constant Summary collapse

DEFAULT_ACCESS_ORDER =

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

Default dictionary access order, change it with the option :dictionary_access

[:symbol, :string, :method, :instance_variable].freeze

Instance Method Summary collapse

Methods inherited from Filter

#on_slim_embedded, #on_slim_text

Constructor Details

#initialize(opts = {}) ⇒ LogicLess

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 LogicLess.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/slim/logic_less/filter.rb', line 14

def initialize(opts = {})
  super
  access = [options[:dictionary_access]].flatten.compact
  access.each do |type|
    raise ArgumentError, "Invalid dictionary access #{type.inspect}" unless DEFAULT_ACCESS_ORDER.include?(type)
  end
  raise ArgumentError, 'Option dictionary access is missing' if access.empty?
  @access = access.inspect
end

Instance Method Details

#call(exp) ⇒ 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.



24
25
26
27
28
29
30
31
32
33
# File 'lib/slim/logic_less/filter.rb', line 24

def call(exp)
  if options[:logic_less]
    @context = unique_name
    [:multi,
     [:code, "#{@context} = ::Slim::LogicLess::Context.new(#{options[:dictionary]}, #{@access})"],
     super]
  else
    exp
  end
end

#on_code(code) ⇒ 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)


64
65
66
# File 'lib/slim/logic_less/filter.rb', line 64

def on_code(code)
  raise Temple::FilterError, 'Embedded code is forbidden in logic less mode'
end

#on_dynamic(code) ⇒ 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)


60
61
62
# File 'lib/slim/logic_less/filter.rb', line 60

def on_dynamic(code)
  raise Temple::FilterError, 'Embedded code is forbidden in logic less mode'
end

#on_slim_attrvalue(escape, value) ⇒ 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.



52
53
54
# File 'lib/slim/logic_less/filter.rb', line 52

def on_slim_attrvalue(escape, value)
  [:slim, :attrvalue, escape, access(value)]
end

#on_slim_control(name, content) ⇒ 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.

Interpret control blocks as sections or inverted sections



36
37
38
39
40
41
42
43
44
45
# File 'lib/slim/logic_less/filter.rb', line 36

def on_slim_control(name, content)
  method =
    if name =~ /\A!\s*(.*)/
      name = $1
      'inverted_section'
    else
      'section'
    end
  [:block, "#{@context}.#{method}(#{name.to_sym.inspect}) do", compile(content)]
end

#on_slim_output(escape, name, content) ⇒ 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.



47
48
49
50
# File 'lib/slim/logic_less/filter.rb', line 47

def on_slim_output(escape, name, content)
  [:slim, :output, escape, empty_exp?(content) ? access(name) :
   "#{@context}.lambda(#{name.to_sym.inspect}) do", compile(content)]
end

#on_slim_splat(code) ⇒ 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.



56
57
58
# File 'lib/slim/logic_less/filter.rb', line 56

def on_slim_splat(code)
  [:slim, :splat, access(code)]
end