archival 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823433cd1bdae7bc4e3a6179451a875e7fbe5de17c4ceaa8a0b246cdd9fa3b61
4
- data.tar.gz: 778ef490bf23365d6e1fa1207d0f959ead5a59edbaebebeebe16837981a6c230
3
+ metadata.gz: 7403410bc5164f3be23c22494a716fe7af6d6e805fc38ddb12c920bed918dba7
4
+ data.tar.gz: ebb064928f3295b914609a9751c11cf663ae54af6671b655def56f5d03dab93e
5
5
  SHA512:
6
- metadata.gz: cbbbd3c0ef92fabfcc08608adc376ce1272c36e30aa6f3b6d9e12d0ce5b9dd781b1fac4663262b144a85fe42ad951df396004f08518059820f6fc0c45d8a082c
7
- data.tar.gz: fee79490a8d086eee8779e985483f0b80e75b1ec0df657eb19ed8c74a3a2e5590a8c2e4f74f20ce529e1536e204c3f62574cc5c6ac777bc38c07ebcd1723f3b4
6
+ metadata.gz: 866d33fea5f99757f5a5a01254769ba4a1527341f0f68df03c0daeda38fc642a5177c011d18a902937b72027c2061f92efb0eddea765eae295b520c562188f74
7
+ data.tar.gz: 802638fe184d75b2596bfbb378e02fe8de985bfdda46463dcba009937493faef442c65280307a7d3d25fd3ecbc762584846d305f3e7ceb2cf4bf4949cfe5d057
data/archival.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'archival'
5
- s.version = '0.0.6'
5
+ s.version = '0.0.7'
6
6
  s.summary = 'An incredibly simple CMS for durable websites'
7
7
  s.description = 'https://jesseditson.com/the-simplest-cms-part-1'
8
8
  s.authors = ['Jesse Ditson']
@@ -35,6 +35,8 @@ module Archival
35
35
  @variables = {}
36
36
  @object_types = {}
37
37
  @page_templates = {}
38
+ @dynamic_pages = Set.new
39
+ @dynamic_templates = {}
38
40
 
39
41
  Liquid::Template.file_system = Liquid::LocalFileSystem.new(
40
42
  File.join(@config.root, @config.pages_dir), '_%s.liquid'
@@ -46,8 +48,8 @@ module Archival
46
48
  @object_types = Tomlrb.load_file(objects_definition_file)
47
49
  end
48
50
 
49
- update_pages
50
51
  update_objects
52
+ update_pages
51
53
  end
52
54
 
53
55
  def full_rebuild
@@ -59,6 +61,16 @@ module Archival
59
61
  do_update_pages(File.join(@config.root, @config.pages_dir))
60
62
  end
61
63
 
64
+ def dynamic?(file)
65
+ @dynamic_pages.include? File.basename(file, '.liquid')
66
+ end
67
+
68
+ def template_for_page(template_file)
69
+ content = @file_system.read_template_file(template_file)
70
+ content += dev_mode_content if @config.dev_mode
71
+ Liquid::Template.parse(content)
72
+ end
73
+
62
74
  def do_update_pages(dir, prefix = nil)
63
75
  add_prefix = lambda { |entry|
64
76
  prefix ? File.join(prefix, entry) : entry
@@ -72,14 +84,13 @@ module Archival
72
84
  add_prefix(entry))
73
85
  end
74
86
  elsif File.file? File.join(dir, entry)
75
- if entry.end_with?('.liquid') && !(entry.start_with? '_')
76
- page_name = File.basename(entry,
77
- '.liquid')
78
- template_file = add_prefix.call(page_name)
79
- content = @file_system.read_template_file(template_file)
80
- content += dev_mode_content if @config.dev_mode
81
- @page_templates[add_prefix.call(page_name)] =
82
- Liquid::Template.parse(content)
87
+ page_name = File.basename(entry, '.liquid')
88
+ template_file = add_prefix.call(page_name)
89
+ if dynamic? entry
90
+ @dynamic_templates[template_file] = template_for_page(template_file)
91
+ elsif entry.end_with?('.liquid') && !(entry.start_with? '_')
92
+ @page_templates[template_file] =
93
+ template_for_page(template_file)
83
94
  end
84
95
  end
85
96
  end
@@ -104,6 +115,9 @@ module Archival
104
115
  object[:name] =
105
116
  File.basename(file, '.toml')
106
117
  objects[name][object[:name]] = parse_object(object, definition)
118
+ if definition.key? 'template'
119
+ @dynamic_pages << definition['template']
120
+ end
107
121
  end
108
122
  end
109
123
  end
@@ -147,18 +161,35 @@ module Archival
147
161
  template.render(@variables)
148
162
  end
149
163
 
164
+ def render_dynamic(page, obj)
165
+ template = @dynamic_templates[page]
166
+ template.render(@variables.merge({ page => obj }))
167
+ end
168
+
150
169
  def write_all
151
170
  Dir.mkdir(@config.build_dir) unless File.exist? @config.build_dir
152
171
  @page_templates.each_key do |template|
153
172
  out_dir = File.join(@config.build_dir,
154
173
  File.dirname(template))
155
174
  Dir.mkdir(out_dir) unless File.exist? out_dir
156
- out_path = File.join(@config.build_dir,
175
+ out_path = File.join(out_dir,
157
176
  "#{template}.html")
158
177
  File.open(out_path, 'w+') do |file|
159
178
  file.write(render(template))
160
179
  end
161
180
  end
181
+ @dynamic_pages.each do |page|
182
+ out_dir = File.join(@config.build_dir, page)
183
+ Dir.mkdir(out_dir) unless File.exist? out_dir
184
+ objects = @variables['objects'][page]
185
+ objects.each do |obj|
186
+ out_path = File.join(out_dir, "#{obj[:name]}.html")
187
+ obj['path'] = out_path
188
+ File.open(out_path, 'w+') do |file|
189
+ file.write(render_dynamic(page, obj))
190
+ end
191
+ end
192
+ end
162
193
  return if @config.dev_mode
163
194
 
164
195
  # in production, also copy all assets to the dist folder.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Archival
4
- VERSION = '0.0.6'
4
+ VERSION = '0.0.7'
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "archival",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "An incredibly simple CMS for durable websites",
5
5
  "bin": "build.rb",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archival
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Ditson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-13 00:00:00.000000000 Z
11
+ date: 2021-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: liquid