bridgetown-core 0.15.0 → 0.16.0.beta1
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 +4 -4
- data/Rakefile +14 -0
- data/bridgetown-core.gemspec +1 -0
- data/lib/bridgetown-core.rb +6 -1
- data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
- data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
- data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
- data/lib/bridgetown-core/concerns/publishable.rb +10 -0
- data/lib/bridgetown-core/concerns/site/configurable.rb +62 -31
- data/lib/bridgetown-core/concerns/site/content.rb +88 -29
- data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
- data/lib/bridgetown-core/concerns/site/processable.rb +12 -10
- data/lib/bridgetown-core/concerns/site/renderable.rb +22 -2
- data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
- data/lib/bridgetown-core/concerns/validatable.rb +59 -0
- data/lib/bridgetown-core/configuration.rb +1 -0
- data/lib/bridgetown-core/converter.rb +34 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +61 -0
- data/lib/bridgetown-core/converters/markdown.rb +6 -23
- data/lib/bridgetown-core/converters/smartypants.rb +0 -10
- data/lib/bridgetown-core/document.rb +8 -52
- data/lib/bridgetown-core/errors.rb +2 -0
- data/lib/bridgetown-core/excerpt.rb +1 -6
- data/lib/bridgetown-core/filters.rb +2 -0
- data/lib/bridgetown-core/layout.rb +24 -1
- data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
- data/lib/bridgetown-core/page.rb +33 -24
- data/lib/bridgetown-core/regenerator.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +38 -12
- data/lib/bridgetown-core/ruby_template_view.rb +84 -0
- data/lib/bridgetown-core/tags/class_map.rb +90 -0
- data/lib/bridgetown-core/tags/webpack_path.rb +48 -16
- data/lib/bridgetown-core/version.rb +2 -2
- metadata +24 -3
- data/lib/bridgetown-core/concerns/convertible.rb +0 -235
@@ -2,38 +2,70 @@
|
|
2
2
|
|
3
3
|
module Bridgetown
|
4
4
|
module Tags
|
5
|
+
# A helper class to help find the path to webpack asset inside of a webpack
|
6
|
+
# manifest file.
|
5
7
|
class WebpackPath < Liquid::Tag
|
6
8
|
include Bridgetown::Filters::URLFilters
|
7
9
|
|
8
|
-
|
10
|
+
# @param tag_name [String] Name of the tag
|
11
|
+
# @param asset_type [String] The type of asset to parse (js, css)
|
12
|
+
# @param options [Hash] An options hash
|
13
|
+
# @return WebpackPath
|
14
|
+
# @see {https://www.rdoc.info/github/Shopify/liquid/Liquid/Tag#initialize-instance_method}
|
15
|
+
def initialize(tag_name, asset_type, options)
|
9
16
|
super
|
10
17
|
|
11
18
|
# js or css
|
12
19
|
@asset_type = asset_type.strip
|
13
20
|
end
|
14
21
|
|
22
|
+
# Render the contents of a webpack manifest file
|
23
|
+
# @param context [String] Root directory that contains the manifest file
|
24
|
+
#
|
25
|
+
# @return [String] Returns "MISSING_WEBPACK_MANIFEST" if the manifest
|
26
|
+
# file isnt found
|
27
|
+
# @return [nil] Returns nil if the asset isnt found
|
28
|
+
# @return [String] Returns the path to the asset if no issues parsing
|
29
|
+
#
|
30
|
+
# @raise [WebpackAssetError] if unable to find css or js in the manifest
|
31
|
+
# file
|
15
32
|
def render(context)
|
16
33
|
@context = context
|
17
34
|
site = context.registers[:site]
|
18
35
|
|
36
|
+
manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
|
37
|
+
|
38
|
+
parse_manifest_file(manifest_file)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def parse_manifest_file(manifest_file)
|
44
|
+
return "MISSING_WEBPACK_MANIFEST" unless File.exist?(manifest_file)
|
45
|
+
|
46
|
+
manifest = JSON.parse(File.read(manifest_file))
|
19
47
|
frontend_path = relative_url("_bridgetown/static")
|
20
48
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
else
|
31
|
-
Bridgetown.logger.error("Unknown Webpack asset type", @asset_type)
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
else
|
35
|
-
"MISSING_WEBPACK_MANIFEST"
|
49
|
+
known_assets = %w(js css)
|
50
|
+
|
51
|
+
if known_assets.include?(@asset_type)
|
52
|
+
asset_path = manifest["main.#{@asset_type}"]
|
53
|
+
|
54
|
+
log_webpack_asset_error(@asset_type) if asset_path.nil?
|
55
|
+
|
56
|
+
asset_path = asset_path.split("/").last
|
57
|
+
return [frontend_path, @asset_type, asset_path].join("/")
|
36
58
|
end
|
59
|
+
|
60
|
+
Bridgetown.logger.error("Unknown Webpack asset type", @asset_type)
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def log_webpack_asset_error(asset_type)
|
65
|
+
error_message = "There was an error parsing your #{asset_type} files. \
|
66
|
+
Please check your #{asset_type} for any errors."
|
67
|
+
|
68
|
+
Bridgetown.logger.warn(Errors::WebpackAssetError, error_message)
|
37
69
|
end
|
38
70
|
end
|
39
71
|
end
|
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: 0.
|
4
|
+
version: 0.16.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bridgetown Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -262,6 +262,20 @@ dependencies:
|
|
262
262
|
- - "~>"
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: '1.0'
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: tilt
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: '2.0'
|
272
|
+
type: :runtime
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: '2.0'
|
265
279
|
description: Bridgetown is a Webpack-aware, Ruby-powered static site generator for
|
266
280
|
the modern Jamstack era
|
267
281
|
email: maintainers@bridgetownrb.com
|
@@ -292,15 +306,20 @@ files:
|
|
292
306
|
- lib/bridgetown-core/commands/registrations.rb
|
293
307
|
- lib/bridgetown-core/commands/serve.rb
|
294
308
|
- lib/bridgetown-core/commands/serve/servlet.rb
|
295
|
-
- lib/bridgetown-core/concerns/
|
309
|
+
- lib/bridgetown-core/concerns/data_accessible.rb
|
310
|
+
- lib/bridgetown-core/concerns/layout_placeable.rb
|
311
|
+
- lib/bridgetown-core/concerns/liquid_renderable.rb
|
312
|
+
- lib/bridgetown-core/concerns/publishable.rb
|
296
313
|
- lib/bridgetown-core/concerns/site/configurable.rb
|
297
314
|
- lib/bridgetown-core/concerns/site/content.rb
|
298
315
|
- lib/bridgetown-core/concerns/site/extensible.rb
|
299
316
|
- lib/bridgetown-core/concerns/site/processable.rb
|
300
317
|
- lib/bridgetown-core/concerns/site/renderable.rb
|
301
318
|
- lib/bridgetown-core/concerns/site/writable.rb
|
319
|
+
- lib/bridgetown-core/concerns/validatable.rb
|
302
320
|
- lib/bridgetown-core/configuration.rb
|
303
321
|
- lib/bridgetown-core/converter.rb
|
322
|
+
- lib/bridgetown-core/converters/erb_templates.rb
|
304
323
|
- lib/bridgetown-core/converters/identity.rb
|
305
324
|
- lib/bridgetown-core/converters/markdown.rb
|
306
325
|
- lib/bridgetown-core/converters/markdown/kramdown_parser.rb
|
@@ -355,8 +374,10 @@ files:
|
|
355
374
|
- lib/bridgetown-core/regenerator.rb
|
356
375
|
- lib/bridgetown-core/related_posts.rb
|
357
376
|
- lib/bridgetown-core/renderer.rb
|
377
|
+
- lib/bridgetown-core/ruby_template_view.rb
|
358
378
|
- lib/bridgetown-core/site.rb
|
359
379
|
- lib/bridgetown-core/static_file.rb
|
380
|
+
- lib/bridgetown-core/tags/class_map.rb
|
360
381
|
- lib/bridgetown-core/tags/highlight.rb
|
361
382
|
- lib/bridgetown-core/tags/include.rb
|
362
383
|
- lib/bridgetown-core/tags/link.rb
|
@@ -1,235 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Convertible provides methods for converting a pagelike item
|
4
|
-
# from a certain type of markup into actual content
|
5
|
-
#
|
6
|
-
# Requires
|
7
|
-
# self.site -> Bridgetown::Site
|
8
|
-
# self.content
|
9
|
-
# self.content=
|
10
|
-
# self.data=
|
11
|
-
# self.ext=
|
12
|
-
# self.output=
|
13
|
-
# self.name
|
14
|
-
# self.path
|
15
|
-
# self.type -> :page or :post
|
16
|
-
|
17
|
-
module Bridgetown
|
18
|
-
module Convertible
|
19
|
-
# Returns the contents as a String.
|
20
|
-
def to_s
|
21
|
-
content || ""
|
22
|
-
end
|
23
|
-
|
24
|
-
# Whether the file is published or not, as indicated in YAML front-matter
|
25
|
-
def published?
|
26
|
-
!(data.key?("published") && data["published"] == false)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Read the YAML frontmatter.
|
30
|
-
#
|
31
|
-
# base - The String path to the dir containing the file.
|
32
|
-
# name - The String filename of the file.
|
33
|
-
# opts - optional parameter to File.read, default at site configs
|
34
|
-
#
|
35
|
-
# Returns nothing.
|
36
|
-
# rubocop:disable Metrics/AbcSize
|
37
|
-
def read_yaml(base, name, opts = {})
|
38
|
-
filename = File.join(base, name)
|
39
|
-
|
40
|
-
begin
|
41
|
-
self.content = File.read(@path || site.in_source_dir(base, name),
|
42
|
-
**Utils.merged_file_read_opts(site, opts))
|
43
|
-
if content =~ Document::YAML_FRONT_MATTER_REGEXP
|
44
|
-
self.content = $POSTMATCH
|
45
|
-
self.data = SafeYAML.load(Regexp.last_match(1))&.with_indifferent_access
|
46
|
-
end
|
47
|
-
rescue Psych::SyntaxError => e
|
48
|
-
Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
|
49
|
-
raise e if site.config["strict_front_matter"]
|
50
|
-
rescue StandardError => e
|
51
|
-
Bridgetown.logger.warn "Error reading file #{filename}: #{e.message}"
|
52
|
-
raise e if site.config["strict_front_matter"]
|
53
|
-
end
|
54
|
-
|
55
|
-
self.data ||= ActiveSupport::HashWithIndifferentAccess.new
|
56
|
-
|
57
|
-
validate_data! filename
|
58
|
-
validate_permalink! filename
|
59
|
-
|
60
|
-
self.data
|
61
|
-
end
|
62
|
-
# rubocop:enable Metrics/AbcSize
|
63
|
-
|
64
|
-
def validate_data!(filename)
|
65
|
-
unless self.data.is_a?(Hash)
|
66
|
-
raise Errors::InvalidYAMLFrontMatterError,
|
67
|
-
"Invalid YAML front matter in #{filename}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def validate_permalink!(filename)
|
72
|
-
if self.data["permalink"]&.to_s&.empty?
|
73
|
-
raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# TODO: this method never seems to get called...why's it here?
|
78
|
-
# Transform the contents based on the content type.
|
79
|
-
#
|
80
|
-
# Returns the transformed contents.
|
81
|
-
def transform
|
82
|
-
_renderer.convert(content)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Determine the extension depending on content_type.
|
86
|
-
#
|
87
|
-
# Returns the String extension for the output file.
|
88
|
-
# e.g. ".html" for an HTML output file.
|
89
|
-
def output_ext
|
90
|
-
_renderer.output_ext
|
91
|
-
end
|
92
|
-
|
93
|
-
# Determine which converter to use based on this convertible's
|
94
|
-
# extension.
|
95
|
-
#
|
96
|
-
# Returns the Converter instance.
|
97
|
-
def converters
|
98
|
-
_renderer.converters
|
99
|
-
end
|
100
|
-
|
101
|
-
# Render Liquid in the content
|
102
|
-
#
|
103
|
-
# content - the raw Liquid content to render
|
104
|
-
# payload - the payload for Liquid
|
105
|
-
# info - the info for Liquid
|
106
|
-
#
|
107
|
-
# Returns the converted content
|
108
|
-
def render_liquid(content, payload, info, path)
|
109
|
-
_renderer.render_liquid(content, payload, info, path)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Convert this Convertible's data to a Hash suitable for use by Liquid.
|
113
|
-
#
|
114
|
-
# Returns the Hash representation of this Convertible.
|
115
|
-
def to_liquid(attrs = nil)
|
116
|
-
further_data = \
|
117
|
-
(attrs || self.class::ATTRIBUTES_FOR_LIQUID).each_with_object({}) do |attribute, hsh|
|
118
|
-
hsh[attribute] = send(attribute)
|
119
|
-
end
|
120
|
-
|
121
|
-
defaults = site.frontmatter_defaults.all(relative_path, type)
|
122
|
-
Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
|
123
|
-
end
|
124
|
-
|
125
|
-
# The type of a document,
|
126
|
-
# i.e., its classname downcase'd and to_sym'd.
|
127
|
-
#
|
128
|
-
# Returns the type of self.
|
129
|
-
def type
|
130
|
-
:pages if is_a?(Page)
|
131
|
-
end
|
132
|
-
|
133
|
-
# returns the owner symbol for hook triggering
|
134
|
-
def hook_owner
|
135
|
-
:pages if is_a?(Page)
|
136
|
-
end
|
137
|
-
|
138
|
-
# TODO: Depricated
|
139
|
-
# Used to determine CoffeeScript and Sass/SCSS files.
|
140
|
-
def asset_file?
|
141
|
-
false
|
142
|
-
end
|
143
|
-
|
144
|
-
# Determine whether the file should be rendered with Liquid.
|
145
|
-
#
|
146
|
-
# Returns true if the file has Liquid Tags or Variables, false otherwise.
|
147
|
-
def render_with_liquid?
|
148
|
-
return false if data["render_with_liquid"] == false
|
149
|
-
|
150
|
-
Bridgetown::Utils.has_liquid_construct?(content)
|
151
|
-
end
|
152
|
-
|
153
|
-
# Determine whether the file should be placed into layouts.
|
154
|
-
#
|
155
|
-
# Returns false if the document is an asset file or if the front matter
|
156
|
-
# specifies `layout: none`
|
157
|
-
def place_in_layout?
|
158
|
-
!(asset_file? || no_layout?)
|
159
|
-
end
|
160
|
-
|
161
|
-
# Checks if the layout specified in the document actually exists
|
162
|
-
#
|
163
|
-
# layout - the layout to check
|
164
|
-
#
|
165
|
-
# Returns true if the layout is invalid, false if otherwise
|
166
|
-
def invalid_layout?(layout)
|
167
|
-
!data["layout"].nil? && layout.nil? && !(is_a? Bridgetown::Excerpt)
|
168
|
-
end
|
169
|
-
|
170
|
-
# Recursively render layouts
|
171
|
-
#
|
172
|
-
# layouts - a list of the layouts
|
173
|
-
# payload - the payload for Liquid
|
174
|
-
# info - the info for Liquid
|
175
|
-
#
|
176
|
-
# Returns nothing
|
177
|
-
def render_all_layouts(layouts, payload, info)
|
178
|
-
_renderer.layouts = layouts
|
179
|
-
self.output = _renderer.place_in_layouts(output, payload, info)
|
180
|
-
ensure
|
181
|
-
@_renderer = nil # this will allow the modifications above to disappear
|
182
|
-
end
|
183
|
-
|
184
|
-
# Add any necessary layouts to this convertible document.
|
185
|
-
#
|
186
|
-
# payload - The site payload Drop or Hash.
|
187
|
-
# layouts - A Hash of {"name" => "layout"}.
|
188
|
-
#
|
189
|
-
# Returns nothing.
|
190
|
-
def do_layout(payload, layouts)
|
191
|
-
_renderer.tap do |renderer|
|
192
|
-
renderer.layouts = layouts
|
193
|
-
renderer.payload = payload
|
194
|
-
end.run
|
195
|
-
ensure
|
196
|
-
@_renderer = nil # this will allow the modifications above to disappear
|
197
|
-
end
|
198
|
-
|
199
|
-
# Write the generated page file to the destination directory.
|
200
|
-
#
|
201
|
-
# dest - The String path to the destination dir.
|
202
|
-
#
|
203
|
-
# Returns nothing.
|
204
|
-
def write(dest)
|
205
|
-
path = destination(dest)
|
206
|
-
FileUtils.mkdir_p(File.dirname(path))
|
207
|
-
Bridgetown.logger.debug "Writing:", path
|
208
|
-
File.write(path, output, mode: "wb")
|
209
|
-
Bridgetown::Hooks.trigger hook_owner, :post_write, self
|
210
|
-
end
|
211
|
-
|
212
|
-
# Accessor for data properties by Liquid.
|
213
|
-
#
|
214
|
-
# property - The String name of the property to retrieve.
|
215
|
-
#
|
216
|
-
# Returns the String value or nil if the property isn't included.
|
217
|
-
def [](property)
|
218
|
-
if self.class::ATTRIBUTES_FOR_LIQUID.include?(property)
|
219
|
-
send(property)
|
220
|
-
else
|
221
|
-
data[property]
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
private
|
226
|
-
|
227
|
-
def _renderer
|
228
|
-
@_renderer ||= Bridgetown::Renderer.new(site, self)
|
229
|
-
end
|
230
|
-
|
231
|
-
def no_layout?
|
232
|
-
data["layout"] == "none"
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|