Class: Slim::Parser Private
- Inherits:
-
Temple::Parser
- Object
- Temple::Parser
- Slim::Parser
- Defined in:
- lib/slim/parser.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.
Parses Slim code and transforms it to a Temple expression
Direct Known Subclasses
Defined Under Namespace
Classes: SyntaxError
Instance Method Summary collapse
-
#call(str) ⇒ Array
private
Compile string to Temple expression.
-
#initialize(opts = {}) ⇒ Parser
constructor
private
A new instance of Parser.
Constructor Details
#initialize(opts = {}) ⇒ Parser
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 Parser.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/slim/parser.rb', line 46 def initialize(opts = {}) super @attr_list_delims = [:attr_list_delims] @code_attr_delims = [:code_attr_delims] tabsize = [:tabsize] if tabsize > 1 @tab_re = /\G((?: {#{tabsize}})*) {0,#{tabsize-1}}\t/ @tab = '\1' + ' ' * tabsize else @tab_re = "\t" @tab = ' ' end @tag_shortcut, @attr_shortcut = {}, {} [:shortcut].each do |k,v| raise ArgumentError, 'Shortcut requires :tag and/or :attr' unless (v[:attr] || v[:tag]) && (v.keys - [:attr, :tag]).empty? @tag_shortcut[k] = v[:tag] || [:default_tag] if v.include?(:attr) @attr_shortcut[k] = [v[:attr]].flatten raise ArgumentError, 'You can only use special characters for attribute shortcuts' if k =~ /(\p{Word}|-)/ end end keys = Regexp.union @attr_shortcut.keys.sort_by {|k| -k.size } @attr_shortcut_re = /\A(#{keys}+)((?:\p{Word}|-)*)/ keys = Regexp.union @tag_shortcut.keys.sort_by {|k| -k.size } @tag_re = /\A(?:#{keys}|\*(?=[^\s]+)|(\p{Word}(?:\p{Word}|:|-)*\p{Word}|\p{Word}+))/ keys = Regexp.escape @code_attr_delims.keys.join @code_attr_delims_re = /\A[#{keys}]/ keys = Regexp.escape @attr_list_delims.keys.join @attr_list_delims_re = /\A\s*([#{keys}])/ @embedded_re = /\A(#{Regexp.union(Embedded.engines.keys.map(&:to_s))}):(\s*)/ @attr_name = "\\A\\s*([^\0\"'><\/=\s#{(@attr_list_delims.flatten + @code_attr_delims.flatten).map {|x| Regexp.escape(x) }.join}]+)" @quoted_attr_re = /#{@attr_name}\s*=(=?)\s*("|')/ @code_attr_re = /#{@attr_name}\s*=(=?)\s*/ end |
Instance Method Details
#call(str) ⇒ 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.
Compile string to Temple expression
85 86 87 88 89 90 91 92 93 |
# File 'lib/slim/parser.rb', line 85 def call(str) result = [:multi] reset(str.split(/\r?\n/), [result]) parse_line while next_line reset result end |