ragerender 0.1.2 → 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: f50082e3a10f4085a8bec12f5dbc5386af2fa209239abffc1a01c051e6ed3ea4
4
- data.tar.gz: eb27a5b3de3f325b9c998174c7e2be1a37ebe953c3595431833619d2ff261fdb
3
+ metadata.gz: 87b99ec72e739c37527a89acfc8124efb5ed6f293446ee36ae84ffdc072f061b
4
+ data.tar.gz: cb2735417a459577704a526ff90b4723709101faca6ec4b7d927edf598dfc697
5
5
  SHA512:
6
- metadata.gz: 1e0a5e77617c32868ca965f36e903ee208442de230d620499802d2dbad9c2c110341feb32077b5cc7a41fee69f4a81a95f307bff405b9098c13c28b45fa96dd8
7
- data.tar.gz: 8d41968f7a7ff34622c489fad7731e7dcf8a8573aea3871bf869538eb086503c7116102c87291a395123e23a6658affa4939f497a8b214846b56a8084dc97a20
6
+ metadata.gz: 45d46421b5e611dbb14debb3e290a89dd50b38586c843d51da42557cf87402fc7a9afe354680e7cd5ca8cc05a33e7c338605fc1e0526190a848c64b5288315c1
7
+ data.tar.gz: c3f33f3eeb53ad63cfe135acd394a838446dd6270388605fa299f3d303ba6fb3876844b569b0b611b27f2c5d641a4d2256067b29863fdd60a97fffc8bc6074ea
data/README.rdoc CHANGED
@@ -183,6 +183,20 @@ that and more with optional Front Matter:
183
183
  ---
184
184
  <h1>yo check out my bonus content!</h1>
185
185
 
186
+ === Controlling the front page
187
+
188
+ As on ComicFury you have a few options for setting the front page of you site.
189
+ You control this by setting a <tt>frontpage</tt> key in your site config.
190
+
191
+ - <tt>latest</tt> will display the latest comic (also the default)
192
+ - <tt>first</tt> will display the first comic
193
+ - <tt>chapter</tt> will display the first comic in the latest chapter
194
+ - <tt>blog</tt> will display the list of blog posts
195
+ - <tt>archive</tt> will display the comic archive
196
+ - <tt>overview</tt> will display the comic overview (blogs and latest page)
197
+ - anything else will display the extra page that has the matching
198
+ <tt>slug</tt> in its Front Matter
199
+
186
200
  === Stuff that doesn't work
187
201
 
188
202
  Here is a probably incomplete list of things you can expect to be different
data/assets/blog.html CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  title: Blog
3
3
  layout: blog-archive
4
- permalink: "/blog/"
4
+ permalink: "/blog/index.html"
5
5
  hidden: true
6
6
  ---
@@ -0,0 +1,30 @@
1
+ require 'cgi'
2
+
3
+ # Include this module to get ComicFury intrinsic functions available in
4
+ # templates.
5
+ module RageRender
6
+ module TemplateFunctions
7
+ def js str
8
+ '"' + CGI.escape_html(str) + '"'
9
+ end
10
+
11
+ def randomnumber 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, '')
28
+ end
29
+ end
30
+ end
@@ -2,6 +2,7 @@ def setup_collection site, label, permalink, **kwargs
2
2
  site.config['collections'][label.to_s] = {
3
3
  'output' => true,
4
4
  'permalink' => permalink,
5
+ 'sort_by' => 'date',
5
6
  }
6
7
 
7
8
  site.config['defaults'].prepend({
@@ -3,6 +3,7 @@ require 'stringio'
3
3
  require 'jekyll'
4
4
  require 'dimensions'
5
5
  require_relative 'language'
6
+ require_relative 'functions'
6
7
  require_relative 'to_liquid'
7
8
  require_relative 'date_formats'
8
9
  require_relative 'jekyll/archive'
@@ -39,6 +40,7 @@ Jekyll::Hooks.register :site, :after_init do |site|
39
40
  end
40
41
 
41
42
  Jekyll::Hooks.register :site, :post_read do |site|
43
+ Liquid::Template.register_filter(RageRender::TemplateFunctions)
42
44
  site.layouts.each do |(name, layout)|
43
45
  layout.data['layout'] = 'overall' unless name == 'overall'
44
46
  layout.content = RageRender.to_liquid(RageRender::Language.parse(StringIO.new(layout.content))).join
@@ -63,15 +65,15 @@ class RageRender::FrontpageGenerator < Jekyll::Generator
63
65
  collection = site.collections['comics'].docs
64
66
  chapter = comics.docs.last.data['chapter']
65
67
  comics.docs.detect {|c| c.data['chapter'] == chapter }
66
- when 'overview'
68
+ when 'blog', 'archive', 'overview'
67
69
  collection = site.pages
68
- site.pages.detect {|p| p.data["permalink"] == '/overview/index.html' }
70
+ site.pages.detect {|p| p.data["permalink"] == "/#{frontpage}/index.html" }
69
71
  else
70
72
  collection = site.pages
71
73
  site.pages.detect {|p| p.data["slug"] == frontpage }
72
74
  end.dup
73
- index.instance_variable_set(:"@destination", {site.dest => File.join(site.dest, 'index.html')})
74
75
  index.instance_variable_set(:"@data", index.data.dup)
76
+ index.data['permalink'] = '/index.html'
75
77
  index.data['slug'] = 'frontpage'
76
78
  collection << index
77
79
  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,13 +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',
9
- 'js' => 'escape', # TODO: check these do the same thing!
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 }
10
11
  }
11
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
+
12
36
  def self.render_value value
13
37
  case value
14
38
  when String
@@ -21,6 +45,10 @@ module RageRender
21
45
  else
22
46
  value.path.join('.')
23
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(' | ')
24
52
  when nil
25
53
  ""
26
54
  end
@@ -35,7 +63,7 @@ module RageRender
35
63
  chunk
36
64
 
37
65
  when Language::Variable
38
- "{{ #{render_value chunk} }}"
66
+ "{{ #{render_value chunk} | #{REPLACE_QUOTES} }}"
39
67
 
40
68
  when Language::Conditional
41
69
  tag_stack << (chunk.reversed ? :endunless : :endif)
@@ -77,10 +105,9 @@ module RageRender
77
105
  output.join
78
106
 
79
107
  when Language::Function
80
- params = chunk.params.map {|p| render_value p }
81
- name = LIQUID_FUNCTIONS.fetch(chunk.name, chunk.name)
82
- args = params.drop(1).map {|p| "#{name}: #{p}" }.join(' | ')
83
- "{{ #{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
84
111
 
85
112
  when Language::Loop
86
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.2
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-06-09 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
@@ -253,6 +253,20 @@ description: |-
253
253
  ---
254
254
  <h1>yo check out my bonus content!</h1>
255
255
 
256
+ === Controlling the front page
257
+
258
+ As on ComicFury you have a few options for setting the front page of you site.
259
+ You control this by setting a <tt>frontpage</tt> key in your site config.
260
+
261
+ - <tt>latest</tt> will display the latest comic (also the default)
262
+ - <tt>first</tt> will display the first comic
263
+ - <tt>chapter</tt> will display the first comic in the latest chapter
264
+ - <tt>blog</tt> will display the list of blog posts
265
+ - <tt>archive</tt> will display the comic archive
266
+ - <tt>overview</tt> will display the comic overview (blogs and latest page)
267
+ - anything else will display the extra page that has the matching
268
+ <tt>slug</tt> in its Front Matter
269
+
256
270
  === Stuff that doesn't work
257
271
 
258
272
  Here is a probably incomplete list of things you can expect to be different
@@ -305,6 +319,7 @@ files:
305
319
  - assets/search.html
306
320
  - lib/ragerender.rb
307
321
  - lib/ragerender/date_formats.rb
322
+ - lib/ragerender/functions.rb
308
323
  - lib/ragerender/jekyll.rb
309
324
  - lib/ragerender/jekyll/archive.rb
310
325
  - lib/ragerender/jekyll/blog.rb