bridgetown-core 0.18.6 → 0.20.0
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 +4 -4
- data/lib/bridgetown-core.rb +46 -13
- data/lib/bridgetown-core/cleaner.rb +7 -1
- data/lib/bridgetown-core/collection.rb +173 -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 +28 -1
- data/lib/bridgetown-core/commands/plugins.rb +1 -0
- data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
- data/lib/bridgetown-core/concerns/site/configurable.rb +7 -3
- data/lib/bridgetown-core/concerns/site/content.rb +57 -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 +11 -1
- data/lib/bridgetown-core/concerns/validatable.rb +1 -0
- data/lib/bridgetown-core/configuration.rb +39 -19
- 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 +14 -0
- data/lib/bridgetown-core/converters/erb_templates.rb +6 -13
- 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/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/resource_drop.rb +81 -0
- data/lib/bridgetown-core/drops/site_drop.rb +33 -8
- data/lib/bridgetown-core/drops/unified_payload_drop.rb +4 -0
- data/lib/bridgetown-core/entry_filter.rb +10 -23
- data/lib/bridgetown-core/errors.rb +0 -2
- data/lib/bridgetown-core/filters.rb +4 -3
- data/lib/bridgetown-core/generator.rb +2 -1
- data/lib/bridgetown-core/generators/prototype_generator.rb +37 -19
- data/lib/bridgetown-core/layout.rb +2 -2
- 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/file_origin.rb +119 -0
- data/lib/bridgetown-core/model/origin.rb +38 -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 +25 -12
- 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 +5 -12
- data/lib/bridgetown-core/resource/base.rb +275 -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/taxonomy_term.rb +25 -0
- data/lib/bridgetown-core/resource/taxonomy_type.rb +47 -0
- data/lib/bridgetown-core/resource/transformer.rb +173 -0
- data/lib/bridgetown-core/ruby_template_view.rb +13 -2
- 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 +40 -40
- data/lib/bridgetown-core/utils/platforms.rb +1 -0
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/site_template/README.md +70 -0
- data/lib/site_template/frontend/javascript/index.js.erb +11 -0
- data/lib/site_template/frontend/styles/index.css +19 -0
- data/lib/site_template/{package.json → package.json.erb} +14 -8
- data/lib/site_template/postcss.config.js.erb +11 -0
- data/lib/site_template/src/_components/footer.liquid +1 -1
- data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
- data/lib/site_template/{webpack.config.js → webpack.config.js.erb} +47 -5
- metadata +67 -42
- data/lib/bridgetown-core/page_without_a_file.rb +0 -14
- 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
- data/lib/site_template/frontend/javascript/index.js +0 -3
@@ -27,11 +27,21 @@ class Bridgetown::Site
|
|
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,6 +1,7 @@
|
|
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
6
|
# FIXME: there should be ONE TRUE METHOD to read the YAML frontmatter
|
6
7
|
# in the entire project. Both this and the equivalent Document method
|
@@ -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,
|
@@ -95,8 +99,8 @@ module Bridgetown
|
|
95
99
|
# user_config - a Hash or Configuration of overrides.
|
96
100
|
#
|
97
101
|
# Returns a Configuration filled with defaults.
|
98
|
-
def from(user_config)
|
99
|
-
Utils.deep_merge_hashes(
|
102
|
+
def from(user_config, starting_defaults = DEFAULTS)
|
103
|
+
Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
|
100
104
|
.merge_environment_specific_options!
|
101
105
|
.add_default_collections
|
102
106
|
.add_default_excludes
|
@@ -242,23 +246,38 @@ module Bridgetown
|
|
242
246
|
self
|
243
247
|
end
|
244
248
|
|
245
|
-
def add_default_collections
|
249
|
+
def add_default_collections # rubocop:todo all
|
246
250
|
# It defaults to `{}`, so this is only if someone sets it to null manually.
|
247
|
-
return self if self[
|
251
|
+
return self if self[:collections].nil?
|
248
252
|
|
249
253
|
# Ensure we have a hash.
|
250
|
-
if self[
|
251
|
-
self[
|
254
|
+
if self[:collections].is_a?(Array)
|
255
|
+
self[:collections] = self[:collections].each_with_object({}) do |collection, hash|
|
252
256
|
hash[collection] = {}
|
253
257
|
end
|
254
258
|
end
|
255
259
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
260
|
+
# Setup default collections
|
261
|
+
self[:collections][:posts] = {} unless self[:collections][:posts]
|
262
|
+
self[:collections][:posts][:output] = true
|
263
|
+
self[:collections][:posts][:sort_direction] ||= "descending"
|
264
|
+
|
265
|
+
if self[:content_engine] == "resource"
|
266
|
+
self[:permalink] = "pretty" if self[:permalink].blank?
|
267
|
+
self[:collections][:pages] = {} unless self[:collections][:pages]
|
268
|
+
self[:collections][:pages][:output] = true
|
269
|
+
self[:collections][:pages][:permalink] ||= "/:path/"
|
270
|
+
|
271
|
+
self[:collections][:data] = {} unless self[:collections][:data]
|
272
|
+
self[:collections][:data][:output] = false
|
273
|
+
|
274
|
+
unless self[:collections][:posts][:permalink]
|
275
|
+
self[:collections][:posts][:permalink] = self[:permalink]
|
276
|
+
end
|
277
|
+
else
|
278
|
+
self[:permalink] = "date" if self[:permalink].blank?
|
279
|
+
unless self[:collections][:posts][:permalink]
|
280
|
+
self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
|
262
281
|
end
|
263
282
|
end
|
264
283
|
|
@@ -284,9 +303,9 @@ module Bridgetown
|
|
284
303
|
self["ruby_in_front_matter"]
|
285
304
|
end
|
286
305
|
|
287
|
-
#
|
288
|
-
def style_to_permalink(permalink_style)
|
289
|
-
case permalink_style.to_sym
|
306
|
+
# Deprecated, to be removed when Bridgetown goes Resource-only
|
307
|
+
def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
|
308
|
+
case permalink_style.to_s.to_sym
|
290
309
|
when :pretty
|
291
310
|
"/:categories/:year/:month/:day/:title/"
|
292
311
|
when :simple
|
@@ -303,7 +322,6 @@ module Bridgetown
|
|
303
322
|
permalink_style.to_s
|
304
323
|
end
|
305
324
|
end
|
306
|
-
# rubocop:enable Metrics/CyclomaticComplexity #
|
307
325
|
|
308
326
|
def check_include_exclude
|
309
327
|
%w(include exclude).each do |option|
|
@@ -314,8 +332,10 @@ module Bridgetown
|
|
314
332
|
"'#{option}' should be set as an array, but was: #{self[option].inspect}."
|
315
333
|
end
|
316
334
|
|
317
|
-
|
318
|
-
|
335
|
+
unless self[:include].include?("_pages") || self[:content_engine] == "resource"
|
336
|
+
# add _pages to includes set
|
337
|
+
self[:include] << "_pages"
|
338
|
+
end
|
319
339
|
|
320
340
|
self
|
321
341
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
# Taken from https://docs.netlify.com/configure-builds/file-based-configuration/#inject-environment-variable-values
|
3
|
+
|
4
|
+
echo "Updating netlify.toml with references to our built files"
|
5
|
+
|
6
|
+
CSS_PATH=`find output/_bridgetown/static/css/*.css -type f | sed -e 's,output\/,/,g'`
|
7
|
+
JS_PATH=`find output/_bridgetown/static/js/*.js -type f | sed -e 's,output\/,/,g'`
|
8
|
+
|
9
|
+
echo "CSS Path: ${CSS_PATH}"
|
10
|
+
echo "JS Path: ${JS_PATH}"
|
11
|
+
|
12
|
+
sed -i s,CSS_PATH,${CSS_PATH},g netlify.toml
|
13
|
+
sed -i s,JS_PATH,${JS_PATH},g netlify.toml
|
14
|
+
sed -i s,NETLIFY_IMAGES_CDN_DOMAIN,${NETLIFY_IMAGES_CDN_DOMAIN},g netlify.toml
|
@@ -0,0 +1,44 @@
|
|
1
|
+
[build]
|
2
|
+
command = "yarn deploy && ./bin/netlify.sh"
|
3
|
+
publish = "output"
|
4
|
+
|
5
|
+
[build.environment]
|
6
|
+
NODE_ENV = "development"
|
7
|
+
BRIDGETOWN_ENV = "production"
|
8
|
+
|
9
|
+
[build.processing]
|
10
|
+
skip_processing = false
|
11
|
+
[build.processing.css]
|
12
|
+
bundle = false
|
13
|
+
minify = true
|
14
|
+
[build.processing.js]
|
15
|
+
bundle = false
|
16
|
+
minify = true
|
17
|
+
[build.processing.html]
|
18
|
+
pretty_urls = true
|
19
|
+
[build.processing.images]
|
20
|
+
compress = true
|
21
|
+
|
22
|
+
[[headers]]
|
23
|
+
for = "*"
|
24
|
+
[headers.values]
|
25
|
+
X-Frame-Options = "DENY"
|
26
|
+
X-XSS-Protection = "1; mode=block"
|
27
|
+
X-Content-Type-Options = "nosniff"
|
28
|
+
Strict-Transport-Security = "max-age=15552000; includeSubDomains"
|
29
|
+
Referrer-Policy = "no-referrer-when-downgrade"
|
30
|
+
Cache-Control = "public, max-age=604800, s-max-age=604800"
|
31
|
+
|
32
|
+
[[headers]]
|
33
|
+
for = "/"
|
34
|
+
[headers.values]
|
35
|
+
Link = [
|
36
|
+
"<CSS_PATH>; rel=preload; as=style",
|
37
|
+
"<JS_PATH>; rel=preload; as=script",
|
38
|
+
"<https://NETLIFY_IMAGES_CDN_DOMAIN>; rel=preconnect"
|
39
|
+
]
|
40
|
+
|
41
|
+
[[headers]]
|
42
|
+
for = "/*.(png|jpg|js|css|svg|woff|ttf|eot|ico|woff2)"
|
43
|
+
[headers.values]
|
44
|
+
Cache-Control = "public, max-age=31536000, s-max-age=31536000"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable all
|
4
|
+
|
5
|
+
say_status :purgecss, "Installing PurgeCSS"
|
6
|
+
|
7
|
+
run "yarn add -D purgecss"
|
8
|
+
|
9
|
+
create_builder "purgecss_builder.rb" do
|
10
|
+
<<~RUBY
|
11
|
+
class PurgeCSS < SiteBuilder
|
12
|
+
def build
|
13
|
+
unless config[:watch] # don't run in "watch mode"
|
14
|
+
hook :site, :post_write do
|
15
|
+
purgecss_file = site.in_root_dir("purgecss.config.js")
|
16
|
+
unless File.exist?(purgecss_file)
|
17
|
+
config_js = <<~PURGE
|
18
|
+
module.exports = {
|
19
|
+
content: ['frontend/javascript/*.js','./output/**/*.html'],
|
20
|
+
output: "./output/_bridgetown/static/css"
|
21
|
+
}
|
22
|
+
PURGE
|
23
|
+
File.write(purgecss_file, config_js.strip)
|
24
|
+
end
|
25
|
+
manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
|
26
|
+
if File.exist?(manifest_file)
|
27
|
+
manifest = JSON.parse(File.read(manifest_file))
|
28
|
+
css_file = manifest["main.css"].split("/").last
|
29
|
+
css_path = ["output", "_bridgetown", "static", "css", css_file].join("/")
|
30
|
+
Bridgetown.logger.info "PurgeCSS", "Purging \#{css_file}"
|
31
|
+
oldsize = File.stat(css_path).size / 1000
|
32
|
+
system "./node_modules/.bin/purgecss -c purgecss.config.js -css \#{css_path}"
|
33
|
+
newsize = File.stat(css_path).size / 1000
|
34
|
+
if newsize < oldsize
|
35
|
+
Bridgetown.logger.info "PurgeCSS", "Done! File size reduced from \#{oldsize}kB to \#{newsize}kB"
|
36
|
+
else
|
37
|
+
Bridgetown.logger.info "PurgeCSS", "Done. No apparent change in file size (\#{newsize}kB)."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
RUBY
|
45
|
+
end
|
46
|
+
|
47
|
+
say_status :purgecss, "All set! Open plugins/builders/purgecss_builder.rb if you'd like to customize the PurgeCSS config."
|
48
|
+
|
49
|
+
# rubocop:enable all
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
say "Installing Stimulus...", :green
|
6
|
+
|
7
|
+
run("yarn add stimulus")
|
8
|
+
|
9
|
+
say 'Adding Stimulus to "frontend/javascript/index.js"...', :magenta
|
10
|
+
|
11
|
+
javascript_import do
|
12
|
+
<<~JS
|
13
|
+
import { Application } from "stimulus"
|
14
|
+
import { definitionsFromContext } from "stimulus/webpack-helpers"
|
15
|
+
JS
|
16
|
+
end
|
17
|
+
|
18
|
+
javascript_dir = File.join("frontend", "javascript")
|
19
|
+
|
20
|
+
append_to_file(File.join(javascript_dir, "index.js")) do
|
21
|
+
<<~JS
|
22
|
+
const application = Application.start()
|
23
|
+
const context = require.context("./controllers", true, /\.js$/)
|
24
|
+
application.load(definitionsFromContext(context))
|
25
|
+
JS
|
26
|
+
end
|
27
|
+
|
28
|
+
controller_dir = File.join(javascript_dir, "controllers")
|
29
|
+
|
30
|
+
say "Creating a `./#{controller_dir}` directory...", :magenta
|
31
|
+
FileUtils.mkdir_p(controller_dir)
|
32
|
+
|
33
|
+
say "Creating an example Stimulus Controller for you!...", :magenta
|
34
|
+
create_file(File.join(controller_dir, "example_controller.js")) do
|
35
|
+
<<~JS
|
36
|
+
import { Controller } from "stimulus"
|
37
|
+
export default class extends Controller {
|
38
|
+
connect() {
|
39
|
+
console.log("Hello, Stimulus!", this.element)
|
40
|
+
}
|
41
|
+
}
|
42
|
+
JS
|
43
|
+
end
|
44
|
+
|
45
|
+
say "Stimulus successfully added", :green
|
46
|
+
|
47
|
+
say "To start adding controllers, visit the `./frontend/javascript/controllers/` directory", :blue
|
48
|
+
say "Make sure your controllers follow the `[name]_controller.js` convention", :blue
|
49
|
+
say 'For further reading, check out "https://stimulus.hotwire.dev/"', :blue
|