archival 0.0.0 → 0.0.5

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.
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+
5
+ class Layout < Liquid::Tag
6
+ # Adds a `layout` tag to liquid. Usage:
7
+ #
8
+ # {% layout [layout-name], "key" => "value" %}
9
+ #
10
+ # This will wrap the entire current template in the specified layout, with
11
+ # the arguments provided as local variables.
12
+
13
+ prepend Liquid::Tag::Disableable
14
+ @@layout_cache = {}
15
+
16
+ SYNTAX = /(#{Liquid::QuotedFragment}+)/o.freeze
17
+
18
+ attr_reader :layout_name_expr, :attributes
19
+
20
+ def self.reset_cache
21
+ @@layout_cache = {}
22
+ end
23
+
24
+ def initialize(tag_name, markup, tokens)
25
+ super
26
+
27
+ @page_content = []
28
+ raise 'Invalid layout syntax' unless markup =~ SYNTAX
29
+
30
+ layout_name = Regexp.last_match(1)
31
+ @layout_name_expr = parse_expression(layout_name)
32
+ @attributes = {}
33
+
34
+ markup.scan(Liquid::TagAttributes) do |key, value|
35
+ @attributes[key] = parse_expression(value)
36
+ end
37
+ end
38
+
39
+ def layout_path
40
+ base_path = Dir.pwd
41
+ layout_dir = 'layout'
42
+ layout_path = File.join(base_path, layout_dir)
43
+ raise "Layout dir #{layout_path} not found" unless File.exist? layout_path
44
+
45
+ layout_path
46
+ end
47
+
48
+ def load_layout(layout_name)
49
+ return @@layout_cache[layout_name] if @@layout_cache[layout_name]
50
+
51
+ found_layout = nil
52
+ Dir.entries(layout_path).each do |f|
53
+ next unless File.file? File.join(
54
+ layout_path, f
55
+ )
56
+
57
+ next unless File.basename(f, '.*') == layout_name
58
+ raise "More than one layout named #{layout_name} found." if found_layout
59
+
60
+ found_layout = File.join(layout_path, f)
61
+ end
62
+ raise "No layouts named #{layout_name} found." if found_layout.nil?
63
+
64
+ layout = File.read(found_layout)
65
+ @@layout_cache[layout_name] =
66
+ Liquid::Template.parse(layout)
67
+ @@layout_cache[layout_name]
68
+ end
69
+
70
+ def parse(tokens)
71
+ t = tokens.shift
72
+ while t
73
+ @page_content.push t
74
+ t = tokens.shift
75
+ end
76
+ end
77
+
78
+ def render_to_output_buffer(context, output)
79
+ layout_name = context.evaluate(@layout_name_expr)
80
+ raise 'Bad layout name argument' unless layout_name
81
+
82
+ layout = load_layout(layout_name)
83
+
84
+ old_template_name = context.template_name
85
+ old_partial = context.partial
86
+ begin
87
+ context.template_name = layout_name
88
+ context.partial = true
89
+ context.stack do
90
+ @attributes.each do |key, value|
91
+ context[key] = context.evaluate(value)
92
+ end
93
+ rendered_page = Liquid::Template.parse(@page_content.join)
94
+ .render(context)
95
+ context['page_content'] = rendered_page
96
+ layout.render_to_output_buffer(context,
97
+ output)
98
+ end
99
+ ensure
100
+ context.template_name = old_template_name
101
+ context.partial = old_partial
102
+ end
103
+
104
+ output
105
+ end
106
+ end
data/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "archival",
3
+ "version": "0.0.5",
4
+ "description": "An incredibly simple CMS for durable websites",
5
+ "bin": "build.rb",
6
+ "directories": {
7
+ "lib": "lib"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/jesseditson/archival.git"
12
+ },
13
+ "author": "Jesse Ditson <jesse.ditson@gmail.com>",
14
+ "license": "Unlicense",
15
+ "bugs": {
16
+ "url": "https://github.com/jesseditson/archival/issues"
17
+ },
18
+ "homepage": "https://github.com/jesseditson/archival#readme"
19
+ }
metadata CHANGED
@@ -1,23 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archival
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Ditson
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: tomlrb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
13
69
  description: https://jesseditson.com/the-simplest-cms-part-1
14
70
  email: jesse.ditson@gmail.com
15
- executables: []
71
+ executables:
72
+ - archival
16
73
  extensions: []
17
74
  extra_rdoc_files: []
18
75
  files:
76
+ - ".bundle/config"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".vscode/launch.json"
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - action.yml
86
+ - archival.gemspec
87
+ - bin/archival
88
+ - bin/bundle
89
+ - bin/htmldiff
90
+ - bin/ldiff
91
+ - bin/listen
92
+ - bin/rake
93
+ - bin/redcarpet
94
+ - bin/rspec
95
+ - bin/rubocop
96
+ - bin/ruby-parse
97
+ - bin/ruby-rewrite
98
+ - bin/setup
99
+ - exe/archival
100
+ - helper/js/archival-helper.js
19
101
  - lib/archival.rb
20
- homepage: https://rubygems.org/gems/archival
102
+ - lib/archival/builder.rb
103
+ - lib/archival/config.rb
104
+ - lib/archival/helper_server.rb
105
+ - lib/archival/listen.rb
106
+ - lib/archival/logger.rb
107
+ - lib/archival/rake_tasks.rb
108
+ - lib/archival/version.rb
109
+ - lib/tags/layout.rb
110
+ - package.json
111
+ homepage: https://archival.dev
21
112
  licenses:
22
113
  - Unlicense
23
114
  metadata: {}
@@ -29,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
120
  requirements:
30
121
  - - ">="
31
122
  - !ruby/object:Gem::Version
32
- version: '0'
123
+ version: '2.5'
33
124
  required_rubygems_version: !ruby/object:Gem::Requirement
34
125
  requirements:
35
126
  - - ">="