bridgetown-core 0.15.0.beta1 → 0.16.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/bridgetown-core.gemspec +2 -0
  4. data/lib/bridgetown-core.rb +6 -1
  5. data/lib/bridgetown-core/commands/concerns/actions.rb +54 -21
  6. data/lib/bridgetown-core/commands/console.rb +12 -2
  7. data/lib/bridgetown-core/commands/serve.rb +5 -0
  8. data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
  9. data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
  10. data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
  11. data/lib/bridgetown-core/concerns/publishable.rb +10 -0
  12. data/lib/bridgetown-core/concerns/site/configurable.rb +62 -31
  13. data/lib/bridgetown-core/concerns/site/content.rb +88 -29
  14. data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
  15. data/lib/bridgetown-core/concerns/site/processable.rb +12 -10
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +23 -4
  17. data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
  18. data/lib/bridgetown-core/concerns/validatable.rb +59 -0
  19. data/lib/bridgetown-core/configuration.rb +1 -0
  20. data/lib/bridgetown-core/converter.rb +34 -0
  21. data/lib/bridgetown-core/converters/erb_templates.rb +61 -0
  22. data/lib/bridgetown-core/converters/markdown.rb +6 -23
  23. data/lib/bridgetown-core/converters/smartypants.rb +0 -10
  24. data/lib/bridgetown-core/document.rb +8 -52
  25. data/lib/bridgetown-core/drops/document_drop.rb +9 -1
  26. data/lib/bridgetown-core/drops/page_drop.rb +1 -1
  27. data/lib/bridgetown-core/errors.rb +2 -0
  28. data/lib/bridgetown-core/excerpt.rb +5 -7
  29. data/lib/bridgetown-core/filters.rb +2 -0
  30. data/lib/bridgetown-core/layout.rb +24 -1
  31. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -4
  32. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
  33. data/lib/bridgetown-core/page.rb +36 -42
  34. data/lib/bridgetown-core/plugin_manager.rb +27 -13
  35. data/lib/bridgetown-core/regenerator.rb +1 -1
  36. data/lib/bridgetown-core/renderer.rb +41 -15
  37. data/lib/bridgetown-core/ruby_template_view.rb +84 -0
  38. data/lib/bridgetown-core/tags/class_map.rb +90 -0
  39. data/lib/bridgetown-core/tags/include.rb +2 -0
  40. data/lib/bridgetown-core/tags/render_content.rb +14 -2
  41. data/lib/bridgetown-core/tags/webpack_path.rb +48 -16
  42. data/lib/bridgetown-core/utils.rb +44 -0
  43. data/lib/bridgetown-core/version.rb +2 -2
  44. data/lib/site_template/bridgetown.config.yml +5 -3
  45. data/lib/site_template/package.json +1 -0
  46. data/lib/site_template/src/_components/{footer.html → footer.liquid} +0 -0
  47. data/lib/site_template/src/_components/{head.html → head.liquid} +0 -0
  48. data/lib/site_template/src/_components/{navbar.html → navbar.liquid} +0 -0
  49. data/lib/site_template/src/_layouts/default.html +1 -1
  50. data/lib/site_template/webpack.config.js +3 -3
  51. metadata +41 -6
  52. data/lib/bridgetown-core/concerns/convertible.rb +0 -238
@@ -287,6 +287,50 @@ module Bridgetown
287
287
  merged
288
288
  end
289
289
 
290
+ # Returns a string that's been reindented so that Markdown's four+ spaces =
291
+ # code doesn't get triggered for nested Liquid components
292
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
293
+ def reindent_for_markdown(input)
294
+ lines = input.lines
295
+ return input if lines.first.nil?
296
+
297
+ starting_indentation = lines.find { |line| line != "\n" }&.match(%r!^ +!)
298
+ return input unless starting_indentation
299
+
300
+ starting_indent_length = starting_indentation[0].length
301
+
302
+ skip_pre_lines = false
303
+ lines.map do |line|
304
+ continue_processing = !skip_pre_lines
305
+
306
+ if skip_pre_lines
307
+ skip_pre_lines = false if line.include?("</pre>")
308
+ end
309
+ if line.include?("<pre")
310
+ skip_pre_lines = true
311
+ continue_processing = false
312
+ end
313
+
314
+ if continue_processing
315
+ line_indentation = line.match(%r!^ +!).yield_self do |indent|
316
+ indent.nil? ? "" : indent[0]
317
+ end
318
+ new_indentation = line_indentation.rjust(starting_indent_length, " ")
319
+
320
+ if %r!^ +!.match?(line)
321
+ line
322
+ .sub(%r!^ {1,#{starting_indent_length}}!, new_indentation)
323
+ .sub(%r!^#{new_indentation}!, "")
324
+ else
325
+ line
326
+ end
327
+ else
328
+ line
329
+ end
330
+ end.join("")
331
+ end
332
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
333
+
290
334
  private
291
335
 
292
336
  def merge_values(target, overwrite)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.15.0.beta1"
5
- CODE_NAME = "Overlook"
4
+ VERSION = "0.16.0.beta1"
5
+ CODE_NAME = "Crystal Springs"
6
6
  end
@@ -10,12 +10,14 @@
10
10
  # For reloadable site metadata like title, SEO description, social media
11
11
  # handles, etc., take a look at src/_data/site_metadata.yml
12
12
  #
13
- # If you need help with YAML syntax, here are some quick references for you:
13
+ # If you need help with YAML syntax, here are some quick references for you:
14
14
  # https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml
15
15
  # https://learnxinyminutes.com/docs/yaml/
16
16
  #
17
17
 
18
18
  baseurl: "" # OPTIONAL: the subpath of your site, e.g. /blog
19
- url: "" # the base hostname & protocol for your site, e.g. http://example.com
19
+ url: "" # the base hostname & protocol for your site, e.g. https://example.com
20
20
 
21
- # Additional build settings go here
21
+ permalink: pretty
22
+
23
+ # timezone: America/Los_Angeles
@@ -14,6 +14,7 @@
14
14
  "devDependencies": {
15
15
  "@babel/core": "^7.9.0",
16
16
  "@babel/plugin-proposal-class-properties": "^7.8.3",
17
+ "@babel/plugin-proposal-decorators": "^7.10.1",
17
18
  "@babel/plugin-transform-runtime": "^7.9.0",
18
19
  "@babel/preset-env": "^7.9.0",
19
20
  "babel-loader": "^8.1.0",
@@ -4,7 +4,7 @@
4
4
  {% render "head", metadata: site.metadata, title: page.title %}
5
5
  </head>
6
6
  <body class="{{ page.layout }} {{ page.page_class }}">
7
- {% render "navbar" %}
7
+ {% render "navbar", metadata: site.metadata, page: page %}
8
8
 
9
9
  <main>
10
10
  {{ content }}
@@ -36,7 +36,8 @@ module.exports = {
36
36
  options: {
37
37
  presets: ["@babel/preset-env"],
38
38
  plugins: [
39
- "@babel/plugin-proposal-class-properties",
39
+ ["@babel/plugin-proposal-decorators", { "legacy": true }],
40
+ ["@babel/plugin-proposal-class-properties", { "loose" : true }],
40
41
  [
41
42
  "@babel/plugin-transform-runtime",
42
43
  {
@@ -57,8 +58,7 @@ module.exports = {
57
58
  options: {
58
59
  sassOptions: {
59
60
  includePaths: [
60
- path.resolve(__dirname, "src/_components"),
61
- path.resolve(__dirname, "src/_includes"),
61
+ path.resolve(__dirname, "src/_components")
62
62
  ],
63
63
  },
64
64
  },
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0.beta1
4
+ version: 0.16.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: colorator
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -248,6 +262,20 @@ dependencies:
248
262
  - - "~>"
249
263
  - !ruby/object:Gem::Version
250
264
  version: '1.0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: tilt
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '2.0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: '2.0'
251
279
  description: Bridgetown is a Webpack-aware, Ruby-powered static site generator for
252
280
  the modern Jamstack era
253
281
  email: maintainers@bridgetownrb.com
@@ -278,15 +306,20 @@ files:
278
306
  - lib/bridgetown-core/commands/registrations.rb
279
307
  - lib/bridgetown-core/commands/serve.rb
280
308
  - lib/bridgetown-core/commands/serve/servlet.rb
281
- - lib/bridgetown-core/concerns/convertible.rb
309
+ - lib/bridgetown-core/concerns/data_accessible.rb
310
+ - lib/bridgetown-core/concerns/layout_placeable.rb
311
+ - lib/bridgetown-core/concerns/liquid_renderable.rb
312
+ - lib/bridgetown-core/concerns/publishable.rb
282
313
  - lib/bridgetown-core/concerns/site/configurable.rb
283
314
  - lib/bridgetown-core/concerns/site/content.rb
284
315
  - lib/bridgetown-core/concerns/site/extensible.rb
285
316
  - lib/bridgetown-core/concerns/site/processable.rb
286
317
  - lib/bridgetown-core/concerns/site/renderable.rb
287
318
  - lib/bridgetown-core/concerns/site/writable.rb
319
+ - lib/bridgetown-core/concerns/validatable.rb
288
320
  - lib/bridgetown-core/configuration.rb
289
321
  - lib/bridgetown-core/converter.rb
322
+ - lib/bridgetown-core/converters/erb_templates.rb
290
323
  - lib/bridgetown-core/converters/identity.rb
291
324
  - lib/bridgetown-core/converters/markdown.rb
292
325
  - lib/bridgetown-core/converters/markdown/kramdown_parser.rb
@@ -341,8 +374,10 @@ files:
341
374
  - lib/bridgetown-core/regenerator.rb
342
375
  - lib/bridgetown-core/related_posts.rb
343
376
  - lib/bridgetown-core/renderer.rb
377
+ - lib/bridgetown-core/ruby_template_view.rb
344
378
  - lib/bridgetown-core/site.rb
345
379
  - lib/bridgetown-core/static_file.rb
380
+ - lib/bridgetown-core/tags/class_map.rb
346
381
  - lib/bridgetown-core/tags/highlight.rb
347
382
  - lib/bridgetown-core/tags/include.rb
348
383
  - lib/bridgetown-core/tags/link.rb
@@ -370,9 +405,9 @@ files:
370
405
  - lib/site_template/plugins/builders/.keep
371
406
  - lib/site_template/plugins/site_builder.rb
372
407
  - lib/site_template/src/404.html
373
- - lib/site_template/src/_components/footer.html
374
- - lib/site_template/src/_components/head.html
375
- - lib/site_template/src/_components/navbar.html
408
+ - lib/site_template/src/_components/footer.liquid
409
+ - lib/site_template/src/_components/head.liquid
410
+ - lib/site_template/src/_components/navbar.liquid
376
411
  - lib/site_template/src/_data/site_metadata.yml
377
412
  - lib/site_template/src/_layouts/default.html
378
413
  - lib/site_template/src/_layouts/home.html
@@ -1,238 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Convertible provides methods for converting a pagelike item
4
- # from a certain type of markup into actual content
5
- #
6
- # Requires
7
- # self.site -> Bridgetown::Site
8
- # self.content
9
- # self.content=
10
- # self.data=
11
- # self.ext=
12
- # self.output=
13
- # self.name
14
- # self.path
15
- # self.type -> :page or :post
16
-
17
- module Bridgetown
18
- module Convertible
19
- # Returns the contents as a String.
20
- def to_s
21
- content || ""
22
- end
23
-
24
- # Whether the file is published or not, as indicated in YAML front-matter
25
- def published?
26
- !(data.key?("published") && data["published"] == false)
27
- end
28
-
29
- # Read the YAML frontmatter.
30
- #
31
- # base - The String path to the dir containing the file.
32
- # name - The String filename of the file.
33
- # opts - optional parameter to File.read, default at site configs
34
- #
35
- # Returns nothing.
36
- # rubocop:disable Metrics/AbcSize
37
- def read_yaml(base, name, opts = {})
38
- filename = File.join(base, name)
39
-
40
- begin
41
- self.content = File.read(@path || site.in_source_dir(base, name),
42
- **Utils.merged_file_read_opts(site, opts))
43
- if content =~ Document::YAML_FRONT_MATTER_REGEXP
44
- self.content = $POSTMATCH
45
- self.data = SafeYAML.load(Regexp.last_match(1))&.with_indifferent_access
46
- end
47
- rescue Psych::SyntaxError => e
48
- Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
49
- raise e if site.config["strict_front_matter"]
50
- rescue StandardError => e
51
- Bridgetown.logger.warn "Error reading file #{filename}: #{e.message}"
52
- raise e if site.config["strict_front_matter"]
53
- end
54
-
55
- self.data ||= ActiveSupport::HashWithIndifferentAccess.new
56
-
57
- validate_data! filename
58
- validate_permalink! filename
59
-
60
- self.data
61
- end
62
- # rubocop:enable Metrics/AbcSize
63
-
64
- def validate_data!(filename)
65
- unless self.data.is_a?(Hash)
66
- raise Errors::InvalidYAMLFrontMatterError,
67
- "Invalid YAML front matter in #{filename}"
68
- end
69
- end
70
-
71
- def validate_permalink!(filename)
72
- if self.data["permalink"]&.to_s&.empty?
73
- raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
74
- end
75
- end
76
-
77
- # TODO: this method never seems to get called...why's it here?
78
- # Transform the contents based on the content type.
79
- #
80
- # Returns the transformed contents.
81
- def transform
82
- _renderer.convert(content)
83
- end
84
-
85
- # Determine the extension depending on content_type.
86
- #
87
- # Returns the String extension for the output file.
88
- # e.g. ".html" for an HTML output file.
89
- def output_ext
90
- _renderer.output_ext
91
- end
92
-
93
- # Determine which converter to use based on this convertible's
94
- # extension.
95
- #
96
- # Returns the Converter instance.
97
- def converters
98
- _renderer.converters
99
- end
100
-
101
- # Render Liquid in the content
102
- #
103
- # content - the raw Liquid content to render
104
- # payload - the payload for Liquid
105
- # info - the info for Liquid
106
- #
107
- # Returns the converted content
108
- def render_liquid(content, payload, info, path)
109
- _renderer.render_liquid(content, payload, info, path)
110
- end
111
-
112
- # Convert this Convertible's data to a Hash suitable for use by Liquid.
113
- #
114
- # Returns the Hash representation of this Convertible.
115
- def to_liquid(attrs = nil)
116
- further_data = \
117
- (attrs || self.class::ATTRIBUTES_FOR_LIQUID).each_with_object({}) do |attribute, hsh|
118
- hsh[attribute] = send(attribute)
119
- end
120
-
121
- defaults = site.frontmatter_defaults.all(relative_path, type)
122
- Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
123
- end
124
-
125
- # The type of a document,
126
- # i.e., its classname downcase'd and to_sym'd.
127
- #
128
- # Returns the type of self.
129
- def type
130
- :pages if is_a?(Page)
131
- end
132
-
133
- # returns the owner symbol for hook triggering
134
- def hook_owner
135
- :pages if is_a?(Page)
136
- end
137
-
138
- # TODO: Depricated
139
- # Used to determine CoffeeScript and Sass/SCSS files.
140
- def asset_file?
141
- false
142
- end
143
-
144
- # Determine whether the file should be rendered with Liquid.
145
- #
146
- # Returns true if the file has Liquid Tags or Variables, false otherwise.
147
- def render_with_liquid?
148
- return false if data["render_with_liquid"] == false
149
-
150
- Bridgetown::Utils.has_liquid_construct?(content)
151
- end
152
-
153
- # Determine whether the file should be placed into layouts.
154
- #
155
- # Returns false if the document is an asset file or if the front matter
156
- # specifies `layout: none`
157
- def place_in_layout?
158
- !(asset_file? || no_layout?)
159
- end
160
-
161
- # Checks if the layout specified in the document actually exists
162
- #
163
- # layout - the layout to check
164
- #
165
- # Returns true if the layout is invalid, false if otherwise
166
- def invalid_layout?(layout)
167
- !data["layout"].nil? && layout.nil? && !(is_a? Bridgetown::Excerpt)
168
- end
169
-
170
- # Recursively render layouts
171
- #
172
- # layouts - a list of the layouts
173
- # payload - the payload for Liquid
174
- # info - the info for Liquid
175
- #
176
- # Returns nothing
177
- def render_all_layouts(layouts, payload, info)
178
- _renderer.layouts = layouts
179
- self.output = _renderer.place_in_layouts(output, payload, info)
180
- ensure
181
- @_renderer = nil # this will allow the modifications above to disappear
182
- end
183
-
184
- # Add any necessary layouts to this convertible document.
185
- #
186
- # payload - The site payload Drop or Hash.
187
- # layouts - A Hash of {"name" => "layout"}.
188
- #
189
- # Returns nothing.
190
- def do_layout(payload, layouts)
191
- self.output = _renderer.tap do |renderer|
192
- renderer.layouts = layouts
193
- renderer.payload = payload
194
- end.run
195
-
196
- Bridgetown.logger.debug "Post-Render Hooks:", relative_path
197
- Bridgetown::Hooks.trigger hook_owner, :post_render, self
198
- ensure
199
- @_renderer = nil # this will allow the modifications above to disappear
200
- end
201
-
202
- # Write the generated page file to the destination directory.
203
- #
204
- # dest - The String path to the destination dir.
205
- #
206
- # Returns nothing.
207
- def write(dest)
208
- path = destination(dest)
209
- FileUtils.mkdir_p(File.dirname(path))
210
- Bridgetown.logger.debug "Writing:", path
211
- File.write(path, output, mode: "wb")
212
- Bridgetown::Hooks.trigger hook_owner, :post_write, self
213
- end
214
-
215
- # Accessor for data properties by Liquid.
216
- #
217
- # property - The String name of the property to retrieve.
218
- #
219
- # Returns the String value or nil if the property isn't included.
220
- def [](property)
221
- if self.class::ATTRIBUTES_FOR_LIQUID.include?(property)
222
- send(property)
223
- else
224
- data[property]
225
- end
226
- end
227
-
228
- private
229
-
230
- def _renderer
231
- @_renderer ||= Bridgetown::Renderer.new(site, self)
232
- end
233
-
234
- def no_layout?
235
- data["layout"] == "none"
236
- end
237
- end
238
- end