Class: Slim::Interpolation Private
- Defined in:
- lib/slim/interpolation.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.
Perform interpolation of #var_name
Instance Method Summary collapse
-
#on_slim_text(string) ⇒ Array
private
Handle text expression ‘[:slim, :text, string]`.
- #parse_expression(string) ⇒ Object private
Methods inherited from Filter
#on_slim_attrs, #on_slim_comment, #on_slim_control, #on_slim_output, #on_slim_tag, #tmp_var
Instance Method Details
#on_slim_text(string) ⇒ 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 text expression ‘[:slim, :text, string]`
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/slim/interpolation.rb', line 9 def on_slim_text(string) # Interpolate variables in text (#{variable}). # Split the text into multiple dynamic and static parts. block = [:multi] until string.empty? case string when /^\\#\{/ # Escaped interpolation block << [:static, '#{'] string = $' when /^#\{/ # Interpolation string, code = parse_expression($') escape = code !~ /^\{.*\}$/ block << [:slim, :output, escape, escape ? code : code[1..-2], [:multi]] when /^([^#]+|#)/ # Static text block << [:static, $&] string = $' end end block end |
#parse_expression(string) ⇒ 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/slim/interpolation.rb', line 33 def parse_expression(string) stack, code = [], '' until string.empty? if stack.empty? && string =~ /^\}/ # Stack is empty, this means we are finished # if the next character is a closing bracket string.slice!(0) break elsif string =~ Parser::DELIMITER_REGEX # Delimiter found, push it on the stack stack << Parser::DELIMITERS[$&] code << string.slice!(0) elsif string =~ Parser::CLOSE_DELIMITER_REGEX # Closing delimiter found, pop it from the stack if everything is ok raise "Text interpolation: Unexpected closing #{$&}" if stack.empty? raise "Text interpolation: Expected closing #{stack.last}" if stack.last != $& code << string.slice!(0) stack.pop else code << string.slice!(0) end end return string, code end |