bridgetown-core 1.0.0.alpha1 → 1.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) 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/webpack.rb +1 -1
  17. data/lib/bridgetown-core/component.rb +1 -5
  18. data/lib/bridgetown-core/concerns/site/configurable.rb +1 -1
  19. data/lib/bridgetown-core/concerns/site/content.rb +2 -2
  20. data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
  21. data/lib/bridgetown-core/concerns/site/localizable.rb +1 -1
  22. data/lib/bridgetown-core/concerns/site/ssr.rb +1 -1
  23. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  24. data/lib/bridgetown-core/configuration.rb +1 -1
  25. data/lib/bridgetown-core/converter.rb +1 -0
  26. data/lib/bridgetown-core/converters/erb_templates.rb +1 -1
  27. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  28. data/lib/bridgetown-core/converters/smartypants.rb +1 -0
  29. data/lib/bridgetown-core/drops/drop.rb +4 -4
  30. data/lib/bridgetown-core/entry_filter.rb +1 -0
  31. data/lib/bridgetown-core/filters/url_filters.rb +1 -1
  32. data/lib/bridgetown-core/filters.rb +11 -12
  33. data/lib/bridgetown-core/frontmatter_defaults.rb +5 -7
  34. data/lib/bridgetown-core/generated_page.rb +1 -3
  35. data/lib/bridgetown-core/generators/prototype_generator.rb +36 -37
  36. data/lib/bridgetown-core/helpers.rb +1 -1
  37. data/lib/bridgetown-core/hooks.rb +2 -2
  38. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  39. data/lib/bridgetown-core/log_adapter.rb +1 -1
  40. data/lib/bridgetown-core/log_writer.rb +1 -1
  41. data/lib/bridgetown-core/model/base.rb +2 -2
  42. data/lib/bridgetown-core/model/builder_origin.rb +1 -1
  43. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  44. data/lib/bridgetown-core/plugin_manager.rb +2 -2
  45. data/lib/bridgetown-core/publisher.rb +1 -1
  46. data/lib/bridgetown-core/rack/routes.rb +1 -5
  47. data/lib/bridgetown-core/rack/static_indexes.rb +2 -2
  48. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  49. data/lib/bridgetown-core/renderer.rb +1 -1
  50. data/lib/bridgetown-core/resource/base.rb +7 -7
  51. data/lib/bridgetown-core/resource/permalink_processor.rb +3 -2
  52. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  53. data/lib/bridgetown-core/resource/transformer.rb +7 -5
  54. data/lib/bridgetown-core/ruby_template_view.rb +1 -3
  55. data/lib/bridgetown-core/static_file.rb +5 -7
  56. data/lib/bridgetown-core/tags/find.rb +6 -6
  57. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  58. data/lib/bridgetown-core/tags/include.rb +22 -19
  59. data/lib/bridgetown-core/tags/post_url.rb +6 -6
  60. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  61. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +1 -1
  62. data/lib/bridgetown-core/url.rb +3 -3
  63. data/lib/bridgetown-core/utils.rb +7 -9
  64. data/lib/bridgetown-core/version.rb +1 -1
  65. data/lib/bridgetown-core/watcher.rb +2 -2
  66. data/lib/bridgetown-core.rb +2 -1
  67. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 835cfe03f425b73a33a5086c3d36a343c81bad231d31bf01049a4f7dd0d6cea5
4
- data.tar.gz: 9c9a1a226a5ec9f40ad74203d8b692c4d4c126b3e35ab672893f69bea71dc79b
3
+ metadata.gz: a735962a1880837aa59641e65afa3985f0ebb091861ae32972d0b875229cfc7d
4
+ data.tar.gz: a64d7710c18a4c80805bd7196eacd07387fa1b3061616e8ed2b4de8b9a228871
5
5
  SHA512:
6
- metadata.gz: ad5c876760ccc74c3662b989e682e7aa774fa91fb55e616ecc88d9237b37fede1edb0b5e2a48eccb9d9ecf5880cef46d5c8357ec4fb8550f4cad48c88c4b66b7
7
- data.tar.gz: fa62ec5bbb0b5a121a1f0d0d68e11a562dba1a6714539c1a29802994722b9c783722313bc43248b99b75f87e979d9d74a7e84a40e11da567e9555dd3ae4b295c
6
+ metadata.gz: 7c136fee524ff82c30ceedcc8ef0ef11fc877ac82066c6bd1d16e0d55cc47391b2b211b72c9f2229d7d83685edb98968e516d2eea09510a1c7c3c4ab0466e6e9
7
+ data.tar.gz: 05b65d5c57dfdbd0dcea25ab15875b637868ecd4c69a76a288fe23dd64dc06eb2c3ee6ec980f30b3957888859fbed2e7771a007cf7188cf7572808a17a5c9372
data/.rubocop.yml ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ inherit_from: ../.rubocop.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - "*.gemspec"
7
+ - bin/**/*
8
+ - exe/**/*
9
+ - benchmark/**/*
10
+ - script/**/*
11
+ - vendor/**/*
12
+ - tmp/**/*
13
+ - test/source/**/*
14
+ - lib/site_template/Rakefile
15
+ - lib/site_template/config.ru
16
+ - lib/site_template/config/**/*
17
+ - lib/site_template/plugins/site_builder.rb
18
+
19
+ Lint/ConstantDefinitionInBlock:
20
+ Exclude:
21
+ - test/test_filters.rb
22
+ - test/test_liquid_extensions.rb
23
+ - test/test_site.rb
24
+
25
+ Lint/MissingSuper:
26
+ Exclude:
27
+ - test/test_liquid_extensions.rb
28
+
29
+ Performance/CollectionLiteralInLoop:
30
+ Exclude:
31
+ - test/test_filters.rb
32
+
33
+ Style/StringConcatenation:
34
+ Exclude:
35
+ - test/test_apply_command.rb
data/Rakefile CHANGED
@@ -13,16 +13,16 @@ Rake::TestTask.new(:test) do |test|
13
13
  test.verbose = true
14
14
  end
15
15
 
16
- require 'yard'
16
+ require "yard"
17
17
  YARD::Rake::YardocTask.new(:yard) do |t|
18
- t.files = ['lib/**/*.rb']
19
- t.options = ['--no-output']
20
- t.stats_options = ['--list-undoc']
18
+ t.files = ["lib/**/*.rb"]
19
+ t.options = ["--no-output"]
20
+ t.stats_options = ["--list-undoc"]
21
21
  end
22
22
 
23
23
  namespace :yard do
24
24
  task :serve do
25
- port = ENV['YARD_PORT'] || "8808"
25
+ port = ENV["YARD_PORT"] || "8808"
26
26
  sh("yard server --reload -p #{port}")
27
27
  end
28
28
  end
@@ -82,11 +82,9 @@ module Bridgetown
82
82
  return @cache[key] if @cache.key?(key)
83
83
 
84
84
  path = path_to(hash(key))
85
- if disk_cache_enabled? && File.file?(path) && File.readable?(path)
86
- @cache[key] = load(path)
87
- else
88
- raise
89
- end
85
+ raise unless disk_cache_enabled? && File.file?(path) && File.readable?(path)
86
+
87
+ @cache[key] = load(path)
90
88
  end
91
89
 
92
90
  # Add an item to cache
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  # Handles the cleanup of a site's destination before it is built.
5
5
  class Cleaner
6
- HIDDEN_FILE_REGEX = %r!\/\.{1,2}$!.freeze
6
+ HIDDEN_FILE_REGEX = %r!/\.{1,2}$!.freeze
7
7
  attr_reader :site
8
8
 
9
9
  def initialize(site)
@@ -104,7 +104,7 @@ module Bridgetown
104
104
  #
105
105
  # Returns the regular expression
106
106
  def keep_file_regex
107
- %r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.config.keep_files).source})!
107
+ %r!\A#{Regexp.quote(site.dest)}/(#{Regexp.union(site.config.keep_files).source})!
108
108
  end
109
109
  end
110
110
  end
@@ -190,7 +190,7 @@ module Bridgetown
190
190
  # @param label [String] the possibly-unsafe label
191
191
  # @return [String] sanitized version of the label.
192
192
  def sanitize_label(label)
193
- label.gsub(%r![^a-z0-9_\-\.]!i, "")
193
+ label.gsub(%r![^a-z0-9_\-.]!i, "")
194
194
  end
195
195
 
196
196
  # Produce a representation of this Collection for use in Liquid.
@@ -215,9 +215,7 @@ module Bridgetown
215
215
  # Used by Resource's permalink processor
216
216
  # @return [String]
217
217
  def default_permalink
218
- metadata.fetch("permalink") do
219
- "/:collection/:path/"
220
- end
218
+ metadata.fetch("permalink", "/:collection/:path/")
221
219
  end
222
220
 
223
221
  # Extract options for this collection from the site configuration.
@@ -227,7 +225,7 @@ module Bridgetown
227
225
  site.config.collections[label] || HashWithDotAccess::Hash.new
228
226
  end
229
227
 
230
- def merge_data_resources # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
228
+ def merge_data_resources # rubocop:todo Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
231
229
  data_contents = {}
232
230
 
233
231
  sanitize_filename = ->(name) do
@@ -349,7 +347,7 @@ module Bridgetown
349
347
 
350
348
  def order_with_warning(sort_key, resource, order)
351
349
  Bridgetown.logger.warn "Sort warning:", "'#{sort_key}' not defined in" \
352
- " #{resource.relative_path}"
350
+ " #{resource.relative_path}"
353
351
  order
354
352
  end
355
353
 
@@ -17,9 +17,10 @@ module Bridgetown
17
17
  class << self
18
18
  # Override single character commands if necessary
19
19
  def find_command_possibilities(subcommand)
20
- if subcommand == "c"
20
+ case subcommand
21
+ when "c"
21
22
  ["console"]
22
- elsif subcommand == "s"
23
+ when "s"
23
24
  ["start"]
24
25
  else
25
26
  super
@@ -53,7 +54,7 @@ module Bridgetown
53
54
  cmd = cmd.split("[")
54
55
  args = []
55
56
  if cmd[1]
56
- args = cmd[1].gsub('\,', "__COMMA__").delete_suffix!("]").split(",").map do |item|
57
+ args = cmd[1].gsub("\\,", "__COMMA__").delete_suffix!("]").split(",").map do |item|
57
58
  item.gsub("__COMMA__", ",")
58
59
  end
59
60
  end
@@ -23,7 +23,7 @@ module Bridgetown
23
23
 
24
24
  def self.print_startup_message
25
25
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
26
- " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
26
+ " (codename \"#{Bridgetown::CODE_NAME.yellow}\")"
27
27
  end
28
28
 
29
29
  # Build your bridgetown site
@@ -46,7 +46,7 @@ module Bridgetown
46
46
 
47
47
  if config_options.fetch("skip_initial_build", false)
48
48
  Bridgetown.logger.warn "Build Warning:", "Skipping the initial build." \
49
- " This may result in an out-of-date site."
49
+ " This may result in an out-of-date site."
50
50
  else
51
51
  build_site(config_options)
52
52
  end
@@ -78,19 +78,20 @@ module Bridgetown
78
78
  Bridgetown.logger.info "Generating…"
79
79
  @site.process
80
80
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
81
- " #{(Time.now - t).ceil(2)} seconds."
82
- if config_options[:using_puma]
83
- require "socket"
84
- external_ip = Socket.ip_address_list.find do |ai|
85
- ai.ipv4? && !ai.ipv4_loopback?
86
- end&.ip_address
87
- scheme = config_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
88
- port = config_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
89
- Bridgetown.logger.info ""
90
- Bridgetown.logger.info "Now serving at:", "#{scheme}://localhost:#{port}".magenta
91
- Bridgetown.logger.info "", "#{scheme}://#{external_ip}:#{port}".magenta if external_ip
92
- Bridgetown.logger.info ""
93
- end
81
+ " #{(Time.now - t).ceil(2)} seconds."
82
+
83
+ return unless config_options[:using_puma]
84
+
85
+ require "socket"
86
+ external_ip = Socket.ip_address_list.find do |ai|
87
+ ai.ipv4? && !ai.ipv4_loopback?
88
+ end&.ip_address
89
+ scheme = config_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
90
+ port = config_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
91
+ Bridgetown.logger.info ""
92
+ Bridgetown.logger.info "Now serving at:", "#{scheme}://localhost:#{port}".magenta
93
+ Bridgetown.logger.info "", "#{scheme}://#{external_ip}:#{port}".magenta if external_ip
94
+ Bridgetown.logger.info ""
94
95
  end
95
96
 
96
97
  # Watch for file changes and rebuild the site.
@@ -114,10 +115,10 @@ module Bridgetown
114
115
  Bridgetown.logger.info "Source:", source
115
116
  Bridgetown.logger.info "Destination:", destination
116
117
  # TODO: work with arrays
117
- if config_options["plugins_dir"].is_a?(String)
118
- plugins_dir = File.expand_path(config_options["plugins_dir"])
119
- Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
120
- end
118
+ return unless config_options["plugins_dir"].is_a?(String)
119
+
120
+ plugins_dir = File.expand_path(config_options["plugins_dir"])
121
+ Bridgetown.logger.info "Custom Plugins:", plugins_dir if Dir.exist?(plugins_dir)
121
122
  end
122
123
  end
123
124
  end
@@ -25,7 +25,7 @@ module Bridgetown
25
25
  create_file("plugins/builders/#{filename}", data, verbose: false)
26
26
  end
27
27
 
28
- def javascript_import(data = nil, filename: "index.js")
28
+ def javascript_import(data = nil, filename: "index.js") # rubocop:todo Metrics/PerceivedComplexity
29
29
  data ||= yield if block_given?
30
30
  data += "\n" unless data.chars.last == "\n"
31
31
 
@@ -97,7 +97,7 @@ module Bridgetown
97
97
  github_match = GITHUB_REGEX.match(arg)
98
98
 
99
99
  arg = if arg.start_with?("https://gist.github.com")
100
- arg.sub(
100
+ arg.sub( # rubocop:disable Style/StringConcatenation
101
101
  "https://gist.github.com", "https://gist.githubusercontent.com"
102
102
  ) + "/raw"
103
103
  elsif github_match
@@ -32,8 +32,8 @@ module Bridgetown
32
32
  require "amazing_print" unless options[:"bypass-ap"]
33
33
 
34
34
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
35
- " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
36
- " console…"
35
+ " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
36
+ " console…"
37
37
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
38
38
  site = Bridgetown::Site.new(configuration_with_overrides(options))
39
39
 
@@ -54,7 +54,7 @@ module Bridgetown
54
54
  IRB.conf[:IRB_RC]&.call(irb.context)
55
55
  IRB.conf[:MAIN_CONTEXT] = irb.context
56
56
  eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
57
- Bridgetown.logger.info "Console:", "Now loaded as " + "site".cyan + " variable."
57
+ Bridgetown.logger.info "Console:", "Now loaded as #{"site".cyan} variable."
58
58
 
59
59
  trap("SIGINT") do
60
60
  irb.signal_handle
@@ -50,7 +50,7 @@ module Bridgetown
50
50
  "Detected '_posts' directory outside custom `collections_dir`!"
51
51
  Bridgetown.logger.warn "",
52
52
  "Please move '#{posts_at_root}' into the custom directory at " \
53
- "'#{site.in_source_dir(site.config["collections_dir"])}'"
53
+ "'#{site.in_source_dir(site.config["collections_dir"])}'"
54
54
  false
55
55
  end
56
56
 
@@ -64,7 +64,7 @@ module Bridgetown
64
64
 
65
65
  conflicting_urls = true
66
66
  Bridgetown.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
67
- " for the following pages: #{paths.join(", ")}"
67
+ " for the following pages: #{paths.join(", ")}"
68
68
  end
69
69
  conflicting_urls
70
70
  end
@@ -76,9 +76,11 @@ module Bridgetown
76
76
  next unless real_urls.uniq.size > 1
77
77
 
78
78
  urls_only_differ_by_case = true
79
- Bridgetown.logger.warn "Warning:", "The following URLs only differ" \
80
- " by case. On a case-insensitive file system one of the URLs" \
81
- " will be overwritten by the other: #{real_urls.join(", ")}"
79
+ Bridgetown.logger.warn(
80
+ "Warning:",
81
+ "The following URLs only differ by case. On a case-insensitive file system one of the" \
82
+ " URLs will be overwritten by the other: #{real_urls.join(", ")}"
83
+ )
82
84
  end
83
85
  urls_only_differ_by_case
84
86
  end
@@ -117,7 +119,7 @@ module Bridgetown
117
119
  return true unless url.nil? || url.empty?
118
120
 
119
121
  Bridgetown.logger.warn "Warning:", "You didn't set an URL in the config file, "\
120
- "you may encounter problems with some plugins."
122
+ "you may encounter problems with some plugins."
121
123
  false
122
124
  end
123
125
 
@@ -128,7 +130,7 @@ module Bridgetown
128
130
  # https://git.io/vFfbx
129
131
  rescue TypeError
130
132
  Bridgetown.logger.warn "Warning:", "The site URL does not seem to be valid, "\
131
- "check the value of `url` in your config file."
133
+ "check the value of `url` in your config file."
132
134
  false
133
135
  end
134
136
 
@@ -136,7 +138,7 @@ module Bridgetown
136
138
  return true if url.is_a?(String) && Addressable::URI.parse(url).absolute?
137
139
 
138
140
  Bridgetown.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\
139
- "check the value of `url` in your config file."
141
+ "check the value of `url` in your config file."
140
142
  false
141
143
  end
142
144
  end
@@ -59,8 +59,10 @@ module Bridgetown
59
59
 
60
60
  if preserve_source_location?(new_site_path, options)
61
61
  say_status :conflict, "#{new_site_path} exists and is not empty.", :red
62
- Bridgetown.logger.abort_with "Ensure #{new_site_path} is empty or else " \
63
- "try again with `--force` to proceed and overwrite any files."
62
+ Bridgetown.logger.abort_with(
63
+ "Ensure #{new_site_path} is empty or else try again with `--force` to proceed and" \
64
+ " overwrite any files."
65
+ )
64
66
  end
65
67
 
66
68
  self.destination_root = self.class.created_site_dir = new_site_path
@@ -122,7 +124,7 @@ module Bridgetown
122
124
  bt_start = "bin/bridgetown start"
123
125
  logger.info ""
124
126
  logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
125
- " generated in #{cli_path.cyan}."
127
+ " generated in #{cli_path.cyan}."
126
128
  if options["skip-yarn"]
127
129
  logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
128
130
  logger.info "You'll probably also want to #{"yarn install".cyan}" \
@@ -112,12 +112,12 @@ module Bridgetown
112
112
  source_manifest.origin.to_s == directive[0]
113
113
  end
114
114
 
115
- if manifest&.respond_to?(directive[1].downcase)
115
+ if manifest.respond_to?(directive[1].downcase)
116
116
  dir = manifest.send(directive[1].downcase)
117
117
  Bridgetown.logger.info("Opening the #{dir.green} folder for" \
118
- " #{manifest.origin.to_s.cyan}…")
118
+ " #{manifest.origin.to_s.cyan}…")
119
119
  Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
120
- " return to your site root.")
120
+ " return to your site root.")
121
121
  puts
122
122
 
123
123
  Dir.chdir dir do
@@ -133,13 +133,12 @@ module Bridgetown
133
133
  Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
134
134
  else
135
135
  Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
136
- " #{directive[1]} folder for #{directive[0]}")
136
+ " #{directive[1]} folder for #{directive[0]}")
137
137
  end
138
138
  end
139
139
 
140
140
  desc "new NAME", "Create a new plugin NAME (please-use-dashes) by" \
141
141
  " cloning the sample plugin repo"
142
- # rubocop:disable Layout/LineLength
143
142
  def new(plugin_name)
144
143
  folder_name = plugin_name.underscore
145
144
  name = folder_name.dasherize
@@ -187,11 +186,10 @@ module Bridgetown
187
186
  say ""
188
187
  say_status "Done!", "Have fun writing your new #{name} plugin :)"
189
188
  say_status "Remember:", "Don't forget to rename the SamplePlugin" \
190
- " code identifiers and paths to your own" \
191
- " indentifer, as well as update your README " \
192
- " and CHANGELOG files as necessary."
189
+ " code identifiers and paths to your own" \
190
+ " indentifer, as well as update your README " \
191
+ " and CHANGELOG files as necessary."
193
192
  end
194
- # rubocop:enable Layout/LineLength
195
193
 
196
194
  protected
197
195
 
@@ -8,7 +8,7 @@ module Bridgetown
8
8
  class Servlet < WEBrick::HTTPServlet::FileHandler
9
9
  DEFAULTS = {
10
10
  "Cache-Control" => "private, max-age=0, proxy-revalidate, " \
11
- "no-store, no-cache, must-revalidate",
11
+ "no-store, no-cache, must-revalidate",
12
12
  }.freeze
13
13
 
14
14
  def initialize(server, root, callbacks)
@@ -51,9 +51,9 @@ module Bridgetown
51
51
  key = res.header.keys.grep(%r!content-type!i).first
52
52
  typ = res.header[key]
53
53
 
54
- unless %r!;\s*charset=!.match?(typ)
55
- res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}"
56
- end
54
+ return if %r!;\s*charset=!.match?(typ)
55
+
56
+ res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}"
57
57
  end
58
58
 
59
59
  def set_defaults
@@ -48,8 +48,9 @@ module Bridgetown
48
48
  ).freeze
49
49
 
50
50
  def serve
51
- Bridgetown::Deprecator.deprecation_message "The serve command will be " \
52
- "removed in favor of using Puma in the next major release of Bridgetown"
51
+ Bridgetown::Deprecator.deprecation_message(
52
+ "WEBrick (serve) will be removed in favor of Puma (start) in the next Bridgetown release"
53
+ )
53
54
 
54
55
  @mutex = Mutex.new
55
56
  @run_cond = ConditionVariable.new
@@ -58,7 +59,6 @@ module Bridgetown
58
59
  no_watch = options["watch"] == false
59
60
 
60
61
  options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
61
-
62
62
  options["serving"] = true
63
63
  options["watch"] = true unless no_watch
64
64
 
@@ -88,12 +88,12 @@ module Bridgetown
88
88
  require_relative "serve/servlet"
89
89
 
90
90
  FileUtils.mkdir_p(destination)
91
- if File.exist?(File.join(destination, "404.html"))
92
- WEBrick::HTTPResponse.class_eval do
93
- def create_error_page
94
- @header["Content-Type"] = "text/html; charset=UTF-8"
95
- @body = IO.read(File.join(@config[:DocumentRoot], "404.html"))
96
- end
91
+ return unless File.exist?(File.join(destination, "404.html"))
92
+
93
+ WEBrick::HTTPResponse.class_eval do
94
+ def create_error_page
95
+ @header["Content-Type"] = "text/html; charset=UTF-8"
96
+ @body = File.read(File.join(@config[:DocumentRoot], "404.html"))
97
97
  end
98
98
  end
99
99
  end
@@ -211,34 +211,32 @@ module Bridgetown
211
211
  begin
212
212
  opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
213
213
  rescue StandardError
214
- if defined?(OpenSSL::PKey::EC)
215
- opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
216
- else
217
- raise
218
- end
214
+ raise unless defined?(OpenSSL::PKey::EC)
215
+
216
+ opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
219
217
  end
220
218
  opts[:SSLEnable] = true
221
219
  end
222
220
 
223
221
  def start_callback(detached)
224
- unless detached
225
- proc do
226
- @mutex.synchronize do
227
- @running = true
228
- Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
229
- @run_cond.broadcast
230
- end
222
+ return if detached
223
+
224
+ proc do
225
+ @mutex.synchronize do
226
+ @running = true
227
+ Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
228
+ @run_cond.broadcast
231
229
  end
232
230
  end
233
231
  end
234
232
 
235
233
  def stop_callback(detached)
236
- unless detached
237
- proc do
238
- @mutex.synchronize do
239
- @running = false
240
- @run_cond.broadcast
241
- end
234
+ return if detached
235
+
236
+ proc do
237
+ @mutex.synchronize do
238
+ @running = false
239
+ @run_cond.broadcast
242
240
  end
243
241
  end
244
242
  end
@@ -66,7 +66,7 @@ module Bridgetown
66
66
 
67
67
  longest_action = supported_actions.keys.max_by(&:size).size
68
68
  supported_actions.each do |action, description|
69
- say action.ljust(longest_action).to_s.bold.blue + "\t" + "# #{description}"
69
+ say "#{action.ljust(longest_action).to_s.bold.blue}\t# #{description}"
70
70
  end
71
71
  end
72
72
 
@@ -97,9 +97,7 @@ module Bridgetown
97
97
  #
98
98
  # @return [String] or nil
99
99
  def content
100
- @_content ||= begin
101
- view_context.capture(self, &@_content_block) if @_content_block
102
- end
100
+ @_content ||= (view_context.capture(self, &@_content_block) if @_content_block)
103
101
  end
104
102
 
105
103
  # Provide a render helper for evaluation within the component context.
@@ -166,7 +164,6 @@ module Bridgetown
166
164
  end
167
165
  end
168
166
 
169
- # rubocop:disable Style/MissingRespondToMissing
170
167
  ruby2_keywords def method_missing(method, *args, &block)
171
168
  if helpers.respond_to?(method.to_sym)
172
169
  helpers.send method.to_sym, *args, &block
@@ -178,6 +175,5 @@ module Bridgetown
178
175
  def respond_to_missing?(method, include_private = false)
179
176
  helpers.respond_to?(method.to_sym, include_private) || super
180
177
  end
181
- # rubocop:enable Style/MissingRespondToMissing
182
178
  end
183
179
  end
@@ -165,7 +165,7 @@ class Bridgetown::Site
165
165
  dir.is_a?(Array) ? dir : [dir]
166
166
  end
167
167
  local_components_load_paths.map! do |dir|
168
- if !!(dir =~ %r!^\.\.?\/!)
168
+ if !!(dir =~ %r!^\.\.?/!)
169
169
  # allow ./dir or ../../dir type options
170
170
  File.expand_path(dir.to_s, root_dir)
171
171
  else
@@ -5,8 +5,8 @@ class Bridgetown::Site
5
5
  module Content
6
6
  def resources_grouped_by_taxonomy(taxonomy)
7
7
  data.site_taxonomies_hash ||= {}
8
- data.site_taxonomies_hash[taxonomy.label] ||= begin
9
- taxonomy.terms.transform_values { |terms| terms.map(&:resource).sort.reverse }
8
+ data.site_taxonomies_hash[taxonomy.label] ||= taxonomy.terms.transform_values do |terms|
9
+ terms.map(&:resource).sort.reverse
10
10
  end
11
11
  end
12
12
 
@@ -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
@@ -203,7 +203,7 @@ module Bridgetown
203
203
  end
204
204
  rescue ArgumentError => e
205
205
  Bridgetown.logger.warn "WARNING:", "Error reading configuration. Using defaults" \
206
- " (and options)."
206
+ " (and options)."
207
207
  warn e
208
208
  end
209
209
 
@@ -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