mvz-ruby-handlebars 0.0.8 → 0.0.9

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.
@@ -0,0 +1,34 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require_relative '../../../lib/ruby-handlebars'
4
+ require_relative '../../../lib/ruby-handlebars/helpers/register_default_helpers'
5
+
6
+
7
+ describe Handlebars::Helpers do
8
+ context '.register_default_helpers' do
9
+ it 'registers the default helpers' do
10
+ hbs = double(Handlebars::Handlebars)
11
+ allow(hbs).to receive(:register_helper)
12
+ allow(hbs).to receive(:register_as_helper)
13
+
14
+
15
+ Handlebars::Helpers.register_default_helpers(hbs)
16
+
17
+ expect(hbs)
18
+ .to have_received(:register_helper)
19
+ .once
20
+ .with('if')
21
+ .once
22
+ .with('unless')
23
+ .once
24
+ .with('each')
25
+ .once
26
+ .with('helperMissing')
27
+
28
+ expect(hbs)
29
+ .to have_received(:register_as_helper)
30
+ .once
31
+ .with('each')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,55 @@
1
+ shared_context "shared apply helper" do
2
+ # Use to test which blocks are called based on the params values.
3
+ let(:block) { double(Handlebars::Tree::Block.new([])) }
4
+ let(:else_block) { double(Handlebars::Tree::Block.new([])) }
5
+
6
+ before do
7
+ allow(block).to receive(:fn)
8
+ allow(else_block).to receive(:fn)
9
+ end
10
+ end
11
+
12
+ shared_context "shared helpers integration tests" do
13
+ let(:hbs) {Handlebars::Handlebars.new}
14
+
15
+ def evaluate(template, args = {})
16
+ hbs.compile(template).call(args)
17
+ end
18
+ end
19
+
20
+ shared_examples "a registerable helper" do |name|
21
+ it "registers the \"#{name}\" helper" do
22
+ hbs = double(Handlebars::Handlebars)
23
+ allow(hbs).to receive(:register_helper)
24
+ allow(hbs).to receive(:register_as_helper)
25
+
26
+ subject.register(hbs)
27
+
28
+ expect(hbs)
29
+ .to have_received(:register_helper)
30
+ .once
31
+ .with(name)
32
+ end
33
+ end
34
+
35
+ shared_examples "a helper running the main block" do |title, params|
36
+ include_context "shared apply helper"
37
+
38
+ it "when condition is #{title}" do
39
+ subject.apply(ctx, params, block, else_block)
40
+
41
+ expect(block).to have_received(:fn).once
42
+ expect(else_block).not_to have_received(:fn)
43
+ end
44
+ end
45
+
46
+ shared_examples "a helper running the else block" do |title, params|
47
+ include_context "shared apply helper"
48
+
49
+ it "when condition is #{title}" do
50
+ subject.apply(ctx, params, block, else_block)
51
+
52
+ expect(block).not_to have_received(:fn)
53
+ expect(else_block).to have_received(:fn).once
54
+ end
55
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../spec_helper'
2
+ require_relative './shared'
3
+
4
+ require_relative '../../../lib/ruby-handlebars'
5
+ require_relative '../../../lib/ruby-handlebars/helpers/unless_helper'
6
+
7
+
8
+ describe Handlebars::Helpers::UnlessHelper do
9
+ let(:subject) { Handlebars::Helpers::UnlessHelper }
10
+ let(:hbs) {Handlebars::Handlebars.new}
11
+ let(:ctx) {Handlebars::Context.new(hbs, {})}
12
+
13
+ it_behaves_like "a registerable helper", "unless"
14
+
15
+ context '.apply' do
16
+ it_behaves_like "a helper running the main block", "false", false
17
+ it_behaves_like "a helper running the main block", "an empty string", ""
18
+ it_behaves_like "a helper running the main block", "an empty list", []
19
+ it_behaves_like "a helper running the main block", "an empty hash", {}
20
+
21
+ it_behaves_like "a helper running the else block", 'true', true
22
+ it_behaves_like "a helper running the else block", 'a non-empty string', 'something'
23
+ it_behaves_like "a helper running the else block", 'a non-empty list', ['a']
24
+ it_behaves_like "a helper running the else block", 'a non-empty hash', {a: 'b'}
25
+
26
+ context 'when else_block is not present' do
27
+ include_context "shared apply helper"
28
+ let(:params) { true }
29
+ let(:else_block) { nil }
30
+
31
+ it 'returns an empty-string' do
32
+ expect(subject.apply(ctx, params, block, else_block)).to eq("")
33
+
34
+ expect(block).not_to have_received(:fn)
35
+ expect(else_block).not_to have_received(:fn)
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'integration' do
41
+ include_context "shared helpers integration tests"
42
+
43
+ it 'without else' do
44
+ template = [
45
+ "{{#unless condition}}",
46
+ " Show something",
47
+ "{{/unless}}"
48
+ ].join("\n")
49
+ expect(evaluate(template, {condition: false})).to eq("\n Show something\n")
50
+ expect(evaluate(template, {condition: true})).to eq("")
51
+ end
52
+
53
+ it 'with an else' do
54
+ template = [
55
+ "{{#unless condition}}",
56
+ " Show something",
57
+ "{{ else }}",
58
+ " Do not show something",
59
+ "{{/unless}}"
60
+ ].join("\n")
61
+ expect(evaluate(template, {condition: false})).to eq("\n Show something\n")
62
+ expect(evaluate(template, {condition: true})).to eq("\n Do not show something\n")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require "pry"
5
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvz-ruby-handlebars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Pretre
8
8
  - Hiptest R&D
9
9
  - Matijs van Zuijlen
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
  date: 2019-05-13 00:00:00.000000000 Z
@@ -102,7 +102,21 @@ dependencies:
102
102
  - - "~>"
103
103
  - !ruby/object:Gem::Version
104
104
  version: '3.10'
105
- description:
105
+ - !ruby/object:Gem::Dependency
106
+ name: simplecov
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ description:
106
120
  email: matijs@matijs.net
107
121
  executables: []
108
122
  extensions: []
@@ -110,25 +124,41 @@ extra_rdoc_files:
110
124
  - LICENSE
111
125
  - README.md
112
126
  files:
127
+ - CHANGELOG.md
113
128
  - Gemfile
114
129
  - LICENSE
115
130
  - README.md
116
131
  - Rakefile
117
132
  - lib/ruby-handlebars.rb
118
133
  - lib/ruby-handlebars/context.rb
134
+ - lib/ruby-handlebars/escapers/dummy_escaper.rb
135
+ - lib/ruby-handlebars/escapers/html_escaper.rb
119
136
  - lib/ruby-handlebars/helper.rb
137
+ - lib/ruby-handlebars/helpers/default_helper.rb
138
+ - lib/ruby-handlebars/helpers/each_helper.rb
139
+ - lib/ruby-handlebars/helpers/helper_missing_helper.rb
140
+ - lib/ruby-handlebars/helpers/if_helper.rb
141
+ - lib/ruby-handlebars/helpers/register_default_helpers.rb
142
+ - lib/ruby-handlebars/helpers/unless_helper.rb
120
143
  - lib/ruby-handlebars/parser.rb
121
144
  - lib/ruby-handlebars/template.rb
122
145
  - lib/ruby-handlebars/tree.rb
123
146
  - lib/ruby-handlebars/version.rb
124
147
  - spec/handlebars_spec.rb
125
148
  - spec/parser_spec.rb
149
+ - spec/ruby-handlebars/context_spec.rb
150
+ - spec/ruby-handlebars/helpers/each_helper_spec.rb
151
+ - spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb
152
+ - spec/ruby-handlebars/helpers/if_helper_spec.rb
153
+ - spec/ruby-handlebars/helpers/register_default_helpers_spec.rb
154
+ - spec/ruby-handlebars/helpers/shared.rb
155
+ - spec/ruby-handlebars/helpers/unless_helper_spec.rb
126
156
  - spec/spec_helper.rb
127
157
  - spec/tree_spec.rb
128
158
  homepage: https://github.com/mvz/ruby-handlebars
129
159
  licenses: []
130
160
  metadata: {}
131
- post_install_message:
161
+ post_install_message:
132
162
  rdoc_options: []
133
163
  require_paths:
134
164
  - lib
@@ -143,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
173
  - !ruby/object:Gem::Version
144
174
  version: '0'
145
175
  requirements: []
146
- rubygems_version: 3.1.4
147
- signing_key:
176
+ rubygems_version: 3.2.3
177
+ signing_key:
148
178
  specification_version: 4
149
179
  summary: Pure Ruby library for Handlebars templates
150
180
  test_files: []