bridgetown-core 1.2.0 → 1.3.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +21 -22
  3. data/lib/bridgetown-core/collection.rb +1 -1
  4. data/lib/bridgetown-core/commands/build.rb +3 -0
  5. data/lib/bridgetown-core/commands/console.rb +0 -1
  6. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +12 -2
  7. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +64 -18
  8. data/lib/bridgetown-core/commands/esbuild/jsconfig.json +10 -0
  9. data/lib/bridgetown-core/commands/esbuild/setup.rb +1 -0
  10. data/lib/bridgetown-core/commands/esbuild/update.rb +3 -0
  11. data/lib/bridgetown-core/commands/new.rb +2 -0
  12. data/lib/bridgetown-core/configuration/configuration_dsl.rb +1 -1
  13. data/lib/bridgetown-core/configuration.rb +13 -12
  14. data/lib/bridgetown-core/configurations/is-land.rb +15 -0
  15. data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -1
  16. data/lib/bridgetown-core/configurations/lit.rb +9 -54
  17. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  18. data/lib/bridgetown-core/configurations/ruby2js/ruby2js.rb +10 -0
  19. data/lib/bridgetown-core/configurations/ruby2js.rb +12 -40
  20. data/lib/bridgetown-core/configurations/turbo.rb +17 -7
  21. data/lib/bridgetown-core/errors.rb +10 -1
  22. data/lib/bridgetown-core/filters/localization_filters.rb +11 -0
  23. data/lib/bridgetown-core/helpers.rb +34 -0
  24. data/lib/bridgetown-core/plugin_manager.rb +0 -24
  25. data/lib/bridgetown-core/rack/boot.rb +13 -1
  26. data/lib/bridgetown-core/rack/routes.rb +40 -6
  27. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  28. data/lib/bridgetown-core/tags/dsd.rb +15 -0
  29. data/lib/bridgetown-core/tags/l.rb +14 -0
  30. data/lib/bridgetown-core/utils/aux.rb +2 -0
  31. data/lib/bridgetown-core/utils/loaders_manager.rb +7 -0
  32. data/lib/bridgetown-core/utils.rb +52 -5
  33. data/lib/bridgetown-core/version.rb +2 -2
  34. data/lib/bridgetown-core/watcher.rb +15 -8
  35. data/lib/bridgetown-core.rb +12 -0
  36. data/lib/roda/plugins/bridgetown_server.rb +140 -0
  37. data/lib/site_template/Gemfile.erb +6 -3
  38. data/lib/site_template/frontend/javascript/index.js.erb +10 -1
  39. data/lib/site_template/package.json.erb +6 -6
  40. data/lib/site_template/server/roda_app.rb +4 -2
  41. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  42. metadata +16 -27
  43. data/lib/bridgetown-core/commands/serve/servlet.rb +0 -68
  44. data/lib/bridgetown-core/commands/serve.rb +0 -253
  45. data/lib/bridgetown-core/rack/roda.rb +0 -157
  46. data/lib/roda/plugins/bridgetown_boot.rb +0 -25
@@ -1,157 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- unless Bridgetown::Current.preloaded_configuration
4
- raise "You must supply a preloaded configuration before loading Bridgetown's Roda superclass"
5
- end
6
-
7
- module Bridgetown
8
- module Rack
9
- class Roda < ::Roda
10
- class << self
11
- def inherited(klass)
12
- super
13
- klass.plugin :initializers
14
- end
15
-
16
- # rubocop:disable Bridgetown/NoPutsAllowed
17
- def print_routes
18
- # TODO: this needs to be fully documented
19
- routes = begin
20
- JSON.parse(
21
- File.read(
22
- File.join(Bridgetown::Current.preloaded_configuration.root_dir, ".routes.json")
23
- )
24
- )
25
- rescue StandardError
26
- []
27
- end
28
- puts
29
- puts "Routes:"
30
- puts "======="
31
- if routes.blank?
32
- puts "No routes found. Have you commented all of your routes?"
33
- puts "Documentation: https://github.com/jeremyevans/roda-route_list#basic-usage-"
34
- end
35
-
36
- routes.each do |route|
37
- puts [
38
- route["methods"]&.join("|") || "GET",
39
- route["path"],
40
- route["file"] ? "\n File: #{route["file"]}" : nil,
41
- ].compact.join(" ")
42
- end
43
- puts
44
- end
45
- # rubocop:enable Bridgetown/NoPutsAllowed
46
- end
47
-
48
- SiteContext = Struct.new(:registers) # for use by Liquid-esque URL helpers
49
-
50
- plugin :method_override
51
- plugin :all_verbs
52
- plugin :hooks
53
- plugin :common_logger, Bridgetown::Rack::Logger.new($stdout), method: :info
54
- plugin :json
55
- plugin :json_parser
56
- plugin :indifferent_params
57
- plugin :cookies
58
- plugin :streaming
59
- plugin :bridgetown_boot
60
- plugin :public, root: Bridgetown::Current.preloaded_configuration.destination
61
- plugin :not_found do
62
- output_folder = Bridgetown::Current.preloaded_configuration.destination
63
- File.read(File.join(output_folder, "404.html"))
64
- rescue Errno::ENOENT
65
- "404 Not Found"
66
- end
67
- plugin :exception_page
68
- plugin :error_handler do |e|
69
- Bridgetown::Errors.print_build_error(
70
- e, logger: Bridgetown::LogAdapter.new(self.class.opts[:common_logger])
71
- )
72
- next exception_page(e) if ENV.fetch("RACK_ENV", nil) == "development"
73
-
74
- output_folder = Bridgetown::Current.preloaded_configuration.destination
75
- File.read(File.join(output_folder, "500.html"))
76
- rescue Errno::ENOENT
77
- "500 Internal Server Error"
78
- end
79
-
80
- ::Roda::RodaPlugins::ExceptionPage.class_eval do
81
- def self.css
82
- <<~CSS
83
- html * { padding:0; margin:0; }
84
- body * { padding:10px 20px; }
85
- body * * { padding:0; }
86
- body { font-family: -apple-system, sans-serif; font-size: 90%; }
87
- body>div { border-bottom:1px solid #ddd; }
88
- code { font-family: ui-monospace, monospace; }
89
- h1 { font-weight: bold; margin-block-end: .8em; }
90
- h2 { margin-block-end:.8em; }
91
- h2 span { font-size:80%; color:#f7f7db; font-weight:normal; }
92
- h3 { margin:1em 0 .5em 0; }
93
- h4 { margin:0 0 .5em 0; font-weight: normal; }
94
- table {
95
- border:1px solid #ccc; border-collapse: collapse; background:white; }
96
- tbody td, tbody th { vertical-align:top; padding:2px 3px; }
97
- thead th {
98
- padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
99
- font-weight:normal; font-size:11px; border:1px solid #ddd; }
100
- tbody th { text-align:right; opacity: 0.7; padding-right:.5em; }
101
- table.vars { margin:5px 0 2px 40px; }
102
- table.vars td, table.req td { font-family: ui-monospace, monospace; }
103
- table td.code { width:100%;}
104
- table td.code div { overflow:hidden; }
105
- table.source th { color:#666; }
106
- table.source td {
107
- font-family: ui-monospace, monospace; white-space:pre; border-bottom:1px solid #eee; }
108
- ul.traceback { list-style-type:none; }
109
- ul.traceback li.frame { margin-bottom:1em; }
110
- div.context { margin: 10px 0; }
111
- div.context ol {
112
- padding-left:30px; margin:0 10px; list-style-position: inside; }
113
- div.context ol li {
114
- font-family: ui-monospace, monospace; white-space:pre; color:#666; cursor:pointer; }
115
- div.context ol.context-line li { color:black; background-color:#f7f7db; }
116
- div.context ol.context-line li span { float: right; }
117
- div.commands { margin-left: 40px; }
118
- div.commands a { color:black; text-decoration:none; }
119
- #summary { background: #1D453C; color: white; }
120
- #summary h2 { font-weight: normal; color: white; }
121
- #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
122
- #summary ul#quicklinks li { float: left; padding: 0 1em; }
123
- #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
124
- #summary a { color: #f47c3c; }
125
- #explanation { background:#eee; }
126
- #traceback { background: white; }
127
- #requestinfo { background:#f6f6f6; padding-left:120px; }
128
- #summary table { border:none; background:transparent; }
129
- #requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
130
- #requestinfo h3 { margin-bottom:-1em; }
131
- .error { background: #ffc; }
132
- .specific { color:#cc3300; font-weight:bold; }
133
- CSS
134
- end
135
- end
136
-
137
- before do
138
- if self.class.opts[:bridgetown_site]
139
- # The site had previously been initialized via the bridgetown_ssr plugin
140
- Bridgetown::Current.sites[self.class.opts[:bridgetown_site].label] =
141
- self.class.opts[:bridgetown_site]
142
- @context ||= SiteContext.new({ site: self.class.opts[:bridgetown_site] })
143
- end
144
- Bridgetown::Current.preloaded_configuration ||=
145
- self.class.opts[:bridgetown_preloaded_config]
146
-
147
- request.root do
148
- output_folder = Bridgetown::Current.preloaded_configuration.destination
149
- File.read(File.join(output_folder, "index.html"))
150
- rescue StandardError
151
- response.status = 500
152
- "<p>ERROR: cannot find <code>index.html</code> in the output folder.</p>"
153
- end
154
- end
155
- end
156
- end
157
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Roda
4
- module RodaPlugins
5
- module BridgetownBoot
6
- Roda::RodaRequest.alias_method :_previous_roda_cookies, :cookies
7
-
8
- module RequestMethods
9
- # Monkeypatch Roda/Rack's Request object so it returns a hash which allows for
10
- # indifferent access
11
- def cookies
12
- # TODO: maybe replace with a simpler hash that offers an overloaded `[]` method
13
- _previous_roda_cookies.with_indifferent_access
14
- end
15
-
16
- # Starts up the Bridgetown routing system
17
- def bridgetown
18
- Bridgetown::Rack::Routes.start!(scope)
19
- end
20
- end
21
- end
22
-
23
- register_plugin :bridgetown_boot, BridgetownBoot
24
- end
25
- end