Class: Slim::LogicLess Private
- 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
- #call(exp) ⇒ Object private
-
#initialize(opts = {}) ⇒ LogicLess
constructor
private
A new instance of LogicLess.
- #on_code(code) ⇒ Object private
- #on_dynamic(code) ⇒ Object private
- #on_slim_attrvalue(escape, value) ⇒ Object private
-
#on_slim_control(name, content) ⇒ Object
private
Interpret control blocks as sections or inverted sections.
- #on_slim_output(escape, name, content) ⇒ Object private
- #on_slim_splat(code) ⇒ Object private
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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/slim/logic_less/filter.rb', line 13 def initialize(opts = {}) super access = [[: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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/slim/logic_less/filter.rb', line 23 def call(exp) if [:logic_less] @context = unique_name [:multi, [:code, "#{@context} = ::Slim::LogicLess::Context.new(#{[: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.
63 64 65 |
# File 'lib/slim/logic_less/filter.rb', line 63 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.
59 60 61 |
# File 'lib/slim/logic_less/filter.rb', line 59 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.
51 52 53 |
# File 'lib/slim/logic_less/filter.rb', line 51 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
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/slim/logic_less/filter.rb', line 35 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.
46 47 48 49 |
# File 'lib/slim/logic_less/filter.rb', line 46 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.
55 56 57 |
# File 'lib/slim/logic_less/filter.rb', line 55 def on_slim_splat(code) [:slim, :splat, access(code)] end |