sablon 0.4.0 → 0.4.1

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: c83f07a4e1add4db3c1c12d6ffab63e53b7f0acc89e7947efa8cac8a140a35eb
4
- data.tar.gz: 23b8e9d2685409410dc418f615c8a23742dbcbc58c3f7a93fcb6a594e84450bf
3
+ metadata.gz: 720cffa05ff6bb8247f98dcf41bc071337261dcea325efe2b7f711bc728b342d
4
+ data.tar.gz: 1a75ef6694f0a608c5d5fc2ceec212017bf2ff0a547970291b1de86ef44f436c
5
5
  SHA512:
6
- metadata.gz: 8bf3e622843f453b9f2f8b7b9ebbaa18560ec83ecd11ca2386a885bc497ca0149e6e9db64be4a9220a508bf625b7e81748ca636456e03f274d58883efce5453c
7
- data.tar.gz: 5bfe0d0737b928420342146c8b920283f0a4c3f9fa32b585871792076df75305048e17c348c44b7ca470408a84e763c2b47ac401a7711cd5219e26270c9d310a
6
+ metadata.gz: 43becf98304baf22069a66dd2f7317f78acb66047523129f9f108d83b682b3bcbdb154142a536bc629d3c71a56edeef3c1b1aac81004fbc71946499d5587fb98
7
+ data.tar.gz: ee6d21a857e7ae944bc173663868b7987b60c96752e2fae6d303b96ded3208f7e041cc8f38018547a8f9b469a9574677a237666a72cffd1a60ba7113480fa47b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sablon (0.4.0)
4
+ sablon (0.4.1)
5
5
  nokogiri (>= 1.8.5)
6
6
  rubyzip (>= 1.3.0)
7
7
 
@@ -9,9 +9,9 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  minitest (5.20.0)
12
- nokogiri (1.15.5)
12
+ nokogiri (1.16.5-arm64-darwin)
13
13
  racc (~> 1.4)
14
- racc (1.7.3)
14
+ racc (1.8.0)
15
15
  rake (13.1.0)
16
16
  rexml (3.2.6)
17
17
  rubyzip (2.3.2)
@@ -19,7 +19,7 @@ GEM
19
19
  rexml
20
20
 
21
21
  PLATFORMS
22
- ruby
22
+ arm64-darwin-23
23
23
 
24
24
  DEPENDENCIES
25
25
  bundler (>= 1.6)
@@ -6,6 +6,9 @@ module Sablon
6
6
  # user supplied hash into a data structure suitable for rendering the
7
7
  # docx template.
8
8
  module Context
9
+ class << self; attr_accessor :content_regex end
10
+ self.content_regex = /\A([^:]+):(.+)\z/
11
+
9
12
  class << self
10
13
  def transform_hash(hash)
11
14
  Hash[hash.map { |k, v| transform_pair(k.to_s, v) }]
@@ -25,12 +28,12 @@ module Sablon
25
28
  end
26
29
 
27
30
  def transform_pair(key, value)
28
- if key =~ /\A([^:]+):(.+)\z/
31
+ if match = content_regex.match(key)
29
32
  if value.nil?
30
- [Regexp.last_match[2], value]
33
+ [match[2], value]
31
34
  else
32
- key_sym = Regexp.last_match[1].to_sym
33
- [Regexp.last_match[2], Content.make(key_sym, value)]
35
+ type_id = match[1].to_sym
36
+ [match[2], Content.make(type_id, value)]
34
37
  end
35
38
  else
36
39
  transform_standard_key(key, value)
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/test/context_test.rb CHANGED
@@ -61,4 +61,26 @@ class ContextTest < Sablon::TestCase
61
61
  context = Sablon::Context.transform_hash(input_context)
62
62
  assert_equal expected_context, context
63
63
  end
64
+
65
+ def test_tune_typed_content_regex
66
+ input_context = {
67
+ default: "string",
68
+ "word_ml:runs" => "<w:r><w:t>Text</w:t><w:r>",
69
+ "urn:some:example" => "string as well"
70
+ }
71
+ expected_context = {
72
+ "default" => "string",
73
+ "runs" => Sablon.content(:word_ml, "<w:r><w:t>Text</w:t><w:r>"),
74
+ "urn:some:example" => "string as well"
75
+ }
76
+
77
+ original_regex = Sablon::Context.content_regex
78
+ begin
79
+ Sablon::Context.content_regex = /\A((?!urn:)[^:]+):(.+)\z/
80
+ context = Sablon::Context.transform_hash(input_context)
81
+ assert_equal expected_context, context
82
+ ensure
83
+ Sablon::Context.content_regex = original_regex
84
+ end
85
+ end
64
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sablon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Senn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 3.3.7
249
+ rubygems_version: 3.5.9
250
250
  signing_key:
251
251
  specification_version: 4
252
252
  summary: docx template processor