mvz-ruby-handlebars 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c677856bd3e74f5198f64f3b10b9348530b95024889ff1cf6db380c1165c771f
4
- data.tar.gz: 1ff2e3bba711f257d9412ef9aa074fad8ca87429ab5b2ad0033187b289c586e0
3
+ metadata.gz: 2ee7a7f7964d4f0ea1f63848d114c4877fab021a61bce513e485cb6f13444a55
4
+ data.tar.gz: f671688ece97795863fed6e673206967469e61529a8c5c6e9b46f5ebb50edfac
5
5
  SHA512:
6
- metadata.gz: 00be980edd23a6f537a5c7e6354f592826651a795f4a4b7055f26db4d31778c90c7e8a9367e9450578bf0b8c74d690409c52137c337017074edd6163c8148ff2
7
- data.tar.gz: 2d89f9b244cad437e7ee33b75562197071dac7d0ccb66be0b83d183f86b9774b16c79178f467fa8f72201b9ef563bbc8b7bc7c2288b81462718f0a7aff5b1b07
6
+ metadata.gz: 29845db860dcd376e53ac0b64ca9fe8c0e3691e3355bc38401432edadbce83d2c237850faf16d04346e1f94ee48cd4c8f5e9e5401b49e0db280b9d782c2b9685
7
+ data.tar.gz: 531d60ce02ad77d3b8a58e9dc71147400fa169499f9c26c494f3b2a8f9810775970461c63e48249f3741109fbc5cc1d229547145164a3ffc770a1fc90de63d25
data/CHANGELOG.md CHANGED
@@ -1,10 +1,25 @@
1
- mvz-ruby-handlebars changelog
2
- =============================
1
+ # Changelog
3
2
 
4
- 0.0.9 (2021-01-04)
5
- ------------------
3
+ ## 0.0.10 (2021-08-31)
6
4
 
7
- - Pull in upstream master. See
8
- https://github.com/SmartBear/ruby-handlebars/blob/master/CHANGELOG.md for
9
- included changes.
10
- - Prefer variable over helper when processing a replacement if the helper has the wrong arity
5
+ * Pull in upstream master. See
6
+ https://github.com/SmartBear/ruby-handlebars/blob/2a8ce9ef584f2c34cd5714a4ed36711c2dd9d58a/CHANGELOG.md
7
+ for included changes
8
+ * Make helpers with only optional arguments work in replacement form
9
+
10
+ ## 0.0.9 (2021-01-04)
11
+
12
+ * Pull in upstream master. See
13
+ https://github.com/SmartBear/ruby-handlebars/blob/44dc6800dd5006865fc2dc1c26a9d4e5c1411bce/CHANGELOG.md
14
+ for included changes
15
+ * Prefer variable over helper when processing a replacement if the helper has
16
+ the wrong arity
17
+
18
+ ## 0.0.8
19
+
20
+ * Update dependencies
21
+
22
+ ## 0.0.7
23
+
24
+ * Set up forked gem mvz-ruby-handlebars
25
+ * Several improvements
@@ -2,7 +2,6 @@ module Handlebars
2
2
  class Context
3
3
  def initialize(hbs, data)
4
4
  @hbs = hbs
5
- @locals = {}
6
5
  @data = data
7
6
  end
8
7
 
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module Handlebars
2
4
  module Escapers
3
5
  class HTMLEscaper
@@ -6,4 +8,4 @@ module Handlebars
6
8
  end
7
9
  end
8
10
  end
9
- end
11
+ end
@@ -2,6 +2,7 @@ require_relative 'each_helper'
2
2
  require_relative 'helper_missing_helper'
3
3
  require_relative 'if_helper'
4
4
  require_relative 'unless_helper'
5
+ require_relative 'with_helper'
5
6
 
6
7
  module Handlebars
7
8
  module Helpers
@@ -10,6 +11,7 @@ module Handlebars
10
11
  HelperMissingHelper.register(hbs)
11
12
  IfHelper.register(hbs)
12
13
  UnlessHelper.register(hbs)
14
+ WithHelper.register(hbs)
13
15
  end
14
16
  end
15
17
  end
@@ -0,0 +1,25 @@
1
+ require_relative 'default_helper'
2
+
3
+ module Handlebars
4
+ module Helpers
5
+ class WithHelper < DefaultHelper
6
+ def self.registry_name
7
+ 'with'
8
+ end
9
+
10
+ def self.apply(context, data, block, else_block)
11
+ if data
12
+ context.with_temporary_context(data) do
13
+ block.fn(context)
14
+ end
15
+ else
16
+ else_block.fn(context)
17
+ end
18
+ end
19
+
20
+ def self.apply_as(context, data, name, block, else_block)
21
+ self.apply(context, { name.to_sym => data }, block, else_block)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -17,7 +17,7 @@ module Handlebars
17
17
  class Replacement < TreeItem.new(:item)
18
18
  def _eval(context)
19
19
  helper = context.get_helper(item.to_s)
20
- if helper && helper.arity == 1
20
+ if helper && (helper.arity == 1 || helper.arity == -2)
21
21
  helper.apply(context)
22
22
  else
23
23
  context.get(item.to_s)
@@ -1,3 +1,3 @@
1
1
  module Handlebars
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -117,6 +117,11 @@ describe Handlebars::Handlebars do
117
117
  expect(evaluate("{{{add left '&' right}}}", {left: 'Law', right: 'Order'})).to eq("Law & Order")
118
118
  end
119
119
 
120
+ it 'with optional arguments not specified' do
121
+ hbs.register_helper('rainbow') {|context, *opts| "-"}
122
+ expect(evaluate("{{rainbow}}")).to eq("-")
123
+ end
124
+
120
125
  it 'with an empty string argument' do
121
126
  hbs.register_helper('noah') {|context, value| value.to_s.gsub(/a/, '')}
122
127
 
@@ -0,0 +1,80 @@
1
+ require_relative '../../spec_helper'
2
+ require_relative './shared'
3
+
4
+ require_relative '../../../lib/ruby-handlebars'
5
+ require_relative '../../../lib/ruby-handlebars/tree'
6
+ require_relative '../../../lib/ruby-handlebars/helpers/with_helper'
7
+
8
+ describe Handlebars::Helpers::WithHelper do
9
+ let(:subject) { Handlebars::Helpers::WithHelper }
10
+ let(:hbs) { Handlebars::Handlebars.new }
11
+
12
+ it_behaves_like "a registerable helper", "with"
13
+
14
+ context '.apply' do
15
+ include_context "shared apply helper"
16
+ end
17
+
18
+ context "integration" do
19
+ include_context "shared helpers integration tests"
20
+
21
+ let(:person_data) { { person: { firstname: "Yehuda", lastname: "Katz" }} }
22
+ let(:city_data) { {
23
+ city: {
24
+ name: "San Francisco",
25
+ summary: "San Francisco is the <b>cultural center</b> of <b>Northern California</b>",
26
+ location: {
27
+ north: "37.73,",
28
+ east: -122.44,
29
+ },
30
+ population: 883305,
31
+ },
32
+ } }
33
+
34
+ it "changes the evaluation context" do
35
+ template = <<~HANDLEBARS
36
+ {{#with person}}
37
+ {{firstname}} {{lastname}}
38
+ {{/with}}
39
+ HANDLEBARS
40
+
41
+ expect(evaluate(template, person_data).strip).to eq("Yehuda Katz")
42
+ end
43
+
44
+ it "supports block parameters" do
45
+ template = <<~HANDLEBARS
46
+ {{#with city as | city |}}
47
+ {{#with city.location as | loc |}}
48
+ {{city.name}}: {{loc.north}} {{loc.east}}
49
+ {{/with}}
50
+ {{/with}}
51
+ HANDLEBARS
52
+
53
+ expect(evaluate(template, city_data).strip).to eq("San Francisco: 37.73, -122.44")
54
+ end
55
+
56
+ it "supports else blocks" do
57
+ template = <<~HANDLEBARS
58
+ {{#with city}}
59
+ {{city.name}} (not shown because there is no city)
60
+ {{else}}
61
+ No city found
62
+ {{/with}}
63
+ HANDLEBARS
64
+
65
+ expect(evaluate(template, person_data).strip).to eq("No city found")
66
+ end
67
+
68
+ it "supports relative paths", skip: "Relative paths are not yet supported" do
69
+ template = <<~HANDLEBARS
70
+ {{#with city as | city |}}
71
+ {{#with city.location as | loc |}}
72
+ {{city.name}}: {{../population}}
73
+ {{/with}}
74
+ {{/with}}
75
+ HANDLEBARS
76
+
77
+ expect(evaluate(template, city_data).strip).to eq("San Francisco: 883305")
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvz-ruby-handlebars
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Pretre
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 0.13.1
35
+ version: 0.14.0
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.13.1
42
+ version: 0.14.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: pry-stack_explorer
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - lib/ruby-handlebars/helpers/if_helper.rb
141
141
  - lib/ruby-handlebars/helpers/register_default_helpers.rb
142
142
  - lib/ruby-handlebars/helpers/unless_helper.rb
143
+ - lib/ruby-handlebars/helpers/with_helper.rb
143
144
  - lib/ruby-handlebars/parser.rb
144
145
  - lib/ruby-handlebars/template.rb
145
146
  - lib/ruby-handlebars/tree.rb
@@ -153,6 +154,7 @@ files:
153
154
  - spec/ruby-handlebars/helpers/register_default_helpers_spec.rb
154
155
  - spec/ruby-handlebars/helpers/shared.rb
155
156
  - spec/ruby-handlebars/helpers/unless_helper_spec.rb
157
+ - spec/ruby-handlebars/helpers/with_helper_spec.rb
156
158
  - spec/spec_helper.rb
157
159
  - spec/tree_spec.rb
158
160
  homepage: https://github.com/mvz/ruby-handlebars
@@ -173,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
175
  - !ruby/object:Gem::Version
174
176
  version: '0'
175
177
  requirements: []
176
- rubygems_version: 3.2.3
178
+ rubygems_version: 3.2.22
177
179
  signing_key:
178
180
  specification_version: 4
179
181
  summary: Pure Ruby library for Handlebars templates