ragerender 0.1.1 → 0.1.3

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: 670837503b9bdfb7e314412c2ad7f3fbed616035c83e231e94afbc1a8461ae7d
4
- data.tar.gz: 4642302a27d7a2433267abca12fda09703a5b583593501279f87196f0885aa28
3
+ metadata.gz: e8f4de79ae989bb91629afddccfe914b06ac2a734bf1e3be4394e3be6377025d
4
+ data.tar.gz: 22e88907930952d291a3a79868fb8927ce9592a8b30304ee2136d2fe347bda0d
5
5
  SHA512:
6
- metadata.gz: 6dcfa8001b76f24b00360b52da55889307e2ada02b93b5fe9f1dfa8561b28f3c2cf6939a477977f27c356c43a1e7a596ba7d5007f371a689b9b17b2ccb29e7d1
7
- data.tar.gz: 687ccd2273c923d13178dce12e9de7afba951e6bcabe576c9c1fe67e6a2a21b987b99dda8a73bd95897ca930cd05b96e7029af377e48e7387e6fd3f1847892e4
6
+ metadata.gz: 8bde6a8ebb2c8495ddc554d053088e0ae163250cd5ee24775e13d8322656c7c9578098852fcdf5527880edf41eaa5b6493fbe523321944850084a54c6df35bd2
7
+ data.tar.gz: 55a5fed8c1912be039122714f98afe2c50c019ecc2687592ccf502ac98cb2b6931910f86e3c52c7384537e77bd7142b6865e487659a8ab328b026748d1864f93
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,15 @@
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..b
13
+ end
14
+ end
15
+ end
@@ -49,10 +49,10 @@ module RageRender
49
49
  # handle that pagination manually by calling another paginator for each page
50
50
  # we generate here.
51
51
  class ChapterArchiveGenerator < Jekyll::Generator
52
- priority :high
52
+ priority :normal
53
53
 
54
54
  def generate site
55
- site.collections['chapters'].docs.each do |page|
55
+ site.collections['chapters'].docs.to_a.dup.each do |page|
56
56
  page.data['mode'] = 'chapters'
57
57
  ChapterArchivePaginator.new(page).generate(site)
58
58
  end
@@ -72,6 +72,12 @@ module RageRender
72
72
  @page
73
73
  end
74
74
 
75
+ def duplicate original
76
+ page = Jekyll::Document.new(original.path, site: original.site, collection: original.collection)
77
+ page.merge_data! original.data, source: 'original document'
78
+ page
79
+ end
80
+
75
81
  def num_pages site
76
82
  site.collections['comics'].docs.select do |c|
77
83
  c.data['chapter'] == @page.data['slug']
@@ -79,7 +85,13 @@ module RageRender
79
85
  end
80
86
 
81
87
  def permalink
82
- Pathname.new(@page.permalink).join('../').join('page/:number/index.html').to_path
88
+ path = Pathname.new(@page.url)
89
+ path = path.dirname unless @page.url.end_with?('/')
90
+ path.join('page/:number/index.html').to_path
91
+ end
92
+
93
+ def handle_page page
94
+ page.collection.docs << page
83
95
  end
84
96
  end
85
97
 
@@ -102,7 +114,9 @@ module RageRender
102
114
 
103
115
  def chapters
104
116
  unless show_chapter_overview
105
- @obj.site.collections['chapters'].docs.map do |page|
117
+ @obj.site.collections['chapters'].docs.reject do |page|
118
+ page.data['hidden']
119
+ end.map do |page|
106
120
  ChapterDrop.new(page).to_liquid
107
121
  end
108
122
  end
@@ -1,9 +1,13 @@
1
1
  require 'jekyll/generator'
2
2
  require 'jekyll/drops/document_drop'
3
+ require_relative 'named_data_delegator'
4
+ require_relative 'setup_collection'
3
5
 
4
6
  # Add default values for the 'unchapter' which is used to hold all comics that
5
7
  # don't have a chapter.
6
8
  Jekyll::Hooks.register :site, :after_init do |site|
9
+ setup_collection site, :chapters, '/archive/:slug/', layout: 'archive'
10
+
7
11
  site.config['defaults'].prepend({
8
12
  'scope' => {
9
13
  'path' => '_chapters/0.html',
@@ -32,6 +36,7 @@ module RageRender
32
36
  existing = Set.new(site.collections['chapters'].docs.map {|c| c.data['slug'] })
33
37
  missing = required - existing
34
38
  missing.each do |slug|
39
+ Jekyll.logger.debug 'Adding chapter:', slug
35
40
  filename = Pathname.new(site.collections['chapters'].relative_directory).join("#{slug}.html")
36
41
  chapter = Jekyll::Document.new(filename.to_path, site: site, collection: site.collections['chapters'])
37
42
  chapter.send(:merge_defaults)
@@ -1,15 +1,16 @@
1
1
  module RageRender
2
- def self.duplicate_page page
3
- Jekyll::Page.new(
4
- page.site,
5
- page.instance_variable_get(:"@base"),
6
- page.instance_variable_get(:"@dir"),
7
- page.name,
8
- )
9
- end
10
-
11
2
  module PaginationGenerator
12
3
  def handle_page page
4
+ page.site.pages << page
5
+ end
6
+
7
+ def duplicate page
8
+ Jekyll::Page.new(
9
+ page.site,
10
+ page.instance_variable_get(:"@base"),
11
+ page.instance_variable_get(:"@dir"),
12
+ page.name,
13
+ )
13
14
  end
14
15
 
15
16
  def generate site
@@ -17,11 +18,11 @@ module RageRender
17
18
  archive.data['number'] = 1
18
19
 
19
20
  num_pages(site).times.each do |number|
20
- paged_archive = RageRender.duplicate_page archive
21
+ paged_archive = duplicate archive
21
22
  paged_archive.data['permalink'] = permalink.gsub(/:number/, (number + 1).to_s)
22
23
  paged_archive.data['number'] = number + 1
24
+ paged_archive.data['hidden'] = true
23
25
  Jekyll.logger.debug 'Paginating:', paged_archive.data['permalink']
24
- site.pages << paged_archive
25
26
  handle_page paged_archive
26
27
  end
27
28
  end
@@ -0,0 +1,20 @@
1
+ def setup_collection site, label, permalink, **kwargs
2
+ site.config['collections'][label.to_s] = {
3
+ 'output' => true,
4
+ 'permalink' => permalink,
5
+ 'sort_by' => 'date',
6
+ }
7
+
8
+ site.config['defaults'].prepend({
9
+ 'scope' => {
10
+ 'path' => '',
11
+ 'type' => label.to_s,
12
+ },
13
+ 'values' => {
14
+ 'permalink' => permalink,
15
+ **kwargs.map do |k, v|
16
+ [k.to_s, v]
17
+ end.to_h,
18
+ },
19
+ })
20
+ end
@@ -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'
@@ -14,26 +15,7 @@ require_relative 'jekyll/overview'
14
15
  require_relative 'jekyll/error'
15
16
  require_relative 'jekyll/search'
16
17
  require_relative 'jekyll/named_data_delegator'
17
-
18
- def setup_collection site, label, permalink, **kwargs
19
- site.config['collections'][label.to_s] = {
20
- 'output' => true,
21
- 'permalink' => permalink,
22
- }
23
-
24
- site.config['defaults'].prepend({
25
- 'scope' => {
26
- 'path' => '',
27
- 'type' => label.to_s,
28
- },
29
- 'values' => {
30
- 'permalink' => permalink,
31
- **kwargs.map do |k, v|
32
- [k.to_s, v]
33
- end.to_h,
34
- },
35
- })
36
- end
18
+ require_relative 'jekyll/setup_collection'
37
19
 
38
20
  Jekyll::Hooks.register :site, :after_init do |site|
39
21
  # This is obviously quite naughty for many reasons,
@@ -46,7 +28,6 @@ Jekyll::Hooks.register :site, :after_init do |site|
46
28
 
47
29
  setup_collection site, :comics, '/:collection/:slug/', layout: 'comic-page', chapter: '0'
48
30
  setup_collection site, :posts, '/blogarchive/:slug/', layout: 'blog-display'
49
- setup_collection site, :chapters, '/archive/:slug/', layout: 'archive'
50
31
 
51
32
  site.config['defaults'].push({
52
33
  'scope' => {
@@ -59,6 +40,7 @@ Jekyll::Hooks.register :site, :after_init do |site|
59
40
  end
60
41
 
61
42
  Jekyll::Hooks.register :site, :post_read do |site|
43
+ Liquid::Template.register_filter(RageRender::TemplateFunctions)
62
44
  site.layouts.each do |(name, layout)|
63
45
  layout.data['layout'] = 'overall' unless name == 'overall'
64
46
  layout.content = RageRender.to_liquid(RageRender::Language.parse(StringIO.new(layout.content))).join
@@ -83,15 +65,15 @@ class RageRender::FrontpageGenerator < Jekyll::Generator
83
65
  collection = site.collections['comics'].docs
84
66
  chapter = comics.docs.last.data['chapter']
85
67
  comics.docs.detect {|c| c.data['chapter'] == chapter }
86
- when 'overview'
68
+ when 'blog', 'archive', 'overview'
87
69
  collection = site.pages
88
- site.pages.detect {|p| p.data["permalink"] == '/overview/index.html' }
70
+ site.pages.detect {|p| p.data["permalink"] == "/#{frontpage}/index.html" }
89
71
  else
90
72
  collection = site.pages
91
73
  site.pages.detect {|p| p.data["slug"] == frontpage }
92
74
  end.dup
93
- index.instance_variable_set(:"@destination", {site.dest => File.join(site.dest, 'index.html')})
94
75
  index.instance_variable_set(:"@data", index.data.dup)
76
+ index.data['permalink'] = '/index.html'
95
77
  index.data['slug'] = 'frontpage'
96
78
  collection << index
97
79
  end
@@ -28,7 +28,7 @@ module RageRender
28
28
  # PATH parses dotted paths: 'dotted.name' => ['dotted', 'name']
29
29
  PATH = IDENT.join('.'.r).even
30
30
 
31
- OPERATOR = %w{= != ~ !~ < > <= >= % !%}.map(&:r).reduce {|a, b| a | b }
31
+ OPERATOR = %w{= != ~ !~ <= >= < > % !%}.map(&:r).reduce {|a, b| a | b }
32
32
 
33
33
  # VARIABLE parses names: 'v:name' => Variable.new(['name'])
34
34
  # VARIABLE parses dotted paths: 'v:dotted.name' => Variable.new(['dotted', 'name'])
@@ -39,6 +39,7 @@ module RageRender
39
39
  # CONDITIONAL tests for falsiness: 'c:!variable' => Conditional.new(true, Variable.new(['variable']), nil, nil)
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
+ # CONDITIONAL tests for greater than: 'c:variable>=3' => Conditional.new(false, Variable.new(['variable']), '>=', '3')
42
43
  CONDITIONAL = ('c:'.r >> seq_(
43
44
  /!?/.r.map {|c| c == '!' },
44
45
  PATH.map {|p| Variable.new(p) },
@@ -1,6 +1,13 @@
1
1
  require_relative 'language'
2
2
 
3
3
  module RageRender
4
+ ERB_OPERATORS = {
5
+ 'add' => '+',
6
+ 'subtract' => '-',
7
+ 'multiply' => '*',
8
+ 'divide' => '/',
9
+ }
10
+
4
11
  def self.to_erb document
5
12
  document.map do |chunk|
6
13
  case chunk
@@ -8,32 +15,73 @@ module RageRender
8
15
  chunk
9
16
 
10
17
  when Language::Variable
11
- "<%= #{chunk.path.join('.')} %>"
18
+ if chunk.path == ['l', 'aiteration']
19
+ '<%= (index+1) %>'
20
+ elsif chunk.path == ['l', 'iteration']
21
+ '<%= index %>'
22
+ else
23
+ "<%= #{chunk.path.join('.')} rescue nil %>"
24
+ end
12
25
 
13
26
  when Language::Conditional
27
+ lhs = chunk.lhs.path.join('.')
14
28
  rhs = case chunk.rhs
15
- when String
16
- "\"#{chunk.rhs}\""
17
29
  when Language::Variable
18
30
  chunk.rhs.path.join('.')
31
+ when /^[0-9]+$/
32
+ chunk.rhs
33
+ when String
34
+ "\"#{chunk.rhs}\""
19
35
  when nil
20
36
  ""
21
37
  end
22
- "<% if #{chunk.reversed ? 'not ' : ''} #{chunk.lhs.path.join('.')} #{chunk.operator} #{rhs} %>"
38
+
39
+ lhs, rhs, operator = case chunk.operator
40
+ when '='
41
+ [lhs, rhs, '==']
42
+ when '%', '!%'
43
+ ["#{lhs} % #{rhs}", 0, if chunk.operator[0] == '!' then '!=' else '==' end]
44
+ when '~', '!~'
45
+ ["#{lhs}.downcase", "#{rhs}.downcase", if chunk.operator[0] == '!' then '!=' else '==' end]
46
+ else
47
+ [lhs, rhs, chunk.operator]
48
+ end
49
+
50
+ if chunk.lhs.is_a?(Language::Variable) && chunk.lhs.path.first == "l"
51
+ case chunk.lhs.path.last
52
+ when "is_first", "is_last"
53
+ lhs = "index"
54
+ rhs = {"is_first" => "0", "is_last" => "(forloop.size - 1)"}[chunk.lhs.path.last]
55
+ operator = "=="
56
+ when "is_even", "is_odd"
57
+ lhs = 'index % 2'
58
+ rhs = '0'
59
+ operator = {'is_even' => '==', 'is_odd' => '!='}[chunk.lhs.path.last]
60
+ end
61
+ end
62
+
63
+ "<% if #{chunk.reversed ? 'not ' : ''} #{lhs} #{operator} #{rhs} %>"
23
64
 
24
65
  when Language::Function
25
66
  params = chunk.params.map do |param|
26
67
  case param
27
68
  when Language::Variable
28
69
  param.path.join('.')
70
+ when /^[0-9]+$/
71
+ param
29
72
  else
30
73
  "\"#{param}\""
31
74
  end
32
75
  end
33
- "<%= #{chunk.name}(#{params.join(', ')}) %>"
76
+
77
+ if ERB_OPERATORS.include? chunk.name
78
+ "<%= #{params.join(ERB_OPERATORS[chunk.name])} %>"
79
+ else
80
+ "<%= #{chunk.name}(#{params.join(', ')}) %>"
81
+ end
34
82
 
35
83
  when Language::Loop
36
- "<% for l in #{chunk.path.join('.')} %>"
84
+ "<% #{chunk.path.join('.')}.each_with_object(#{chunk.path.join('.')}).each_with_index do |(l, forloop), index| %>"
37
85
 
38
86
  when Language::Layout
39
87
  "<%= #{chunk.name} %>"
@@ -6,7 +6,6 @@ module RageRender
6
6
  'subtract' => 'minus',
7
7
  'multiply' => 'times',
8
8
  'divide' => 'divided_by',
9
- 'js' => 'escape', # TODO: check these do the same thing!
10
9
  }
11
10
 
12
11
  def self.render_value value
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.1
4
+ version: 0.1.3
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-05-30 00:00:00.000000000 Z
11
+ date: 2025-07-02 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
@@ -316,6 +331,7 @@ files:
316
331
  - lib/ragerender/jekyll/overview.rb
317
332
  - lib/ragerender/jekyll/pagination.rb
318
333
  - lib/ragerender/jekyll/search.rb
334
+ - lib/ragerender/jekyll/setup_collection.rb
319
335
  - lib/ragerender/language.rb
320
336
  - lib/ragerender/to_erb.rb
321
337
  - lib/ragerender/to_liquid.rb