Class: Slim::Sections Private
- Defined in:
- lib/slim/sections.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 “sections”
Instance Method Summary collapse
- #compile(exp) ⇒ Object private
-
#initialize(opts = {}) ⇒ Sections
constructor
private
A new instance of Sections.
-
#on_slim_control(name, content) ⇒ Object
private
Interpret control blocks as sections or inverted sections.
- #on_slim_inverted_section(name, content) ⇒ Object private
- #on_slim_output(escape, name, content) ⇒ Object private
- #on_slim_section(name, content) ⇒ Object private
Methods inherited from Filter
#on_slim_attrs, #on_slim_comment, #on_slim_tag, #tmp_var
Constructor Details
#initialize(opts = {}) ⇒ Sections
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 Sections.
10 11 12 13 14 15 |
# File 'lib/slim/sections.rb', line 10 def initialize(opts = {}) super unless [:string, :symbol, :wrapped].include?([:dictionary_access]) raise "Invalid dictionary access #{[:dictionary_access].inspect}" end end |
Instance Method Details
#compile(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.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/slim/sections.rb', line 17 def compile(exp) if [:sections] # Store the dictionary in the _slimdict variable dictionary = [:dictionary] dictionary = "Slim::Wrapper.new(#{dictionary})" if [:dictionary_access] == :wrapped [:multi, [:block, "_slimdict = #{dictionary}"], super] else exp end 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
31 32 33 34 35 36 37 |
# File 'lib/slim/sections.rb', line 31 def on_slim_control(name, content) if name =~ /^!\s*(.*)/ on_slim_inverted_section($1, content) else on_slim_section(name, content) end end |
#on_slim_inverted_section(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.
39 40 41 42 43 44 45 46 |
# File 'lib/slim/sections.rb', line 39 def on_slim_inverted_section(name, content) tmp = tmp_var('section') [:multi, [:block, "#{tmp} = #{access name}"], [:block, "if !#{tmp} || #{tmp}.respond_to?(:empty) && #{tmp}.empty?"], compile!(content), [:block, 'end']] 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.
68 69 70 71 |
# File 'lib/slim/sections.rb', line 68 def on_slim_output(escape, name, content) raise 'Output statements with content are forbidden in sections mode' if !empty_exp?(content) [:slim, :output, escape, access(name), content] end |
#on_slim_section(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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/slim/sections.rb', line 48 def on_slim_section(name, content) content = compile!(content) tmp1, tmp2 = tmp_var('dict'), tmp_var('dict') [:multi, [:block, "if #{tmp1} = #{access name}"], [:block, "if #{tmp1} == true"], content, [:block, 'else'], # Wrap map in array because maps implement each [:block, "#{tmp1} = [#{tmp1}] if #{tmp1}.respond_to?(:has_key?) || !#{tmp1}.respond_to?(:map)"], [:block, "#{tmp2} = _slimdict"], [:block, "#{tmp1}.each do |_slimdict|"], content, [:block, 'end'], [:block, "_slimdict = #{tmp2}"], [:block, 'end'], [:block, 'end']] end |