code-ruby 1.8.10 → 1.8.12

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: 39ea9f0344599a91472afa6ef86546347d23cf8b3346eb1ec71d2e2d5126d182
4
- data.tar.gz: daa2d568d0bec5a74c9e41bb8f9bf36b4b8a385e090d9f40d4d1717491ab177d
3
+ metadata.gz: fb3e1b31e839dba96ab92f56d22b75ccbc4cd8dbe9438723d80a52e9879f442f
4
+ data.tar.gz: 6e9bbb17dbc604462f1321b56c0626d2f70187a45c29ce4bea89abf710211512
5
5
  SHA512:
6
- metadata.gz: d7cd28054fbfd498c28da87a7928e0af9210da1280253b0ffe619eca7fa15cceacdf8e87d20e3fd68e199a57191ecf2b5c929a4a0000389875f3fd03ac7663ab
7
- data.tar.gz: 139266dc5fffb71c2df8907a3e936071f0e686ef3b263d6a82a1a047f92d8acb81ddf310b9d0366a3bf7ba1dafd26e66ae4c1bed685766e8e2367002e4c5f8b2
6
+ metadata.gz: f8a270b56aeab04407826bf87623ef1c6f5ad04ad55d3645d7884fe941db774cfe1e65626e44470c44d98a84182f1c2c97df3cd6ff872f191619632d09e522f7
7
+ data.tar.gz: c6d5d99bb099906a95f92a956d1295fa6286485cf79503307205ad023ce67b4c619a025aee526c3792db470ba06697a6c717fb49b0b83f70b89a9a9db8eff4bc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.8.10)
4
+ code-ruby (1.8.12)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.10
1
+ 1.8.12
@@ -36,6 +36,9 @@ class Code
36
36
  when "escape"
37
37
  sig(args) { Object.maybe }
38
38
  code_escape(*code_arguments.raw, **globals)
39
+ when "unescape"
40
+ sig(args) { Object.maybe }
41
+ code_unescape(*code_arguments.raw, **globals)
39
42
  when "join"
40
43
  sig(args) { [Object.maybe, Object.maybe] }
41
44
  code_join(*code_arguments.raw, **globals)
@@ -103,7 +106,17 @@ class Code
103
106
  code_value = value_or_function.to_code
104
107
  end
105
108
 
106
- String.new(CGI.escapeHTML(value.to_s))
109
+ String.new(CGI.escapeHTML(code_value.to_s))
110
+ end
111
+
112
+ def self.code_unescape(value_or_function = nil, **globals)
113
+ if value_or_function.is_a?(Function)
114
+ code_value = value_or_function.to_code.call(**globals)
115
+ else
116
+ code_value = value_or_function.to_code
117
+ end
118
+
119
+ String.new(Nokogiri::HTML.fragment(code_value.to_s).text)
107
120
  end
108
121
 
109
122
  def self.code_join(first = nil, second = nil, **globals)
@@ -43,6 +43,15 @@ class Code
43
43
  when "starts_with?"
44
44
  sig(args) { String }
45
45
  code_starts_with?(code_value)
46
+ when "start_with?"
47
+ sig(args) { String }
48
+ code_start_with?(code_value)
49
+ when "ends_with?"
50
+ sig(args) { String }
51
+ code_ends_with?(code_value)
52
+ when "end_with?"
53
+ sig(args) { String }
54
+ code_end_with?(code_value)
46
55
  when "first"
47
56
  sig(args) { Integer.maybe }
48
57
  code_first(code_value)
@@ -95,6 +104,19 @@ class Code
95
104
  Boolean.new(raw.start_with?(code_value.raw))
96
105
  end
97
106
 
107
+ def code_start_with?(value)
108
+ code_starts_with?(value)
109
+ end
110
+
111
+ def code_end_with?(value)
112
+ code_value = value.to_code
113
+ Boolean.new(raw.end_with?(code_value.raw))
114
+ end
115
+
116
+ def code_ends_with?(value)
117
+ code_end_with?(value)
118
+ end
119
+
98
120
  def code_plus(other)
99
121
  code_other = other.to_code
100
122
  String.new(raw + code_other.to_s)
data/spec/code_spec.rb CHANGED
@@ -190,6 +190,12 @@ RSpec.describe Code do
190
190
  %w[9975×14÷8 17456.25],
191
191
  %w["Hello".starts_with?("He") true],
192
192
  %w["Hello".starts_with?("lo") false],
193
+ %w["Hello".start_with?("He") true],
194
+ %w["Hello".start_with?("lo") false],
195
+ %w["Hello".ends_with?("lo") true],
196
+ %w["Hello".ends_with?("He") false],
197
+ %w["Hello".end_with?("lo") true],
198
+ %w["Hello".end_with?("He") false],
193
199
  %w[:Hello.include?(:H) true],
194
200
  %w[:admin? :admin?],
195
201
  %w[:hello :hello],
@@ -418,6 +424,14 @@ RSpec.describe Code do
418
424
  "Html.div { Html.raw(\"<span>ok</span>\") }.to_html",
419
425
  "'<div><span>ok</span></div>'"
420
426
  ],
427
+ [
428
+ "Html.escape(\"<span>&</span>\")",
429
+ "'&lt;span&gt;&amp;&lt;/span&gt;'"
430
+ ],
431
+ [
432
+ "Html.unescape(\"A&nbsp;&nbsp;B &amp; C\")",
433
+ "'A  B & C'"
434
+ ],
421
435
  ["[1, 2, 3].any?", "true"],
422
436
  ["[1, 2, 3].any?(&:even?)", "true"],
423
437
  ["[1, 2, 3].none?", "false"],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.10
4
+ version: 1.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié