bridgetown-core 0.15.0.beta4 → 0.17.0
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 +3 -1
- data/lib/bridgetown-core.rb +7 -1
- data/lib/bridgetown-core/commands/concerns/actions.rb +2 -1
- data/lib/bridgetown-core/commands/console.rb +4 -4
- 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 +66 -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/localizable.rb +20 -0
- data/lib/bridgetown-core/concerns/site/processable.rb +12 -10
- data/lib/bridgetown-core/concerns/site/renderable.rb +21 -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 +5 -2
- data/lib/bridgetown-core/converter.rb +34 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +78 -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/drops/site_drop.rb +1 -1
- data/lib/bridgetown-core/errors.rb +2 -0
- data/lib/bridgetown-core/excerpt.rb +1 -6
- data/lib/bridgetown-core/filters.rb +3 -48
- data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
- data/lib/bridgetown-core/frontmatter_defaults.rb +17 -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/plugin_manager.rb +10 -2
- data/lib/bridgetown-core/reader.rb +1 -0
- data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
- data/lib/bridgetown-core/readers/data_reader.rb +1 -0
- data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
- data/lib/bridgetown-core/readers/page_reader.rb +1 -0
- data/lib/bridgetown-core/readers/post_reader.rb +1 -0
- data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
- data/lib/bridgetown-core/regenerator.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +38 -12
- data/lib/bridgetown-core/ruby_template_view.rb +102 -0
- data/lib/bridgetown-core/site.rb +2 -0
- data/lib/bridgetown-core/tags/class_map.rb +90 -0
- data/lib/bridgetown-core/tags/find.rb +86 -0
- data/lib/bridgetown-core/tags/t.rb +14 -0
- data/lib/bridgetown-core/tags/webpack_path.rb +19 -22
- data/lib/bridgetown-core/utils.rb +55 -2
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/site_template/src/_layouts/{default.html → default.liquid} +0 -0
- data/lib/site_template/src/_layouts/{home.html → home.liquid} +0 -0
- data/lib/site_template/src/_layouts/{page.html → page.liquid} +0 -0
- data/lib/site_template/src/_layouts/{post.html → post.liquid} +0 -0
- metadata +50 -10
- data/lib/bridgetown-core/concerns/convertible.rb +0 -235
@@ -68,12 +68,20 @@ module Bridgetown
|
|
68
68
|
# If that exact package hasn't been installed, execute yarn add
|
69
69
|
#
|
70
70
|
# Returns nothing.
|
71
|
-
def self.install_yarn_dependencies(required_gems)
|
71
|
+
def self.install_yarn_dependencies(required_gems, single_gemname = nil)
|
72
72
|
return unless File.exist?("package.json")
|
73
73
|
|
74
74
|
package_json = JSON.parse(File.read("package.json"))
|
75
75
|
|
76
|
-
|
76
|
+
gems_to_search = if single_gemname
|
77
|
+
required_gems.select do |loaded_gem|
|
78
|
+
loaded_gem.to_spec&.name == single_gemname.to_s
|
79
|
+
end
|
80
|
+
else
|
81
|
+
required_gems
|
82
|
+
end
|
83
|
+
|
84
|
+
gems_to_search.each do |loaded_gem|
|
77
85
|
yarn_dependency = find_yarn_dependency(loaded_gem)
|
78
86
|
next unless add_yarn_dependency?(yarn_dependency, package_json)
|
79
87
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
class DefaultsReader
|
5
|
+
attr_reader :site, :path_defaults
|
6
|
+
|
7
|
+
def initialize(site)
|
8
|
+
@site = site
|
9
|
+
@path_defaults = ActiveSupport::HashWithIndifferentAccess.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def read
|
13
|
+
return unless File.directory?(site.source)
|
14
|
+
|
15
|
+
entries = Dir.chdir(site.source) do
|
16
|
+
Dir["**/_defaults.{yaml,yml,json}"]
|
17
|
+
end
|
18
|
+
|
19
|
+
entries.each do |entry|
|
20
|
+
path = @site.in_source_dir(entry)
|
21
|
+
@path_defaults[File.dirname(path) + File::SEPARATOR] = SafeYAML.load_file(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
@path_defaults
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -163,7 +163,7 @@ module Bridgetown
|
|
163
163
|
end
|
164
164
|
|
165
165
|
def regenerate_page?(document)
|
166
|
-
document.
|
166
|
+
document.data["regenerate"] ||
|
167
167
|
source_modified_or_dest_missing?(
|
168
168
|
site.in_source_dir(document.relative_path), document.destination(@site.dest)
|
169
169
|
)
|
@@ -58,6 +58,7 @@ module Bridgetown
|
|
58
58
|
Bridgetown.logger.debug "Rendering:", document.relative_path
|
59
59
|
|
60
60
|
assign_pages!
|
61
|
+
# TODO: this can be eliminated I think:
|
61
62
|
assign_current_document!
|
62
63
|
assign_highlighter_options!
|
63
64
|
assign_layout_data!
|
@@ -83,7 +84,7 @@ module Bridgetown
|
|
83
84
|
end
|
84
85
|
|
85
86
|
Bridgetown.logger.debug "Rendering Markup:", document.relative_path
|
86
|
-
output = convert(output.to_s)
|
87
|
+
output = convert(output.to_s, document)
|
87
88
|
document.content = output
|
88
89
|
|
89
90
|
if document.place_in_layout?
|
@@ -140,9 +141,13 @@ module Bridgetown
|
|
140
141
|
# Convert the document using the converters which match this renderer's document.
|
141
142
|
#
|
142
143
|
# Returns String the converted content.
|
143
|
-
def convert(content)
|
144
|
+
def convert(content, document)
|
144
145
|
converters.reduce(content) do |output, converter|
|
145
|
-
converter.convert
|
146
|
+
if converter.method(:convert).arity == 1
|
147
|
+
converter.convert output
|
148
|
+
else
|
149
|
+
converter.convert output, document
|
150
|
+
end
|
146
151
|
rescue StandardError => e
|
147
152
|
Bridgetown.logger.error "Conversion error:",
|
148
153
|
"#{converter.class} encountered an error while "\
|
@@ -202,17 +207,38 @@ module Bridgetown
|
|
202
207
|
# Render layout content into document.output
|
203
208
|
#
|
204
209
|
# Returns String rendered content
|
210
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
205
211
|
def render_layout(output, layout, liquid_context)
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
212
|
+
if layout.render_with_liquid?
|
213
|
+
payload["content"] = output
|
214
|
+
payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {})
|
215
|
+
|
216
|
+
render_liquid(
|
217
|
+
layout.content,
|
218
|
+
payload,
|
219
|
+
liquid_context,
|
220
|
+
layout.path
|
221
|
+
)
|
222
|
+
else
|
223
|
+
layout_converters ||= site.converters.select { |c| c.matches(layout.ext) }.sort
|
224
|
+
|
225
|
+
layout_content = layout.content.dup
|
226
|
+
layout_converters.reduce(layout_content) do |layout_output, converter|
|
227
|
+
next(layout_output) unless converter.method(:convert).arity == 2
|
228
|
+
|
229
|
+
layout.current_document = document
|
230
|
+
layout.current_document_output = output
|
231
|
+
converter.convert layout_output, layout
|
232
|
+
rescue StandardError => e
|
233
|
+
Bridgetown.logger.error "Conversion error:",
|
234
|
+
"#{converter.class} encountered an error while "\
|
235
|
+
"converting '#{document.relative_path}':"
|
236
|
+
Bridgetown.logger.error("", e.to_s)
|
237
|
+
raise e
|
238
|
+
end
|
239
|
+
end
|
215
240
|
end
|
241
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
216
242
|
|
217
243
|
def add_regenerator_dependencies(layout)
|
218
244
|
return unless document.write?
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "digest"
|
4
|
+
require "active_support/core_ext/hash/keys"
|
5
|
+
|
6
|
+
module Bridgetown
|
7
|
+
class RubyTemplateView
|
8
|
+
class Helpers
|
9
|
+
include Bridgetown::Filters
|
10
|
+
|
11
|
+
Context = Struct.new(:registers)
|
12
|
+
|
13
|
+
def initialize(site)
|
14
|
+
@site = site
|
15
|
+
|
16
|
+
# duck typing for Liquid context
|
17
|
+
@context = Context.new({ site: @site })
|
18
|
+
end
|
19
|
+
|
20
|
+
def webpack_path(asset_type)
|
21
|
+
Bridgetown::Utils.parse_webpack_manifest_file(@site, asset_type.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def t(*args)
|
25
|
+
I18n.send :t, *args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_reader :layout, :page, :site, :content
|
30
|
+
|
31
|
+
def initialize(convertible)
|
32
|
+
if convertible.is_a?(Layout)
|
33
|
+
@layout = convertible
|
34
|
+
@page = layout.current_document
|
35
|
+
@content = layout.current_document_output
|
36
|
+
else
|
37
|
+
@page = convertible
|
38
|
+
end
|
39
|
+
@site = page.site
|
40
|
+
end
|
41
|
+
|
42
|
+
def partial(_partial_name, _options = {})
|
43
|
+
raise "Must be implemented in a subclass"
|
44
|
+
end
|
45
|
+
|
46
|
+
def site_drop
|
47
|
+
site.site_payload.site
|
48
|
+
end
|
49
|
+
|
50
|
+
def liquid_render(component, options = {})
|
51
|
+
render_statement = _render_statement(component, options)
|
52
|
+
|
53
|
+
template = site.liquid_renderer.file(
|
54
|
+
"#{page.path}.#{Digest::SHA2.hexdigest(render_statement)}"
|
55
|
+
).parse(render_statement)
|
56
|
+
template.warnings.each do |e|
|
57
|
+
Bridgetown.logger.warn "Liquid Warning:",
|
58
|
+
LiquidRenderer.format_error(e, path || document.relative_path)
|
59
|
+
end
|
60
|
+
template.render!(options.deep_stringify_keys, _liquid_context)
|
61
|
+
end
|
62
|
+
|
63
|
+
def helpers
|
64
|
+
@helpers ||= Helpers.new(@site)
|
65
|
+
end
|
66
|
+
|
67
|
+
def method_missing(method, *args, &block)
|
68
|
+
if helpers.respond_to?(method.to_sym)
|
69
|
+
helpers.send method.to_sym, *args, &block
|
70
|
+
else
|
71
|
+
super
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_missing?(method, include_private = false)
|
76
|
+
helpers.respond_to?(method.to_sym, include_private) || super
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def _render_statement(component, options)
|
82
|
+
render_statement = ["{% render \"#{component}\""]
|
83
|
+
unless options.empty?
|
84
|
+
render_statement << ", " + options.keys.map { |k| "#{k}: #{k}" }.join(", ")
|
85
|
+
end
|
86
|
+
render_statement << " %}"
|
87
|
+
render_statement.join
|
88
|
+
end
|
89
|
+
|
90
|
+
def _liquid_context
|
91
|
+
{
|
92
|
+
registers: {
|
93
|
+
site: site,
|
94
|
+
page: page,
|
95
|
+
cached_partials: Bridgetown::Renderer.cached_partials,
|
96
|
+
},
|
97
|
+
strict_filters: site.config["liquid"]["strict_filters"],
|
98
|
+
strict_variables: site.config["liquid"]["strict_variables"],
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/bridgetown-core/site.rb
CHANGED
@@ -7,6 +7,7 @@ module Bridgetown
|
|
7
7
|
include Configurable
|
8
8
|
include Content
|
9
9
|
include Extensible
|
10
|
+
include Localizable
|
10
11
|
include Processable
|
11
12
|
include Renderable
|
12
13
|
include Writable
|
@@ -25,6 +26,7 @@ module Bridgetown
|
|
25
26
|
# config - A Hash containing site configuration details.
|
26
27
|
def initialize(config)
|
27
28
|
self.config = config
|
29
|
+
locale
|
28
30
|
|
29
31
|
@plugin_manager = PluginManager.new(self)
|
30
32
|
@cleaner = Cleaner.new(self)
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
|
5
|
+
module Bridgetown
|
6
|
+
module Tags
|
7
|
+
# A ClassMap class is meant to take a hash and append styles based on if the
|
8
|
+
# value is truthy or falsy
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# center-var = true
|
12
|
+
# small-var = nil
|
13
|
+
#
|
14
|
+
# # input
|
15
|
+
# <div class="{% class_map has-centered-text: center-var, is-small: small-var %}">
|
16
|
+
# Text
|
17
|
+
# </div>
|
18
|
+
#
|
19
|
+
# # output
|
20
|
+
# <div class="has-centered-text">
|
21
|
+
# Text
|
22
|
+
# </div>
|
23
|
+
class ClassMap < Liquid::Tag
|
24
|
+
# @see https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
|
25
|
+
FALSE_VALUES = [
|
26
|
+
nil, "nil", "NIL", false, 0, "0", :"0", "f", :f, "F", :F, "false",
|
27
|
+
false, "FALSE", :FALSE,
|
28
|
+
].to_set.freeze
|
29
|
+
|
30
|
+
# @param tag_name [String] The name to use for the tag
|
31
|
+
# @param input [String] The input to the tag
|
32
|
+
# @param tokens [Hash] A hash of config tokens for Liquid.
|
33
|
+
#
|
34
|
+
#
|
35
|
+
# @return [ClassMap] Returns a ClassMap object
|
36
|
+
def initialize(tag_name, input, tokens)
|
37
|
+
super
|
38
|
+
@input = input
|
39
|
+
end
|
40
|
+
|
41
|
+
def render(context)
|
42
|
+
class_map(@input, context)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def class_map(string, context)
|
48
|
+
ary = []
|
49
|
+
|
50
|
+
string.split(%r!,\s+!).each do |item|
|
51
|
+
kv_pair = item.split(%r!:\s+!)
|
52
|
+
klass = kv_pair[0]
|
53
|
+
variable = kv_pair[1]
|
54
|
+
|
55
|
+
# Check if a user wants the opposite of the variable
|
56
|
+
if variable[0] == "!"
|
57
|
+
check_opposite = true
|
58
|
+
variable.slice!(1..-1)
|
59
|
+
end
|
60
|
+
|
61
|
+
variable = find_variable(context, variable)
|
62
|
+
|
63
|
+
if check_opposite
|
64
|
+
ary.push(klass) if FALSE_VALUES.include?(variable)
|
65
|
+
else
|
66
|
+
ary.push(klass) unless FALSE_VALUES.include?(variable)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
ary.join(" ")
|
71
|
+
|
72
|
+
# Gracefully handle if syntax is improper
|
73
|
+
rescue NoMethodError
|
74
|
+
"invalid-class-map"
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_variable(context, variable)
|
78
|
+
lookup = context
|
79
|
+
|
80
|
+
variable.split(".").each do |value|
|
81
|
+
lookup = lookup[value.strip]
|
82
|
+
end
|
83
|
+
|
84
|
+
lookup || nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Liquid::Template.register_tag("class_map", Bridgetown::Tags::ClassMap)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Tags
|
5
|
+
class Find < Liquid::Tag
|
6
|
+
include Bridgetown::Filters::ConditionHelpers
|
7
|
+
include Bridgetown::LiquidExtensions
|
8
|
+
|
9
|
+
SYNTAX = %r!^(.*?) (where|in) (.*?),(.*)$!.freeze
|
10
|
+
CONDITIONS_SEP = "~FINDSEP~"
|
11
|
+
|
12
|
+
def initialize(tag_name, markup, tokens)
|
13
|
+
super
|
14
|
+
if markup.strip =~ SYNTAX
|
15
|
+
@new_var_name = Regexp.last_match(1).strip
|
16
|
+
@single_or_group = Regexp.last_match(2)
|
17
|
+
@arr_name = Regexp.last_match(3).strip
|
18
|
+
@conditions = process_conditions(Regexp.last_match(4).strip)
|
19
|
+
else
|
20
|
+
raise SyntaxError, <<~MSG
|
21
|
+
Syntax Error in tag 'find' while parsing the following markup:
|
22
|
+
|
23
|
+
#{markup}
|
24
|
+
|
25
|
+
Valid syntax: find <varname> where|in <array>, <condition(s)>
|
26
|
+
MSG
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def render(context)
|
31
|
+
@group = lookup_variable(context, @arr_name)
|
32
|
+
return "" unless @group.respond_to?(:select)
|
33
|
+
|
34
|
+
@group = @group.values if @group.is_a?(Hash)
|
35
|
+
|
36
|
+
expression = @conditions.split(CONDITIONS_SEP).map do |condition|
|
37
|
+
"__find_tag_item__.#{condition.strip}"
|
38
|
+
end.join(" and ")
|
39
|
+
@liquid_condition = parse_condition(expression)
|
40
|
+
|
41
|
+
context[@new_var_name] = if @single_or_group == "where"
|
42
|
+
group_evaluate(context)
|
43
|
+
else
|
44
|
+
single_evaluate(context)
|
45
|
+
end
|
46
|
+
|
47
|
+
""
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def process_conditions(conditions)
|
53
|
+
processed_conditions = +""
|
54
|
+
in_quotes = false
|
55
|
+
|
56
|
+
conditions.each_char do |c|
|
57
|
+
in_quotes = !in_quotes if c == '"'
|
58
|
+
|
59
|
+
processed_conditions << (c == "," && !in_quotes ? CONDITIONS_SEP : c)
|
60
|
+
end
|
61
|
+
|
62
|
+
processed_conditions
|
63
|
+
end
|
64
|
+
|
65
|
+
def group_evaluate(context)
|
66
|
+
context.stack do
|
67
|
+
@group.select do |object|
|
68
|
+
context["__find_tag_item__"] = object
|
69
|
+
@liquid_condition.evaluate(context)
|
70
|
+
end
|
71
|
+
end || []
|
72
|
+
end
|
73
|
+
|
74
|
+
def single_evaluate(context)
|
75
|
+
context.stack do
|
76
|
+
@group.find do |object|
|
77
|
+
context["__find_tag_item__"] = object
|
78
|
+
@liquid_condition.evaluate(context)
|
79
|
+
end
|
80
|
+
end || nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Liquid::Template.register_tag("find", Bridgetown::Tags::Find)
|