ragerender 0.1.3 → 0.1.4

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: e8f4de79ae989bb91629afddccfe914b06ac2a734bf1e3be4394e3be6377025d
4
- data.tar.gz: 22e88907930952d291a3a79868fb8927ce9592a8b30304ee2136d2fe347bda0d
3
+ metadata.gz: 87b99ec72e739c37527a89acfc8124efb5ed6f293446ee36ae84ffdc072f061b
4
+ data.tar.gz: cb2735417a459577704a526ff90b4723709101faca6ec4b7d927edf598dfc697
5
5
  SHA512:
6
- metadata.gz: 8bde6a8ebb2c8495ddc554d053088e0ae163250cd5ee24775e13d8322656c7c9578098852fcdf5527880edf41eaa5b6493fbe523321944850084a54c6df35bd2
7
- data.tar.gz: 55a5fed8c1912be039122714f98afe2c50c019ecc2687592ccf502ac98cb2b6931910f86e3c52c7384537e77bd7142b6865e487659a8ab328b026748d1864f93
6
+ metadata.gz: 45d46421b5e611dbb14debb3e290a89dd50b38586c843d51da42557cf87402fc7a9afe354680e7cd5ca8cc05a33e7c338605fc1e0526190a848c64b5288315c1
7
+ data.tar.gz: c3f33f3eeb53ad63cfe135acd394a838446dd6270388605fa299f3d303ba6fb3876844b569b0b611b27f2c5d641a4d2256067b29863fdd60a97fffc8bc6074ea
@@ -9,7 +9,22 @@ module RageRender
9
9
  end
10
10
 
11
11
  def randomnumber a, b
12
- rand a..b
12
+ rand a.to_i..b.to_i
13
+ end
14
+
15
+ # https://github.com/Shopify/liquid/blob/9bb7fbf123e6e2bd61e00189b1c83159f375d3f3/lib/liquid/standardfilters.rb#L24-L29
16
+ # Used under the MIT License.
17
+ STRIP_HTML_BLOCKS = Regexp.union(
18
+ %r{<script.*?</script>}m,
19
+ /<!--.*?-->/m,
20
+ %r{<style.*?</style>}m,
21
+ )
22
+ STRIP_HTML_TAGS = /<.*?>/m
23
+
24
+ # This is only used for ERB – for Liquid, we use the native `strip_html`
25
+ # This pretty much mirrors the Liquid implementation.
26
+ def removehtmltags str
27
+ str.gsub(STRIP_HTML_BLOCKS, '').gsub(STRIP_HTML_TAGS, '')
13
28
  end
14
29
  end
15
30
  end
@@ -40,6 +40,7 @@ module RageRender
40
40
  # CONDITIONAL tests for equality: 'c:variable=My comic about bees' => Conditional.new(false, Variable.new(['variable']), '=', 'My comic about bees')
41
41
  # CONDITIONAL tests for inequality: 'c:variable!=My comic about bees' => Conditional.new(false, Variable.new(['variable']), '!=', 'My comic about bees')
42
42
  # CONDITIONAL tests for greater than: 'c:variable>=3' => Conditional.new(false, Variable.new(['variable']), '>=', '3')
43
+ # CONDITIONAL tests against two variables: 'c:variable=v:other' => Conditional.new(false, Variable.new(['variable']), '=', Variable.new(['other']))
43
44
  CONDITIONAL = ('c:'.r >> seq_(
44
45
  /!?/.r.map {|c| c == '!' },
45
46
  PATH.map {|p| Variable.new(p) },
@@ -20,7 +20,7 @@ module RageRender
20
20
  elsif chunk.path == ['l', 'iteration']
21
21
  '<%= index %>'
22
22
  else
23
- "<%= #{chunk.path.join('.')} rescue nil %>"
23
+ "<%= #{chunk.path.join('.')}.to_s.gsub(/'/, '&#039;').gsub(/\"/, '&quot;') rescue nil %>"
24
24
  end
25
25
 
26
26
  when Language::Conditional
@@ -76,7 +76,17 @@ module RageRender
76
76
 
77
77
  if ERB_OPERATORS.include? chunk.name
78
78
  "<%= #{params.join(ERB_OPERATORS[chunk.name])} %>"
79
+ elsif chunk.name == 'rawhtml'
80
+ "<%= #{params.first} %>"
79
81
  else
82
+ params = params.zip(chunk.params).map do |param, old_param|
83
+ case old_param
84
+ when Language::Variable
85
+ param + ".to_s.gsub(/'/, '&#039;').gsub(/\"/, '&quot;')"
86
+ else
87
+ param
88
+ end
89
+ end
80
90
  "<%= #{chunk.name}(#{params.join(', ')}) %>"
81
91
  end
82
92
 
@@ -2,12 +2,37 @@ require_relative 'language'
2
2
 
3
3
  module RageRender
4
4
  LIQUID_FUNCTIONS = {
5
- 'add' => 'plus',
6
- 'subtract' => 'minus',
7
- 'multiply' => 'times',
8
- 'divide' => 'divided_by',
5
+ 'add' => proc {|f| [Language::Function.new('plus', f.params)] },
6
+ 'subtract' => proc {|f| [Language::Function.new('minus', f.params)] },
7
+ 'multiply' => proc {|f| [Language::Function.new('times', f.params)] },
8
+ 'divide' => proc {|f| [Language::Function.new('divided_by', f.params)] },
9
+ 'removehtmltags' => proc {|f| QUOTE_ESCAPER.call(Language::Function.new('strip_html', f.params)) },
10
+ 'rawhtml' => proc {|f| f.params }
9
11
  }
10
12
 
13
+ QUOTE_REPLACEMENTS = {
14
+ '"' => '&quot;',
15
+ "'" => '&#039;',
16
+ }
17
+
18
+ REPLACE_QUOTES = ["replace: '\"', '&quot;'", "replace: \"'\", '&#039;'"].join(' | ')
19
+
20
+ QUOTE_ESCAPER = proc do |f|
21
+ output = []
22
+ params = f.params.each_with_index do |param, index|
23
+ case param
24
+ when Language::Variable
25
+ new_name = param.path.join('_')
26
+ output << "{% assign #{new_name} = #{render_value(param)} | #{REPLACE_QUOTES} %}"
27
+ Language::Variable.new([new_name])
28
+ else
29
+ param
30
+ end
31
+ end
32
+ output << Language::Function.new(f.name, params)
33
+ output
34
+ end
35
+
11
36
  def self.render_value value
12
37
  case value
13
38
  when String
@@ -20,6 +45,10 @@ module RageRender
20
45
  else
21
46
  value.path.join('.')
22
47
  end
48
+ when Language::Function
49
+ params = value.params.map {|p| render_value p }
50
+ args = params.drop(1).map {|p| "#{value.name}: #{p}" }.join(' | ')
51
+ [params.first, args.empty? ? value.name : args].join(' | ')
23
52
  when nil
24
53
  ""
25
54
  end
@@ -34,7 +63,7 @@ module RageRender
34
63
  chunk
35
64
 
36
65
  when Language::Variable
37
- "{{ #{render_value chunk} }}"
66
+ "{{ #{render_value chunk} | #{REPLACE_QUOTES} }}"
38
67
 
39
68
  when Language::Conditional
40
69
  tag_stack << (chunk.reversed ? :endunless : :endif)
@@ -76,10 +105,9 @@ module RageRender
76
105
  output.join
77
106
 
78
107
  when Language::Function
79
- params = chunk.params.map {|p| render_value p }
80
- name = LIQUID_FUNCTIONS.fetch(chunk.name, chunk.name)
81
- args = params.drop(1).map {|p| "#{name}: #{p}" }.join(' | ')
82
- "{{ #{params.first} | #{args.empty? ? name : args} }}"
108
+ *output, func = LIQUID_FUNCTIONS.fetch(chunk.name, QUOTE_ESCAPER).call(chunk)
109
+ output << "{{ #{render_value(func)} }}"
110
+ output.join
83
111
 
84
112
  when Language::Loop
85
113
  tag_stack << :endfor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragerender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Worthington
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-02 00:00:00.000000000 Z
11
+ date: 2025-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsec