lm_docstache 1.2.0 → 1.2.4

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: b345230c53f335f5de05dccdaca946bf30edaee21031c219dbdad1315c61c915
4
- data.tar.gz: 554faf30a6988614877f20d72d172d1a66c11bcb2a145f4eb4efd45f7a598fb0
3
+ metadata.gz: c127a60845dc1c0d7d532fb71bbd4707fb9e7c57dd7471308fa01715d409f56f
4
+ data.tar.gz: 35a7e1c75e45bf01615912a7aaf8ac5552a79a4dd7a1f03249f08eae8878a96a
5
5
  SHA512:
6
- metadata.gz: 66732e83ef4cbd515c10904dd293a29346bb1278f1bcfa3ad7becc6e027798f8ca2ca1534f2a9ffc86ee1e4db2d632cd6c926fd703975f386524fd42ccd48516
7
- data.tar.gz: f3ff05f0d5e5b55e3c6eb3e070713b625f74544d667816a71a761d48521ffda12146ff72b3a1189b9a794b8a190a60ea7227a374c0c58711471fba1786de0ce4
6
+ metadata.gz: f703252194067f0478974ed8823cbdb68a3cfd4fcf853c038e9f183b5e2865ce6775f521ec8977ecc53db4ae79ecfdbf753f5248725bdd7dc353473bd6914ae6
7
+ data.tar.gz: 3386aacc5a80637145a24dfc13fa2fcefe9c0114701f911554e0e2bf53f5f3aaedee8669c54792f63d069e658d9c74786f89c1dfa063c7f668a74dfcf8c1ad0e
@@ -0,0 +1,29 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on: push
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
+ # uses: ruby/setup-ruby@v1
23
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
24
+ with:
25
+ ruby-version: 2.6
26
+ - name: Install dependencies
27
+ run: bundle install
28
+ - name: Run tests
29
+ run: rspec
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  spec/example_input/tmp
3
3
  .idea/
4
4
  *.gem
5
+ Gemfile.lock
@@ -1,4 +1,15 @@
1
1
  # Changelog
2
+ ## 1.2.4
3
+ * Add support for pipe character in merge tags so we can use as a modifier for the context of merge tag.
4
+
5
+ ## 1.2.3
6
+ * Fix issue where some paragraphs do not contain text as their first block. If this is the case, we just use the first block that does contain text.
7
+
8
+ ## 1.2.2
9
+ * Remove uneccessary runtime dependency on active support.
10
+
11
+ ## 1.2.1
12
+ * Fix inline conditional issues such as no support for multi conditionals.
2
13
 
3
14
  ## 1.2.0
4
15
  * Add support for inline conditionals.
@@ -45,7 +45,7 @@ module LMDocstache
45
45
  if match.elements.any?
46
46
  find_all(name: name, data: data, elements: match.elements, inverted: inverted, condition: condition, child: true)
47
47
  else
48
- extract_block_from_element(name: name, data: data, element: match, inverted: inverted, condition: condition)
48
+ extract_block_from_element(name, data, match, inverted, condition)
49
49
  end
50
50
  end
51
51
  else
@@ -64,7 +64,7 @@ module LMDocstache
64
64
  end
65
65
  end
66
66
 
67
- def self.extract_block_from_element(name: name, data: data, element: element, inverted: inverted, condition: condition)
67
+ def self.extract_block_from_element(name, data, element, inverted, condition)
68
68
  return Block.new(name: name, data: data, opening_element: element.parent.previous, content_elements: [element.parent], closing_element: element.parent.next, inverted: inverted, condition: condition, inline: true)
69
69
  end
70
70
  end
@@ -111,7 +111,12 @@ module LMDocstache
111
111
 
112
112
  def flatten_paragraph(p)
113
113
  runs = p.css('w|r')
114
+
114
115
  host_run = runs.shift
116
+ until host_run.at_css('w|t').present? || runs.size == 0 do
117
+ host_run = runs.shift
118
+ end
119
+
115
120
  runs.each do |run|
116
121
  host_run.at_css('w|t').content += run.text
117
122
  run.unlink
@@ -43,7 +43,7 @@ module LMDocstache
43
43
  def expand_and_replace_block(block)
44
44
  case block.type
45
45
  when :conditional
46
- condition = get_condition(block)
46
+ condition = get_condition(block.name, block.condition, block.inverted)
47
47
  unless condition
48
48
  block.content_elements.each(&:unlink)
49
49
  end
@@ -69,13 +69,13 @@ module LMDocstache
69
69
  end
70
70
 
71
71
  def replace_conditionals(block)
72
- condition = get_condition(block)
73
-
74
72
  @content.css('w|t').each do |text_el|
75
73
  rendered_string = text_el.text
76
74
 
77
75
  if !(results = rendered_string.scan(/{{#(.*?)}}(.*?){{\/(.*?)}}/)).empty?
78
76
  results.each do |r|
77
+ vals = r[0].split('==')
78
+ condition = get_condition(vals[0].strip, "== #{vals[1]}")
79
79
  if condition
80
80
  rendered_string.sub!("{{##{r[0]}}}", "")
81
81
  rendered_string.sub!("{{/#{r[2]}}}", "")
@@ -86,10 +86,12 @@ module LMDocstache
86
86
  end
87
87
 
88
88
  # the only difference in this code block is caret instead of pound in three places,
89
- # and the condition being inverted. maybe combine them?
89
+ # the inverted value passed to get_condition, and the condition being inverted. maybe combine them?
90
90
  if !(results = rendered_string.scan(/{{\^(.*?)}}(.*?){{\/(.*?)}}/)).empty?
91
91
  results.each do |r|
92
- if !condition
92
+ vals = r[0].split('==')
93
+ condition = get_condition(vals[0].strip, "== #{vals[1]}", true)
94
+ if condition
93
95
  rendered_string.sub!("{{^#{r[0]}}}", "")
94
96
  rendered_string.sub!("{{/#{r[2]}}}", "")
95
97
  else
@@ -104,7 +106,7 @@ module LMDocstache
104
106
 
105
107
  def replace_tags(elements, data)
106
108
  elements.css('w|t').each do |text_el|
107
- if !(results = text_el.text.scan(/\{\{([\w\.]+)\}\}/).flatten).empty?
109
+ if !(results = text_el.text.scan(/\{\{([\w\.\|]+)\}\}/).flatten).empty?
108
110
  rendered_string = text_el.text
109
111
  results.each do |r|
110
112
  rendered_string.gsub!("{{#{r}}}", data.get(r).to_s)
@@ -117,14 +119,14 @@ module LMDocstache
117
119
 
118
120
  private
119
121
 
120
- def get_condition(block)
121
- case condition = @data.get(block.name, condition: block.condition)
122
+ def get_condition(name, condition, inverted = false)
123
+ case condition = @data.get(name, condition: condition)
122
124
  when Array
123
125
  condition = !condition.empty?
124
126
  else
125
127
  condition = !!condition
126
128
  end
127
- condition = !condition if block.inverted
129
+ condition = !condition if inverted
128
130
 
129
131
  condition
130
132
  end
@@ -1,3 +1,3 @@
1
1
  module LMDocstache
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_runtime_dependency 'nokogiri', '~> 1.6'
21
21
  s.add_runtime_dependency 'rubyzip', '~> 1.1'
22
22
 
23
- s.add_development_dependency 'rspec', '>= 3.1.0'
24
- s.add_development_dependency 'pry-byebug', '>= 1'
23
+ s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
24
+ s.add_development_dependency 'pry-byebug', '~> 1'
25
+ s.add_development_dependency 'activesupport', '~> 3'
25
26
  end
@@ -2,9 +2,10 @@ require 'spec_helper'
2
2
  require 'nokogiri'
3
3
 
4
4
  module LMDocstache
5
- module TestData
5
+ module BlockTestData
6
6
  DATA = {
7
7
  gender: 'Male',
8
+ num: '2',
8
9
  first_name: 'Hector',
9
10
  last_name: 'Jones'
10
11
  }
@@ -12,7 +13,7 @@ module LMDocstache
12
13
  end
13
14
 
14
15
  describe LMDocstache::Renderer do
15
- let(:data) { Marshal.load(Marshal.dump(LMDocstache::TestData::DATA)) } # deep copy
16
+ let(:data) { Marshal.load(Marshal.dump(LMDocstache::BlockTestData::DATA)) } # deep copy
16
17
  let(:base_path) { SPEC_BASE_PATH.join('example_input') }
17
18
  let(:blank_doc_path) { "#{base_path}/blank.docx" }
18
19
  let(:blank_doc) { LMDocstache::Document.new(blank_doc_path) }
@@ -64,6 +65,24 @@ describe LMDocstache::Renderer do
64
65
  expect(result_text).to eq(expected_text)
65
66
  end
66
67
 
68
+ it 'should handle multiple positive checks in one line' do
69
+ result_text = render_docx("Refer to the matter as {{#gender == 'Male'}}him{{/gender}}{{#gender == 'Female'}}her{{/gender}} please")
70
+ expected_text = "Refer to the matter as him please"
71
+ expect(result_text).to eq(expected_text)
72
+ end
73
+
74
+ it 'should handle multiple positive checks and multiple negative checks in one line' do
75
+ result_text = render_docx("be {{#num == 1}}1{{/num}}{{#num == 2}}2{{/num}} and {{^num == 2}}!2{{/num}}{{^num == 1}}!1{{/num}} please")
76
+ expected_text = "be 2 and !1 please"
77
+ expect(result_text).to eq(expected_text)
78
+ end
79
+
80
+ it 'should handle multiple types of conditionals in one line' do
81
+ result_text = render_docx("be{{#gender == Male}} he {{/gender}}{{#num == 1}}1{{/num}}{{#num == 2}}2{{/num}} and {{^num == 2}}!2{{/num}}{{^num == 1}}!1{{/num}} please")
82
+ expected_text = "be he 2 and !1 please"
83
+ expect(result_text).to eq(expected_text)
84
+ end
85
+
67
86
  it 'should handle multiline conditional tags' do
68
87
  text = [
69
88
  "Refer to the matter as",
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: 1.2.0
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roey Chasman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-15 00:00:00.000000000 Z
13
+ date: 2020-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -47,6 +47,9 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.1.0
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.1'
50
53
  type: :development
51
54
  prerelease: false
52
55
  version_requirements: !ruby/object:Gem::Requirement
@@ -54,20 +57,37 @@ dependencies:
54
57
  - - ">="
55
58
  - !ruby/object:Gem::Version
56
59
  version: 3.1.0
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
57
63
  - !ruby/object:Gem::Dependency
58
64
  name: pry-byebug
59
65
  requirement: !ruby/object:Gem::Requirement
60
66
  requirements:
61
- - - ">="
67
+ - - "~>"
62
68
  - !ruby/object:Gem::Version
63
69
  version: '1'
64
70
  type: :development
65
71
  prerelease: false
66
72
  version_requirements: !ruby/object:Gem::Requirement
67
73
  requirements:
68
- - - ">="
74
+ - - "~>"
69
75
  - !ruby/object:Gem::Version
70
76
  version: '1'
77
+ - !ruby/object:Gem::Dependency
78
+ name: activesupport
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3'
71
91
  description: Integrates data into MS Word docx template files. Processing supports
72
92
  loops and replacement of strings of data both outside and within loops.
73
93
  email:
@@ -78,10 +98,10 @@ executables: []
78
98
  extensions: []
79
99
  extra_rdoc_files: []
80
100
  files:
101
+ - ".github/workflows/ruby.yml"
81
102
  - ".gitignore"
82
103
  - CHANGELOG.md
83
104
  - Gemfile
84
- - Gemfile.lock
85
105
  - LICENSE.txt
86
106
  - README.md
87
107
  - Rakefile
@@ -1,48 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- lm_docstache (1.2.0)
5
- nokogiri (~> 1.6)
6
- rubyzip (~> 1.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- byebug (11.1.3)
12
- coderay (1.1.3)
13
- diff-lcs (1.4.4)
14
- method_source (1.0.0)
15
- mini_portile2 (2.4.0)
16
- nokogiri (1.10.10)
17
- mini_portile2 (~> 2.4.0)
18
- pry (0.13.1)
19
- coderay (~> 1.1)
20
- method_source (~> 1.0)
21
- pry-byebug (3.9.0)
22
- byebug (~> 11.0)
23
- pry (~> 0.13.0)
24
- rspec (3.9.0)
25
- rspec-core (~> 3.9.0)
26
- rspec-expectations (~> 3.9.0)
27
- rspec-mocks (~> 3.9.0)
28
- rspec-core (3.9.2)
29
- rspec-support (~> 3.9.3)
30
- rspec-expectations (3.9.2)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.9.0)
33
- rspec-mocks (3.9.1)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.9.0)
36
- rspec-support (3.9.3)
37
- rubyzip (1.3.0)
38
-
39
- PLATFORMS
40
- ruby
41
-
42
- DEPENDENCIES
43
- lm_docstache!
44
- pry-byebug (>= 1)
45
- rspec (>= 3.1.0)
46
-
47
- BUNDLED WITH
48
- 1.17.2