ragerender 0.1.1 → 0.1.2

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: f50082e3a10f4085a8bec12f5dbc5386af2fa209239abffc1a01c051e6ed3ea4
4
+ data.tar.gz: eb27a5b3de3f325b9c998174c7e2be1a37ebe953c3595431833619d2ff261fdb
5
5
  SHA512:
6
- metadata.gz: 6dcfa8001b76f24b00360b52da55889307e2ada02b93b5fe9f1dfa8561b28f3c2cf6939a477977f27c356c43a1e7a596ba7d5007f371a689b9b17b2ccb29e7d1
7
- data.tar.gz: 687ccd2273c923d13178dce12e9de7afba951e6bcabe576c9c1fe67e6a2a21b987b99dda8a73bd95897ca930cd05b96e7029af377e48e7387e6fd3f1847892e4
6
+ metadata.gz: 1e0a5e77617c32868ca965f36e903ee208442de230d620499802d2dbad9c2c110341feb32077b5cc7a41fee69f4a81a95f307bff405b9098c13c28b45fa96dd8
7
+ data.tar.gz: 8d41968f7a7ff34622c489fad7731e7dcf8a8573aea3871bf869538eb086503c7116102c87291a395123e23a6658affa4939f497a8b214846b56a8084dc97a20
@@ -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,19 @@
1
+ def setup_collection site, label, permalink, **kwargs
2
+ site.config['collections'][label.to_s] = {
3
+ 'output' => true,
4
+ 'permalink' => permalink,
5
+ }
6
+
7
+ site.config['defaults'].prepend({
8
+ 'scope' => {
9
+ 'path' => '',
10
+ 'type' => label.to_s,
11
+ },
12
+ 'values' => {
13
+ 'permalink' => permalink,
14
+ **kwargs.map do |k, v|
15
+ [k.to_s, v]
16
+ end.to_h,
17
+ },
18
+ })
19
+ end
@@ -14,26 +14,7 @@ require_relative 'jekyll/overview'
14
14
  require_relative 'jekyll/error'
15
15
  require_relative 'jekyll/search'
16
16
  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
17
+ require_relative 'jekyll/setup_collection'
37
18
 
38
19
  Jekyll::Hooks.register :site, :after_init do |site|
39
20
  # This is obviously quite naughty for many reasons,
@@ -46,7 +27,6 @@ Jekyll::Hooks.register :site, :after_init do |site|
46
27
 
47
28
  setup_collection site, :comics, '/:collection/:slug/', layout: 'comic-page', chapter: '0'
48
29
  setup_collection site, :posts, '/blogarchive/:slug/', layout: 'blog-display'
49
- setup_collection site, :chapters, '/archive/:slug/', layout: 'archive'
50
30
 
51
31
  site.config['defaults'].push({
52
32
  'scope' => {
@@ -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} %>"
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.2
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-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rsec
@@ -316,6 +316,7 @@ files:
316
316
  - lib/ragerender/jekyll/overview.rb
317
317
  - lib/ragerender/jekyll/pagination.rb
318
318
  - lib/ragerender/jekyll/search.rb
319
+ - lib/ragerender/jekyll/setup_collection.rb
319
320
  - lib/ragerender/language.rb
320
321
  - lib/ragerender/to_erb.rb
321
322
  - lib/ragerender/to_liquid.rb