bridgetown-core 0.19.3 → 0.21.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core.rb +37 -29
  4. data/lib/bridgetown-core/cleaner.rb +9 -3
  5. data/lib/bridgetown-core/collection.rb +177 -78
  6. data/lib/bridgetown-core/commands/base.rb +9 -0
  7. data/lib/bridgetown-core/commands/build.rb +0 -11
  8. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  9. data/lib/bridgetown-core/commands/configure.rb +8 -3
  10. data/lib/bridgetown-core/commands/console.rb +4 -0
  11. data/lib/bridgetown-core/commands/doctor.rb +1 -19
  12. data/lib/bridgetown-core/commands/new.rb +6 -6
  13. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  14. data/lib/bridgetown-core/commands/serve.rb +0 -14
  15. data/lib/bridgetown-core/commands/webpack.rb +75 -0
  16. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
  17. data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
  18. data/lib/bridgetown-core/commands/webpack/update.rb +3 -0
  19. data/lib/bridgetown-core/commands/webpack/webpack.config.js +18 -0
  20. data/lib/{site_template/webpack.config.js.erb → bridgetown-core/commands/webpack/webpack.defaults.js.erb} +32 -16
  21. data/lib/bridgetown-core/component.rb +183 -0
  22. data/lib/bridgetown-core/concerns/data_accessible.rb +1 -0
  23. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  24. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  25. data/lib/bridgetown-core/concerns/site/configurable.rb +10 -10
  26. data/lib/bridgetown-core/concerns/site/content.rb +56 -15
  27. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  28. data/lib/bridgetown-core/concerns/site/processable.rb +6 -4
  29. data/lib/bridgetown-core/concerns/site/renderable.rb +26 -0
  30. data/lib/bridgetown-core/concerns/site/writable.rb +12 -2
  31. data/lib/bridgetown-core/concerns/validatable.rb +2 -5
  32. data/lib/bridgetown-core/configuration.rb +61 -33
  33. data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
  34. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  35. data/lib/bridgetown-core/configurations/tailwindcss.rb +6 -6
  36. data/lib/bridgetown-core/converter.rb +23 -0
  37. data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
  38. data/lib/bridgetown-core/converters/identity.rb +0 -9
  39. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  40. data/lib/bridgetown-core/converters/markdown.rb +14 -4
  41. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +5 -38
  42. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  43. data/lib/bridgetown-core/converters/smartypants.rb +3 -1
  44. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  45. data/lib/bridgetown-core/current.rb +10 -0
  46. data/lib/bridgetown-core/document.rb +9 -16
  47. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  48. data/lib/bridgetown-core/drops/page_drop.rb +4 -0
  49. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  50. data/lib/bridgetown-core/drops/resource_drop.rb +83 -0
  51. data/lib/bridgetown-core/drops/site_drop.rb +33 -8
  52. data/lib/bridgetown-core/drops/unified_payload_drop.rb +5 -0
  53. data/lib/bridgetown-core/entry_filter.rb +17 -28
  54. data/lib/bridgetown-core/errors.rb +0 -2
  55. data/lib/bridgetown-core/filters.rb +3 -26
  56. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  57. data/lib/bridgetown-core/filters/url_filters.rb +12 -0
  58. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  59. data/lib/bridgetown-core/generators/prototype_generator.rb +59 -20
  60. data/lib/bridgetown-core/helpers.rb +48 -9
  61. data/lib/bridgetown-core/layout.rb +53 -21
  62. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -0
  63. data/lib/bridgetown-core/liquid_renderer/table.rb +1 -0
  64. data/lib/bridgetown-core/model/base.rb +138 -0
  65. data/lib/bridgetown-core/model/builder_origin.rb +40 -0
  66. data/lib/bridgetown-core/model/origin.rb +38 -0
  67. data/lib/bridgetown-core/model/repo_origin.rb +126 -0
  68. data/lib/bridgetown-core/page.rb +11 -2
  69. data/lib/bridgetown-core/plugin_manager.rb +1 -3
  70. data/lib/bridgetown-core/publisher.rb +8 -2
  71. data/lib/bridgetown-core/reader.rb +37 -22
  72. data/lib/bridgetown-core/readers/data_reader.rb +5 -5
  73. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  74. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  75. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  76. data/lib/bridgetown-core/readers/post_reader.rb +5 -4
  77. data/lib/bridgetown-core/regenerator.rb +9 -2
  78. data/lib/bridgetown-core/related_posts.rb +9 -6
  79. data/lib/bridgetown-core/renderer.rb +6 -13
  80. data/lib/bridgetown-core/resource/base.rb +329 -0
  81. data/lib/bridgetown-core/resource/destination.rb +49 -0
  82. data/lib/bridgetown-core/resource/permalink_processor.rb +179 -0
  83. data/lib/bridgetown-core/resource/relations.rb +132 -0
  84. data/lib/bridgetown-core/resource/taxonomy_term.rb +34 -0
  85. data/lib/bridgetown-core/resource/taxonomy_type.rb +56 -0
  86. data/lib/bridgetown-core/resource/transformer.rb +177 -0
  87. data/lib/bridgetown-core/ruby_template_view.rb +11 -11
  88. data/lib/bridgetown-core/site.rb +13 -6
  89. data/lib/bridgetown-core/static_file.rb +33 -10
  90. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  91. data/lib/bridgetown-core/tags/include.rb +1 -1
  92. data/lib/bridgetown-core/tags/post_url.rb +2 -2
  93. data/lib/bridgetown-core/url.rb +1 -0
  94. data/lib/bridgetown-core/utils.rb +49 -43
  95. data/lib/bridgetown-core/utils/require_gems.rb +60 -0
  96. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  97. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  98. data/lib/bridgetown-core/version.rb +2 -2
  99. data/lib/bridgetown-core/watcher.rb +2 -1
  100. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  101. data/lib/site_template/config/.keep +0 -0
  102. data/lib/site_template/package.json.erb +4 -4
  103. data/lib/site_template/plugins/site_builder.rb +1 -1
  104. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  105. metadata +46 -41
  106. data/lib/bridgetown-core/external.rb +0 -58
  107. data/lib/bridgetown-core/page_without_a_file.rb +0 -17
  108. data/lib/bridgetown-core/path_manager.rb +0 -31
  109. data/lib/bridgetown-core/readers/collection_reader.rb +0 -23
  110. data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
  111. data/lib/bridgetown-core/utils/exec.rb +0 -26
  112. data/lib/bridgetown-core/utils/internet.rb +0 -37
  113. data/lib/bridgetown-core/utils/platforms.rb +0 -80
  114. data/lib/bridgetown-core/utils/thread_event.rb +0 -31
  115. data/lib/bridgetown-core/utils/win_tz.rb +0 -75
@@ -11,6 +11,7 @@ class Bridgetown::Site
11
11
  # @see #cleanup
12
12
  # @see #write
13
13
  def process
14
+ Bridgetown::Current.site = self
14
15
  reset
15
16
  read
16
17
  generate # Extensible
@@ -41,8 +42,6 @@ class Bridgetown::Site
41
42
  @liquid_renderer.reset
42
43
  frontmatter_defaults.reset
43
44
 
44
- raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative?
45
-
46
45
  Bridgetown::Cache.clear_if_config_changed config
47
46
  Bridgetown::Hooks.trigger :site, :after_reset, self
48
47
  end
@@ -60,8 +59,11 @@ class Bridgetown::Site
60
59
 
61
60
  # Limits the current posts; removes the posts which exceed the limit_posts
62
61
  def limit_posts!
63
- if limit_posts.positive?
64
- limit = posts.docs.length < limit_posts ? posts.docs.length : limit_posts
62
+ if config.limit_posts.positive?
63
+ Bridgetown::Deprecator.deprecation_message(
64
+ "The limit_posts config option will be removed prior to Bridgetown 1.0"
65
+ )
66
+ limit = posts.docs.length < config.limit_posts ? posts.docs.length : config.limit_posts
65
67
  posts.docs = posts.docs[-limit, limit]
66
68
  end
67
69
  end
@@ -29,6 +29,26 @@ class Bridgetown::Site
29
29
  end
30
30
  end
31
31
 
32
+ def matched_converters_for_convertible(convertible)
33
+ @layout_converters ||= {}
34
+
35
+ if convertible.is_a?(Bridgetown::Layout) && @layout_converters[convertible]
36
+ return @layout_converters[convertible]
37
+ end
38
+
39
+ matches = converters.select do |converter|
40
+ if converter.method(:matches).arity == 1
41
+ converter.matches(convertible.extname)
42
+ else
43
+ converter.matches(convertible.extname, convertible)
44
+ end
45
+ end
46
+
47
+ @layout_converters[convertible] = matches if convertible.is_a?(Bridgetown::Layout)
48
+
49
+ matches
50
+ end
51
+
32
52
  # Renders all documents
33
53
  # @return [void]
34
54
  def render_docs
@@ -38,6 +58,12 @@ class Bridgetown::Site
38
58
  render_regenerated document
39
59
  end
40
60
  end
61
+
62
+ collection.resources.each do |resource|
63
+ render_with_locale(resource) do
64
+ resource.transform!
65
+ end
66
+ end
41
67
  end
42
68
  end
43
69
 
@@ -21,17 +21,27 @@ class Bridgetown::Site
21
21
  end
22
22
 
23
23
  # Yields all content objects while looping through {#pages},
24
- # {#static_files_to_write}, and {#docs_to_write}.
24
+ # {#static_files_to_write}, {#docs_to_write}, {#resources_to_write}.
25
25
  #
26
26
  # @yieldparam item [Document, Page, StaticFile]
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,11 +1,8 @@
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
- # FIXME: there should be ONE TRUE METHOD to read the YAML frontmatter
6
- # in the entire project. Both this and the equivalent Document method
7
- # should be extracted and generalized.
8
- #
9
6
  # Read the YAML frontmatter.
10
7
  #
11
8
  # base - The String path to the dir containing the file.
@@ -22,7 +19,7 @@ module Bridgetown
22
19
  **Utils.merged_file_read_opts(site, opts))
23
20
  if content =~ Document::YAML_FRONT_MATTER_REGEXP
24
21
  self.content = $POSTMATCH
25
- self.data = SafeYAML.load(Regexp.last_match(1))&.with_dot_access
22
+ self.data = YAMLParser.load(Regexp.last_match(1))&.with_dot_access
26
23
  end
27
24
  rescue Psych::SyntaxError => e
28
25
  Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
@@ -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" => "date",
63
+ "permalink" => nil, # default is set according to content engine
60
64
  "timezone" => nil, # use the local timezone
61
65
 
62
66
  "quiet" => false,
@@ -70,15 +74,16 @@ module Bridgetown
70
74
  },
71
75
 
72
76
  "kramdown" => {
73
- "auto_ids" => true,
74
- "toc_levels" => (1..6).to_a,
75
- "entity_output" => "as_char",
76
- "smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
77
- "input" => "GFM",
78
- "hard_wrap" => false,
79
- "guess_lang" => true,
80
- "footnote_nr" => 1,
81
- "show_warnings" => false,
77
+ "auto_ids" => true,
78
+ "toc_levels" => (1..6).to_a,
79
+ "entity_output" => "as_char",
80
+ "smart_quotes" => "lsquo,rsquo,ldquo,rdquo",
81
+ "input" => "GFM",
82
+ "hard_wrap" => false,
83
+ "guess_lang" => true,
84
+ "footnote_nr" => 1,
85
+ "show_warnings" => false,
86
+ "include_extraction_tags" => false,
82
87
  },
83
88
  }.each_with_object(Configuration.new) { |(k, v), hsh| hsh[k] = v.freeze }.freeze
84
89
 
@@ -95,8 +100,8 @@ module Bridgetown
95
100
  # user_config - a Hash or Configuration of overrides.
96
101
  #
97
102
  # Returns a Configuration filled with defaults.
98
- def from(user_config)
99
- Utils.deep_merge_hashes(DEFAULTS, Configuration[user_config])
103
+ def from(user_config, starting_defaults = DEFAULTS)
104
+ Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
100
105
  .merge_environment_specific_options!
101
106
  .add_default_collections
102
107
  .add_default_excludes
@@ -113,7 +118,7 @@ module Bridgetown
113
118
  # override - the command-line options hash
114
119
  #
115
120
  # Returns the path to the Bridgetown root directory
116
- def root_dir(override)
121
+ def root_dir(override = "")
117
122
  get_config_value_with_override("root_dir", override)
118
123
  end
119
124
 
@@ -122,7 +127,7 @@ module Bridgetown
122
127
  # override - the command-line options hash
123
128
  #
124
129
  # Returns the path to the Bridgetown source directory
125
- def source(override)
130
+ def source(override = "")
126
131
  get_config_value_with_override("source", override)
127
132
  end
128
133
 
@@ -139,10 +144,10 @@ module Bridgetown
139
144
  def safe_load_file(filename)
140
145
  case File.extname(filename)
141
146
  when %r!\.toml!i
142
- Bridgetown::External.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
147
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
143
148
  Tomlrb.load_file(filename)
144
149
  when %r!\.ya?ml!i
145
- SafeYAML.load_file(filename) || {}
150
+ YAMLParser.load_file(filename) || {}
146
151
  else
147
152
  raise ArgumentError,
148
153
  "No parser for '#{filename}' is available. Use a .y(a)ml or .toml file instead."
@@ -221,7 +226,7 @@ module Bridgetown
221
226
  raise ArgumentError, "Configuration file: (INVALID) #{file}".yellow
222
227
  end
223
228
 
224
- Bridgetown.logger.info "Configuration file:", file
229
+ Bridgetown.logger.debug "Configuration file:", file
225
230
  next_config
226
231
  rescue SystemCallError
227
232
  if @default_config_file ||= nil
@@ -242,23 +247,38 @@ module Bridgetown
242
247
  self
243
248
  end
244
249
 
245
- def add_default_collections
250
+ def add_default_collections # rubocop:todo all
246
251
  # It defaults to `{}`, so this is only if someone sets it to null manually.
247
- return self if self["collections"].nil?
252
+ return self if self[:collections].nil?
248
253
 
249
254
  # Ensure we have a hash.
250
- if self["collections"].is_a?(Array)
251
- self["collections"] = self["collections"].each_with_object({}) do |collection, hash|
255
+ if self[:collections].is_a?(Array)
256
+ self[:collections] = self[:collections].each_with_object({}) do |collection, hash|
252
257
  hash[collection] = {}
253
258
  end
254
259
  end
255
260
 
256
- self["collections"] = Utils.deep_merge_hashes(
257
- { "posts" => {} }, self["collections"]
258
- ).tap do |collections|
259
- collections["posts"]["output"] = true
260
- if self["permalink"]
261
- collections["posts"]["permalink"] ||= style_to_permalink(self["permalink"])
261
+ # Setup default collections
262
+ self[:collections][:posts] = {} unless self[:collections][:posts]
263
+ self[:collections][:posts][:output] = true
264
+ self[:collections][:posts][:sort_direction] ||= "descending"
265
+
266
+ if self[:content_engine] == "resource"
267
+ self[:permalink] = "pretty" if self[:permalink].blank?
268
+ self[:collections][:pages] = {} unless self[:collections][:pages]
269
+ self[:collections][:pages][:output] = true
270
+ self[:collections][:pages][:permalink] ||= "/:path/"
271
+
272
+ self[:collections][:data] = {} unless self[:collections][:data]
273
+ self[:collections][:data][:output] = false
274
+
275
+ unless self[:collections][:posts][:permalink]
276
+ self[:collections][:posts][:permalink] = self[:permalink]
277
+ end
278
+ else
279
+ self[:permalink] = "date" if self[:permalink].blank?
280
+ unless self[:collections][:posts][:permalink]
281
+ self[:collections][:posts][:permalink] = style_to_permalink(self[:permalink])
262
282
  end
263
283
  end
264
284
 
@@ -284,9 +304,9 @@ module Bridgetown
284
304
  self["ruby_in_front_matter"]
285
305
  end
286
306
 
287
- # rubocop:disable Metrics/CyclomaticComplexity #
288
- def style_to_permalink(permalink_style)
289
- case permalink_style.to_sym
307
+ # Deprecated, to be removed when Bridgetown goes Resource-only
308
+ def style_to_permalink(permalink_style) # rubocop:todo Metrics/CyclomaticComplexity
309
+ case permalink_style.to_s.to_sym
290
310
  when :pretty
291
311
  "/:categories/:year/:month/:day/:title/"
292
312
  when :simple
@@ -303,7 +323,6 @@ module Bridgetown
303
323
  permalink_style.to_s
304
324
  end
305
325
  end
306
- # rubocop:enable Metrics/CyclomaticComplexity #
307
326
 
308
327
  def check_include_exclude
309
328
  %w(include exclude).each do |option|
@@ -314,10 +333,19 @@ module Bridgetown
314
333
  "'#{option}' should be set as an array, but was: #{self[option].inspect}."
315
334
  end
316
335
 
317
- # add _pages to includes set
318
- self[:include] << "_pages"
336
+ unless self[:include].include?("_pages") || self[:content_engine] == "resource"
337
+ # add _pages to includes set
338
+ self[:include] << "_pages"
339
+ end
319
340
 
320
341
  self
321
342
  end
343
+
344
+ # Whether or not PostCSS is being used to process stylesheets.
345
+ #
346
+ # @return [Boolean] true if `postcss.config.js` exists, false if not
347
+ def uses_postcss?
348
+ File.exist?(Bridgetown.sanitized_path(root_dir, "postcss.config.js"))
349
+ end
322
350
  end
323
351
  end
@@ -4,23 +4,23 @@
4
4
 
5
5
  TEMPLATE_PATH = File.expand_path("./bt-postcss", __dir__)
6
6
 
7
- begin
8
- find_in_source_paths("postcss.config.js")
9
- rescue Thor::Error
7
+ unless File.exist?("postcss.config.js")
10
8
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
9
 
12
10
  @logger.error "\nError:".red, "🚨 #{error_message}"
13
- @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
11
+ @logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
14
12
 
15
13
  return
16
14
  end
17
15
 
16
+ confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
17
+ return unless confirm.casecmp?("Y")
18
+
18
19
  plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
19
20
 
20
21
  say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
21
22
  run "yarn add -D #{plugins.join(' ')}"
22
23
 
23
- remove_file "postcss.config.js"
24
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
24
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
25
25
 
26
26
  # rubocop:enable all
@@ -4,3 +4,4 @@ TEMPLATE_PATH = File.expand_path("./netlify", __dir__)
4
4
 
5
5
  copy_file "#{TEMPLATE_PATH}/netlify.toml", "netlify.toml"
6
6
  copy_file "#{TEMPLATE_PATH}/netlify.sh", "bin/netlify.sh"
7
+ `chmod a+x ./bin/netlify.sh`
@@ -4,22 +4,22 @@
4
4
 
5
5
  TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
6
6
 
7
- begin
8
- find_in_source_paths("postcss.config.js")
9
- rescue Thor::Error
7
+ unless File.exist?("postcss.config.js")
10
8
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
11
9
 
12
10
  @logger.error "\nError:".red, "🚨 #{error_message}"
13
- @logger.info "\nFor new projects, you can use #{"bridgetown new my_project --use-postcss".bold.blue}\n"
11
+ @logger.info "\nRun #{"bridgetown webpack enable-postcss".bold.blue} to set it up.\n"
14
12
 
15
13
  return
16
14
  end
17
15
 
16
+ confirm = ask "This configuration will ovewrite your existing #{"postcss.config.js".bold.white}. Would you like to continue? [Yn]"
17
+ return unless confirm.casecmp?("Y")
18
+
18
19
  run "yarn add -D tailwindcss"
19
20
  run "npx tailwindcss init"
20
21
 
21
- remove_file "postcss.config.js"
22
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js"
22
+ copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
23
23
 
24
24
  prepend_to_file "frontend/styles/index.css",
25
25
  File.read("#{TEMPLATE_PATH}/css_imports.css")
@@ -23,6 +23,16 @@ module Bridgetown
23
23
  @config = config
24
24
  end
25
25
 
26
+ # Logic to do the content conversion.
27
+ #
28
+ # @param content [String] content of file (without front matter).
29
+ # @param convertible [Bridgetown::Document, Bridgetown::Layout, Bridgetown::Resource::Base]
30
+ #
31
+ # @return [String] the converted content.
32
+ def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument
33
+ content
34
+ end
35
+
26
36
  # Does the given extension match this converter's list of acceptable extensions?
27
37
  #
28
38
  # @param [String] ext
@@ -42,5 +52,18 @@ module Bridgetown
42
52
  def output_ext(_ext)
43
53
  ".html"
44
54
  end
55
+
56
+ def line_start(convertible)
57
+ if convertible.is_a?(Bridgetown::Resource::Base) &&
58
+ convertible.model.origin.respond_to?(:front_matter_line_count)
59
+ convertible.model.origin.front_matter_line_count + 4
60
+ else
61
+ 1
62
+ end
63
+ end
64
+
65
+ def inspect
66
+ "#<#{self.class}#{self.class.extname_list ? " #{self.class.extname_list.join(", ")}" : nil}>"
67
+ end
45
68
  end
46
69
  end
@@ -3,14 +3,26 @@
3
3
  require "tilt/erubi"
4
4
 
5
5
  module Bridgetown
6
- class ERBBuffer < String
7
- def concat_to_s(input)
8
- concat input.to_s
6
+ class OutputBuffer < ActiveSupport::SafeBuffer
7
+ def initialize(*)
8
+ super
9
+ encode!
9
10
  end
10
11
 
11
- alias_method :safe_append=, :concat_to_s
12
- alias_method :append=, :concat_to_s
13
- alias_method :safe_expr_append=, :concat_to_s
12
+ def <<(value)
13
+ return self if value.nil?
14
+
15
+ super(value.to_s)
16
+ end
17
+ alias_method :append=, :<<
18
+
19
+ def safe_expr_append=(val)
20
+ return self if val.nil? # rubocop:disable Lint/ReturnInVoidContext
21
+
22
+ safe_concat val.to_s
23
+ end
24
+
25
+ alias_method :safe_append=, :safe_concat
14
26
  end
15
27
 
16
28
  class ERBEngine < Erubi::Engine
@@ -22,24 +34,47 @@ module Bridgetown
22
34
  @src << ";" unless code[Erubi::RANGE_LAST] == "\n"
23
35
  end
24
36
 
37
+ def add_text(text)
38
+ return if text.empty?
39
+
40
+ src << bufvar << ".safe_append='"
41
+ src << text.gsub(%r{['\\]}, '\\\\\&')
42
+ src << "'.freeze;"
43
+ end
44
+
25
45
  # pulled from Rails' ActionView
26
46
  BLOCK_EXPR = %r!\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z!.freeze
27
47
 
28
48
  def add_expression(indicator, code)
49
+ src << bufvar << if (indicator == "==") || @escape
50
+ ".safe_expr_append="
51
+ else
52
+ ".append="
53
+ end
54
+
29
55
  if BLOCK_EXPR.match?(code)
30
- src << "#{@bufvar}.append= " << code
56
+ src << " " << code
31
57
  else
32
- super
58
+ src << "(" << code << ");"
33
59
  end
34
60
  end
61
+ end
35
62
 
36
- # Don't allow == to output escaped strings, as that's the opposite of Rails
37
- def add_expression_result_escaped(code)
38
- add_expression_result(code)
63
+ module ERBCapture
64
+ def capture(*args)
65
+ previous_buffer_state = @_erbout
66
+ @_erbout = OutputBuffer.new
67
+ result = yield(*args)
68
+ result = @_erbout.presence || result
69
+ @_erbout = previous_buffer_state
70
+
71
+ result.is_a?(String) ? ERB::Util.h(result) : result
39
72
  end
40
73
  end
41
74
 
42
75
  class ERBView < RubyTemplateView
76
+ include ERBCapture
77
+
43
78
  def h(input)
44
79
  Erubi.h(input)
45
80
  end
@@ -55,30 +90,10 @@ module Bridgetown
55
90
  Tilt::ErubiTemplate.new(
56
91
  site.in_source_dir(site.config[:partials_dir], "#{partial_name}.erb"),
57
92
  outvar: "@_erbout",
58
- bufval: "Bridgetown::ERBBuffer.new",
93
+ bufval: "Bridgetown::OutputBuffer.new",
59
94
  engine_class: ERBEngine
60
95
  ).render(self, options)
61
96
  end
62
-
63
- def markdownify(input = nil, &block)
64
- content = Bridgetown::Utils.reindent_for_markdown(
65
- block.nil? ? input.to_s : capture(&block)
66
- )
67
- converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
68
- result = converter.convert(content).strip
69
- result.respond_to?(:html_safe) ? result.html_safe : result
70
- end
71
-
72
- def capture(*args, &block)
73
- return capture_in_view_component(*args, &block) if @in_view_component
74
-
75
- previous_buffer_state = @_erbout
76
- @_erbout = ERBBuffer.new
77
- result = yield(*args)
78
- @_erbout = previous_buffer_state
79
-
80
- result.respond_to?(:html_safe) ? result.html_safe : result
81
- end
82
97
  end
83
98
 
84
99
  module Converters
@@ -89,7 +104,7 @@ module Bridgetown
89
104
  # Logic to do the ERB content conversion.
90
105
  #
91
106
  # @param content [String] Content of the file (without front matter).
92
- # @params convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
107
+ # @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
93
108
  # The instantiated object which is processing the file.
94
109
  #
95
110
  # @return [String] The converted content.
@@ -100,14 +115,15 @@ module Bridgetown
100
115
 
101
116
  erb_renderer = Tilt::ErubiTemplate.new(
102
117
  convertible.relative_path,
118
+ line_start(convertible),
103
119
  outvar: "@_erbout",
104
- bufval: "Bridgetown::ERBBuffer.new",
120
+ bufval: "Bridgetown::OutputBuffer.new",
105
121
  engine_class: ERBEngine
106
122
  ) { content }
107
123
 
108
124
  if convertible.is_a?(Bridgetown::Layout)
109
125
  erb_renderer.render(erb_view) do
110
- convertible.current_document_output
126
+ convertible.current_document_output.html_safe
111
127
  end
112
128
  else
113
129
  erb_renderer.render(erb_view)