bridgetown-core 1.0.0.beta2 → 1.1.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/.rubocop.yml +6 -1
- data/lib/bridgetown-core/collection.rb +37 -20
- data/lib/bridgetown-core/commands/concerns/actions.rb +3 -2
- data/lib/bridgetown-core/commands/configure.rb +1 -1
- data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +20 -16
- data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +95 -12
- data/lib/bridgetown-core/commands/new.rb +10 -9
- data/lib/bridgetown-core/commands/plugins.rb +2 -0
- data/lib/bridgetown-core/commands/start.rb +3 -0
- data/lib/bridgetown-core/commands/webpack/update.rb +2 -2
- data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +11 -2
- data/lib/bridgetown-core/component.rb +13 -7
- data/lib/bridgetown-core/concerns/localizable.rb +20 -0
- data/lib/bridgetown-core/concerns/prioritizable.rb +44 -0
- data/lib/bridgetown-core/concerns/publishable.rb +11 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +2 -10
- data/lib/bridgetown-core/concerns/site/localizable.rb +5 -1
- data/lib/bridgetown-core/concerns/site/renderable.rb +27 -16
- data/lib/bridgetown-core/concerns/site/ssr.rb +3 -3
- data/lib/bridgetown-core/concerns/site/writable.rb +28 -0
- data/lib/bridgetown-core/concerns/transformable.rb +62 -0
- data/lib/bridgetown-core/configuration.rb +2 -0
- data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +5 -3
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -1
- data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +33 -0
- data/lib/bridgetown-core/configurations/gh-pages.rb +16 -0
- data/lib/bridgetown-core/configurations/lit/esbuild-plugins.js +21 -0
- data/lib/bridgetown-core/configurations/lit/happy-days.lit.js +26 -0
- data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -0
- data/lib/bridgetown-core/configurations/lit/lit-ssr.config.js +6 -0
- data/lib/bridgetown-core/configurations/lit.rb +95 -0
- data/lib/bridgetown-core/configurations/open-props/variables.css.erb +11 -0
- data/lib/bridgetown-core/configurations/open-props.rb +21 -0
- data/lib/bridgetown-core/configurations/ruby2js/hello_world.js.rb +9 -0
- data/lib/bridgetown-core/configurations/ruby2js.rb +67 -0
- data/lib/bridgetown-core/configurations/shoelace.rb +50 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +16 -2
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/drops/generated_page_drop.rb +2 -1
- data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
- data/lib/bridgetown-core/errors.rb +5 -5
- data/lib/bridgetown-core/filters/translation_filters.rb +11 -0
- data/lib/bridgetown-core/filters/url_filters.rb +37 -10
- data/lib/bridgetown-core/filters.rb +3 -0
- data/lib/bridgetown-core/frontmatter_defaults.rb +14 -8
- data/lib/bridgetown-core/generated_page.rb +82 -17
- data/lib/bridgetown-core/kramdown/parser/gfm.rb +36 -0
- data/lib/bridgetown-core/model/base.rb +1 -2
- data/lib/bridgetown-core/plugin.rb +6 -37
- data/lib/bridgetown-core/plugin_manager.rb +3 -2
- data/lib/bridgetown-core/rack/boot.rb +5 -0
- data/lib/bridgetown-core/rack/logger.rb +14 -4
- data/lib/bridgetown-core/rack/roda.rb +102 -10
- data/lib/bridgetown-core/rack/routes.rb +87 -6
- data/lib/bridgetown-core/resource/base.rb +4 -6
- data/lib/bridgetown-core/resource/destination.rb +18 -0
- data/lib/bridgetown-core/resource/permalink_processor.rb +6 -4
- data/lib/bridgetown-core/resource/relations.rb +1 -1
- data/lib/bridgetown-core/resource/transformer.rb +21 -85
- data/lib/bridgetown-core/utils/aux.rb +2 -1
- data/lib/bridgetown-core/utils/require_gems.rb +3 -6
- data/lib/bridgetown-core/utils.rb +25 -12
- data/lib/bridgetown-core/version.rb +2 -2
- data/lib/bridgetown-core/watcher.rb +19 -6
- data/lib/bridgetown-core.rb +9 -3
- data/lib/site_template/Gemfile.erb +1 -1
- data/lib/site_template/README.md +2 -2
- data/lib/site_template/TEMPLATES/erb/_components/shared/navbar.erb +4 -4
- data/lib/site_template/TEMPLATES/liquid/_components/navbar.liquid +4 -4
- data/lib/site_template/TEMPLATES/serbea/_components/shared/navbar.serb +4 -4
- data/lib/site_template/bridgetown.config.yml +10 -3
- data/lib/site_template/frontend/javascript/index.js.erb +1 -0
- data/lib/site_template/frontend/styles/syntax-highlighting.css +77 -0
- data/lib/site_template/package.json.erb +18 -17
- data/lib/site_template/server/roda_app.rb +3 -6
- data/lib/site_template/src/404.html +2 -1
- data/lib/site_template/src/500.html +10 -0
- metadata +21 -4
- data/lib/bridgetown-core/publisher.rb +0 -29
- data/lib/bridgetown-core/renderer.rb +0 -169
@@ -38,7 +38,7 @@ class Bridgetown::Site
|
|
38
38
|
# @param strip_slash_only [Boolean] set to true if you wish "/" to be returned as ""
|
39
39
|
# @return [String]
|
40
40
|
def base_path(strip_slash_only: false)
|
41
|
-
(config[:base_path] || config[:baseurl]).
|
41
|
+
(config[:base_path] || config[:baseurl]).then do |path|
|
42
42
|
strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path
|
43
43
|
end
|
44
44
|
end
|
@@ -61,14 +61,6 @@ class Bridgetown::Site
|
|
61
61
|
@frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
|
62
62
|
end
|
63
63
|
|
64
|
-
# Returns the current instance of {Publisher} or creates a new instance of
|
65
|
-
# {Publisher} if one doesn't exist.
|
66
|
-
#
|
67
|
-
# @return [Publisher] Returns an instance of {Publisher}
|
68
|
-
def publisher
|
69
|
-
@publisher ||= Bridgetown::Publisher.new(self)
|
70
|
-
end
|
71
|
-
|
72
64
|
# Prefix a path or paths with the {#root_dir} directory.
|
73
65
|
#
|
74
66
|
# @see Bridgetown.sanitized_path
|
@@ -166,7 +158,7 @@ class Bridgetown::Site
|
|
166
158
|
plugin_components_load_paths = Bridgetown::PluginManager.source_manifests
|
167
159
|
.filter_map(&:components)
|
168
160
|
|
169
|
-
local_components_load_paths = config["components_dir"].
|
161
|
+
local_components_load_paths = config["components_dir"].then do |dir|
|
170
162
|
dir.is_a?(Array) ? dir : [dir]
|
171
163
|
end
|
172
164
|
local_components_load_paths.map! do |dir|
|
@@ -7,11 +7,15 @@ class Bridgetown::Site
|
|
7
7
|
def locale
|
8
8
|
@locale ||= begin
|
9
9
|
locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
|
10
|
-
Dir["#{in_source_dir("_locales")}/*.yml"].each do |locale_path|
|
10
|
+
Dir["#{in_source_dir("_locales")}/*.{json,rb,yml}"].each do |locale_path|
|
11
11
|
I18n.load_path << locale_path
|
12
12
|
end
|
13
13
|
I18n.available_locales = config[:available_locales]
|
14
14
|
I18n.default_locale = locale
|
15
|
+
I18n.fallbacks = (config[:available_locales] + [:en]).uniq.to_h do |available_locale|
|
16
|
+
[available_locale, [available_locale, locale, :en].uniq]
|
17
|
+
end
|
18
|
+
locale
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -10,7 +10,7 @@ class Bridgetown::Site
|
|
10
10
|
Bridgetown::Hooks.trigger :site, :pre_render, self
|
11
11
|
execute_inline_ruby_for_layouts!
|
12
12
|
render_resources
|
13
|
-
|
13
|
+
generated_pages.each(&:transform!)
|
14
14
|
Bridgetown::Hooks.trigger :site, :post_render, self
|
15
15
|
end
|
16
16
|
|
@@ -46,6 +46,32 @@ class Bridgetown::Site
|
|
46
46
|
matches
|
47
47
|
end
|
48
48
|
|
49
|
+
# @return [Array<Bridgetown::Layout>]
|
50
|
+
def validated_layouts_for(convertible, layout_name)
|
51
|
+
layout = layouts[layout_name]
|
52
|
+
warn_on_missing_layout convertible, layout, layout_name
|
53
|
+
|
54
|
+
layout_list = Set.new([layout])
|
55
|
+
while layout
|
56
|
+
layout_name = layout.data.layout
|
57
|
+
layout = layouts[layout_name]
|
58
|
+
warn_on_missing_layout convertible, layout, layout_name
|
59
|
+
|
60
|
+
layout_list << layout
|
61
|
+
end
|
62
|
+
|
63
|
+
layout_list.to_a.compact
|
64
|
+
end
|
65
|
+
|
66
|
+
def warn_on_missing_layout(convertible, layout, layout_name)
|
67
|
+
return unless layout.nil? && layout_name
|
68
|
+
|
69
|
+
Bridgetown.logger.warn(
|
70
|
+
"Build Warning:",
|
71
|
+
"Layout '#{layout_name}' requested via #{convertible.relative_path} does not exist."
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
49
75
|
# Renders all resources
|
50
76
|
# @return [void]
|
51
77
|
def render_resources
|
@@ -58,14 +84,6 @@ class Bridgetown::Site
|
|
58
84
|
end
|
59
85
|
end
|
60
86
|
|
61
|
-
# Renders all generated pages
|
62
|
-
# @return [void]
|
63
|
-
def render_generated_pages
|
64
|
-
generated_pages.each do |page|
|
65
|
-
render_page page
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
87
|
# Renders a content item while ensuring site locale is set if the data is available.
|
70
88
|
# @param item [Document, Page, Bridgetown::Resource::Base] The item to render
|
71
89
|
# @yield Runs the block in between locale setting and resetting
|
@@ -80,12 +98,5 @@ class Bridgetown::Site
|
|
80
98
|
yield
|
81
99
|
end
|
82
100
|
end
|
83
|
-
|
84
|
-
# Regenerates a content item using {Renderer}
|
85
|
-
# @param item [Page] The page to render
|
86
|
-
# @return [void]
|
87
|
-
def render_page(page)
|
88
|
-
Bridgetown::Renderer.new(self, page).run
|
89
|
-
end
|
90
101
|
end
|
91
102
|
end
|
@@ -32,7 +32,7 @@ class Bridgetown::Site
|
|
32
32
|
@ssr_enabled = true
|
33
33
|
end
|
34
34
|
|
35
|
-
def ssr_setup
|
35
|
+
def ssr_setup(&block)
|
36
36
|
config.serving = true
|
37
37
|
Bridgetown::Hooks.trigger :site, :pre_read, self
|
38
38
|
defaults_reader.tap do |d|
|
@@ -46,10 +46,10 @@ class Bridgetown::Site
|
|
46
46
|
end
|
47
47
|
Bridgetown::Hooks.trigger :site, :post_read, self
|
48
48
|
|
49
|
-
|
49
|
+
block&.call(self) # provide additional setup hook
|
50
50
|
return if Bridgetown.env.production?
|
51
51
|
|
52
|
-
Bridgetown::Watcher.watch(self, config)
|
52
|
+
Bridgetown::Watcher.watch(self, config, &block)
|
53
53
|
end
|
54
54
|
|
55
55
|
def disable_ssr
|
@@ -14,6 +14,8 @@ class Bridgetown::Site
|
|
14
14
|
# @return [void]
|
15
15
|
def write
|
16
16
|
each_site_file { |item| item.write(dest) }
|
17
|
+
write_redirecting_index if config.prefix_default_locale
|
18
|
+
|
17
19
|
Bridgetown::Hooks.trigger :site, :post_write, self
|
18
20
|
end
|
19
21
|
|
@@ -40,5 +42,31 @@ class Bridgetown::Site
|
|
40
42
|
}
|
41
43
|
end
|
42
44
|
end
|
45
|
+
|
46
|
+
def write_redirecting_index
|
47
|
+
resource = resources.find do |item|
|
48
|
+
item.data.slug == "index" && item.data.locale == config.default_locale
|
49
|
+
end
|
50
|
+
|
51
|
+
unless resource
|
52
|
+
Bridgetown.logger.warn(
|
53
|
+
"Index file not found in the source folder, cannot generate top-level redirect file"
|
54
|
+
)
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
index_html = <<~HTML
|
59
|
+
<!DOCTYPE html>
|
60
|
+
<html>
|
61
|
+
<head>
|
62
|
+
<title>Redirecting…</title>
|
63
|
+
<meta http-equiv="refresh" content="0; url=#{resource.relative_url}" />
|
64
|
+
</head>
|
65
|
+
<body></body>
|
66
|
+
</html>
|
67
|
+
HTML
|
68
|
+
|
69
|
+
File.write(in_dest_dir("index.html"), index_html, mode: "wb")
|
70
|
+
end
|
43
71
|
end
|
44
72
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bridgetown
|
4
|
+
module Transformable
|
5
|
+
# Transforms an input document by running it through available converters
|
6
|
+
# (requires a `converter` method to be present on the including class)
|
7
|
+
#
|
8
|
+
# @param document [Bridgetown::GeneratedPage, Bridgetown::Resource::Base]
|
9
|
+
# @return String
|
10
|
+
# @yieldparam converter [Bridgetown::Converter]
|
11
|
+
# @yieldparam index [Integer] index of the conversion step
|
12
|
+
# @yieldparam output [String]
|
13
|
+
def transform_content(document)
|
14
|
+
converters.each_with_index.inject(document.content.to_s) do |content, (converter, index)|
|
15
|
+
output = if converter.method(:convert).arity == 1
|
16
|
+
converter.convert content
|
17
|
+
else
|
18
|
+
converter.convert content, document
|
19
|
+
end
|
20
|
+
|
21
|
+
yield converter, index, output if block_given?
|
22
|
+
|
23
|
+
output.html_safe
|
24
|
+
rescue StandardError => e
|
25
|
+
Bridgetown.logger.error "Conversion error:",
|
26
|
+
"#{converter.class} encountered an error while "\
|
27
|
+
"converting `#{document.relative_path}'"
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Transforms an input document by placing it within the specified layout
|
33
|
+
#
|
34
|
+
# @param layout [Bridgetown::Layout]
|
35
|
+
# @param output [String] the output from document content conversions
|
36
|
+
# @param document [Bridgetown::GeneratedPage, Bridgetown::Resource::Base]
|
37
|
+
# @return String
|
38
|
+
# @yieldparam converter [Bridgetown::Converter]
|
39
|
+
# @yieldparam layout_output [String]
|
40
|
+
def transform_with_layout(layout, output, document)
|
41
|
+
layout_converters = site.matched_converters_for_convertible(layout)
|
42
|
+
layout_input = layout.content.dup
|
43
|
+
|
44
|
+
layout_converters.inject(layout_input) do |content, converter|
|
45
|
+
next(content) unless [2, -2].include?(converter.method(:convert).arity) # rubocop:disable Performance/CollectionLiteralInLoop
|
46
|
+
|
47
|
+
layout.current_document = document
|
48
|
+
layout.current_document_output = output
|
49
|
+
layout_output = converter.convert content, layout
|
50
|
+
|
51
|
+
yield converter, layout_output if block_given?
|
52
|
+
|
53
|
+
layout_output
|
54
|
+
rescue StandardError => e
|
55
|
+
Bridgetown.logger.error "Conversion error:",
|
56
|
+
"#{converter.class} encountered an error while "\
|
57
|
+
"converting `#{document.relative_path}'"
|
58
|
+
raise e
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -59,6 +59,7 @@ module Bridgetown
|
|
59
59
|
# Output Configuration
|
60
60
|
"available_locales" => [:en],
|
61
61
|
"default_locale" => :en,
|
62
|
+
"prefix_default_locale" => false,
|
62
63
|
"permalink" => nil, # default is set according to content engine
|
63
64
|
"timezone" => nil, # use the local timezone
|
64
65
|
|
@@ -83,6 +84,7 @@ module Bridgetown
|
|
83
84
|
"footnote_nr" => 1,
|
84
85
|
"show_warnings" => false,
|
85
86
|
"include_extraction_tags" => false,
|
87
|
+
"mark_highlighting" => true,
|
86
88
|
},
|
87
89
|
}.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
|
88
90
|
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module.exports = {
|
2
2
|
plugins: {
|
3
|
-
'postcss-easy-import': {},
|
4
3
|
'postcss-mixins': {},
|
5
|
-
'postcss-color-function': {
|
4
|
+
'postcss-color-mod-function': {
|
5
|
+
// Uncomment the following to import CSS variables for use in `color-mod`:
|
6
|
+
// importFrom: "frontend/styles/variables.css"
|
7
|
+
},
|
6
8
|
'postcss-flexbugs-fixes': {},
|
7
9
|
'postcss-preset-env': {
|
8
10
|
autoprefixer: {
|
@@ -14,7 +16,7 @@ module.exports = {
|
|
14
16
|
'custom-media-queries': true
|
15
17
|
},
|
16
18
|
},
|
17
|
-
'cssnano'
|
19
|
+
'cssnano': {
|
18
20
|
preset: 'default'
|
19
21
|
}
|
20
22
|
}
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
|
15
15
|
return unless confirm.casecmp?("Y")
|
16
16
|
|
17
|
-
plugins = %w(postcss-
|
17
|
+
plugins = %w(postcss-mixins postcss-color-mod-function cssnano)
|
18
18
|
|
19
19
|
say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
|
20
20
|
run "yarn add -D #{plugins.join(' ')}"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Deploy to GitHub pages
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
deploy:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
|
14
|
+
- name: Setup Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
bundler-cache: true
|
18
|
+
|
19
|
+
- name: Setup Node
|
20
|
+
uses: actions/setup-node@v2
|
21
|
+
with:
|
22
|
+
node-version: "16"
|
23
|
+
cache: "yarn"
|
24
|
+
- run: yarn install
|
25
|
+
|
26
|
+
- name: Build
|
27
|
+
run: bin/bridgetown deploy
|
28
|
+
|
29
|
+
- name: Deploy
|
30
|
+
uses: peaceiris/actions-gh-pages@v3
|
31
|
+
with:
|
32
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
33
|
+
publish_dir: ./output
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
`bundle lock --add-platform x86_64-linux`
|
4
|
+
copy_file in_templates_dir("gh-pages.yml"), ".github/workflows/gh-pages.yml"
|
5
|
+
|
6
|
+
# rubocop:disable Layout/LineLength
|
7
|
+
say "🎉 A GitHub action to deploy your site to GitHub pages has been configured!"
|
8
|
+
say ""
|
9
|
+
|
10
|
+
say "🛠️ After pushing the action, go to your repository settings and configure GitHub Pages to deploy from the branch `gh-pages`."
|
11
|
+
say ""
|
12
|
+
|
13
|
+
say "You'll likely also need to set `base_path` in your `bridgetown.config.yml` to your repository's name. If you do this you'll need to use the `relative_url` helper for all links and assets in your HTML."
|
14
|
+
say "If you're using esbuild for frontend assets, edit `esbuild.config.js` to update `publicPath`."
|
15
|
+
say ""
|
16
|
+
# rubocop:enable Layout/LineLength
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// You can add "full-stack" esbuild plugins here that you wish to share between
|
2
|
+
// the frontend bundles and Lit SSR. Just import your plugins and add them and
|
3
|
+
// any additional configuration to the `plugins` array below.
|
4
|
+
|
5
|
+
// This plugin will let you import `.lit.css` files as sidecar stylesheets.
|
6
|
+
// Read https://edge.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
|
7
|
+
const { litCssPlugin } = require("esbuild-plugin-lit-css")
|
8
|
+
const postCssConfig = require("postcss-load-config").sync()
|
9
|
+
const postCssProcessor = require("postcss")([...postCssConfig.plugins])
|
10
|
+
|
11
|
+
module.exports = {
|
12
|
+
plugins: [
|
13
|
+
litCssPlugin({
|
14
|
+
filter: /\.lit\.css$/,
|
15
|
+
transform: async (css, { filePath }) => {
|
16
|
+
const results = await postCssProcessor.process(css, { ...postCssConfig.options, from: filePath })
|
17
|
+
return results.css
|
18
|
+
}
|
19
|
+
}),
|
20
|
+
]
|
21
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { LitElement, html, css } from "lit"
|
2
|
+
|
3
|
+
export class HappyDaysElement extends LitElement {
|
4
|
+
static styles = css`
|
5
|
+
:host {
|
6
|
+
display: block;
|
7
|
+
border: 2px dashed gray;
|
8
|
+
padding: 20px;
|
9
|
+
max-width: 300px;
|
10
|
+
}
|
11
|
+
`
|
12
|
+
|
13
|
+
static properties = {
|
14
|
+
hello: { type: String }
|
15
|
+
}
|
16
|
+
|
17
|
+
render() {
|
18
|
+
return html`
|
19
|
+
<p>Hello ${this.hello}! ${Date.now()}</p>
|
20
|
+
`;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
// Try adding `<%= lit :happy_days, hello: "there" %>` somewhere in an ERB template
|
25
|
+
// on your site to see this example Lit component in action!
|
26
|
+
customElements.define("happy-days", HappyDaysElement)
|
@@ -0,0 +1 @@
|
|
1
|
+
import components from "bridgetownComponents/**/*.{lit.js,lit.js.rb}"
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless Bridgetown::Utils.frontend_bundler_type == :esbuild
|
4
|
+
error_message = "#{"esbuild.config.js".bold} not found. (This configuration doesn't currently " \
|
5
|
+
"support Webpack.)"
|
6
|
+
|
7
|
+
@logger.error "\nError:".red, "🚨 #{error_message}"
|
8
|
+
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
say_status :lit, "Installing Lit + SSR Plugin..."
|
13
|
+
|
14
|
+
add_bridgetown_plugin "bridgetown-lit-renderer", version: "2.0.0.beta3"
|
15
|
+
|
16
|
+
run "yarn add lit esbuild-plugin-lit-css bridgetown-lit-renderer@2.0.0-beta3"
|
17
|
+
|
18
|
+
copy_file in_templates_dir("lit-ssr.config.js"), "config/lit-ssr.config.js"
|
19
|
+
copy_file in_templates_dir("lit-components-entry.js"), "config/lit-components-entry.js"
|
20
|
+
copy_file in_templates_dir("esbuild-plugins.js"), "config/esbuild-plugins.js"
|
21
|
+
|
22
|
+
insert_into_file "esbuild.config.js",
|
23
|
+
after: 'const build = require("./config/esbuild.defaults.js")' do
|
24
|
+
<<~JS
|
25
|
+
|
26
|
+
const { plugins } = require("./config/esbuild-plugins.js")
|
27
|
+
JS
|
28
|
+
end
|
29
|
+
|
30
|
+
found_match = false
|
31
|
+
gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
|
32
|
+
found_match = true
|
33
|
+
|
34
|
+
<<~JS
|
35
|
+
const esbuildOptions = {
|
36
|
+
plugins: [...plugins],
|
37
|
+
// Uncomment the following to opt into `.global.css` & `.lit.css` nomenclature.
|
38
|
+
// Read https://edge.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
|
39
|
+
/*
|
40
|
+
postCssPluginConfig: {
|
41
|
+
filter: /(?:index|\.global)\.css$/,
|
42
|
+
},
|
43
|
+
*/
|
44
|
+
}
|
45
|
+
JS
|
46
|
+
end
|
47
|
+
|
48
|
+
unless found_match
|
49
|
+
insert_into_file "esbuild.config.js",
|
50
|
+
after: 'const { plugins } = require("./config/esbuild-plugins.js")' do
|
51
|
+
<<~JS
|
52
|
+
|
53
|
+
// TODO: You will manually need to move any plugins below you wish to share with
|
54
|
+
// Lit SSR into the `config/esbuild-plugins.js` file.
|
55
|
+
// Then add `...plugins` as an item in your plugins array.
|
56
|
+
//
|
57
|
+
// You might also want to include the following in your esbuild config to opt into
|
58
|
+
// `.global.css` & `.lit.css` nomenclature.
|
59
|
+
// Read https://edge.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
|
60
|
+
/*
|
61
|
+
postCssPluginConfig: {
|
62
|
+
filter: /(?:index|\.global)\.css$/,
|
63
|
+
},
|
64
|
+
*/
|
65
|
+
JS
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
copy_file in_templates_dir("happy-days.lit.js"), "src/_components/happy-days.lit.js"
|
70
|
+
|
71
|
+
javascript_import do
|
72
|
+
<<~JS
|
73
|
+
import "bridgetown-lit-renderer"
|
74
|
+
JS
|
75
|
+
end
|
76
|
+
|
77
|
+
insert_into_file "frontend/javascript/index.js",
|
78
|
+
before: 'import components from "bridgetownComponents/**/*.{js,jsx,js.rb,css}"' do
|
79
|
+
<<~JS
|
80
|
+
// To opt into `.global.css` & `.lit.css` nomenclature, change the `css` extension below to `global.css`.
|
81
|
+
// Read https://edge.bridgetownrb.com/docs/components/lit#sidecar-css-files for documentation.
|
82
|
+
JS
|
83
|
+
end
|
84
|
+
|
85
|
+
if found_match
|
86
|
+
say_status :lit, "Lit is now configured!"
|
87
|
+
say_status :lit,
|
88
|
+
"The `config/esbuild-plugins.js` file will let you add full-stack plugins in future."
|
89
|
+
else
|
90
|
+
say_status :lit, "Lit is just about configured!"
|
91
|
+
say_status :lit, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
|
92
|
+
end
|
93
|
+
|
94
|
+
say "Check out the example `happy-days.lit.js` file in `src/_components`", :blue
|
95
|
+
say 'For further reading, check out "https://edge.bridgetownrb.com/docs/components/lit"', :blue
|
@@ -0,0 +1,11 @@
|
|
1
|
+
@import "open-props/<% if Bridgetown::Utils.frontend_bundler_type == :esbuild %>open-props.min.css<% else %>style<% end %>";
|
2
|
+
|
3
|
+
/* Uncomment this if you want addiitonal "default" styles applied: */
|
4
|
+
/* @import "open-props/normalize<% if Bridgetown::Utils.frontend_bundler_type == :esbuild %>.min.css<% end %>"; */
|
5
|
+
|
6
|
+
:root {
|
7
|
+
/* Define additional variables here. */
|
8
|
+
|
9
|
+
/* You can use variables from Open Props in your own custom properties. */
|
10
|
+
--color-medium-gray: var(--gray-7);
|
11
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
run "yarn add open-props"
|
4
|
+
|
5
|
+
variables_import = <<~CSS
|
6
|
+
@import "variables.css";
|
7
|
+
|
8
|
+
CSS
|
9
|
+
|
10
|
+
if File.exist?("frontend/styles/index.css")
|
11
|
+
prepend_to_file "frontend/styles/index.css", variables_import
|
12
|
+
elsif File.exist?("frontend/styles/index.scss")
|
13
|
+
prepend_to_file "frontend/styles/index.scss", variables_import
|
14
|
+
else
|
15
|
+
say "\nPlease add the following lines to your CSS index file:"
|
16
|
+
say variables_import
|
17
|
+
end
|
18
|
+
|
19
|
+
template in_templates_dir("variables.css.erb"), "frontend/styles/variables.css"
|
20
|
+
|
21
|
+
say_status :open_props, "Open Props is now configured."
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class HelloWorld < HTMLElement
|
2
|
+
def connected_callback()
|
3
|
+
self.inner_html = "<p><strong>Hello World!</strong></p>"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
# Try adding `<hello-world></hello-world>` somewhere on your site to see this
|
8
|
+
# example web component in action!
|
9
|
+
custom_elements.define "hello-world", HelloWorld
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless Bridgetown::Utils.frontend_bundler_type == :esbuild
|
4
|
+
error_message = "#{"esbuild.config.js".bold} not found. (This configuration doesn't currently " \
|
5
|
+
"support Webpack.)"
|
6
|
+
|
7
|
+
@logger.error "\nError:".red, "🚨 #{error_message}"
|
8
|
+
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
say_status :ruby2js, "Installing Ruby2JS..."
|
13
|
+
|
14
|
+
run "yarn add -D @ruby2js/esbuild-plugin"
|
15
|
+
|
16
|
+
found_match = false
|
17
|
+
gsub_file "esbuild.config.js", %r{const esbuildOptions = {}\n} do |_match|
|
18
|
+
found_match = true
|
19
|
+
|
20
|
+
<<~JS
|
21
|
+
const ruby2js = require("@ruby2js/esbuild-plugin")
|
22
|
+
|
23
|
+
const esbuildOptions = {
|
24
|
+
plugins: [
|
25
|
+
// See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
|
26
|
+
ruby2js({
|
27
|
+
eslevel: 2022,
|
28
|
+
autoexports: "default",
|
29
|
+
filters: ["camelCase", "functions", "lit", "esm", "return"]
|
30
|
+
})
|
31
|
+
]
|
32
|
+
}
|
33
|
+
JS
|
34
|
+
end
|
35
|
+
|
36
|
+
unless found_match
|
37
|
+
insert_into_file "esbuild.config.js",
|
38
|
+
after: 'const build = require("./config/esbuild.defaults.js")' do
|
39
|
+
<<~JS
|
40
|
+
|
41
|
+
const ruby2js = require("@ruby2js/esbuild-plugin")
|
42
|
+
|
43
|
+
// TODO: Uncomment and move the following into your plugins array:
|
44
|
+
//
|
45
|
+
// ruby2js({
|
46
|
+
// eslevel: 2022,
|
47
|
+
// autoexports: "default",
|
48
|
+
// filters: ["camelCase", "functions", "lit", "esm", "return"]
|
49
|
+
// })
|
50
|
+
//
|
51
|
+
// See docs on Ruby2JS options here: https://www.ruby2js.com/docs/options
|
52
|
+
|
53
|
+
JS
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
copy_file in_templates_dir("hello_world.js.rb"), "src/_components/hello_world.js.rb"
|
58
|
+
|
59
|
+
if found_match
|
60
|
+
say_status :ruby2js, "Ruby2JS is now configured!"
|
61
|
+
else
|
62
|
+
say_status :ruby2js, "Ruby2JS is just about configured!"
|
63
|
+
say_status :ruby2js, "You will need to edit `esbuild.config.js` to finish setting up the plugin."
|
64
|
+
end
|
65
|
+
|
66
|
+
say "Check out the example `hello_world.js.rb` file in `src/_components`", :blue
|
67
|
+
say 'For further reading, check out "https://www.ruby2js.com"', :blue
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
say_status :shoelace, "Installing Shoelace..."
|
4
|
+
|
5
|
+
run "yarn add @shoelace-style/shoelace"
|
6
|
+
|
7
|
+
say 'Adding Shoelace to "frontend/javascript/index.js"...', :magenta
|
8
|
+
|
9
|
+
javascript_import do
|
10
|
+
<<~JS
|
11
|
+
// Import the base Shoelace stylesheet:
|
12
|
+
import "@shoelace-style/shoelace/dist/themes/light.css"
|
13
|
+
|
14
|
+
// Example components, mix 'n' match however you like!
|
15
|
+
import "@shoelace-style/shoelace/dist/components/button/button.js"
|
16
|
+
import "@shoelace-style/shoelace/dist/components/icon/icon.js"
|
17
|
+
import "@shoelace-style/shoelace/dist/components/spinner/spinner.js"
|
18
|
+
|
19
|
+
// Use the public icons folder:
|
20
|
+
import { setBasePath } from "@shoelace-style/shoelace/dist/utilities/base-path.js"
|
21
|
+
setBasePath("/shoelace-assets")
|
22
|
+
JS
|
23
|
+
end
|
24
|
+
|
25
|
+
say "Updating frontend build commands...", :magenta
|
26
|
+
|
27
|
+
if Bridgetown::Utils.frontend_bundler_type == :esbuild
|
28
|
+
insert_into_file "package.json", before: ' "esbuild": "node' do
|
29
|
+
<<-JS
|
30
|
+
"shoelace:copy-assets": "mkdir -p src/shoelace-assets && cp -r node_modules/@shoelace-style/shoelace/dist/assets src/shoelace-assets",
|
31
|
+
JS
|
32
|
+
end
|
33
|
+
gsub_file "package.json", %r{"esbuild": "node}, '"esbuild": "yarn shoelace:copy-assets && node'
|
34
|
+
gsub_file "package.json", %r{"esbuild-dev": "node},
|
35
|
+
'"esbuild-dev": "yarn shoelace:copy-assets && node'
|
36
|
+
else
|
37
|
+
insert_into_file "package.json", before: ' "webpack-build": "webpack' do
|
38
|
+
<<-JS
|
39
|
+
"shoelace:copy-assets": "mkdir -p src/shoelace-assets && cp -r node_modules/@shoelace-style/shoelace/dist/assets src/shoelace-assets",
|
40
|
+
JS
|
41
|
+
end
|
42
|
+
gsub_file "package.json", %r{"webpack-build": "webpack},
|
43
|
+
'"webpack-build": "yarn shoelace:copy-assets && webpack'
|
44
|
+
gsub_file "package.json", %r{"webpack-dev": "webpack},
|
45
|
+
'"webpack-dev": "yarn shoelace:copy-assets && webpack'
|
46
|
+
end
|
47
|
+
|
48
|
+
say_status :shoelace, "Shoelace is now configured!"
|
49
|
+
|
50
|
+
say 'For further reading, check out "https://shoelace.style"', :blue
|