nanoc 4.1.1 → 4.1.2

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/Gemfile.lock +16 -20
  3. data/LICENSE +1 -1
  4. data/NEWS.md +11 -0
  5. data/lib/nanoc.rb +1 -1
  6. data/lib/nanoc/base/compilation/compiler.rb +6 -5
  7. data/lib/nanoc/base/compilation/filter.rb +1 -1
  8. data/lib/nanoc/base/compilation/outdatedness_checker.rb +10 -2
  9. data/lib/nanoc/base/core_ext/array.rb +1 -1
  10. data/lib/nanoc/base/core_ext/hash.rb +1 -1
  11. data/lib/nanoc/base/entities/configuration.rb +5 -4
  12. data/lib/nanoc/base/entities/document.rb +1 -1
  13. data/lib/nanoc/base/entities/identifiable_collection.rb +2 -1
  14. data/lib/nanoc/base/entities/identifier.rb +1 -1
  15. data/lib/nanoc/base/entities/item_rep.rb +5 -5
  16. data/lib/nanoc/base/entities/rule_memory_action.rb +1 -1
  17. data/lib/nanoc/base/entities/rule_memory_actions/snapshot.rb +1 -1
  18. data/lib/nanoc/base/entities/site.rb +4 -3
  19. data/lib/nanoc/base/repos/site_loader.rb +5 -5
  20. data/lib/nanoc/base/services/executor.rb +6 -5
  21. data/lib/nanoc/base/services/item_rep_writer.rb +1 -1
  22. data/lib/nanoc/base/views/config_view.rb +1 -1
  23. data/lib/nanoc/base/views/item_rep_view.rb +1 -1
  24. data/lib/nanoc/base/views/item_without_reps_view.rb +1 -1
  25. data/lib/nanoc/base/views/mixins/document_view_mixin.rb +7 -9
  26. data/lib/nanoc/base/views/view.rb +14 -0
  27. data/lib/nanoc/cli.rb +2 -2
  28. data/lib/nanoc/cli/ansi_string_colorizer.rb +1 -1
  29. data/lib/nanoc/cli/cleaning_stream.rb +1 -1
  30. data/lib/nanoc/cli/command_runner.rb +7 -14
  31. data/lib/nanoc/cli/commands/check.rb +1 -1
  32. data/lib/nanoc/cli/commands/create-site.rb +5 -5
  33. data/lib/nanoc/cli/commands/shell.rb +1 -1
  34. data/lib/nanoc/cli/commands/show-plugins.rb +2 -2
  35. data/lib/nanoc/cli/commands/show-rules.rb +1 -1
  36. data/lib/nanoc/cli/commands/view.rb +1 -1
  37. data/lib/nanoc/cli/error_handler.rb +3 -11
  38. data/lib/nanoc/cli/logger.rb +2 -2
  39. data/lib/nanoc/data_sources/filesystem_unified.rb +6 -5
  40. data/lib/nanoc/extra/checking/checks/external_links.rb +7 -6
  41. data/lib/nanoc/extra/checking/checks/internal_links.rb +7 -6
  42. data/lib/nanoc/extra/checking/checks/mixed_content.rb +1 -1
  43. data/lib/nanoc/extra/checking/runner.rb +8 -7
  44. data/lib/nanoc/extra/deployer.rb +1 -1
  45. data/lib/nanoc/extra/deployers/fog.rb +2 -2
  46. data/lib/nanoc/extra/deployers/rsync.rb +1 -1
  47. data/lib/nanoc/extra/jruby_nokogiri_warner.rb +1 -1
  48. data/lib/nanoc/extra/link_collector.rb +1 -1
  49. data/lib/nanoc/filters/colorize_syntax.rb +3 -3
  50. data/lib/nanoc/filters/less.rb +1 -1
  51. data/lib/nanoc/filters/redcarpet.rb +6 -5
  52. data/lib/nanoc/filters/relativize_paths.rb +2 -2
  53. data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +1 -1
  54. data/lib/nanoc/helpers/capturing.rb +1 -1
  55. data/lib/nanoc/helpers/html_escape.rb +3 -2
  56. data/lib/nanoc/helpers/link_to.rb +7 -6
  57. data/lib/nanoc/rule_dsl/compiler_dsl.rb +1 -1
  58. data/lib/nanoc/version.rb +1 -1
  59. data/nanoc.gemspec +3 -3
  60. data/tasks/test.rake +1 -1
  61. data/test/cli/test_cli.rb +2 -2
  62. data/test/extra/checking/checks/test_mixed_content.rb +7 -7
  63. data/test/filters/test_colorize_syntax.rb +2 -2
  64. data/test/filters/test_redcarpet.rb +6 -5
  65. data/test/filters/test_redcloth.rb +1 -1
  66. data/test/filters/test_xsl.rb +6 -6
  67. metadata +2 -2
@@ -1,7 +1,7 @@
1
1
  module Nanoc::Int
2
2
  # @api private
3
3
  class ItemRepWriter
4
- TMP_TEXT_ITEMS_DIR = 'text_items'
4
+ TMP_TEXT_ITEMS_DIR = 'text_items'.freeze
5
5
 
6
6
  def write(item_rep, raw_path)
7
7
  # Create parent directory
@@ -1,7 +1,7 @@
1
1
  module Nanoc
2
2
  class ConfigView < ::Nanoc::View
3
3
  # @api private
4
- NONE = Object.new
4
+ NONE = Object.new.freeze
5
5
 
6
6
  # @api private
7
7
  def initialize(config, context)
@@ -15,7 +15,7 @@ module Nanoc
15
15
  def ==(other)
16
16
  other.respond_to?(:item) && other.respond_to?(:name) && item == other.item && name == other.name
17
17
  end
18
- alias_method :eql?, :==
18
+ alias eql? ==
19
19
 
20
20
  # @see Object#hash
21
21
  def hash
@@ -33,7 +33,7 @@ module Nanoc
33
33
 
34
34
  parent = @context.items[parent_identifier]
35
35
 
36
- parent && self.class.new(parent, @context).freeze
36
+ parent && self.class.new(parent, @context)
37
37
  end
38
38
 
39
39
  # @return [Boolean] True if the item is binary, false otherwise
@@ -1,7 +1,7 @@
1
1
  module Nanoc
2
2
  module DocumentViewMixin
3
3
  # @api private
4
- NONE = Object.new
4
+ NONE = Object.new.freeze
5
5
 
6
6
  # @api private
7
7
  def initialize(document, context)
@@ -18,7 +18,7 @@ module Nanoc
18
18
  def ==(other)
19
19
  other.respond_to?(:identifier) && identifier == other.identifier
20
20
  end
21
- alias_method :eql?, :==
21
+ alias eql? ==
22
22
 
23
23
  # @see Object#hash
24
24
  def hash
@@ -53,14 +53,12 @@ module Nanoc
53
53
 
54
54
  if unwrap.attributes.key?(key)
55
55
  unwrap.attributes[key]
56
+ elsif !fallback.equal?(NONE)
57
+ fallback
58
+ elsif block_given?
59
+ yield(key)
56
60
  else
57
- if !fallback.equal?(NONE)
58
- fallback
59
- elsif block_given?
60
- yield(key)
61
- else
62
- raise KeyError, "key not found: #{key.inspect}"
63
- end
61
+ raise KeyError, "key not found: #{key.inspect}"
64
62
  end
65
63
  end
66
64
 
@@ -8,5 +8,19 @@ module Nanoc
8
8
  def _context
9
9
  @context
10
10
  end
11
+
12
+ # @api private
13
+ def unwrap
14
+ raise NotImplementedError
15
+ end
16
+
17
+ # True if the wrapped object is frozen; false otherwise.
18
+ #
19
+ # @return [Boolean]
20
+ #
21
+ # @see Object#frozen?
22
+ def frozen?
23
+ unwrap.frozen?
24
+ end
11
25
  end
12
26
  end
@@ -180,11 +180,11 @@ module Nanoc::CLI
180
180
  def self.wrap_in_cleaning_stream(io)
181
181
  cio = ::Nanoc::CLI::CleaningStream.new(io)
182
182
 
183
- unless self.enable_utf8?(io)
183
+ unless enable_utf8?(io)
184
184
  cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::UTF8)
185
185
  end
186
186
 
187
- unless self.enable_ansi_colors?(io)
187
+ unless enable_ansi_colors?(io)
188
188
  cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
189
189
  end
190
190
 
@@ -11,7 +11,7 @@ module Nanoc::CLI
11
11
  green: "\e[32m",
12
12
  yellow: "\e[33m",
13
13
  blue: "\e[34m",
14
- }
14
+ }.freeze
15
15
 
16
16
  # @param [String] s The string to colorize
17
17
  #
@@ -114,7 +114,7 @@ module Nanoc::CLI
114
114
 
115
115
  # @see IO.winsize=
116
116
  def winsize=(arg)
117
- @stream.winsize = (arg)
117
+ @stream.winsize = arg
118
118
  end
119
119
 
120
120
  # @see IO.sync
@@ -20,7 +20,7 @@ module Nanoc::CLI
20
20
  def site
21
21
  # Load site if possible
22
22
  @site ||= nil
23
- if self.is_in_site_dir? && @site.nil?
23
+ if is_in_site_dir? && @site.nil?
24
24
  @site = Nanoc::Int::SiteLoader.new.new_from_cwd
25
25
  end
26
26
 
@@ -39,26 +39,19 @@ module Nanoc::CLI
39
39
  def in_site_dir?
40
40
  Nanoc::Int::SiteLoader.cwd_is_nanoc_site?
41
41
  end
42
- alias_method :is_in_site_dir?, :in_site_dir?
42
+ alias is_in_site_dir? in_site_dir?
43
43
 
44
- # Asserts that the current working directory contains a site
45
- # ({Nanoc::Int::Site} instance). If no site is present, prints an error
46
- # message and exits.
44
+ # Asserts that the current working directory contains a site and loads the site into memory.
47
45
  #
48
46
  # @return [void]
49
- def require_site
47
+ def load_site
48
+ print 'Loading site… '
49
+ $stdout.flush
50
+
50
51
  if site.nil?
51
52
  raise ::Nanoc::Int::Errors::GenericTrivial, 'The current working directory does not seem to be a Nanoc site.'
52
53
  end
53
- end
54
54
 
55
- # Asserts that the current working directory contains a site (just like
56
- # {#require_site}) and loads the site into memory.
57
- #
58
- # @return [void]
59
- def load_site
60
- print 'Loading site… '
61
- require_site
62
55
  puts 'done'
63
56
  end
64
57
 
@@ -12,7 +12,7 @@ module Nanoc::CLI::Commands
12
12
  class Check < ::Nanoc::CLI::CommandRunner
13
13
  def run
14
14
  validate_options_and_arguments
15
- require_site
15
+ load_site
16
16
 
17
17
  runner = Nanoc::Extra::Checking::Runner.new(site)
18
18
 
@@ -15,7 +15,7 @@ module Nanoc::CLI::Commands
15
15
  end
16
16
  end
17
17
 
18
- DEFAULT_CONFIG = <<EOS unless defined? DEFAULT_CONFIG
18
+ DEFAULT_CONFIG = <<EOS.freeze unless defined? DEFAULT_CONFIG
19
19
  # The syntax to use for patterns in the Rules file. Can be either `"glob"`
20
20
  # (default) or `"legacy"`. The former will enable glob patterns, which behave
21
21
  # like Ruby’s File.fnmatch. The latter will enable Nanoc 3.x-style patterns.
@@ -108,7 +108,7 @@ checks:
108
108
  exclude_files: []
109
109
  EOS
110
110
 
111
- DEFAULT_RULES = <<EOS unless defined? DEFAULT_RULES
111
+ DEFAULT_RULES = <<EOS.freeze unless defined? DEFAULT_RULES
112
112
  #!/usr/bin/env ruby
113
113
 
114
114
  compile '/**/*.html' do
@@ -139,7 +139,7 @@ end
139
139
  layout '/**/*', :erb
140
140
  EOS
141
141
 
142
- DEFAULT_ITEM = <<EOS unless defined? DEFAULT_ITEM
142
+ DEFAULT_ITEM = <<EOS.freeze unless defined? DEFAULT_ITEM
143
143
  ---
144
144
  title: Home
145
145
  ---
@@ -156,7 +156,7 @@ title: Home
156
156
  <p>If you need any help with customizing your Nanoc web site, be sure to check out the documentation (see sidebar), and be sure to subscribe to the discussion group (also see sidebar). Enjoy!</p>
157
157
  EOS
158
158
 
159
- DEFAULT_STYLESHEET = <<EOS unless defined? DEFAULT_STYLESHEET
159
+ DEFAULT_STYLESHEET = <<EOS.freeze unless defined? DEFAULT_STYLESHEET
160
160
  * {
161
161
  margin: 0;
162
162
  padding: 0;
@@ -260,7 +260,7 @@ a:hover {
260
260
  }
261
261
  EOS
262
262
 
263
- DEFAULT_LAYOUT = <<EOS unless defined? DEFAULT_LAYOUT
263
+ DEFAULT_LAYOUT = <<EOS.freeze unless defined? DEFAULT_LAYOUT
264
264
  <!DOCTYPE HTML>
265
265
  <html lang="en">
266
266
  <head>
@@ -10,7 +10,7 @@ module Nanoc::CLI::Commands
10
10
  def run
11
11
  require 'pry'
12
12
 
13
- require_site
13
+ load_site
14
14
 
15
15
  Nanoc::Int::Context.new(env).pry
16
16
  end
@@ -73,13 +73,13 @@ module Nanoc::CLI::Commands
73
73
  Nanoc::Filter,
74
74
  Nanoc::DataSource,
75
75
  Nanoc::Extra::Deployer,
76
- ] unless defined? PLUGIN_CLASS_ORDER
76
+ ].freeze unless defined? PLUGIN_CLASS_ORDER
77
77
 
78
78
  PLUGIN_CLASSES = {
79
79
  Nanoc::Filter => 'Filters',
80
80
  Nanoc::DataSource => 'Data Sources',
81
81
  Nanoc::Extra::Deployer => 'Deployers',
82
- } unless defined? PLUGIN_CLASSES
82
+ }.freeze unless defined? PLUGIN_CLASSES
83
83
 
84
84
  def name_for_plugin_class(klass)
85
85
  PLUGIN_CLASSES[klass]
@@ -8,7 +8,7 @@ Prints the rules used for all items and layouts in the current site.
8
8
  module Nanoc::CLI::Commands
9
9
  class ShowRules < ::Nanoc::CLI::CommandRunner
10
10
  def run
11
- require_site
11
+ load_site
12
12
 
13
13
  @c = Nanoc::CLI::ANSIStringColorizer
14
14
  @reps = site.compiler.reps
@@ -18,7 +18,7 @@ module Nanoc::CLI::Commands
18
18
  load_adsf
19
19
  require 'rack'
20
20
 
21
- require_site
21
+ load_site
22
22
 
23
23
  # Set options
24
24
  options_for_rack = {
@@ -138,7 +138,6 @@ module Nanoc::CLI
138
138
  write_version_information(stream, verbose: true)
139
139
  write_system_information(stream, verbose: true)
140
140
  write_installed_gems(stream, verbose: true)
141
- write_environment(stream, verbose: true)
142
141
  write_gemfile_lock(stream, verbose: true)
143
142
  write_load_paths(stream, verbose: true)
144
143
  end
@@ -208,7 +207,7 @@ module Nanoc::CLI
208
207
  'rubypants' => 'rubypants',
209
208
  'sass' => 'sass',
210
209
  'w3c_validators' => 'w3c_validators',
211
- }
210
+ }.freeze
212
211
 
213
212
  # Attempts to find a resolution for the given error, or nil if no
214
213
  # resolution can be automatically obtained.
@@ -226,7 +225,7 @@ module Nanoc::CLI
226
225
 
227
226
  # Build message
228
227
  if gem_name
229
- if self.using_bundler?
228
+ if using_bundler?
230
229
  'Make sure the gem is added to Gemfile and run `bundle install`.'
231
230
  else
232
231
  "Install the '#{gem_name}' gem using `gem install #{gem_name}`."
@@ -262,7 +261,7 @@ module Nanoc::CLI
262
261
 
263
262
  stream.puts "#{error.class}: #{error.message}"
264
263
  resolution = resolution_for(error)
265
- stream.puts "#{resolution}" if resolution
264
+ stream.puts resolution.to_s if resolution
266
265
  end
267
266
 
268
267
  def write_compilation_stack(stream, _error, verbose: false)
@@ -320,13 +319,6 @@ module Nanoc::CLI
320
319
  end
321
320
  end
322
321
 
323
- def write_environment(stream, verbose: false)
324
- write_section_header(stream, 'Environment', verbose: verbose)
325
- ENV.sort.each do |e|
326
- stream.puts "#{e.first} => #{e.last.inspect}"
327
- end
328
- end
329
-
330
322
  def write_gemfile_lock(stream, verbose: false)
331
323
  if File.exist?('Gemfile.lock')
332
324
  write_section_header(stream, 'Gemfile.lock', verbose: verbose)
@@ -14,7 +14,7 @@ module Nanoc::CLI
14
14
  identical: '', # (nothing)
15
15
  skip: '', # (nothing)
16
16
  delete: "\e[31m" # red
17
- }
17
+ }.freeze
18
18
 
19
19
  include Singleton
20
20
 
@@ -48,7 +48,7 @@ module Nanoc::CLI
48
48
  "\e[0m",
49
49
  duration.nil? ? '' : format('[%2.2fs] ', duration),
50
50
  name,
51
- )
51
+ ),
52
52
  )
53
53
  end
54
54
 
@@ -89,11 +89,12 @@ module Nanoc::DataSources
89
89
  return Nanoc::Identifier.new(filename)
90
90
  end
91
91
 
92
- if filename =~ /(^|\/)index(\.[^\/]+)?$/
93
- regex = @config && @config[:allow_periods_in_identifiers] ? /\/?(index)?(\.[^\/\.]+)?$/ : /\/?index(\.[^\/]+)?$/
94
- else
95
- regex = @config && @config[:allow_periods_in_identifiers] ? /\.[^\/\.]+$/ : /\.[^\/]+$/
96
- end
92
+ regex =
93
+ if filename =~ /(^|\/)index(\.[^\/]+)?$/
94
+ @config && @config[:allow_periods_in_identifiers] ? /\/?(index)?(\.[^\/\.]+)?$/ : /\/?index(\.[^\/]+)?$/
95
+ else
96
+ @config && @config[:allow_periods_in_identifiers] ? /\.[^\/\.]+$/ : /\.[^\/]+$/
97
+ end
97
98
  Nanoc::Identifier.new(filename.sub(regex, ''), type: :legacy)
98
99
  end
99
100
  end
@@ -90,7 +90,7 @@ module ::Nanoc::Extra::Checking::Checks
90
90
  end
91
91
 
92
92
  # Skip excluded URLs
93
- return nil if self.excluded?(href)
93
+ return nil if excluded?(href)
94
94
 
95
95
  # Skip non-HTTP URLs
96
96
  return nil if url.scheme !~ /^https?$/
@@ -142,11 +142,12 @@ module ::Nanoc::Extra::Checking::Checks
142
142
  end
143
143
 
144
144
  def path_for_url(url)
145
- if url.path.nil? || url.path.empty?
146
- path = '/'
147
- else
148
- path = url.path
149
- end
145
+ path =
146
+ if url.path.nil? || url.path.empty?
147
+ '/'
148
+ else
149
+ url.path
150
+ end
150
151
 
151
152
  if url.query
152
153
  path << '?' << url.query
@@ -34,7 +34,7 @@ module Nanoc::Extra::Checking::Checks
34
34
  return true if href == '.'
35
35
 
36
36
  # Skip hrefs that are specified in the exclude configuration
37
- return true if self.excluded?(href)
37
+ return true if excluded?(href)
38
38
 
39
39
  # Remove target
40
40
  path = href.sub(/#.*$/, '')
@@ -48,11 +48,12 @@ module Nanoc::Extra::Checking::Checks
48
48
  path = URI.unescape(path)
49
49
 
50
50
  # Make absolute
51
- if path[0, 1] == '/'
52
- path = @config[:output_dir] + path
53
- else
54
- path = ::File.expand_path(path, ::File.dirname(origin))
55
- end
51
+ path =
52
+ if path[0, 1] == '/'
53
+ @config[:output_dir] + path
54
+ else
55
+ ::File.expand_path(path, ::File.dirname(origin))
56
+ end
56
57
 
57
58
  # Check whether file exists
58
59
  return true if File.file?(path)
@@ -25,7 +25,7 @@ module Nanoc::Extra::Checking::Checks
25
25
  def guaranteed_insecure?(href)
26
26
  protocol = PROTOCOL_PATTERN.match(href)
27
27
 
28
- protocol && protocol[1].downcase == 'http'
28
+ protocol && protocol[1].casecmp('http').zero?
29
29
  end
30
30
  end
31
31
  end
@@ -3,7 +3,7 @@ module Nanoc::Extra::Checking
3
3
  #
4
4
  # @api private
5
5
  class Runner
6
- CHECKS_FILENAMES = ['Checks', 'Checks.rb', 'checks', 'checks.rb']
6
+ CHECKS_FILENAMES = ['Checks', 'Checks.rb', 'checks', 'checks.rb'].freeze
7
7
 
8
8
  # @param [Nanoc::Int::Site] site The Nanoc site this runner is for
9
9
  def initialize(site)
@@ -19,7 +19,7 @@ module Nanoc::Extra::Checking
19
19
  def dsl_present?
20
20
  checks_filename && File.file?(checks_filename)
21
21
  end
22
- alias_method :has_dsl?, :dsl_present?
22
+ alias has_dsl? dsl_present?
23
23
 
24
24
  # Lists all available checks on stdout.
25
25
  #
@@ -65,11 +65,12 @@ module Nanoc::Extra::Checking
65
65
  def load_dsl_if_available
66
66
  @dsl_loaded ||= false
67
67
  unless @dsl_loaded
68
- if self.dsl_present?
69
- @dsl = Nanoc::Extra::Checking::DSL.from_file(checks_filename)
70
- else
71
- @dsl = nil
72
- end
68
+ @dsl =
69
+ if dsl_present?
70
+ Nanoc::Extra::Checking::DSL.from_file(checks_filename)
71
+ else
72
+ nil
73
+ end
73
74
  @dsl_loaded = true
74
75
  end
75
76
  end