lm_docstache 3.0.7 → 3.0.8

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: d27b230b05c9271e1d519b9b946b829da7041d32b1a99a9ae7c29c86326dedd6
4
- data.tar.gz: 34798fa630422bfa320deb756c445142d67bf17dcd120b246d3b5ab7290246ba
3
+ metadata.gz: b414a4508c323651394880630f25af46409778dfc205ebc5621d72e07a6e69a3
4
+ data.tar.gz: 896ce5a0ef359f2b3a77646a631b66ef74a67fb6f5d8fa2ac218a3d346b8f0f8
5
5
  SHA512:
6
- metadata.gz: 1950a09e8be9fc31324f7b94733de31c7eedb99f3867addca8ad9dcc4ce0ac9ad240bbccccf26bcc412b7138fc5e30dca14807452962d1768df3aa8b68ece95c
7
- data.tar.gz: 33c5485fb1fc5e5e7fe135bff40a06ca2d24a61412cce787c2f54af089aa90976fd12ba5e4bda8db2a823e692d5c53ff43508fc8e3c825c21fa2e76d7447ac6e
6
+ metadata.gz: e14266f143047c25ee683b6544ddca31648ac83b51a7a72756f3f01dfa1800353f684d3c1a82e878f523a29ef829389f99c7e4f60b0c6d5c46708eccffc5c36c
7
+ data.tar.gz: 0f5ee3910f3a77519fec6ee1db604954c49f3ecc5b0e12af4bcc4d7844b0f10bc9ee410070291381fbd90cce25f974c246a8bca6a107b8d63021b8e38ed3cef9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.8
4
+
5
+ #### Bug fixes
6
+
7
+ * Fix a bug on `usable_tags` method, so it now properly and expectedly
8
+ includes conditional tag names that have its opening tag markup as the sole
9
+ content of paragraphs (which represents conditional blocks where both
10
+ opening and closing tags are in separate parapraghs sorrounding one or more
11
+ paragraphs as its conditional block content).
12
+
3
13
  ## 3.0.7
4
14
 
5
15
  #### Bug fixes
@@ -38,7 +38,7 @@ module LMDocstache
38
38
  def tags
39
39
  @documents.values.flat_map do |document|
40
40
  document_text = document.text
41
- extract_tag_names(document_text) + extract_tag_names(document_text, true)
41
+ extract_tag_names(document_text) + extract_tag_names(document_text, :full_block)
42
42
  end
43
43
  end
44
44
 
@@ -47,7 +47,8 @@ module LMDocstache
47
47
  document.css('w|t').reduce(tags) do |document_tags, text_node|
48
48
  text = text_node.text
49
49
  document_tags.push(*extract_tag_names(text))
50
- document_tags.push(*extract_tag_names(text, true))
50
+ document_tags.push(*extract_tag_names(text, :start_block))
51
+ document_tags.push(*extract_tag_names(text, :full_block))
51
52
  end
52
53
  end
53
54
  end
@@ -62,20 +63,10 @@ module LMDocstache
62
63
  end
63
64
 
64
65
  def unusable_tags
65
- conditional_start_tags = text_nodes_containing_only_starting_conditionals.map(&:text)
66
-
67
66
  usable_tags.reduce(tags) do |broken_tags, usable_tag|
68
67
  next broken_tags unless index = broken_tags.index(usable_tag)
69
68
 
70
69
  broken_tags.delete_at(index) && broken_tags
71
- end.reject do |broken_tag|
72
- operator = broken_tag.is_a?(Regexp) ? :=~ : :==
73
- start_tags_index = conditional_start_tags.find_index do |start_tag|
74
- broken_tag.send(operator, start_tag)
75
- end
76
-
77
- conditional_start_tags.delete_at(start_tags_index) if start_tags_index
78
- !!start_tags_index
79
70
  end
80
71
  end
81
72
 
@@ -123,23 +114,17 @@ module LMDocstache
123
114
  .gsub('\\ ', ' ')
124
115
  end
125
116
 
126
- def text_nodes_containing_only_starting_conditionals
127
- @documents.values.flat_map do |document|
128
- document.css('w|t').select do |paragraph|
129
- paragraph.text =~ WHOLE_BLOCK_START_REGEX
117
+ def extract_tag_names(text, tag_type = :variable)
118
+ text, regex, extractor =
119
+ if tag_type == :variable
120
+ [text, Parser::VARIABLE_MATCHER, ->(match) { "{{%s}}" % match }]
121
+ else
122
+ extractor = ->(match) { /#{Regexp.escape("{{%s%s %s %s}}" % match)}/ }
123
+ tag_type == :full_block ? [text, Parser::BLOCK_MATCHER, extractor] :
124
+ [text.strip, WHOLE_BLOCK_START_REGEX, extractor]
130
125
  end
131
- end
132
- end
133
126
 
134
- def extract_tag_names(text, conditional_tag = false)
135
- if conditional_tag
136
- text.scan(Parser::BLOCK_MATCHER).map do |match|
137
- start_block_tag = "{{#{match[0]}#{match[1]} #{match[2]} #{match[3]}}}"
138
- /#{Regexp.escape(start_block_tag)}/
139
- end
140
- else
141
- text.scan(Parser::VARIABLE_MATCHER).map { |match| "{{#{match[0]}}}" }
142
- end
127
+ text.scan(regex).map(&extractor)
143
128
  end
144
129
 
145
130
  def render_documents(data, text = nil, render_options = {})
@@ -1,3 +1,3 @@
1
1
  module LMDocstache
2
- VERSION = "3.0.7"
2
+ VERSION = "3.0.8"
3
3
  end
@@ -70,7 +70,9 @@ describe 'integration test', integration: true do
70
70
  end
71
71
 
72
72
  it 'has the expected amount of usable tags' do
73
- expect(document.usable_tags.count).to eq(28)
73
+ expect { document.fix_errors }.to change {
74
+ document.usable_tags.count
75
+ }.from(29).to(34)
74
76
  end
75
77
 
76
78
  it 'has the expected amount of usable roles tags' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lm_docstache
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roey Chasman
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-06-14 00:00:00.000000000 Z
15
+ date: 2021-06-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: nokogiri