bridgetown-core 0.19.0 → 0.21.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/bridgetown +6 -0
- data/bridgetown-core.gemspec +3 -4
- data/lib/bridgetown-core.rb +34 -12
- data/lib/bridgetown-core/cleaner.rb +7 -1
- data/lib/bridgetown-core/collection.rb +176 -77
- data/lib/bridgetown-core/commands/apply.rb +4 -3
- data/lib/bridgetown-core/commands/base.rb +9 -0
- data/lib/bridgetown-core/commands/concerns/actions.rb +0 -5
- data/lib/bridgetown-core/commands/configure.rb +66 -0
- data/lib/bridgetown-core/commands/console.rb +4 -0
- data/lib/bridgetown-core/commands/new.rb +8 -0
- data/lib/bridgetown-core/commands/plugins.rb +1 -0
- data/lib/bridgetown-core/component.rb +178 -0
- data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
- data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
- data/lib/bridgetown-core/concerns/site/content.rb +56 -15
- data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
- data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
- data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
- data/lib/bridgetown-core/concerns/validatable.rb +1 -4
- data/lib/bridgetown-core/configuration.rb +49 -28
- data/lib/bridgetown-core/configurations/.keep +0 -0
- data/lib/bridgetown-core/configurations/bt-postcss.rb +26 -0
- data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +21 -0
- data/lib/bridgetown-core/configurations/minitesting.rb +95 -0
- data/lib/bridgetown-core/configurations/netlify.rb +6 -0
- data/lib/bridgetown-core/configurations/netlify/netlify.sh +14 -0
- data/lib/bridgetown-core/configurations/netlify/netlify.toml +44 -0
- data/lib/bridgetown-core/configurations/purgecss.rb +49 -0
- data/lib/bridgetown-core/configurations/stimulus.rb +49 -0
- data/lib/bridgetown-core/configurations/swup.rb +37 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +29 -0
- data/lib/bridgetown-core/configurations/tailwindcss/css_imports.css +4 -0
- data/lib/bridgetown-core/configurations/tailwindcss/postcss.config.js +12 -0
- data/lib/bridgetown-core/configurations/turbo.rb +16 -0
- data/lib/bridgetown-core/converter.rb +23 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +50 -41
- data/lib/bridgetown-core/converters/identity.rb +0 -9
- data/lib/bridgetown-core/converters/markdown.rb +14 -4
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +3 -0
- data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
- data/lib/bridgetown-core/current.rb +10 -0
- data/lib/bridgetown-core/document.rb +6 -14
- data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
- data/lib/bridgetown-core/drops/page_drop.rb +4 -0
- data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
- data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
- data/lib/bridgetown-core/drops/site_drop.rb +33 -8
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
- data/lib/bridgetown-core/entry_filter.rb +10 -23
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters.rb +3 -2
- data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
- data/lib/bridgetown-core/generator.rb +2 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
- data/lib/bridgetown-core/helpers.rb +48 -9
- data/lib/bridgetown-core/layout.rb +28 -13
- data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
- data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
- data/lib/bridgetown-core/model/base.rb +138 -0
- data/lib/bridgetown-core/model/builder_origin.rb +40 -0
- data/lib/bridgetown-core/model/origin.rb +38 -0
- data/lib/bridgetown-core/model/repo_origin.rb +126 -0
- data/lib/bridgetown-core/page.rb +9 -1
- data/lib/bridgetown-core/plugin.rb +2 -26
- data/lib/bridgetown-core/plugin_manager.rb +0 -2
- data/lib/bridgetown-core/publisher.rb +7 -1
- data/lib/bridgetown-core/reader.rb +26 -13
- data/lib/bridgetown-core/readers/data_reader.rb +3 -4
- data/lib/bridgetown-core/readers/post_reader.rb +1 -1
- data/lib/bridgetown-core/regenerator.rb +8 -1
- data/lib/bridgetown-core/related_posts.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +6 -13
- data/lib/bridgetown-core/resource/base.rb +317 -0
- data/lib/bridgetown-core/resource/destination.rb +49 -0
- data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
- data/lib/bridgetown-core/resource/relations.rb +132 -0
- data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
- data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
- data/lib/bridgetown-core/resource/transformer.rb +175 -0
- data/lib/bridgetown-core/ruby_template_view.rb +12 -4
- data/lib/bridgetown-core/site.rb +9 -1
- data/lib/bridgetown-core/static_file.rb +33 -10
- data/lib/bridgetown-core/url.rb +1 -0
- data/lib/bridgetown-core/utils.rb +48 -41
- data/lib/bridgetown-core/utils/platforms.rb +1 -0
- data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
- data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +1 -1
- data/lib/site_template/README.md +70 -0
- data/lib/site_template/package.json.erb +2 -2
- data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
- data/lib/site_template/webpack.config.js.erb +26 -6
- metadata +55 -39
- data/lib/bridgetown-core/page_without_a_file.rb +0 -17
- data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
- data/lib/bridgetown-core/utils/exec.rb +0 -26
- data/lib/bridgetown-core/utils/internet.rb +0 -37
- data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -32,6 +32,18 @@ class Bridgetown::Site
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def resources_grouped_by_taxonomy(taxonomy)
|
36
|
+
@post_attr_hash[taxonomy.label] ||= begin
|
37
|
+
taxonomy.terms.transform_values { |terms| terms.map(&:resource).sort.reverse }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def taxonomies
|
42
|
+
taxonomy_types.transform_values do |taxonomy|
|
43
|
+
resources_grouped_by_taxonomy(taxonomy)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
35
47
|
# Returns a hash of "tags" using {#post_attr_hash} where each tag is a key
|
36
48
|
# and each value is a post which contains the key.
|
37
49
|
# @example
|
@@ -41,7 +53,7 @@ class Bridgetown::Site
|
|
41
53
|
# @return [Hash{String, Array<Post>}] Returns a hash of all tags and their corresponding posts
|
42
54
|
# @see post_attr_hash
|
43
55
|
def tags
|
44
|
-
post_attr_hash("tags")
|
56
|
+
uses_resource? ? taxonomies.tag : post_attr_hash("tags")
|
45
57
|
end
|
46
58
|
|
47
59
|
# Returns a hash of "categories" using {#post_attr_hash} where each tag is
|
@@ -54,7 +66,7 @@ class Bridgetown::Site
|
|
54
66
|
# their corresponding posts
|
55
67
|
# @see post_attr_hash
|
56
68
|
def categories
|
57
|
-
post_attr_hash("categories")
|
69
|
+
uses_resource? ? taxonomies.category : post_attr_hash("categories")
|
58
70
|
end
|
59
71
|
|
60
72
|
# Returns the value of `data["site_metadata"]` or creates a new instance of
|
@@ -121,19 +133,25 @@ class Bridgetown::Site
|
|
121
133
|
# An array of collection names.
|
122
134
|
# @return [Array<String>] an array of collection names from the configuration,
|
123
135
|
# or an empty array if the `config["collections"]` key is not set.
|
124
|
-
# @raise ArgumentError Raise an error if `config["collections"]` is not
|
125
|
-
# an Array or a Hash
|
126
136
|
def collection_names
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
+
Array(config.collections&.keys)
|
138
|
+
end
|
139
|
+
|
140
|
+
# @return [Array<Bridgetown::Resource::TaxonomyType>]
|
141
|
+
def taxonomy_types
|
142
|
+
@taxonomy_types ||= config.taxonomies.map do |label, key_or_metadata|
|
143
|
+
key = key_or_metadata
|
144
|
+
tax_metadata = if key_or_metadata.is_a? Hash
|
145
|
+
key = key_or_metadata["key"]
|
146
|
+
key_or_metadata.reject { |k| k == "key" }
|
147
|
+
else
|
148
|
+
HashWithDotAccess::Hash.new
|
149
|
+
end
|
150
|
+
|
151
|
+
[label, Bridgetown::Resource::TaxonomyType.new(
|
152
|
+
site: self, label: label, key: key, metadata: tax_metadata
|
153
|
+
),]
|
154
|
+
end.to_h.with_dot_access
|
137
155
|
end
|
138
156
|
|
139
157
|
# Get all documents.
|
@@ -155,11 +173,28 @@ class Bridgetown::Site
|
|
155
173
|
documents.select(&:write?)
|
156
174
|
end
|
157
175
|
|
158
|
-
# Get all
|
176
|
+
# Get all loaded resources.
|
177
|
+
# @return [Array<Bridgetown::Resource::Base>] an array of resources
|
178
|
+
def resources
|
179
|
+
collections.each_with_object(Set.new) do |(_, collection), set|
|
180
|
+
set.merge(collection.resources)
|
181
|
+
end.to_a
|
182
|
+
end
|
183
|
+
|
184
|
+
def resources_to_write
|
185
|
+
resources.select(&:write?)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Get all posts. Deprecated, to be removed in v1.0.
|
159
189
|
#
|
160
190
|
# @return [Collection] Returns {#collections}`["posts"]`, creating it if need be
|
161
191
|
# @see Collection
|
162
192
|
def posts
|
193
|
+
unless @wrote_deprecation_msg
|
194
|
+
Bridgetown::Deprecator.deprecation_message "Call site.collections.posts " \
|
195
|
+
"instead of site.posts (Ruby code)"
|
196
|
+
end
|
197
|
+
@wrote_deprecation_msg ||= true
|
163
198
|
collections["posts"] ||= Bridgetown::Collection.new(self, "posts")
|
164
199
|
end
|
165
200
|
|
@@ -177,7 +212,13 @@ class Bridgetown::Site
|
|
177
212
|
#
|
178
213
|
# @return [Array]
|
179
214
|
def contents
|
215
|
+
return resources if uses_resource?
|
216
|
+
|
180
217
|
pages + documents
|
181
218
|
end
|
219
|
+
|
220
|
+
def add_generated_page(generated_page)
|
221
|
+
generated_pages << generated_page
|
222
|
+
end
|
182
223
|
end
|
183
224
|
end
|
@@ -29,6 +29,26 @@ class Bridgetown::Site
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def matched_converters_for_convertible(convertible)
|
33
|
+
@layout_converters ||= {}
|
34
|
+
|
35
|
+
if convertible.is_a?(Bridgetown::Layout) && @layout_converters[convertible]
|
36
|
+
return @layout_converters[convertible]
|
37
|
+
end
|
38
|
+
|
39
|
+
matches = converters.select do |converter|
|
40
|
+
if converter.method(:matches).arity == 1
|
41
|
+
converter.matches(convertible.extname)
|
42
|
+
else
|
43
|
+
converter.matches(convertible.extname, convertible)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
@layout_converters[convertible] = matches if convertible.is_a?(Bridgetown::Layout)
|
48
|
+
|
49
|
+
matches
|
50
|
+
end
|
51
|
+
|
32
52
|
# Renders all documents
|
33
53
|
# @return [void]
|
34
54
|
def render_docs
|
@@ -38,6 +58,12 @@ class Bridgetown::Site
|
|
38
58
|
render_regenerated document
|
39
59
|
end
|
40
60
|
end
|
61
|
+
|
62
|
+
collection.resources.each do |resource|
|
63
|
+
render_with_locale(resource) do
|
64
|
+
resource.transform!
|
65
|
+
end
|
66
|
+
end
|
41
67
|
end
|
42
68
|
end
|
43
69
|
|
@@ -21,17 +21,27 @@ class Bridgetown::Site
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Yields all content objects while looping through {#pages},
|
24
|
-
# {#static_files_to_write},
|
24
|
+
# {#static_files_to_write}, {#docs_to_write}, {#resources_to_write}.
|
25
25
|
#
|
26
26
|
# @yieldparam item [Document, Page, StaticFile]
|
27
27
|
#
|
28
28
|
# @return [void]
|
29
29
|
def each_site_file
|
30
|
-
%w(pages static_files_to_write docs_to_write).each do |type|
|
30
|
+
%w(pages static_files_to_write docs_to_write resources_to_write).each do |type|
|
31
31
|
send(type).each do |item|
|
32
32
|
yield item
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
def resources_cache_manifest
|
38
|
+
resources.each_with_object({}) do |resource, hsh|
|
39
|
+
next if resource.relative_url == ""
|
40
|
+
|
41
|
+
hsh[resource.relative_url] = {
|
42
|
+
id: resource.model.id,
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Bridgetown
|
4
|
+
# TODO: to be retired once the Resource engine is made official
|
4
5
|
module Validatable
|
5
|
-
# FIXME: there should be ONE TRUE METHOD to read the YAML frontmatter
|
6
|
-
# in the entire project. Both this and the equivalent Document method
|
7
|
-
# should be extracted and generalized.
|
8
|
-
#
|
9
6
|
# Read the YAML frontmatter.
|
10
7
|
#
|
11
8
|
# base - The String path to the dir containing the file.
|
@@ -23,6 +23,9 @@ module Bridgetown
|
|
23
23
|
"includes_dir" => "_includes",
|
24
24
|
"partials_dir" => "_partials",
|
25
25
|
"collections" => {},
|
26
|
+
"taxonomies" => {
|
27
|
+
category: { key: "categories", title: "Category" }, tag: { key: "tags", title: "Tag" },
|
28
|
+
},
|
26
29
|
|
27
30
|
# Handling Reading
|
28
31
|
"include" => [".htaccess", "_redirects", ".well-known"],
|
@@ -32,6 +35,7 @@ module Bridgetown
|
|
32
35
|
"markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
|
33
36
|
"strict_front_matter" => false,
|
34
37
|
"slugify_categories" => true,
|
38
|
+
"slugify_mode" => "pretty",
|
35
39
|
|
36
40
|
# Filtering Content
|
37
41
|
"limit_posts" => 0,
|
@@ -56,7 +60,7 @@ module Bridgetown
|
|
56
60
|
# Output Configuration
|
57
61
|
"available_locales" => ["en"],
|
58
62
|
"default_locale" => "en",
|
59
|
-
"permalink" =>
|
63
|
+
"permalink" => nil, # default is set according to content engine
|
60
64
|
"timezone" => nil, # use the local timezone
|
61
65
|
|
62
66
|
"quiet" => false,
|
@@ -70,15 +74,16 @@ module Bridgetown
|
|
70
74
|
},
|
71
75
|
|
72
76
|
"kramdown" => {
|
73
|
-
"auto_ids"
|
74
|
-
"toc_levels"
|
75
|
-
"entity_output"
|
76
|
-
"smart_quotes"
|
77
|
-
"input"
|
78
|
-
"hard_wrap"
|
79
|
-
"guess_lang"
|
80
|
-
"footnote_nr"
|
81
|
-
"show_warnings"
|
77
|
+
"auto_ids" => true,
|
78
|
+
"toc_levels" => (1..6).to_a,
|
79
|
+
"entity_output" => "as_char",
|
80
|
+
"smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
|
81
|
+
"input" => "GFM",
|
82
|
+
"hard_wrap" => false,
|
83
|
+
"guess_lang" => true,
|
84
|
+
"footnote_nr" => 1,
|
85
|
+
"show_warnings" => false,
|
86
|
+
"include_extraction_tags" => false,
|
82
87
|
},
|
83
88
|
}.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
|
84
89
|
|
@@ -95,8 +100,8 @@ module Bridgetown
|
|
95
100
|
# user_config - a Hash or Configuration of overrides.
|
96
101
|
#
|
97
102
|
# Returns a Configuration filled with defaults.
|
98
|
-
def from(user_config)
|
99
|
-
Utils.deep_merge_hashes(
|
103
|
+
def from(user_config, starting_defaults = DEFAULTS)
|
104
|
+
Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
|
100
105
|
.merge_environment_specific_options!
|
101
106
|
.add_default_collections
|
102
107
|
.add_default_excludes
|
@@ -242,23 +247,38 @@ module Bridgetown
|
|
242
247
|
self
|
243
248
|
end
|
244
249
|
|
245
|
-
def add_default_collections
|
250
|
+
def add_default_collections # rubocop:todo all
|
246
251
|
# It defaults to `{}`, so this is only if someone sets it to null manually.
|
247
|
-
return self if self[
|
252
|
+
return self if self[:collections].nil?
|
248
253
|
|
249
254
|
# Ensure we have a hash.
|
250
|
-
if self[
|
251
|
-
self[
|
255
|
+
if self[:collections].is_a?(Array)
|
256
|
+
self[:collections] = self[:collections].each_with_object({}) do |collection, hash|
|
252
257
|
hash[collection] = {}
|
253
258
|
end
|
254
259
|
end
|
255
260
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
261
|
+
# Setup default collections
|
262
|
+
self[:collections][:posts] = {} unless self[:collections][:posts]
|
263
|
+
self[:collections][:posts][:output] = true
|
264
|
+
self[:collections][:posts][:sort_direction] ||= "descending"
|
265
|
+
|
266
|
+
if self[:content_engine] == "resource"
|
267
|
+
self[:permalink] = "pretty" if self[:permalink].blank?
|
268
|
+
self[:collections][:pages] = {} unless self[:collections][:pages]
|
269
|
+
self[:collections][:pages][:output] = true
|
270
|
+
self[:collections][:pages][:permalink] ||= "/:path/"
|
271
|
+
|
272
|
+
self[:collections][:data] = {} unless self[:collections][:data]
|
273
|
+
self[:collections][:data][:output] = false
|
274
|
+
|
275
|
+
unless self[:collections][:posts][:permalink]
|
276
|
+
self[:collections][:posts][:permalink] = self[:permalink]
|
277
|
+
end
|
278
|
+
else
|
279
|
+
self[:permalink] = "date" if self[:permalink].blank?
|
280
|
+
unless self[:collections][:posts][:permalink]
|
281
|
+
self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
|
262
282
|
end
|
263
283
|
end
|
264
284
|
|
@@ -284,9 +304,9 @@ module Bridgetown
|
|
284
304
|
self["ruby_in_front_matter"]
|
285
305
|
end
|
286
306
|
|
287
|
-
#
|
288
|
-
def style_to_permalink(permalink_style)
|
289
|
-
case permalink_style.to_sym
|
307
|
+
# Deprecated, to be removed when Bridgetown goes Resource-only
|
308
|
+
def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
|
309
|
+
case permalink_style.to_s.to_sym
|
290
310
|
when :pretty
|
291
311
|
"/:categories/:year/:month/:day/:title/"
|
292
312
|
when :simple
|
@@ -303,7 +323,6 @@ module Bridgetown
|
|
303
323
|
permalink_style.to_s
|
304
324
|
end
|
305
325
|
end
|
306
|
-
# rubocop:enable Metrics/CyclomaticComplexity #
|
307
326
|
|
308
327
|
def check_include_exclude
|
309
328
|
%w(include exclude).each do |option|
|
@@ -314,8 +333,10 @@ module Bridgetown
|
|
314
333
|
"'#{option}' should be set as an array, but was: #{self[option].inspect}."
|
315
334
|
end
|
316
335
|
|
317
|
-
|
318
|
-
|
336
|
+
unless self[:include].include?("_pages") || self[:content_engine] == "resource"
|
337
|
+
# add _pages to includes set
|
338
|
+
self[:include] << "_pages"
|
339
|
+
end
|
319
340
|
|
320
341
|
self
|
321
342
|
end
|
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
|
6
|
+
|
7
|
+
begin
|
8
|
+
find_in_source_paths("postcss.config.js")
|
9
|
+
rescue Thor::Error
|
10
|
+
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
11
|
+
|
12
|
+
@logger.error "\nError:".red, "🚨 #{error_message}"
|
13
|
+
@logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
|
14
|
+
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
|
19
|
+
|
20
|
+
say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
|
21
|
+
run "yarn add -D #{plugins.join(' ')}"
|
22
|
+
|
23
|
+
remove_file "postcss.config.js"
|
24
|
+
copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
|
25
|
+
|
26
|
+
# rubocop:enable all
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module.exports = {
|
2
|
+
plugins: {
|
3
|
+
'postcss-easy-import': {},
|
4
|
+
'postcss-mixins': {},
|
5
|
+
'postcss-color-function': {},
|
6
|
+
'postcss-flexbugs-fixes': {},
|
7
|
+
'postcss-preset-env': {
|
8
|
+
autoprefixer: {
|
9
|
+
flexbox: 'no-2009'
|
10
|
+
},
|
11
|
+
stage: 2,
|
12
|
+
features: {
|
13
|
+
'nesting-rules': true,
|
14
|
+
'custom-media-queries': true
|
15
|
+
},
|
16
|
+
},
|
17
|
+
'cssnano' : {
|
18
|
+
preset: 'default'
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
say_status :minitesting, "Adding test gems, package.json scripts, and examples"
|
6
|
+
|
7
|
+
append_to_file "Gemfile" do
|
8
|
+
<<~GEMS
|
9
|
+
\n
|
10
|
+
group :test, optional: true do
|
11
|
+
gem "nokogiri"
|
12
|
+
gem "minitest"
|
13
|
+
gem "minitest-profile"
|
14
|
+
gem "minitest-reporters"
|
15
|
+
gem "shoulda"
|
16
|
+
gem "rails-dom-testing"
|
17
|
+
end
|
18
|
+
GEMS
|
19
|
+
end
|
20
|
+
|
21
|
+
new_scripts = ' "test": "BRIDGETOWN_ENV=test yarn build",'
|
22
|
+
new_scripts += "\n" + ' "deploy:test": "bundle install --with test && yarn deploy"'
|
23
|
+
package_json = "package.json"
|
24
|
+
script_regex = %r{"scripts": \{(\s+".*,?)*}
|
25
|
+
inject_into_file(package_json, ",\n" + new_scripts, after: script_regex)
|
26
|
+
|
27
|
+
create_file "test/helper.rb" do
|
28
|
+
<<~RUBY
|
29
|
+
require "nokogiri"
|
30
|
+
require "minitest/autorun"
|
31
|
+
require "minitest/reporters"
|
32
|
+
require "minitest/profile"
|
33
|
+
require "shoulda"
|
34
|
+
require "rails-dom-testing"
|
35
|
+
# Report with color.
|
36
|
+
Minitest::Reporters.use! [
|
37
|
+
Minitest::Reporters::DefaultReporter.new(
|
38
|
+
color: true
|
39
|
+
),
|
40
|
+
]
|
41
|
+
Minitest::Test.class_eval do
|
42
|
+
include Rails::Dom::Testing::Assertions
|
43
|
+
def site
|
44
|
+
@site ||= Bridgetown.sites.first
|
45
|
+
end
|
46
|
+
def nokogiri(input)
|
47
|
+
input.respond_to?(:output) ? Nokogiri::HTML(input.output) : Nokogiri::HTML(input)
|
48
|
+
end
|
49
|
+
def document_root(root)
|
50
|
+
@document_root = root.is_a?(Nokogiri::XML::Document) ? root : nokogiri(root)
|
51
|
+
end
|
52
|
+
def document_root_element
|
53
|
+
if @document_root.nil?
|
54
|
+
raise "Call `document_root' with a Nokogiri document before testing your assertions"
|
55
|
+
end
|
56
|
+
@document_root
|
57
|
+
end
|
58
|
+
end
|
59
|
+
RUBY
|
60
|
+
end
|
61
|
+
|
62
|
+
create_file "test/test_homepage.rb" do
|
63
|
+
<<~RUBY
|
64
|
+
require_relative "./helper"
|
65
|
+
class TestHomepage < Minitest::Test
|
66
|
+
context "homepage" do
|
67
|
+
setup do
|
68
|
+
page = site.pages.find { |doc| doc.url == "/" }
|
69
|
+
document_root page
|
70
|
+
end
|
71
|
+
should "exist" do
|
72
|
+
assert_select "body"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
RUBY
|
77
|
+
end
|
78
|
+
|
79
|
+
create_file "plugins/test_output.rb" do
|
80
|
+
<<~RUBY
|
81
|
+
unless Bridgetown.environment == "development"
|
82
|
+
Bridgetown::Hooks.register :site, :post_write do
|
83
|
+
# Load test suite to run on exit
|
84
|
+
require "nokogiri"
|
85
|
+
Dir["test/**/*.rb"].each { |file| require_relative("../\#{file}") }
|
86
|
+
rescue LoadError
|
87
|
+
Bridgetown.logger.warn "Testing:", "To run tests, you must first run \`bundle install --with test\`"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
RUBY
|
91
|
+
end
|
92
|
+
|
93
|
+
say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`yarn test\`"
|
94
|
+
|
95
|
+
# rubocop:enable all
|