bridgetown-core 1.0.0.alpha1 → 1.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/Rakefile +5 -5
  4. data/lib/bridgetown-core/cache.rb +3 -5
  5. data/lib/bridgetown-core/cleaner.rb +2 -2
  6. data/lib/bridgetown-core/collection.rb +4 -6
  7. data/lib/bridgetown-core/commands/base.rb +4 -3
  8. data/lib/bridgetown-core/commands/build.rb +20 -19
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
  10. data/lib/bridgetown-core/commands/console.rb +3 -3
  11. data/lib/bridgetown-core/commands/doctor.rb +10 -8
  12. data/lib/bridgetown-core/commands/new.rb +5 -3
  13. data/lib/bridgetown-core/commands/plugins.rb +7 -9
  14. data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
  15. data/lib/bridgetown-core/commands/serve.rb +25 -27
  16. data/lib/bridgetown-core/commands/start.rb +6 -6
  17. data/lib/bridgetown-core/commands/webpack.rb +1 -1
  18. data/lib/bridgetown-core/component.rb +2 -6
  19. data/lib/bridgetown-core/concerns/liquid_renderable.rb +2 -2
  20. data/lib/bridgetown-core/concerns/site/configurable.rb +1 -6
  21. data/lib/bridgetown-core/concerns/site/content.rb +2 -2
  22. data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
  23. data/lib/bridgetown-core/concerns/site/localizable.rb +1 -1
  24. data/lib/bridgetown-core/concerns/site/ssr.rb +1 -1
  25. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  26. data/lib/bridgetown-core/configuration.rb +1 -2
  27. data/lib/bridgetown-core/converter.rb +1 -0
  28. data/lib/bridgetown-core/converters/erb_templates.rb +6 -4
  29. data/lib/bridgetown-core/converters/liquid_templates.rb +2 -0
  30. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  31. data/lib/bridgetown-core/converters/smartypants.rb +1 -0
  32. data/lib/bridgetown-core/drops/drop.rb +4 -4
  33. data/lib/bridgetown-core/entry_filter.rb +1 -0
  34. data/lib/bridgetown-core/filters/url_filters.rb +1 -1
  35. data/lib/bridgetown-core/filters.rb +11 -12
  36. data/lib/bridgetown-core/frontmatter_defaults.rb +5 -7
  37. data/lib/bridgetown-core/generated_page.rb +1 -3
  38. data/lib/bridgetown-core/generators/prototype_generator.rb +36 -37
  39. data/lib/bridgetown-core/helpers.rb +1 -1
  40. data/lib/bridgetown-core/hooks.rb +2 -2
  41. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  42. data/lib/bridgetown-core/log_adapter.rb +1 -1
  43. data/lib/bridgetown-core/log_writer.rb +1 -1
  44. data/lib/bridgetown-core/model/base.rb +2 -2
  45. data/lib/bridgetown-core/model/builder_origin.rb +3 -3
  46. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  47. data/lib/bridgetown-core/plugin_manager.rb +2 -2
  48. data/lib/bridgetown-core/publisher.rb +1 -1
  49. data/lib/bridgetown-core/rack/boot.rb +8 -0
  50. data/lib/bridgetown-core/rack/routes.rb +1 -5
  51. data/lib/bridgetown-core/rack/static_indexes.rb +2 -2
  52. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  53. data/lib/bridgetown-core/renderer.rb +1 -1
  54. data/lib/bridgetown-core/resource/base.rb +7 -7
  55. data/lib/bridgetown-core/resource/permalink_processor.rb +3 -2
  56. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  57. data/lib/bridgetown-core/resource/transformer.rb +7 -5
  58. data/lib/bridgetown-core/ruby_template_view.rb +1 -3
  59. data/lib/bridgetown-core/static_file.rb +5 -7
  60. data/lib/bridgetown-core/tags/find.rb +6 -6
  61. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  62. data/lib/bridgetown-core/tags/post_url.rb +6 -6
  63. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  64. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +7 -1
  65. data/lib/bridgetown-core/url.rb +3 -3
  66. data/lib/bridgetown-core/utils.rb +7 -9
  67. data/lib/bridgetown-core/version.rb +1 -1
  68. data/lib/bridgetown-core/watcher.rb +2 -2
  69. data/lib/bridgetown-core.rb +2 -1
  70. data/lib/site_template/src/_layouts/default.liquid +1 -1
  71. metadata +3 -3
  72. data/lib/bridgetown-core/tags/include.rb +0 -213
@@ -40,10 +40,9 @@ class Bridgetown::Site
40
40
  # instance implementing the given `Converter` class.
41
41
  def find_converter_instance(klass)
42
42
  @find_converter_instance ||= {}
43
- @find_converter_instance[klass] ||= begin
44
- converters.find { |converter| converter.instance_of?(klass) } || \
45
- raise("No Converters found for #{klass}")
46
- end
43
+ @find_converter_instance[klass] ||= converters.find do |converter|
44
+ converter.instance_of?(klass)
45
+ end || raise("No Converters found for #{klass}")
47
46
  end
48
47
 
49
48
  # Create an array of instances of the subclasses of the class
@@ -7,7 +7,7 @@ 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")}/*.yml"].each do |locale_path|
11
11
  I18n.load_path << locale_path
12
12
  end
13
13
  I18n.available_locales = config[:available_locales]
@@ -8,7 +8,7 @@ class Bridgetown::Site
8
8
 
9
9
  module ClassMethods
10
10
  # Establish an SSR pipeline for a persistent backend process
11
- def start_ssr!
11
+ def start_ssr! # rubocop:todo Metrics/AbcSize
12
12
  if Bridgetown::Current.site
13
13
  raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
14
14
  "Check your Rack app for threading issues"
@@ -25,7 +25,7 @@ class Bridgetown::Site
25
25
  # @return [void]
26
26
  def each_site_file
27
27
  %w(generated_pages static_files_to_write resources_to_write).each do |type|
28
- send(type).each do |item|
28
+ send(type).each do |item| # rubocop:disable Style/ExplicitBlockArgument
29
29
  yield item
30
30
  end
31
31
  end
@@ -20,7 +20,6 @@ module Bridgetown
20
20
  "layouts_dir" => "_layouts",
21
21
  "data_dir" => "_data",
22
22
  "components_dir" => "_components",
23
- "includes_dir" => "_includes",
24
23
  "partials_dir" => "_partials",
25
24
  "collections" => {},
26
25
  "taxonomies" => {
@@ -203,7 +202,7 @@ module Bridgetown
203
202
  end
204
203
  rescue ArgumentError => e
205
204
  Bridgetown.logger.warn "WARNING:", "Error reading configuration. Using defaults" \
206
- " (and options)."
205
+ " (and options)."
207
206
  warn e
208
207
  end
209
208
 
@@ -20,6 +20,7 @@ module Bridgetown
20
20
  #
21
21
  # Returns an initialized Converter.
22
22
  def initialize(config = {})
23
+ super
23
24
  @config = config
24
25
  end
25
26
 
@@ -38,7 +38,7 @@ module Bridgetown
38
38
  return if text.empty?
39
39
 
40
40
  src << bufvar << ".safe_append='"
41
- src << text.gsub(%r{['\\]}, '\\\\\&')
41
+ src << text.gsub(%r{['\\]}, '\\\\\&') # rubocop:disable Style/StringLiterals
42
42
  src << "'.freeze;"
43
43
  end
44
44
 
@@ -110,7 +110,7 @@ module Bridgetown
110
110
  #
111
111
  # @return [String] The converted content.
112
112
  def convert(content, convertible)
113
- return content if convertible.data[:template_engine] != "erb"
113
+ return content if convertible.data[:template_engine].to_s != "erb"
114
114
 
115
115
  erb_view = Bridgetown::ERBView.new(convertible)
116
116
 
@@ -131,10 +131,12 @@ module Bridgetown
131
131
  end
132
132
  end
133
133
 
134
+ # @param ext [String]
135
+ # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
134
136
  def matches(ext, convertible)
135
- if convertible.data[:template_engine] == "erb" ||
137
+ if convertible.data[:template_engine].to_s == "erb" ||
136
138
  (convertible.data[:template_engine].nil? &&
137
- @config[:template_engine] == "erb")
139
+ @config[:template_engine].to_s == "erb")
138
140
  convertible.data[:template_engine] = "erb"
139
141
  return true
140
142
  end
@@ -56,6 +56,8 @@ module Bridgetown
56
56
  # rubocop: enable Metrics/MethodLength
57
57
  # rubocop: enable Metrics/AbcSize
58
58
 
59
+ # @param ext [String]
60
+ # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
59
61
  def matches(ext, convertible)
60
62
  if convertible.render_with_liquid?
61
63
  convertible.data[:template_engine] = "liquid"
@@ -44,7 +44,7 @@ module Kramdown
44
44
  end
45
45
  end
46
46
 
47
- def initialize(source, options = {})
47
+ def initialize(source, options = {}) # rubocop:disable Lint/MissingSuper
48
48
  BridgetownDocument.setup(options)
49
49
 
50
50
  @options = BridgetownDocument.options
@@ -25,6 +25,7 @@ module Bridgetown
25
25
  priority :low
26
26
 
27
27
  def initialize(config)
28
+ super
28
29
  unless defined?(Kramdown)
29
30
  Bridgetown::Utils::RequireGems.require_with_graceful_fail "kramdown"
30
31
  end
@@ -28,7 +28,7 @@ module Bridgetown
28
28
  # drop.
29
29
  #
30
30
  # Returns nothing
31
- def initialize(obj)
31
+ def initialize(obj) # rubocop:disable Lint/MissingSuper
32
32
  @obj = obj
33
33
  end
34
34
 
@@ -69,11 +69,11 @@ module Bridgetown
69
69
  if respond_to?(setter)
70
70
  public_send(setter, val)
71
71
  elsif respond_to?(key.to_s)
72
- if self.class.mutable?
73
- mutations[key] = val
74
- else
72
+ unless self.class.mutable?
75
73
  raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
76
74
  end
75
+
76
+ mutations[key] = val
77
77
  else
78
78
  fallback_data[key] = val
79
79
  end
@@ -3,6 +3,7 @@
3
3
  module Bridgetown
4
4
  class EntryFilter
5
5
  attr_reader :site
6
+
6
7
  SPECIAL_LEADING_CHAR_REGEX = %r!\A#{Regexp.union([".", "_", "#", "~"])}!o.freeze
7
8
  SPECIAL_LEADING_CHAR_NO_UNDERSCORES_REGEX = %r!\A#{Regexp.union([".", "#", "~"])}!o.freeze
8
9
 
@@ -49,7 +49,7 @@ module Bridgetown
49
49
 
50
50
  private
51
51
 
52
- def compute_absolute_url(input) # rubocop:todo Metrics/CyclomaticComplexity
52
+ def compute_absolute_url(input)
53
53
  return if input.nil?
54
54
  return input.absolute_url if input.respond_to?(:absolute_url)
55
55
 
@@ -104,7 +104,7 @@ module Bridgetown
104
104
  def obfuscate_link(input, prefix = "mailto")
105
105
  link = "<a href=\"#{prefix}:#{input}\">#{input}</a>"
106
106
  script = "<script type=\"text/javascript\">document.currentScript.insertAdjacentHTML('"
107
- script += "beforebegin', '#{rot47(link).gsub(%r!\\!, '\\\\\\')}'.replace(/[!-~]/g,"
107
+ script += "beforebegin', '#{rot47(link).gsub(%r!\\!, '\\\\\\')}'.replace(/[!-~]/g," # rubocop:disable Style/StringLiteralsInInterpolation
108
108
  script += "function(c){{var j=c.charCodeAt(0);if((j>=33)&&(j<=126)){"
109
109
  script += "return String.fromCharCode(33+((j+ 14)%94));}"
110
110
  script += "else{return String.fromCharCode(j);}}}));</script>"
@@ -180,7 +180,7 @@ module Bridgetown
180
180
  # their `#inspect` string object.
181
181
  #
182
182
  # Returns the filtered array of objects
183
- def where(input, property, value)
183
+ def where(input, property, value) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
184
184
  return input if !property || value.is_a?(Array) || value.is_a?(Hash)
185
185
  return input unless input.respond_to?(:select)
186
186
 
@@ -194,11 +194,9 @@ module Bridgetown
194
194
  @where_filter_cache[input_id][property] ||= {}
195
195
 
196
196
  # stash or retrive results to return
197
- @where_filter_cache[input_id][property][value] ||= begin
198
- input.select do |object|
199
- compare_property_vs_target(item_property(object, property), value)
200
- end.to_a
201
- end
197
+ @where_filter_cache[input_id][property][value] ||= input.select do |object|
198
+ compare_property_vs_target(item_property(object, property), value)
199
+ end.to_a
202
200
  end
203
201
 
204
202
  # Filters an array of objects against an expression
@@ -247,13 +245,14 @@ module Bridgetown
247
245
  if property.nil?
248
246
  input.sort
249
247
  else
250
- if nils == "first"
248
+ case nils
249
+ when "first"
251
250
  order = - 1
252
- elsif nils == "last"
251
+ when "last"
253
252
  order = + 1
254
253
  else
255
254
  raise ArgumentError, "Invalid nils order: " \
256
- "'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
255
+ "'#{nils}' is not a valid nils order. It must be 'first' or 'last'."
257
256
  end
258
257
 
259
258
  sort_input(input, property, order)
@@ -327,7 +326,7 @@ module Bridgetown
327
326
  # If the property doesn't exist, return the sort order respective of
328
327
  # which item doesn't have the property.
329
328
  # We also utilize the Schwartzian transform to make this more efficient.
330
- def sort_input(input, property, order)
329
+ def sort_input(input, property, order) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
331
330
  input.map { |item| [item_property(item, property), item] }
332
331
  .sort! do |a_info, b_info|
333
332
  a_property = a_info.first
@@ -413,7 +412,7 @@ module Bridgetown
413
412
  case item
414
413
  when Hash
415
414
  pairs = item.map { |k, v| as_liquid([k, v]) }
416
- Hash[pairs]
415
+ Hash[pairs] # rubocop:todo Style/HashConversion
417
416
  when Array
418
417
  item.map { |i| as_liquid(i) }
419
418
  else
@@ -166,10 +166,8 @@ module Bridgetown
166
166
  def matching_sets(path, collection)
167
167
  @matched_set_cache ||= {}
168
168
  @matched_set_cache[path] ||= {}
169
- @matched_set_cache[path][collection] ||= begin
170
- valid_sets.select do |set|
171
- !set.key?("scope") || applies?(set["scope"], path, collection)
172
- end
169
+ @matched_set_cache[path][collection] ||= valid_sets.select do |set|
170
+ !set.key?("scope") || applies?(set["scope"], path, collection)
173
171
  end
174
172
  end
175
173
 
@@ -200,9 +198,9 @@ module Bridgetown
200
198
  def massage_scope!(set)
201
199
  set["scope"] ||= {}
202
200
  set["scope"]["path"] ||= ""
203
- if set["scope"]["type"] && !set["scope"]["collection"]
204
- set["scope"]["collection"] = set["scope"]["type"]
205
- end
201
+ return unless set["scope"]["type"] && !set["scope"]["collection"]
202
+
203
+ set["scope"]["collection"] = set["scope"]["type"]
206
204
  end
207
205
 
208
206
  SANITIZATION_REGEX = %r!\A/|(?<=[^/])\z!.freeze
@@ -7,9 +7,7 @@ module Bridgetown
7
7
  include Publishable
8
8
 
9
9
  attr_writer :dir
10
- attr_accessor :site, :paginator
11
- attr_accessor :name, :ext, :basename
12
- attr_accessor :data, :content, :output
10
+ attr_accessor :site, :paginator, :name, :ext, :basename, :data, :content, :output
13
11
 
14
12
  alias_method :extname, :ext
15
13
 
@@ -44,31 +44,31 @@ module Bridgetown
44
44
  page_list.include?(page)
45
45
  end
46
46
 
47
- if prototype_pages.length.positive?
48
- ensure_pagination_enabled
47
+ return unless prototype_pages.length.positive?
49
48
 
50
- page_list.reject! do |page|
51
- prototype_pages.include? page
52
- end
49
+ ensure_pagination_enabled
50
+
51
+ page_list.reject! do |page|
52
+ prototype_pages.include? page
53
+ end
53
54
 
54
- prototype_pages.each do |prototype_page|
55
- search_term = validate_search_term(prototype_page)
56
- next if search_term.nil?
55
+ prototype_pages.each do |prototype_page|
56
+ search_term = validate_search_term(prototype_page)
57
+ next if search_term.nil?
57
58
 
58
- terms_matching_pages(search_term).each do |term|
59
- generate_new_page_from_prototype(prototype_page, search_term, term)
60
- end
59
+ terms_matching_pages(search_term).each do |term|
60
+ generate_new_page_from_prototype(prototype_page, search_term, term)
61
61
  end
62
62
  end
63
63
  end
64
64
 
65
65
  def ensure_pagination_enabled
66
- unless @site.config.dig(:pagination, :enabled)
67
- Bridgetown.logger.warn(
68
- "Pagination:",
69
- "Must be enabled for prototype pages to contain matches"
70
- )
71
- end
66
+ return if @site.config.dig(:pagination, :enabled)
67
+
68
+ Bridgetown.logger.warn(
69
+ "Pagination:",
70
+ "Must be enabled for prototype pages to contain matches"
71
+ )
72
72
  end
73
73
 
74
74
  # Check incoming prototype configuration and normalize options.
@@ -125,7 +125,7 @@ module Bridgetown
125
125
  # @param collection [Bridgetown::Collection]
126
126
  # @param search_term [String]
127
127
  # @param term [String]
128
- def initialize(prototyped_page, collection, search_term, term)
128
+ def initialize(prototyped_page, collection, search_term, term) # rubocop:disable Lint/MissingSuper
129
129
  @prototyped_page = prototyped_page
130
130
  @site = prototyped_page.site
131
131
  @url = ""
@@ -160,22 +160,21 @@ module Bridgetown
160
160
  slugify_term(term)
161
161
  end
162
162
 
163
- # rubocop:todo Metrics/AbcSize
164
- def process_title_data_placeholder(search_term, term)
165
- if prototyped_page.data["prototype"]["data"]
166
- if data["title"]&.include?(":prototype-data-label")
167
- related_data = site.data[prototyped_page.data["prototype"]["data"]].dig(term)
168
- if related_data
169
- data["#{search_term}_data"] = related_data
170
- data_label = related_data[prototyped_page.data["prototype"]["data_label"]]
171
- data["title"] = data["title"].gsub(
172
- ":prototype-data-label", data_label
173
- )
174
- end
175
- end
163
+ def process_title_data_placeholder(search_term, term) # rubocop:todo Metrics/AbcSize
164
+ unless prototyped_page.data["prototype"]["data"] &&
165
+ data["title"]&.include?(":prototype-data-label")
166
+ return
176
167
  end
168
+
169
+ related_data = site.data[prototyped_page.data["prototype"]["data"]][term]
170
+ return unless related_data
171
+
172
+ data["#{search_term}_data"] = related_data
173
+ data_label = related_data[prototyped_page.data["prototype"]["data_label"]]
174
+ data["title"] = data["title"].gsub(
175
+ ":prototype-data-label", data_label
176
+ )
177
177
  end
178
- # rubocop:enable Metrics/AbcSize
179
178
 
180
179
  def process_title_simple_placeholders(term)
181
180
  if data["title"]&.include?(":prototype-term-titleize")
@@ -184,11 +183,11 @@ module Bridgetown
184
183
  )
185
184
  end
186
185
 
187
- if data["title"]&.include?(":prototype-term")
188
- data["title"] = data["title"].gsub(
189
- ":prototype-term", term
190
- )
191
- end
186
+ return unless data["title"]&.include?(":prototype-term")
187
+
188
+ data["title"] = data["title"].gsub(
189
+ ":prototype-term", term
190
+ )
192
191
  end
193
192
 
194
193
  def slugify_term(term)
@@ -56,7 +56,7 @@ module Bridgetown
56
56
  # `url` or `relative_url`
57
57
  # @return [String] the permalink URL for the file
58
58
  def url_for(relative_path)
59
- if relative_path.respond_to?(:relative_url)
59
+ if relative_path.respond_to?(:relative_url) # rubocop:disable Style/GuardClause
60
60
  return safe(relative_path.relative_url) # new resource engine
61
61
  elsif relative_path.respond_to?(:url)
62
62
  return safe(relative_url(relative_path.url)) # old legacy engine
@@ -72,14 +72,14 @@ module Bridgetown
72
72
  @registry[owner].delete_if { |item| item.block == block }
73
73
  end
74
74
 
75
- def self.trigger(owner, event, *args)
75
+ def self.trigger(owner, event, *args) # rubocop:disable Metrics/CyclomaticComplexity
76
76
  # proceed only if there are hooks to call
77
77
  hooks = @registry[owner]&.select { |item| item.event == event }
78
78
  return if hooks.nil? || hooks.empty?
79
79
 
80
80
  prioritized_hooks(hooks).each do |hook|
81
81
  if ENV["BRIDGETOWN_LOG_LEVEL"] == "debug"
82
- hook_info = args[0]&.respond_to?(:url) ? args[0].relative_path : hook.block
82
+ hook_info = args[0].respond_to?(:url) ? args[0].relative_path : hook.block
83
83
  Bridgetown.logger.debug("Triggering hook:", "#{owner}:#{event} for #{hook_info}")
84
84
  end
85
85
  hook.block.call(*args)
@@ -68,9 +68,7 @@ module Bridgetown
68
68
  private
69
69
 
70
70
  def filename_regex
71
- @filename_regex ||= begin
72
- %r!\A(#{Regexp.escape(source_dir)}/|/*)(.*)!i
73
- end
71
+ @filename_regex ||= %r!\A(#{Regexp.escape(source_dir)}/|/*)(.*)!i
74
72
  end
75
73
 
76
74
  def new_profile_hash
@@ -120,7 +120,7 @@ module Bridgetown
120
120
  # colon -
121
121
  #
122
122
  # Returns the formatted topic statement
123
- def formatted_topic(topic, colon = false)
123
+ def formatted_topic(topic, colon = false) # rubocop:disable Style/OptionalBooleanParameter
124
124
  "#{topic}#{colon ? ": " : " "}".rjust(20)
125
125
  end
126
126
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Bridgetown
4
4
  class LogWriter < ::Logger
5
- def initialize
5
+ def initialize # rubocop:disable Lint/MissingSuper
6
6
  @progname = nil
7
7
  @level = DEBUG
8
8
  @default_formatter = Formatter.new
@@ -122,7 +122,7 @@ module Bridgetown
122
122
  attributes.key?(method_name) || method_name.to_s.end_with?("=") || super
123
123
  end
124
124
 
125
- def method_missing(method_name, *args) # rubocop:disable Style/MethodMissingSuper
125
+ def method_missing(method_name, *args)
126
126
  return attributes[method_name] if attributes.key?(method_name)
127
127
 
128
128
  key = method_name.to_s
@@ -134,7 +134,7 @@ module Bridgetown
134
134
  end
135
135
 
136
136
  Bridgetown.logger.warn "key `#{method_name}' not found in attributes for" \
137
- " #{attributes[:id].presence || ("new " + self.class.to_s)}"
137
+ " #{attributes[:id].presence || "new #{self.class}"}"
138
138
  nil
139
139
  end
140
140
 
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  end
16
16
 
17
17
  def initialize(id)
18
- self.id = id
18
+ super
19
19
  @relative_path = Pathname.new(url.path.delete_prefix("/"))
20
20
  end
21
21
 
@@ -38,9 +38,9 @@ module Bridgetown
38
38
 
39
39
  def read_data_from_builder
40
40
  builder = Kernel.const_get(url.host.gsub(".", "::"))
41
- raise NameError unless builder.respond_to?(:resource_data_for_id)
41
+ raise NameError unless builder.instance_methods.include?(:resource_data_for_id)
42
42
 
43
- builder.resource_data_for_id(id)
43
+ builder.new.resource_data_for_id(id) || raise(NameError)
44
44
  rescue NameError
45
45
  raise(
46
46
  Bridgetown::Errors::FatalException,
@@ -14,7 +14,7 @@ module Bridgetown
14
14
  manifest_origin = Addressable::URI.unescape(url.path.delete_prefix("/")).split("/").first
15
15
  Bridgetown::PluginManager.source_manifests.find do |manifest|
16
16
  manifest.origin.to_s == manifest_origin
17
- end.tap do |manifest| # rubocop:disable Style/MultilineBlockChain
17
+ end.tap do |manifest|
18
18
  raise "Unable to locate a source manifest for #{manifest_origin}" unless manifest
19
19
  end
20
20
  end
@@ -104,7 +104,7 @@ module Bridgetown
104
104
 
105
105
  # check matching version number is see if it's already installed
106
106
  if package_json["dependencies"]
107
- current_version = package_json["dependencies"].dig(yarn_dependency.first)
107
+ current_version = package_json["dependencies"][yarn_dependency.first]
108
108
  package_requires_updating?(current_version, yarn_dependency.last)
109
109
  else
110
110
  true
@@ -112,7 +112,7 @@ module Bridgetown
112
112
  end
113
113
 
114
114
  def self.package_requires_updating?(current_version, dep_version)
115
- current_version.nil? || current_version != dep_version && !current_version.include?("/")
115
+ current_version.nil? || (current_version != dep_version && !current_version.include?("/"))
116
116
  end
117
117
 
118
118
  # Require all .rb files
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  return false unless thing.respond_to?(:date)
16
16
 
17
17
  future_allowed =
18
- thing.respond_to?(:collection) && thing.collection.metadata.future || @site.config.future
18
+ (thing.respond_to?(:collection) && thing.collection.metadata.future) || @site.config.future
19
19
  thing_time = thing.date.is_a?(Date) ? thing.date.to_time.to_i : thing.date.to_i
20
20
  !future_allowed && thing_time > @site.time.to_i
21
21
  end
@@ -17,6 +17,14 @@ module Bridgetown
17
17
  def self.boot
18
18
  autoload_server_folder(root: Dir.pwd)
19
19
  RodaApp.opts[:bridgetown_preloaded_config] = Bridgetown::Current.preloaded_configuration
20
+ rescue Roda::RodaError => e
21
+ if e.message.include?("sessions plugin :secret option")
22
+ raise Bridgetown::Errors::InvalidConfigurationError,
23
+ "The Roda sessions plugin can't find a valid secret. Run `bin/bridgetown secret'" \
24
+ " and put the key in a ENV var you can use to configure the session in `roda_app.rb'"
25
+ end
26
+
27
+ raise e
20
28
  end
21
29
 
22
30
  def self.autoload_server_folder(root:)
@@ -4,7 +4,7 @@ module Bridgetown
4
4
  module Rack
5
5
  class Routes
6
6
  class << self
7
- attr_accessor :tracked_subclasses
7
+ attr_accessor :tracked_subclasses, :router_block
8
8
 
9
9
  def inherited(base)
10
10
  Bridgetown::Rack::Routes.track_subclass base
@@ -24,8 +24,6 @@ module Bridgetown
24
24
  end
25
25
  end
26
26
 
27
- attr_accessor :router_block
28
-
29
27
  def route(&block)
30
28
  self.router_block = block
31
29
  end
@@ -74,7 +72,6 @@ module Bridgetown
74
72
  instance_exec(@_roda_app.request, &self.class.router_block)
75
73
  end
76
74
 
77
- # rubocop:disable Style/MissingRespondToMissing
78
75
  ruby2_keywords def method_missing(method_name, *args, &block)
79
76
  if @_roda_app.respond_to?(method_name.to_sym)
80
77
  @_roda_app.send method_name.to_sym, *args, &block
@@ -86,7 +83,6 @@ module Bridgetown
86
83
  def respond_to_missing?(method_name, include_private = false)
87
84
  @_roda_app.respond_to?(method_name.to_sym, include_private) || super
88
85
  end
89
- # rubocop:enable Style/MissingRespondToMissing
90
86
  end
91
87
  end
92
88
  end
@@ -3,8 +3,8 @@
3
3
  require "roda/plugins/public"
4
4
 
5
5
  Roda::RodaPlugins::Public::RequestMethods.module_eval do
6
- SPLIT = Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact)
7
- def public_path_segments(path) # rubocop:disable Metrics/CyclomaticComplexity
6
+ SPLIT = Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact) # rubocop:disable Lint/ConstantDefinitionInBlock
7
+ def public_path_segments(path) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
8
8
  segments = []
9
9
 
10
10
  path.split(SPLIT).each do |seg|
@@ -47,10 +47,10 @@ module Bridgetown
47
47
  Layout.label_for_file(file)
48
48
  end
49
49
 
50
- def within(directory)
50
+ def within(directory, &block)
51
51
  return unless File.exist?(directory)
52
52
 
53
- Dir.chdir(directory) { yield }
53
+ Dir.chdir(directory, &block)
54
54
  end
55
55
  end
56
56
  end
@@ -119,7 +119,7 @@ module Bridgetown
119
119
  !(document.is_a? Bridgetown::Excerpt)
120
120
 
121
121
  Bridgetown.logger.warn "Build Warning:", "Layout '#{document.data["layout"]}' requested " \
122
- "in #{document.relative_path} does not exist."
122
+ "in #{document.relative_path} does not exist."
123
123
  end
124
124
 
125
125
  # Render layout content into document.output