liquidice 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a391144863c9ca02f6d171de7480c298f530bba3373b926d7ef73e1c083d0eaa
4
- data.tar.gz: b9fa907d2a02fb8e8813aef8188bddf18822eca3d48d88c72770ede08d3f0789
3
+ metadata.gz: 5b8faf5af8b04a7370da5a1afe4327a57548012ea631b18b9d28b32c1631f7bc
4
+ data.tar.gz: 02e4ac0e1219bc3dd3f6832725d025240c66f342bcdf88189ffeb99a0f0bf509
5
5
  SHA512:
6
- metadata.gz: 6990461ad59956cadd62c96de954d745b0ac29a6eb1d3ccb1608e08bf83880c514ca4110dcd93e3c2be14303bd02ee1b4da8823344f8b41f95917ca6ef112a43
7
- data.tar.gz: deef2278f2598f919f093d2cd4222101c551782ea56d558fb83cdefed2ebd68cf3c5a0b27ebcc93ec82e7df9f499941f1b03178cf5d403b7bb544f6ef0aefc44
6
+ metadata.gz: 467417a9b25008e2110d992f62a5230e4372b2fbf5957f38cdffe23fb3ecb562948a203f56e69996997b66f993e31f44aeafb3d4b2a76a09dbe9428cbd144edf
7
+ data.tar.gz: '0856b522b5bd6356b25d052251ab915d4a4c090a81422a2e13014e48a402cba770f8b7542088123c491b913275202c0958efcf1e5288130ad79a20f05342c78f'
@@ -1,5 +1,7 @@
1
1
  module Liquidice
2
2
  module Errors
3
- class InvalidWysiwygTemplate < StandardError; end
3
+ class Base < StandardError; end
4
+ class InvalidSyntax < Base; end
5
+ class TransformerValidationError < Base; end
4
6
  end
5
7
  end
@@ -1,96 +1,76 @@
1
- # Liquidice grammar
2
-
3
1
  grammar LiquidiceGrammar
4
2
  rule liquid_template
5
- (liquid_tag / liquid_text)*
3
+ (liquid_template_interpolation / content_with_tags)+ <Liquidice::TreetopNodes::LiquidTemplate>
6
4
  end
7
5
 
8
- rule liquid_tag
9
- liquid_open_delimeter content_with_tags liquid_close_delimeter
6
+ rule liquid_template_interpolation
7
+ liquid_open_delimeter content_with_tags liquid_close_delimeter <Liquidice::TreetopNodes::LiquidTemplateInterpolation>
10
8
  end
11
9
 
12
10
  rule liquid_open_delimeter
13
- liquid_open_delimeter_start any_tag* (liquid_open_delimeter_start / "%")
11
+ liquid_open_delimeter_start html_tag* (liquid_open_delimeter_start / '%') <Liquidice::TreetopNodes::LiquidOpenDelimiter>
14
12
  end
15
13
 
16
14
  rule liquid_close_delimeter
17
- (liquid_close_delimeter_end / "%") any_tag* liquid_close_delimeter_end
15
+ (liquid_close_delimeter_end / '%') html_tag* liquid_close_delimeter_end <Liquidice::TreetopNodes::LiquidCloseDelimiter>
18
16
  end
19
17
 
20
18
  rule liquid_open_delimeter_start
21
- "{"
19
+ '{'
22
20
  end
23
21
 
24
22
  rule liquid_close_delimeter_end
25
- "}"
23
+ '}'
26
24
  end
27
25
 
28
26
  rule content_with_tags
29
- (any_tag / text_content)*
27
+ (html_tag / text_content)+
30
28
  end
31
29
 
32
30
  rule text_content
33
- (alphabets / digits / dash / ws)*
31
+ [^<{%\/}>]+
34
32
  end
35
33
 
36
- rule any_tag
37
- (tag_open / tag_empty / tag_close)
34
+ rule html_tag
35
+ # TODO: we need to add spaces here because of the way treetop works
36
+ (tag_open / tag_empty / tag_close / spaces)
38
37
  end
39
38
 
40
39
  rule tag_open
41
- "<" tag_name ws* attr_list? ws* ">"
40
+ '<' tag_name spaces* attr_list? '>' <Liquidice::TreetopNodes::HtmlTag>
42
41
  end
43
42
 
44
43
  rule tag_empty
45
- "<" tag_name ws* attr_list? ws* "/>"
44
+ '<' tag_name spaces* attr_list? '/>' <Liquidice::TreetopNodes::HtmlTag>
46
45
  end
47
46
 
48
47
  rule tag_close
49
- "</" tag_name ws* ">"
50
- end
51
-
52
- rule attr_list
53
- (ws+ attr)*
54
- end
55
-
56
- rule attr
57
- attr_empty / attr_unquoted / attr_single_quoted / attr_double_quoted
58
- end
59
-
60
- rule attr_empty
61
- attr_name
62
- end
63
-
64
- rule attr_unquoted
65
- attr_name ws* "=" ws* attr_unquoted_value
66
- end
67
-
68
- rule attr_single_quoted
69
- attr_name ws* "=" ws* "'" attr_single_quoted_value "'"
70
- end
71
-
72
- rule attr_double_quoted
73
- attr_name ws* "=" ws* "\"" attr_double_quoted_value "\""
48
+ '</' spaces* tag_name '>' <Liquidice::TreetopNodes::HtmlTag>
74
49
  end
75
50
 
76
51
  rule tag_name
77
52
  (alphabets / digits / dash)+
78
53
  end
79
54
 
80
- rule attr_name
81
-
82
- rule attr_unquoted_value
83
-
84
- rule attr_single_quoted_value
55
+ rule attr_list
56
+ (spaces / attr)+
57
+ end
85
58
 
86
- rule attr_double_quoted_value
59
+ # TODO: add deeper nesting to attr rule
60
+ rule attr
61
+ [^<{%}>]+
62
+ end
87
63
 
88
64
  rule alphabets
65
+ [a-zA-Z]
66
+ end
89
67
 
90
68
  rule digits
69
+ [0-9]
70
+ end
91
71
 
92
- rule ws
93
- /\s/
72
+ rule spaces
73
+ [ \s\t\r\n]+
94
74
  end
95
75
 
96
76
  rule dash
@@ -1,33 +1,31 @@
1
- require 'treetop'
2
-
3
1
  module Liquidice
4
2
  class Parser
5
3
  Treetop.load(File.expand_path(File.join(File.dirname(__FILE__), 'liquidice_grammar.treetop')))
6
4
 
7
- attr_accessor :strict_mode, :parser, :ast
5
+ attr_accessor :strict_mode, :parser, :ast, :transformed_ast, :transformer
8
6
 
9
7
  def initialize(strict_mode: false)
10
8
  @strict_mode = strict_mode
11
9
  @parser = LiquidiceGrammarParser.new
10
+ @transformer = Liquidice::Transformer::Transformer.new
12
11
  end
13
12
 
14
- def parse_from_wysiwyg(wysiwyg_template)
13
+ def parse(wysiwyg_template)
15
14
  @ast = parser.parse(wysiwyg_template)
16
15
 
17
- raise Liquidice::Errors::InvalidWysiwygTemplate, parser.failure_reason if @ast.nil?
16
+ raise Liquidice::Errors::InvalidSyntax, parser.failure_reason if @ast.nil? && strict_mode
18
17
 
19
18
  @ast
20
19
  end
21
20
 
22
- def transform_to_liquid(ast)
23
- # Transform the AST to a valid Liquid template
24
- transformer = Transformer.new
25
- transformer.apply(ast)
21
+ def transformer_tree
22
+ @transformer_tree ||= transformer.apply(ast)
26
23
  end
27
24
 
28
25
  def parse_and_transform(wysiwyg_template)
29
- ast = parse_from_wysiwyg(wysiwyg_template)
30
- transform_to_liquid(ast)
26
+ parse(wysiwyg_template)
27
+ transformer_tree.transform!
28
+ transformer_tree.to_s
31
29
  end
32
30
  end
33
31
  end
@@ -0,0 +1,57 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class Base
5
+ attr_reader :original_text, :children, :options
6
+
7
+ def initialize(original_text:, children: [], options: {})
8
+ @original_text, @children, @options = original_text, children, options
9
+
10
+ validate!
11
+ end
12
+
13
+ def to_s
14
+ raise NotImplementedError
15
+ end
16
+
17
+ def strict_mode?
18
+ false
19
+ end
20
+
21
+ def transform!
22
+ # do nothing
23
+ end
24
+
25
+ def validate!
26
+ # do nothing
27
+ end
28
+
29
+ def can_be_merged?(other)
30
+ false
31
+ end
32
+
33
+ @@dot_id_counter = 0
34
+
35
+ def dot_id
36
+ @dot_id ||= @@dot_id_counter += 1
37
+ end
38
+
39
+ def write_dot(io)
40
+ io.puts "node#{dot_id} [label=\"'#{original_text}'\"];"
41
+ children.each do |child|
42
+ io.puts "node#{dot_id} -> node#{child.dot_id};"
43
+ child.write_dot(io)
44
+ end
45
+ end
46
+
47
+ def write_dot_file(fname)
48
+ File.open(fname + ".dot","w") do |file|
49
+ file.puts "digraph G {"
50
+ write_dot(file)
51
+ file.puts "}"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class HtmlTag < ::Liquidice::Transformer::Nodes::Base
5
+ TAG_TYPES = [
6
+ OPENING_TYPE = :opening,
7
+ CLOSING_TYPE = :closing,
8
+ EMPTY_TYPE = :empty
9
+ ].freeze
10
+
11
+ def opening?
12
+ type == OPENING_TYPE
13
+ end
14
+
15
+ def closing?
16
+ type == CLOSING_TYPE
17
+ end
18
+
19
+ def empty?
20
+ type == EMPTY_TYPE
21
+ end
22
+
23
+ def type
24
+ @type ||= options[:type]
25
+ end
26
+
27
+ def validate!
28
+ raise(Liquidice::Errors::TransformerValidationError, "Missing :type option") unless options.has_key?(:type)
29
+ raise(Liquidice::Errors::TransformerValidationError, "Children must be empty, it always must be a leaf node") unless children.empty?
30
+ end
31
+
32
+ def text_value
33
+ @original_text
34
+ end
35
+
36
+ def to_s
37
+ @original_text
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class LiquidInterpolationPart < ::Liquidice::Transformer::Nodes::Base
5
+ TYPES = [
6
+ OPEN_DELIMITER_TYPE = :open_delimiter,
7
+ CLOSE_DELIMITER_TYPE = :close_delimiter,
8
+ INTERPOLATION_CONTENT_TYPE = :interpolation_content
9
+ ].freeze
10
+
11
+ def validate!
12
+ raise(Liquidice::Errors::TransformerValidationError, "Children must be empty, it always must be a leaf node") unless children.empty?
13
+ end
14
+
15
+ def open_delimiter?
16
+ type == OPEN_DELIMITER_TYPE
17
+ end
18
+
19
+ def close_delimiter?
20
+ type == CLOSE_DELIMITER_TYPE
21
+ end
22
+
23
+ def interpolation_content?
24
+ type == INTERPOLATION_CONTENT_TYPE
25
+ end
26
+
27
+ def type
28
+ @type ||= options[:type]
29
+ end
30
+
31
+ def merge(other)
32
+ @original_text += other.original_text
33
+ end
34
+
35
+ def can_be_merged?(other)
36
+ other.is_a?(::Liquidice::Transformer::Nodes::LiquidInterpolationPart) && type == other.type
37
+ end
38
+
39
+ def text_value
40
+ @original_text
41
+ end
42
+
43
+ def to_s
44
+ @original_text
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,39 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class LiquidTemplateInterpolation < ::Liquidice::Transformer::Nodes::Base
5
+ def transform!
6
+ head, tail, middle = [], [], []
7
+
8
+ current_interpolation_part_context = ::Liquidice::Transformer::Nodes::LiquidInterpolationPart::OPEN_DELIMITER_TYPE
9
+ children.each do |child|
10
+ if child.is_a?(::Liquidice::Transformer::Nodes::LiquidInterpolationPart)
11
+ middle << child
12
+ current_interpolation_part_context = child.type
13
+ elsif child.is_a?(::Liquidice::Transformer::Nodes::HtmlTag)
14
+ if current_interpolation_part_context == ::Liquidice::Transformer::Nodes::LiquidInterpolationPart::OPEN_DELIMITER_TYPE
15
+ head << child
16
+ elsif current_interpolation_part_context == ::Liquidice::Transformer::Nodes::LiquidInterpolationPart::INTERPOLATION_CONTENT_TYPE
17
+ child.opening? ? head << child : tail << child
18
+ elsif current_interpolation_part_context == ::Liquidice::Transformer::Nodes::LiquidInterpolationPart::CLOSE_DELIMITER_TYPE
19
+ tail << child
20
+ else
21
+ raise "Unknown interpolation part context: #{current_interpolation_part_context}"
22
+ end
23
+ end
24
+ end
25
+
26
+ @children = head + middle + tail
27
+ end
28
+
29
+ def validate!
30
+ raise(Liquidice::Errors::TransformerValidationError, "Children must be present") if children.empty?
31
+ end
32
+
33
+ def to_s
34
+ children.map(&:to_s).join
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class RootNode < ::Liquidice::Transformer::Nodes::Base
5
+ def transform!
6
+ children.map(&:transform!)
7
+ end
8
+
9
+ def to_s
10
+ children.map(&:to_s).join("")
11
+ end
12
+
13
+ def validate!
14
+ raise(Liquidice::Errors::TransformerValidationError, "Children must be present") if children.empty?
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ module Liquidice
2
+ module Transformer
3
+ module Nodes
4
+ class TextContent < ::Liquidice::Transformer::Nodes::Base
5
+ def validate!
6
+ raise(Liquidice::Errors::TransformerValidationError, "Children must be empty, it always must be a leaf node") unless children.empty?
7
+ end
8
+
9
+ def merge(other)
10
+ @original_text += other.original_text
11
+ end
12
+
13
+ def text_value
14
+ @original_text
15
+ end
16
+
17
+ def can_be_merged?(other)
18
+ other.is_a?(::Liquidice::Transformer::Nodes::TextContent)
19
+ end
20
+
21
+ def to_s
22
+ @original_text
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,105 @@
1
+ module Liquidice
2
+ module Transformer
3
+ class Transformer
4
+ def apply(node)
5
+ case node
6
+ when Liquidice::TreetopNodes::LiquidTemplate
7
+ transform_liquid_template(node)
8
+ when Liquidice::TreetopNodes::LiquidTemplateInterpolation
9
+ transform_liquid_template_interpolation(node)
10
+ else
11
+ transform_text_content_node(node)
12
+ end
13
+ end
14
+
15
+ def transform_liquid_template(node)
16
+ ::Liquidice::Transformer::Nodes::RootNode.new(
17
+ original_text: node.text_value,
18
+ children: node.elements.flat_map { |element| apply(element) }
19
+ )
20
+ end
21
+
22
+ def transform_liquid_template_interpolation(node)
23
+ ::Liquidice::Transformer::Nodes::LiquidTemplateInterpolation.new(
24
+ original_text: node.text_value,
25
+ children: merge_nodes_if_possible(
26
+ node.elements.flat_map do |element|
27
+ transform_liquid_template_interpolation_apply(element)
28
+ end
29
+ )
30
+ )
31
+ end
32
+
33
+ def merge_nodes_if_possible(nodes)
34
+ Array(nodes).reduce([]) do |result, node|
35
+ if node.can_be_merged?(result.last)
36
+ result.last.merge(node)
37
+ else
38
+ result << node
39
+ end
40
+ result
41
+ end
42
+ end
43
+
44
+ def transform_liquid_template_interpolation_apply(node)
45
+ if node.is_a?(Liquidice::TreetopNodes::HtmlTag)
46
+ transform_html_tag(node)
47
+ elsif node.elements.nil? || node.elements.empty?
48
+ ::Liquidice::Transformer::Nodes::LiquidInterpolationPart.new(
49
+ original_text: node.text_value,
50
+ options: {
51
+ type: detect_liquid_interpolation_part_type(node)
52
+ }
53
+ )
54
+ else
55
+ merge_nodes_if_possible(
56
+ node.elements.flat_map do |element|
57
+ transform_liquid_template_interpolation_apply(element)
58
+ end
59
+ )
60
+ end
61
+ end
62
+
63
+ def detect_liquid_interpolation_part_type(node)
64
+ if node.has_ascendant?(type: Liquidice::TreetopNodes::LiquidOpenDelimiter, stop_node_type: Liquidice::TreetopNodes::LiquidTemplateInterpolation)
65
+ Liquidice::Transformer::Nodes::LiquidInterpolationPart::OPEN_DELIMITER_TYPE
66
+ elsif node.has_ascendant?(type: Liquidice::TreetopNodes::LiquidCloseDelimiter, stop_node_type: Liquidice::TreetopNodes::LiquidTemplateInterpolation)
67
+ Liquidice::Transformer::Nodes::LiquidInterpolationPart::CLOSE_DELIMITER_TYPE
68
+ else
69
+ Liquidice::Transformer::Nodes::LiquidInterpolationPart::INTERPOLATION_CONTENT_TYPE
70
+ end
71
+ end
72
+
73
+ def transform_html_tag(node)
74
+ transformer_tag_type = if node.text_value.start_with?('</')
75
+ ::Liquidice::Transformer::Nodes::HtmlTag::CLOSING_TYPE
76
+ elsif node.text_value.end_with?('/>')
77
+ ::Liquidice::Transformer::Nodes::HtmlTag::EMPTY_TYPE
78
+ else
79
+ ::Liquidice::Transformer::Nodes::HtmlTag::OPENING_TYPE
80
+ end
81
+
82
+ ::Liquidice::Transformer::Nodes::HtmlTag.new(
83
+ original_text: node.text_value,
84
+ options: {
85
+ type: transformer_tag_type,
86
+ }
87
+ )
88
+ end
89
+
90
+ def transform_text_content_node(node)
91
+ if node.elements.nil? || node.elements.empty?
92
+ ::Liquidice::Transformer::Nodes::TextContent.new(original_text: node.text_value)
93
+ else
94
+ merge_nodes_if_possible(
95
+ node.elements.flat_map { |element| apply(element) }
96
+ )
97
+ end
98
+ end
99
+
100
+ def transform_text_content(node)
101
+ node.text_value
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class Base < ::Treetop::Runtime::SyntaxNode
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class HtmlTag < ::Liquidice::TreetopNodes::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class LiquidCloseDelimiter < ::Liquidice::TreetopNodes::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class LiquidOpenDelimiter < ::Liquidice::TreetopNodes::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class LiquidTemplate < ::Liquidice::TreetopNodes::Base
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Liquidice
2
+ module TreetopNodes
3
+ class LiquidTemplateInterpolation < ::Liquidice::TreetopNodes::Base
4
+ end
5
+ end
6
+ end
@@ -1,7 +1,7 @@
1
1
  module Liquidice #:nodoc:
2
2
  module Version #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 3
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/liquidice.rb CHANGED
@@ -1,3 +1,18 @@
1
+ require "treetop"
2
+ require "treetop/syntax_node_ext"
3
+
1
4
  require "liquidice/errors"
5
+ require "liquidice/transformer/nodes/base"
6
+ require "liquidice/transformer/nodes/root_node"
7
+ require "liquidice/transformer/nodes/liquid_template_interpolation"
8
+ require "liquidice/transformer/nodes/liquid_interpolation_part"
9
+ require "liquidice/transformer/nodes/html_tag"
10
+ require "liquidice/transformer/nodes/text_content"
11
+ require "liquidice/treetop_nodes/base"
12
+ require "liquidice/treetop_nodes/liquid_template"
13
+ require "liquidice/treetop_nodes/liquid_open_delimiter"
14
+ require "liquidice/treetop_nodes/liquid_close_delimiter"
15
+ require "liquidice/treetop_nodes/liquid_template_interpolation"
16
+ require "liquidice/treetop_nodes/html_tag"
2
17
  require "liquidice/parser"
3
- require "liquidice/transformer"
18
+ require "liquidice/transformer/transformer"
@@ -0,0 +1,12 @@
1
+ module Treetop
2
+ module Runtime
3
+ class SyntaxNode
4
+ def has_ascendant?(type:, stop_node_type: Liquidice::TreetopNodes::LiquidTemplate)
5
+ return false if parent.nil?
6
+ return false if self.is_a?(stop_node_type)
7
+
8
+ parent.is_a?(type) || parent.has_ascendant?(type: type, stop_node_type: stop_node_type)
9
+ end
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquidice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Lomau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-01 00:00:00.000000000 Z
11
+ date: 2023-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -66,8 +66,9 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- description: A gem that enables the use of Liquid templates with WYSIWYG editor output
70
- by transforming the output to a valid Liquid template
69
+ description: |
70
+ Liquidice (Liquid-I-See) - enables the use of Liquid templates with WYSIWYG editor output by transforming
71
+ the output to a valid Liquid template
71
72
  email:
72
73
  - aliaksandr.lomau@gmail.com
73
74
  executables: []
@@ -78,13 +79,26 @@ files:
78
79
  - lib/liquidice/errors.rb
79
80
  - lib/liquidice/liquidice_grammar.treetop
80
81
  - lib/liquidice/parser.rb
81
- - lib/liquidice/transformer.rb
82
+ - lib/liquidice/transformer/nodes/base.rb
83
+ - lib/liquidice/transformer/nodes/html_tag.rb
84
+ - lib/liquidice/transformer/nodes/liquid_interpolation_part.rb
85
+ - lib/liquidice/transformer/nodes/liquid_template_interpolation.rb
86
+ - lib/liquidice/transformer/nodes/root_node.rb
87
+ - lib/liquidice/transformer/nodes/text_content.rb
88
+ - lib/liquidice/transformer/transformer.rb
89
+ - lib/liquidice/treetop_nodes/base.rb
90
+ - lib/liquidice/treetop_nodes/html_tag.rb
91
+ - lib/liquidice/treetop_nodes/liquid_close_delimiter.rb
92
+ - lib/liquidice/treetop_nodes/liquid_open_delimiter.rb
93
+ - lib/liquidice/treetop_nodes/liquid_template.rb
94
+ - lib/liquidice/treetop_nodes/liquid_template_interpolation.rb
82
95
  - lib/liquidice/version.rb
96
+ - lib/treetop/syntax_node_ext.rb
83
97
  homepage: https://github.com/allomov/liquidice
84
98
  licenses:
85
99
  - MIT
86
100
  metadata: {}
87
- post_install_message:
101
+ post_install_message:
88
102
  rdoc_options: []
89
103
  require_paths:
90
104
  - lib
@@ -99,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
113
  - !ruby/object:Gem::Version
100
114
  version: '0'
101
115
  requirements: []
102
- rubygems_version: 3.1.6
103
- signing_key:
116
+ rubygems_version: 3.4.10
117
+ signing_key:
104
118
  specification_version: 4
105
- summary: A gem that allows the use of Liquid templates with WYSIWYG editor output
119
+ summary: Allows the use of Liquid templates with WYSIWYG editor output
106
120
  test_files: []
@@ -1,160 +0,0 @@
1
- module Liquidice
2
- class Transformer < Treetop::Runtime::SyntaxNode
3
- def apply(node)
4
- case node
5
- when LiquidiceGrammarParser::LiquidTemplate
6
- transform_liquid_template(node)
7
- when LiquidiceGrammarParser::LiquidTag
8
- transform_liquid_tag(node)
9
- when LiquidiceGrammarParser::LiquidOpenDelimeter
10
- transform_liquid_open_delimeter(node)
11
- when LiquidiceGrammarParser::LiquidCloseDelimeter
12
- transform_liquid_close_delimeter(node)
13
- when LiquidiceGrammarParser::ContentWithTags
14
- transform_content_with_tags(node)
15
- when LiquidiceGrammarParser::TextContent
16
- transform_text_content(node)
17
- when LiquidiceGrammarParser::AnyTag
18
- transform_any_tag(node)
19
- when LiquidiceGrammarParser::TagOpen
20
- transform_tag_open(node)
21
- when LiquidiceGrammarParser::TagEmpty
22
- transform_tag_empty(node)
23
- when LiquidiceGrammarParser::TagClose
24
- transform_tag_close(node)
25
- when LiquidiceGrammarParser::AttrList
26
- transform_attr_list(node)
27
- when LiquidiceGrammarParser::Attr
28
- transform_attr(node)
29
- when LiquidiceGrammarParser::AttrEmpty
30
- transform_attr_empty(node)
31
- when LiquidiceGrammarParser::AttrUnquoted
32
- transform_attr_unquoted(node)
33
- when LiquidiceGrammarParser::AttrSingleQuoted
34
- transform_attr_single_quoted(node)
35
- when LiquidiceGrammarParser::AttrDoubleQuoted
36
- transform_attr_double_quoted(node)
37
- when LiquidiceGrammarParser::TagName
38
- transform_tag_name(node)
39
- when LiquidiceGrammarParser::AttrName
40
- transform_attr_name(node)
41
- when LiquidiceGrammarParser::AttrUnquotedValue
42
- transform_attr_unquoted_value(node)
43
- when LiquidiceGrammarParser::AttrSingleQuotedValue
44
- transform_attr_single_quoted_value(node)
45
- when LiquidiceGrammarParser::AttrDoubleQuotedValue
46
- transform_attr_double_quoted_value(node)
47
- when LiquidiceGrammarParser::Alphabets
48
- transform_alphabets(node)
49
- when LiquidiceGrammarParser::Digits
50
- transform_digits(node)
51
- when LiquidiceGrammarParser::Ws
52
- transform_ws(node)
53
- when LiquidiceGrammarParser::Dash
54
- transform_dash(node)
55
- else
56
- raise "Invalid AST node"
57
- end
58
- end
59
-
60
- def transform_liquid_template(node)
61
- node.elements.map { |element| apply(element) }.join
62
- end
63
-
64
- def transform_liquid_tag(node)
65
- "{{ " + apply(node.content_with_tags) + " }}"
66
- end
67
-
68
- def transform_liquid_open_delimeter(node)
69
- "{% "
70
- end
71
-
72
- def transform_liquid_close_delimeter(node)
73
- " %}"
74
- end
75
-
76
- def transform_content_with_tags(node)
77
- node.elements.map { |element| apply(element) }.join
78
- end
79
-
80
- def transform_text_content(node)
81
- node.text_value
82
- end
83
-
84
- def transform_any_tag(node)
85
- apply(node.tag_open) || apply(node.tag_empty) || apply(node.tag_close)
86
- end
87
-
88
- def transform_tag_open(node)
89
- node.text_value
90
- end
91
-
92
- def transform_tag_empty(node)
93
- node.text_value
94
- end
95
-
96
- def transform_tag_close(node)
97
- node.text_value
98
- end
99
-
100
- def transform_attr_list(node)
101
- node.elements.map { |element| apply(element) }.join
102
- end
103
-
104
- def transform_attr(node)
105
- apply(node.attr_empty) || apply(node.attr_unquoted) || apply(node.attr_single_quoted) || apply(node.attr_double_quoted)
106
- end
107
-
108
- def transform_attr_empty(node)
109
- node.text_value
110
- end
111
-
112
- def transform_attr_unquoted(node)
113
- node.text_value
114
- end
115
-
116
- def transform_attr_single_quoted(node)
117
- node.text_value
118
- end
119
-
120
- def transform_attr_double_quoted(node)
121
- node.text_value
122
- end
123
-
124
- def transform_tag_name(node)
125
- node.text_value
126
- end
127
-
128
- def transform_attr_name(node)
129
- node.text_value
130
- end
131
-
132
- def transform_attr_unquoted_value(node)
133
- node.text_value
134
- end
135
-
136
- def transform_attr_single_quoted_value(node)
137
- node.text_value
138
- end
139
-
140
- def transform_attr_double_quoted_value(node)
141
- node.text_value
142
- end
143
-
144
- def transform_alphabets(node)
145
- node.text_value
146
- end
147
-
148
- def transform_digits(node)
149
- node.text_value
150
- end
151
-
152
- def transform_ws(node)
153
- node.text_value
154
- end
155
-
156
- def transform_dash(node)
157
- node.text_value
158
- end
159
- end
160
- end