bridgetown-core 1.0.0.alpha4 → 1.0.0.alpha5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e1d25e217de2040b4951a2143b0968808ebcd755055351f1745579d362d57df
|
4
|
+
data.tar.gz: 61f132206080c941392bcd1f0bb995f349cadea050dba16b6c02753471e48706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff3379e1bf073afd9fd9d5d882cea276c3130fa527e64586faba1c91f8e4d5563b8b59f8d4d3f78abe9589f59511d2c68e824803ba314bbf50a1270df07dfd2
|
7
|
+
data.tar.gz: 7a2afb73e70f34cc0e1e68ee0304c2973b760530ae51f4a6700caad90a897e9c636be4216653b6c08d43accaf9c47380f0217805c7e25c5527ccfafb09510d80
|
@@ -21,7 +21,6 @@ class Bridgetown::Site
|
|
21
21
|
|
22
22
|
configure_cache
|
23
23
|
configure_component_paths
|
24
|
-
configure_include_paths
|
25
24
|
configure_file_read_opts
|
26
25
|
|
27
26
|
self.permalink_style = (config["permalink"] || "pretty").to_sym
|
@@ -176,10 +175,6 @@ class Bridgetown::Site
|
|
176
175
|
@components_load_paths = plugin_components_load_paths + local_components_load_paths
|
177
176
|
end
|
178
177
|
|
179
|
-
def configure_include_paths
|
180
|
-
@includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s))
|
181
|
-
end
|
182
|
-
|
183
178
|
def configure_file_read_opts
|
184
179
|
self.file_read_opts = {}
|
185
180
|
file_read_opts[:encoding] = config["encoding"] if config["encoding"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridgetown-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -476,7 +476,6 @@ files:
|
|
476
476
|
- lib/bridgetown-core/tags/class_map.rb
|
477
477
|
- lib/bridgetown-core/tags/find.rb
|
478
478
|
- lib/bridgetown-core/tags/highlight.rb
|
479
|
-
- lib/bridgetown-core/tags/include.rb
|
480
479
|
- lib/bridgetown-core/tags/link.rb
|
481
480
|
- lib/bridgetown-core/tags/live_reload_dev_js.rb
|
482
481
|
- lib/bridgetown-core/tags/post_url.rb
|
@@ -1,216 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Bridgetown
|
4
|
-
module Tags
|
5
|
-
class IncludeTag < Liquid::Tag
|
6
|
-
class << self
|
7
|
-
attr_accessor :deprecation_message_shown
|
8
|
-
end
|
9
|
-
|
10
|
-
VALID_SYNTAX = %r!
|
11
|
-
([\w-]+)\s*=\s*
|
12
|
-
(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
|
13
|
-
!x.freeze
|
14
|
-
|
15
|
-
# rubocop:disable Lint/MixedRegexpCaptureTypes
|
16
|
-
VARIABLE_SYNTAX = %r!
|
17
|
-
(?<variable>[^{]*(\{\{\s*[\w\-.]+\s*(\|.*)?\}\}[^\s{}]*)+)
|
18
|
-
(?<params>.*)
|
19
|
-
!mx.freeze
|
20
|
-
# rubocop:enable Lint/MixedRegexpCaptureTypes
|
21
|
-
|
22
|
-
FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
|
23
|
-
VALID_FILENAME_CHARS = %r!^[\w/.-]+$!.freeze
|
24
|
-
INVALID_SEQUENCES = %r![./]{2,}!.freeze
|
25
|
-
|
26
|
-
def initialize(tag_name, markup, tokens)
|
27
|
-
super
|
28
|
-
|
29
|
-
unless self.class.deprecation_message_shown
|
30
|
-
Bridgetown.logger.warn "NOTICE: the {% include %} tag is deprecated and" \
|
31
|
-
" will be removed in Bridgetown 1.0. You should" \
|
32
|
-
" use the {% render %} tag instead."
|
33
|
-
self.class.deprecation_message_shown = true
|
34
|
-
end
|
35
|
-
|
36
|
-
matched = markup.strip.match(VARIABLE_SYNTAX)
|
37
|
-
if matched
|
38
|
-
@file = matched["variable"].strip
|
39
|
-
@params = matched["params"].strip
|
40
|
-
else
|
41
|
-
@file, @params = markup.strip.split(%r!\s+!, 2)
|
42
|
-
end
|
43
|
-
validate_params if @params
|
44
|
-
@tag_name = tag_name
|
45
|
-
end
|
46
|
-
|
47
|
-
def syntax_example
|
48
|
-
"{% #{@tag_name} file.ext param='value' param2='value' %}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_params(context)
|
52
|
-
params = {}
|
53
|
-
markup = @params
|
54
|
-
|
55
|
-
while (match = VALID_SYNTAX.match(markup))
|
56
|
-
markup = markup[match.end(0)..-1]
|
57
|
-
|
58
|
-
value = if match[2]
|
59
|
-
match[2].gsub('\\"', '"')
|
60
|
-
elsif match[3]
|
61
|
-
match[3].gsub("\\'", "'")
|
62
|
-
elsif match[4]
|
63
|
-
context[match[4]]
|
64
|
-
end
|
65
|
-
|
66
|
-
params[match[1]] = value
|
67
|
-
end
|
68
|
-
params
|
69
|
-
end
|
70
|
-
|
71
|
-
def validate_file_name(file)
|
72
|
-
return unless INVALID_SEQUENCES.match?(file) || !VALID_FILENAME_CHARS.match?(file)
|
73
|
-
|
74
|
-
raise ArgumentError, <<~MSG
|
75
|
-
Invalid syntax for include tag. File contains invalid characters or sequences:
|
76
|
-
|
77
|
-
#{file}
|
78
|
-
|
79
|
-
Valid syntax:
|
80
|
-
|
81
|
-
#{syntax_example}
|
82
|
-
|
83
|
-
MSG
|
84
|
-
end
|
85
|
-
|
86
|
-
def validate_params
|
87
|
-
return if FULL_VALID_SYNTAX.match?(@params)
|
88
|
-
|
89
|
-
raise ArgumentError, <<~MSG
|
90
|
-
Invalid syntax for include tag:
|
91
|
-
|
92
|
-
#{@params}
|
93
|
-
|
94
|
-
Valid syntax:
|
95
|
-
|
96
|
-
#{syntax_example}
|
97
|
-
|
98
|
-
MSG
|
99
|
-
end
|
100
|
-
|
101
|
-
# Grab file read opts in the context
|
102
|
-
def file_read_opts(context)
|
103
|
-
context.registers[:site].file_read_opts
|
104
|
-
end
|
105
|
-
|
106
|
-
# Render the variable if required
|
107
|
-
def render_variable(context)
|
108
|
-
Liquid::Template.parse(@file).render(context) if VARIABLE_SYNTAX.match?(@file)
|
109
|
-
end
|
110
|
-
|
111
|
-
def tag_includes_dirs(context)
|
112
|
-
context.registers[:site].includes_load_paths.freeze
|
113
|
-
end
|
114
|
-
|
115
|
-
def locate_include_file(context, file)
|
116
|
-
includes_dirs = tag_includes_dirs(context)
|
117
|
-
includes_dirs.each do |dir|
|
118
|
-
path = File.join(dir, file)
|
119
|
-
return path if valid_include_file?(path, dir.to_s)
|
120
|
-
end
|
121
|
-
raise IOError, could_not_locate_message(file, includes_dirs)
|
122
|
-
end
|
123
|
-
|
124
|
-
def render(context)
|
125
|
-
file = render_variable(context) || @file
|
126
|
-
validate_file_name(file)
|
127
|
-
|
128
|
-
path = locate_include_file(context, file)
|
129
|
-
return unless path
|
130
|
-
|
131
|
-
partial = load_cached_partial(path, context)
|
132
|
-
|
133
|
-
context.stack do
|
134
|
-
context["include"] = parse_params(context) if @params
|
135
|
-
begin
|
136
|
-
partial.render!(context)
|
137
|
-
rescue Liquid::Error => e
|
138
|
-
e.template_name = path
|
139
|
-
e.markup_context = "included " if e.markup_context.nil?
|
140
|
-
raise e
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def load_cached_partial(path, context)
|
146
|
-
context.registers[:cached_partials] ||= {}
|
147
|
-
cached_partial = context.registers[:cached_partials]
|
148
|
-
|
149
|
-
if cached_partial.key?(path)
|
150
|
-
cached_partial[path]
|
151
|
-
else
|
152
|
-
unparsed_file = context.registers[:site]
|
153
|
-
.liquid_renderer
|
154
|
-
.file(path)
|
155
|
-
begin
|
156
|
-
cached_partial[path] = unparsed_file.parse(read_file(path, context))
|
157
|
-
rescue Liquid::Error => e
|
158
|
-
e.template_name = path
|
159
|
-
e.markup_context = "included " if e.markup_context.nil?
|
160
|
-
raise e
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def valid_include_file?(path, _dir)
|
166
|
-
File.file?(path)
|
167
|
-
end
|
168
|
-
|
169
|
-
def realpath_prefixed_with?(path, dir)
|
170
|
-
File.exist?(path) && File.realpath(path).start_with?(dir)
|
171
|
-
rescue StandardError
|
172
|
-
false
|
173
|
-
end
|
174
|
-
|
175
|
-
# This method allows to modify the file content by inheriting from the class.
|
176
|
-
def read_file(file, context)
|
177
|
-
File.read(file, **file_read_opts(context))
|
178
|
-
end
|
179
|
-
|
180
|
-
private
|
181
|
-
|
182
|
-
def could_not_locate_message(file, includes_dirs)
|
183
|
-
"Could not locate the included file '#{file}' in any of #{includes_dirs}." \
|
184
|
-
" Ensure it exists in one of those directories."
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class IncludeRelativeTag < IncludeTag
|
189
|
-
def tag_includes_dirs(context)
|
190
|
-
Array(page_path(context)).freeze
|
191
|
-
end
|
192
|
-
|
193
|
-
def page_path(context)
|
194
|
-
if context.registers[:page].nil?
|
195
|
-
context.registers[:site].source
|
196
|
-
else
|
197
|
-
site = context.registers[:site]
|
198
|
-
page_payload = context.registers[:page]
|
199
|
-
resource_path = \
|
200
|
-
if page_payload["collection"].nil?
|
201
|
-
page_payload["path"]
|
202
|
-
else
|
203
|
-
File.join(site.config["collections_dir"], page_payload["path"])
|
204
|
-
end
|
205
|
-
# rubocop:disable Performance/DeleteSuffix
|
206
|
-
resource_path.sub!(%r!/#excerpt\z!, "")
|
207
|
-
# rubocop:enable Performance/DeleteSuffix
|
208
|
-
site.in_source_dir File.dirname(resource_path)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
Liquid::Template.register_tag("include", Bridgetown::Tags::IncludeTag)
|
216
|
-
Liquid::Template.register_tag("include_relative", Bridgetown::Tags::IncludeRelativeTag)
|