Class: Slim::Compiler Private
- Defined in:
- lib/slim/compiler.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.
Compiles Slim expressions into Temple::HTML expressions.
Instance Method Summary collapse
-
#on_slim_attrs(*attrs) ⇒ Array
private
Handle tag attributes expression ‘[:slim, :attrs, *attrs]`.
-
#on_slim_comment(content) ⇒ Array
private
Handle comment expression ‘[:slim, :comment, content]`.
-
#on_slim_control(code, content) ⇒ Array
private
Handle control expression ‘[:slim, :control, code, content]`.
-
#on_slim_directive(type, args) ⇒ Array
private
Handle directive expression ‘[:slim, :directive, type, args]`.
-
#on_slim_output(escape, code, content) ⇒ Array
private
Handle output expression ‘[:slim, :output, escape, code, content]`.
-
#on_slim_output_block(escape, code, content) ⇒ Array
private
Handle output expression ‘[:slim, :output, escape, code, content]` if content is not empty.
-
#on_slim_tag(name, attrs, closed, content) ⇒ Array
private
Handle tag expression ‘[:slim, :tag, name, attrs, closed, content]`.
Methods inherited from Filter
Instance Method Details
#on_slim_attrs(*attrs) ⇒ Array
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.
Handle tag attributes expression ‘[:slim, :attrs, *attrs]`
96 97 98 |
# File 'lib/slim/compiler.rb', line 96 def on_slim_attrs(*attrs) [:html, :staticattrs, *attrs.map {|k, v| [k.to_s, compile!(v)] }] end |
#on_slim_comment(content) ⇒ Array
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.
Handle comment expression ‘[:slim, :comment, content]`
22 23 24 |
# File 'lib/slim/compiler.rb', line 22 def on_slim_comment(content) [:html, :comment, compile!(content)] end |
#on_slim_control(code, content) ⇒ Array
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.
Handle control expression ‘[:slim, :control, code, content]`
12 13 14 15 16 |
# File 'lib/slim/compiler.rb', line 12 def on_slim_control(code, content) [:multi, [:block, code], compile!(content)] end |
#on_slim_directive(type, args) ⇒ Array
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.
Handle directive expression ‘[:slim, :directive, type, args]`
76 77 78 79 80 |
# File 'lib/slim/compiler.rb', line 76 def on_slim_directive(type, args) if type == 'doctype' [:html, :doctype, args] end end |
#on_slim_output(escape, code, content) ⇒ Array
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.
Handle output expression ‘[:slim, :output, escape, code, content]`
32 33 34 35 36 37 38 |
# File 'lib/slim/compiler.rb', line 32 def on_slim_output(escape, code, content) if empty_exp?(content) [:multi, escape && [:auto_escape] ? [:escape, :dynamic, code] : [:dynamic, code], content] else on_slim_output_block(escape, code, content) end end |
#on_slim_output_block(escape, code, content) ⇒ Array
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.
Handle output expression ‘[:slim, :output, escape, code, content]` if content is not empty.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/slim/compiler.rb', line 47 def on_slim_output_block(escape, code, content) tmp = tmp_var('capture') [:multi, # Capture the result of the code in a variable. We can't do # `[:dynamic, code]` because it's probably not a complete # expression (which is a requirement for Temple). [:block, "#{tmp} = #{code}"], # Capture the content of a block in a separate buffer. This means # that `yield` will not output the content to the current buffer, # but rather return the output. # # The capturing can be disabled with the option :disable_capture. # Output code in the block writes directly to the output buffer then. # Rails handles this by replacing the output buffer for helpers (with_output_buffer - braindead!). [:disable_capture] ? compile!(content) : [:capture, tmp_var('capture'), compile!(content)], # Close the block. [:block, 'end'], # Output the content. on_slim_output(escape, tmp, [:multi])] end |
#on_slim_tag(name, attrs, closed, content) ⇒ Array
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.
Handle tag expression ‘[:slim, :tag, name, attrs, closed, content]`
88 89 90 |
# File 'lib/slim/compiler.rb', line 88 def on_slim_tag(name, attrs, closed, content) [:html, :tag, name, compile!(attrs), closed, compile!(content)] end |