lm_docstache 1.2.0 → 1.2.1
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 +4 -4
- data/.github/workflows/gem-push.yml +42 -0
- data/.github/workflows/ruby.yml +29 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +15 -0
- data/lib/lm_docstache/block.rb +2 -2
- data/lib/lm_docstache/renderer.rb +10 -8
- data/lib/lm_docstache/version.rb +1 -1
- data/lm_docstache.gemspec +1 -0
- data/spec/conditional_block_spec.rb +21 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47845e207f960356863df098a2631bc36d931322a7e40b6186d3d47370019691
|
4
|
+
data.tar.gz: 638c0ff557da45899078382405d497f425aa44e9ba3b7e1a0c65f04d75936b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ba622f15f7c430cf806ee4cb93174e8daa9d3d5651106093f1e6e64bb429788747ef9a47b9dc0ee937da20ccaf4f9641514742b65445c463ce7cadea6fa36c
|
7
|
+
data.tar.gz: 9f9bc5d175c63671065accb0dbe7f2db5a127a6e159338f38f40c6fec967a4209ab28167616a320cd90d8692a42857a977634fcb221d8e4c22806ffbb8b5c626
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6.x
|
20
|
+
|
21
|
+
- name: Publish to GPR
|
22
|
+
run: |
|
23
|
+
mkdir -p $HOME/.gem
|
24
|
+
touch $HOME/.gem/credentials
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
26
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
27
|
+
gem build *.gemspec
|
28
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
29
|
+
env:
|
30
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
31
|
+
OWNER: ${{ github.repository_owner }}
|
32
|
+
|
33
|
+
- name: Publish to RubyGems
|
34
|
+
run: |
|
35
|
+
mkdir -p $HOME/.gem
|
36
|
+
touch $HOME/.gem/credentials
|
37
|
+
chmod 0600 $HOME/.gem/credentials
|
38
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
39
|
+
gem build *.gemspec
|
40
|
+
gem push *.gem
|
41
|
+
env:
|
42
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -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/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,17 +2,28 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
lm_docstache (1.2.0)
|
5
|
+
activesupport (= 6.0.3.2)
|
5
6
|
nokogiri (~> 1.6)
|
6
7
|
rubyzip (~> 1.1)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
activesupport (6.0.3.2)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
11
18
|
byebug (11.1.3)
|
12
19
|
coderay (1.1.3)
|
20
|
+
concurrent-ruby (1.1.6)
|
13
21
|
diff-lcs (1.4.4)
|
22
|
+
i18n (1.8.3)
|
23
|
+
concurrent-ruby (~> 1.0)
|
14
24
|
method_source (1.0.0)
|
15
25
|
mini_portile2 (2.4.0)
|
26
|
+
minitest (5.14.1)
|
16
27
|
nokogiri (1.10.10)
|
17
28
|
mini_portile2 (~> 2.4.0)
|
18
29
|
pry (0.13.1)
|
@@ -35,6 +46,10 @@ GEM
|
|
35
46
|
rspec-support (~> 3.9.0)
|
36
47
|
rspec-support (3.9.3)
|
37
48
|
rubyzip (1.3.0)
|
49
|
+
thread_safe (0.3.6)
|
50
|
+
tzinfo (1.2.7)
|
51
|
+
thread_safe (~> 0.1)
|
52
|
+
zeitwerk (2.4.0)
|
38
53
|
|
39
54
|
PLATFORMS
|
40
55
|
ruby
|
data/lib/lm_docstache/block.rb
CHANGED
@@ -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
|
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
|
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
|
@@ -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
|
-
|
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
|
@@ -117,14 +119,14 @@ module LMDocstache
|
|
117
119
|
|
118
120
|
private
|
119
121
|
|
120
|
-
def get_condition(
|
121
|
-
case condition = @data.get(
|
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
|
129
|
+
condition = !condition if inverted
|
128
130
|
|
129
131
|
condition
|
130
132
|
end
|
data/lib/lm_docstache/version.rb
CHANGED
data/lm_docstache.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
# specify any dependencies here; for example:
|
20
20
|
s.add_runtime_dependency 'nokogiri', '~> 1.6'
|
21
21
|
s.add_runtime_dependency 'rubyzip', '~> 1.1'
|
22
|
+
s.add_runtime_dependency 'activesupport', '6.0.3.2'
|
22
23
|
|
23
24
|
s.add_development_dependency 'rspec', '>= 3.1.0'
|
24
25
|
s.add_development_dependency 'pry-byebug', '>= 1'
|
@@ -2,9 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
4
|
module LMDocstache
|
5
|
-
module
|
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::
|
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.
|
4
|
+
version: 1.2.1
|
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-
|
13
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '1.1'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: activesupport
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 6.0.3.2
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 6.0.3.2
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rspec
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +92,8 @@ executables: []
|
|
78
92
|
extensions: []
|
79
93
|
extra_rdoc_files: []
|
80
94
|
files:
|
95
|
+
- ".github/workflows/gem-push.yml"
|
96
|
+
- ".github/workflows/ruby.yml"
|
81
97
|
- ".gitignore"
|
82
98
|
- CHANGELOG.md
|
83
99
|
- Gemfile
|