Class: Cutaneous::Syntax
- Inherits:
-
Object
- Object
- Cutaneous::Syntax
- Defined in:
- lib/cutaneous/syntax.rb
Instance Attribute Summary collapse
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #compile_start_pattern ⇒ Object
- #compile_start_pattern_with_prefix(prefix) ⇒ Object
- #escaped_tag_pattern ⇒ Object
-
#initialize(tag_definitions) ⇒ Syntax
constructor
A new instance of Syntax.
- #is_dynamic?(text) ⇒ Boolean
- #tag_start_pattern ⇒ Object
-
#token_map ⇒ Object
map the set of tags into a hash used by the parse routine that converts an opening tag into a list of: tag type, the number of opening braces in the tag and the length of the closing tag.
Constructor Details
#initialize(tag_definitions) ⇒ Syntax
Returns a new instance of Syntax.
7 8 9 |
# File 'lib/cutaneous/syntax.rb', line 7 def initialize(tag_definitions) @tags = tag_definitions end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
5 6 7 |
# File 'lib/cutaneous/syntax.rb', line 5 def @tags end |
Instance Method Details
#compile_start_pattern ⇒ Object
23 24 25 26 |
# File 'lib/cutaneous/syntax.rb', line 23 def compile_start_pattern not_escaped = "(?<!\\\\)" compile_start_pattern_with_prefix(not_escaped) end |
#compile_start_pattern_with_prefix(prefix) ⇒ Object
28 29 30 31 |
# File 'lib/cutaneous/syntax.rb', line 28 def compile_start_pattern_with_prefix(prefix) openings = self..map { |type, | Regexp.escape([0]) } Regexp.new("#{prefix}(#{ openings.join("|") })") end |
#escaped_tag_pattern ⇒ Object
19 20 21 |
# File 'lib/cutaneous/syntax.rb', line 19 def escaped_tag_pattern @escaped_tag_pattern ||= compile_start_pattern_with_prefix("\\\\") end |
#is_dynamic?(text) ⇒ Boolean
11 12 13 |
# File 'lib/cutaneous/syntax.rb', line 11 def is_dynamic?(text) !text.index(tag_start_pattern).nil? end |
#tag_start_pattern ⇒ Object
15 16 17 |
# File 'lib/cutaneous/syntax.rb', line 15 def tag_start_pattern @tag_start_pattern ||= compile_start_pattern end |
#token_map ⇒ Object
map the set of tags into a hash used by the parse routine that converts an opening tag into a list of: tag type, the number of opening braces in the tag and the length of the closing tag
35 36 37 |
# File 'lib/cutaneous/syntax.rb', line 35 def token_map @token_map ||= Hash[.map { |type, | [[0], [type, [0].count(?{), [1].length]] }] end |