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.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -1
  3. data/lib/bridgetown-core/collection.rb +37 -20
  4. data/lib/bridgetown-core/commands/concerns/actions.rb +3 -2
  5. data/lib/bridgetown-core/commands/configure.rb +1 -1
  6. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +20 -16
  7. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +95 -12
  8. data/lib/bridgetown-core/commands/new.rb +10 -9
  9. data/lib/bridgetown-core/commands/plugins.rb +2 -0
  10. data/lib/bridgetown-core/commands/start.rb +3 -0
  11. data/lib/bridgetown-core/commands/webpack/update.rb +2 -2
  12. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +11 -2
  13. data/lib/bridgetown-core/component.rb +13 -7
  14. data/lib/bridgetown-core/concerns/localizable.rb +20 -0
  15. data/lib/bridgetown-core/concerns/prioritizable.rb +44 -0
  16. data/lib/bridgetown-core/concerns/publishable.rb +11 -1
  17. data/lib/bridgetown-core/concerns/site/configurable.rb +2 -10
  18. data/lib/bridgetown-core/concerns/site/localizable.rb +5 -1
  19. data/lib/bridgetown-core/concerns/site/renderable.rb +27 -16
  20. data/lib/bridgetown-core/concerns/site/ssr.rb +3 -3
  21. data/lib/bridgetown-core/concerns/site/writable.rb +28 -0
  22. data/lib/bridgetown-core/concerns/transformable.rb +62 -0
  23. data/lib/bridgetown-core/configuration.rb +2 -0
  24. data/lib/bridgetown-core/configurations/bt-postcss/postcss.config.js +5 -3
  25. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -1
  26. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +33 -0
  27. data/lib/bridgetown-core/configurations/gh-pages.rb +16 -0
  28. data/lib/bridgetown-core/configurations/lit/esbuild-plugins.js +21 -0
  29. data/lib/bridgetown-core/configurations/lit/happy-days.lit.js +26 -0
  30. data/lib/bridgetown-core/configurations/lit/lit-components-entry.js +1 -0
  31. data/lib/bridgetown-core/configurations/lit/lit-ssr.config.js +6 -0
  32. data/lib/bridgetown-core/configurations/lit.rb +95 -0
  33. data/lib/bridgetown-core/configurations/open-props/variables.css.erb +11 -0
  34. data/lib/bridgetown-core/configurations/open-props.rb +21 -0
  35. data/lib/bridgetown-core/configurations/ruby2js/hello_world.js.rb +9 -0
  36. data/lib/bridgetown-core/configurations/ruby2js.rb +67 -0
  37. data/lib/bridgetown-core/configurations/shoelace.rb +50 -0
  38. data/lib/bridgetown-core/configurations/tailwindcss.rb +16 -2
  39. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  40. data/lib/bridgetown-core/drops/generated_page_drop.rb +2 -1
  41. data/lib/bridgetown-core/drops/resource_drop.rb +2 -1
  42. data/lib/bridgetown-core/errors.rb +5 -5
  43. data/lib/bridgetown-core/filters/translation_filters.rb +11 -0
  44. data/lib/bridgetown-core/filters/url_filters.rb +37 -10
  45. data/lib/bridgetown-core/filters.rb +3 -0
  46. data/lib/bridgetown-core/frontmatter_defaults.rb +14 -8
  47. data/lib/bridgetown-core/generated_page.rb +82 -17
  48. data/lib/bridgetown-core/kramdown/parser/gfm.rb +36 -0
  49. data/lib/bridgetown-core/model/base.rb +1 -2
  50. data/lib/bridgetown-core/plugin.rb +6 -37
  51. data/lib/bridgetown-core/plugin_manager.rb +3 -2
  52. data/lib/bridgetown-core/rack/boot.rb +5 -0
  53. data/lib/bridgetown-core/rack/logger.rb +14 -4
  54. data/lib/bridgetown-core/rack/roda.rb +102 -10
  55. data/lib/bridgetown-core/rack/routes.rb +87 -6
  56. data/lib/bridgetown-core/resource/base.rb +4 -6
  57. data/lib/bridgetown-core/resource/destination.rb +18 -0
  58. data/lib/bridgetown-core/resource/permalink_processor.rb +6 -4
  59. data/lib/bridgetown-core/resource/relations.rb +1 -1
  60. data/lib/bridgetown-core/resource/transformer.rb +21 -85
  61. data/lib/bridgetown-core/utils/aux.rb +2 -1
  62. data/lib/bridgetown-core/utils/require_gems.rb +3 -6
  63. data/lib/bridgetown-core/utils.rb +25 -12
  64. data/lib/bridgetown-core/version.rb +2 -2
  65. data/lib/bridgetown-core/watcher.rb +19 -6
  66. data/lib/bridgetown-core.rb +9 -3
  67. data/lib/site_template/Gemfile.erb +1 -1
  68. data/lib/site_template/README.md +2 -2
  69. data/lib/site_template/TEMPLATES/erb/_components/shared/navbar.erb +4 -4
  70. data/lib/site_template/TEMPLATES/liquid/_components/navbar.liquid +4 -4
  71. data/lib/site_template/TEMPLATES/serbea/_components/shared/navbar.serb +4 -4
  72. data/lib/site_template/bridgetown.config.yml +10 -3
  73. data/lib/site_template/frontend/javascript/index.js.erb +1 -0
  74. data/lib/site_template/frontend/styles/syntax-highlighting.css +77 -0
  75. data/lib/site_template/package.json.erb +18 -17
  76. data/lib/site_template/server/roda_app.rb +3 -6
  77. data/lib/site_template/src/404.html +2 -1
  78. data/lib/site_template/src/500.html +10 -0
  79. metadata +21 -4
  80. data/lib/bridgetown-core/publisher.rb +0 -29
  81. data/lib/bridgetown-core/renderer.rb +0 -169
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- # This class handles the output rendering and layout placement of pages and
5
- # documents. For rendering of resources in particular, see Bridgetown::Resource::Transformer
6
- class Renderer
7
- attr_reader :document, :site
8
-
9
- def initialize(site, document)
10
- @site = site
11
- @document = document
12
- end
13
-
14
- # Determine which converters to use based on this document's
15
- # extension.
16
- #
17
- # Returns Array of Converter instances.
18
- def converters
19
- @converters ||= site.converters.select do |converter|
20
- if converter.method(:matches).arity == 1
21
- converter.matches(document.extname)
22
- else
23
- converter.matches(document.extname, document)
24
- end
25
- end.sort
26
- end
27
-
28
- # Determine the extname the outputted file should have
29
- #
30
- # Returns String the output extname including the leading period.
31
- def output_ext
32
- @output_ext ||= (permalink_ext || converter_output_ext)
33
- end
34
-
35
- # Run hooks and render the document
36
- #
37
- # Returns nothing
38
- def run
39
- Bridgetown.logger.debug "Rendering:", document.relative_path
40
-
41
- document.trigger_hooks :pre_render
42
- document.output = render_document
43
- document.trigger_hooks :post_render
44
- end
45
-
46
- # Render the document.
47
- #
48
- # Returns String rendered document output
49
- def render_document
50
- execute_inline_ruby!
51
-
52
- output = document.content
53
- Bridgetown.logger.debug "Rendering Markup:", document.relative_path
54
- output = convert(output.to_s, document)
55
- document.content = output.html_safe
56
-
57
- if document.place_in_layout?
58
- Bridgetown.logger.debug "Rendering Layout:", document.relative_path
59
- output = place_in_layouts(output)
60
- end
61
-
62
- output
63
- end
64
-
65
- def execute_inline_ruby!
66
- return unless site.config.should_execute_inline_ruby?
67
-
68
- Bridgetown::Utils::RubyExec.search_data_for_ruby_code(document)
69
- end
70
-
71
- # Convert the document using the converters which match this renderer's document.
72
- #
73
- # Returns String the converted content.
74
- def convert(content, document)
75
- converters.reduce(content) do |output, converter|
76
- if converter.method(:convert).arity == 1
77
- converter.convert output
78
- else
79
- converter.convert output, document
80
- end
81
- rescue StandardError => e
82
- Bridgetown.logger.error "Conversion error:",
83
- "#{converter.class} encountered an error while "\
84
- "converting `#{document.relative_path}'"
85
- raise e
86
- end
87
- end
88
-
89
- # Render layouts and place document content inside.
90
- #
91
- # Returns String rendered content
92
- def place_in_layouts(content)
93
- output = content.dup
94
- layout = site.layouts[document.data["layout"]]
95
- validate_layout(layout)
96
-
97
- used = Set.new([layout])
98
-
99
- while layout
100
- output = render_layout(output, layout)
101
-
102
- next unless (layout = site.layouts[layout.data["layout"]])
103
- break if used.include?(layout)
104
-
105
- used << layout
106
- end
107
- output
108
- end
109
-
110
- private
111
-
112
- # Checks if the layout specified in the document actually exists
113
- #
114
- # layout - the layout to check
115
- # Returns nothing
116
- def validate_layout(layout)
117
- return unless document.data["layout"].present? &&
118
- layout.nil? &&
119
- !(document.is_a? Bridgetown::Excerpt)
120
-
121
- Bridgetown.logger.warn "Build Warning:", "Layout '#{document.data["layout"]}' requested " \
122
- "in #{document.relative_path} does not exist."
123
- end
124
-
125
- # Render layout content into document.output
126
- #
127
- # Returns String rendered content
128
- def render_layout(output, layout)
129
- layout_converters = site.matched_converters_for_convertible(layout)
130
-
131
- layout_content = layout.content.dup
132
- layout_converters.reduce(layout_content) do |layout_output, converter|
133
- next(layout_output) unless converter.method(:convert).arity == 2
134
-
135
- layout.current_document = document
136
- layout.current_document_output = output
137
- converter.convert layout_output, layout
138
- rescue StandardError => e
139
- Bridgetown.logger.error "Conversion error:",
140
- "#{converter.class} encountered an error while "\
141
- "converting `#{document.relative_path}'"
142
- raise e
143
- end
144
- end
145
-
146
- def permalink_ext
147
- document_permalink = document.permalink
148
- if document_permalink &&
149
- !document_permalink.end_with?("/")
150
- permalink_ext = File.extname(document_permalink)
151
- permalink_ext unless permalink_ext.empty?
152
- end
153
- end
154
-
155
- def converter_output_ext
156
- if output_exts.size == 1
157
- output_exts.last
158
- else
159
- output_exts[-2]
160
- end
161
- end
162
-
163
- def output_exts
164
- @output_exts ||= converters.filter_map do |c|
165
- c.output_ext(document.extname)
166
- end
167
- end
168
- end
169
- end