code-ruby 1.8.9 → 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: 2e3f7e0eca6b9a0f46c7173687ec10c4e389565624f96e3de49458ce9449850f
4
- data.tar.gz: 748a9d98e4f5e2f405b5a9cd4b811c7f3a513a5feb39e9491c3de13499c684c1
3
+ metadata.gz: fb3e1b31e839dba96ab92f56d22b75ccbc4cd8dbe9438723d80a52e9879f442f
4
+ data.tar.gz: 6e9bbb17dbc604462f1321b56c0626d2f70187a45c29ce4bea89abf710211512
5
5
  SHA512:
6
- metadata.gz: 9a0fc23897fdb878e0bfef46439d0f6291818e4931625644dbd6e7ba0f249fa0be24b528c8b999cc1dd800cf8436fe17418e83c6146c74e3687387bed463c426
7
- data.tar.gz: e7109f12587180228ed2d24f76dd786d1bfb0489060614245810713cfa29c52be0706149b3abe7ab04880069eec89382fa4bde5ddaed78f7c836ed6bc4b77fd8
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.9)
4
+ code-ruby (1.8.12)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.9
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)
@@ -40,6 +40,18 @@ class Code
40
40
  when "include?"
41
41
  sig(args) { String }
42
42
  code_include?(code_value)
43
+ when "starts_with?"
44
+ sig(args) { String }
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)
43
55
  when "first"
44
56
  sig(args) { Integer.maybe }
45
57
  code_first(code_value)
@@ -87,6 +99,24 @@ class Code
87
99
  String.new(raw * code_other.raw)
88
100
  end
89
101
 
102
+ def code_starts_with?(value)
103
+ code_value = value.to_code
104
+ Boolean.new(raw.start_with?(code_value.raw))
105
+ end
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
+
90
120
  def code_plus(other)
91
121
  code_other = other.to_code
92
122
  String.new(raw + code_other.to_s)
data/spec/code_spec.rb CHANGED
@@ -188,6 +188,14 @@ RSpec.describe Code do
188
188
  %w[2.days.from_now.future? true],
189
189
  %w[2.days.from_now.past? false],
190
190
  %w[9975×14÷8 17456.25],
191
+ %w["Hello".starts_with?("He") true],
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],
191
199
  %w[:Hello.include?(:H) true],
192
200
  %w[:admin? :admin?],
193
201
  %w[:hello :hello],
@@ -416,6 +424,14 @@ RSpec.describe Code do
416
424
  "Html.div { Html.raw(\"<span>ok</span>\") }.to_html",
417
425
  "'<div><span>ok</span></div>'"
418
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
+ ],
419
435
  ["[1, 2, 3].any?", "true"],
420
436
  ["[1, 2, 3].any?(&:even?)", "true"],
421
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.9
4
+ version: 1.8.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié