nanoc 3.6.7 → 3.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +8 -8
  2. data/CONTRIBUTING.md +9 -13
  3. data/Gemfile +5 -1
  4. data/Gemfile.lock +70 -45
  5. data/NEWS.md +15 -1
  6. data/README.md +12 -119
  7. data/doc/yardoc_handlers/identifier.rb +34 -0
  8. data/lib/nanoc/base/compilation/checksum_store.rb +2 -2
  9. data/lib/nanoc/base/compilation/compiler.rb +3 -3
  10. data/lib/nanoc/base/compilation/compiler_dsl.rb +20 -15
  11. data/lib/nanoc/base/compilation/dependency_tracker.rb +4 -4
  12. data/lib/nanoc/base/compilation/filter.rb +5 -5
  13. data/lib/nanoc/base/compilation/item_rep_proxy.rb +2 -2
  14. data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +3 -3
  15. data/lib/nanoc/base/compilation/outdatedness_checker.rb +49 -46
  16. data/lib/nanoc/base/compilation/rule.rb +6 -4
  17. data/lib/nanoc/base/compilation/rule_context.rb +10 -4
  18. data/lib/nanoc/base/compilation/rule_memory_calculator.rb +8 -7
  19. data/lib/nanoc/base/compilation/rule_memory_store.rb +2 -2
  20. data/lib/nanoc/base/compilation/rules_collection.rb +2 -2
  21. data/lib/nanoc/base/core_ext/array.rb +2 -2
  22. data/lib/nanoc/base/core_ext/date.rb +4 -2
  23. data/lib/nanoc/base/core_ext/hash.rb +3 -3
  24. data/lib/nanoc/base/core_ext/pathname.rb +1 -1
  25. data/lib/nanoc/base/directed_graph.rb +6 -6
  26. data/lib/nanoc/base/errors.rb +1 -1
  27. data/lib/nanoc/base/memoization.rb +4 -4
  28. data/lib/nanoc/base/notification_center.rb +1 -1
  29. data/lib/nanoc/base/ordered_hash.rb +207 -179
  30. data/lib/nanoc/base/plugin_registry.rb +7 -7
  31. data/lib/nanoc/base/result_data/item_rep.rb +25 -26
  32. data/lib/nanoc/base/source_data/code_snippet.rb +2 -2
  33. data/lib/nanoc/base/source_data/configuration.rb +1 -1
  34. data/lib/nanoc/base/source_data/data_source.rb +2 -2
  35. data/lib/nanoc/base/source_data/item.rb +16 -15
  36. data/lib/nanoc/base/source_data/item_array.rb +4 -4
  37. data/lib/nanoc/base/source_data/layout.rb +5 -5
  38. data/lib/nanoc/base/source_data/site.rb +6 -6
  39. data/lib/nanoc/base/store.rb +8 -8
  40. data/lib/nanoc/cli/cleaning_stream.rb +11 -12
  41. data/lib/nanoc/cli/command_runner.rb +8 -8
  42. data/lib/nanoc/cli/commands/autocompile.rb +5 -4
  43. data/lib/nanoc/cli/commands/check.rb +12 -11
  44. data/lib/nanoc/cli/commands/compile.rb +50 -52
  45. data/lib/nanoc/cli/commands/create-item.rb +6 -6
  46. data/lib/nanoc/cli/commands/create-layout.rb +6 -6
  47. data/lib/nanoc/cli/commands/create-site.rb +10 -13
  48. data/lib/nanoc/cli/commands/deploy.rb +11 -11
  49. data/lib/nanoc/cli/commands/prune.rb +10 -10
  50. data/lib/nanoc/cli/commands/shell.rb +7 -7
  51. data/lib/nanoc/cli/commands/show-data.rb +22 -23
  52. data/lib/nanoc/cli/commands/show-plugins.rb +3 -3
  53. data/lib/nanoc/cli/commands/show-rules.rb +8 -8
  54. data/lib/nanoc/cli/commands/sync.rb +4 -2
  55. data/lib/nanoc/cli/commands/update.rb +4 -4
  56. data/lib/nanoc/cli/commands/validate-css.rb +3 -3
  57. data/lib/nanoc/cli/commands/validate-html.rb +3 -3
  58. data/lib/nanoc/cli/commands/validate-links.rb +3 -3
  59. data/lib/nanoc/cli/commands/view.rb +5 -3
  60. data/lib/nanoc/cli/commands/watch.rb +12 -12
  61. data/lib/nanoc/cli/error_handler.rb +58 -58
  62. data/lib/nanoc/cli/logger.rb +6 -6
  63. data/lib/nanoc/cli/stream_cleaners/abstract.rb +1 -1
  64. data/lib/nanoc/cli/stream_cleaners.rb +0 -1
  65. data/lib/nanoc/cli.rb +24 -22
  66. data/lib/nanoc/data_sources/deprecated/delicious.rb +1 -1
  67. data/lib/nanoc/data_sources/deprecated/last_fm.rb +16 -14
  68. data/lib/nanoc/data_sources/deprecated/twitter.rb +1 -1
  69. data/lib/nanoc/data_sources/filesystem.rb +22 -20
  70. data/lib/nanoc/data_sources/filesystem_unified.rb +4 -5
  71. data/lib/nanoc/data_sources/filesystem_verbose.rb +2 -3
  72. data/lib/nanoc/data_sources/static.rb +2 -2
  73. data/lib/nanoc/extra/auto_compiler.rb +3 -3
  74. data/lib/nanoc/extra/checking/check.rb +3 -3
  75. data/lib/nanoc/extra/checking/checks/css.rb +2 -2
  76. data/lib/nanoc/extra/checking/checks/external_links.rb +9 -9
  77. data/lib/nanoc/extra/checking/checks/html.rb +2 -3
  78. data/lib/nanoc/extra/checking/checks/internal_links.rb +6 -7
  79. data/lib/nanoc/extra/checking/checks/stale.rb +6 -6
  80. data/lib/nanoc/extra/checking/dsl.rb +1 -1
  81. data/lib/nanoc/extra/checking/runner.rb +19 -19
  82. data/lib/nanoc/extra/chick.rb +11 -9
  83. data/lib/nanoc/extra/core_ext/pathname.rb +1 -2
  84. data/lib/nanoc/extra/core_ext/time.rb +2 -2
  85. data/lib/nanoc/extra/core_ext.rb +0 -1
  86. data/lib/nanoc/extra/deployer.rb +2 -2
  87. data/lib/nanoc/extra/deployers/fog.rb +12 -12
  88. data/lib/nanoc/extra/deployers/rsync.rb +6 -6
  89. data/lib/nanoc/extra/file_proxy.rb +1 -1
  90. data/lib/nanoc/extra/filesystem_tools.rb +5 -5
  91. data/lib/nanoc/extra/link_collector.rb +4 -3
  92. data/lib/nanoc/extra/pruner.rb +5 -5
  93. data/lib/nanoc/extra/validators/links.rb +3 -3
  94. data/lib/nanoc/extra/vcs.rb +1 -1
  95. data/lib/nanoc/filters/asciidoc.rb +3 -3
  96. data/lib/nanoc/filters/bluecloth.rb +1 -1
  97. data/lib/nanoc/filters/coderay.rb +2 -2
  98. data/lib/nanoc/filters/coffeescript.rb +2 -0
  99. data/lib/nanoc/filters/colorize_syntax.rb +16 -16
  100. data/lib/nanoc/filters/erb.rb +5 -5
  101. data/lib/nanoc/filters/erubis.rb +1 -1
  102. data/lib/nanoc/filters/haml.rb +1 -1
  103. data/lib/nanoc/filters/handlebars.rb +2 -2
  104. data/lib/nanoc/filters/kramdown.rb +1 -1
  105. data/lib/nanoc/filters/less.rb +1 -1
  106. data/lib/nanoc/filters/markaby.rb +1 -1
  107. data/lib/nanoc/filters/maruku.rb +1 -1
  108. data/lib/nanoc/filters/mustache.rb +1 -1
  109. data/lib/nanoc/filters/pandoc.rb +1 -1
  110. data/lib/nanoc/filters/rainpress.rb +1 -1
  111. data/lib/nanoc/filters/rdiscount.rb +1 -1
  112. data/lib/nanoc/filters/rdoc.rb +1 -1
  113. data/lib/nanoc/filters/redcarpet.rb +2 -2
  114. data/lib/nanoc/filters/redcloth.rb +9 -9
  115. data/lib/nanoc/filters/relativize_paths.rb +7 -8
  116. data/lib/nanoc/filters/rubypants.rb +1 -1
  117. data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +1 -1
  118. data/lib/nanoc/filters/sass.rb +1 -1
  119. data/lib/nanoc/filters/slim.rb +1 -1
  120. data/lib/nanoc/filters/typogruby.rb +1 -1
  121. data/lib/nanoc/filters/uglify_js.rb +1 -1
  122. data/lib/nanoc/filters/xsl.rb +9 -7
  123. data/lib/nanoc/filters/yui_compressor.rb +2 -0
  124. data/lib/nanoc/helpers/blogging.rb +6 -6
  125. data/lib/nanoc/helpers/breadcrumbs.rb +1 -1
  126. data/lib/nanoc/helpers/capturing.rb +2 -2
  127. data/lib/nanoc/helpers/filtering.rb +1 -1
  128. data/lib/nanoc/helpers/html_escape.rb +3 -3
  129. data/lib/nanoc/helpers/link_to.rb +6 -6
  130. data/lib/nanoc/helpers/rendering.rb +2 -2
  131. data/lib/nanoc/helpers/tagging.rb +2 -2
  132. data/lib/nanoc/helpers/text.rb +1 -1
  133. data/lib/nanoc/helpers/xml_sitemap.rb +2 -2
  134. data/lib/nanoc/version.rb +1 -1
  135. data/lib/nanoc.rb +3 -2
  136. data/nanoc.gemspec +2 -6
  137. data/tasks/rubocop.rake +5 -0
  138. data/test/base/test_compiler_dsl.rb +20 -1
  139. data/test/cli/commands/test_compile.rb +4 -3
  140. data/test/cli/test_error_handler.rb +32 -0
  141. data/test/filters/test_erb.rb +1 -1
  142. data/test/filters/test_less.rb +1 -1
  143. data/test/filters/test_xsl.rb +95 -8
  144. metadata +30 -84
data/lib/nanoc/cli.rb CHANGED
@@ -55,8 +55,8 @@ module Nanoc::CLI
55
55
  # @return [void]
56
56
  def self.run(args)
57
57
  Nanoc::CLI::ErrorHandler.handle_while do
58
- self.setup
59
- self.root_command.run(args)
58
+ setup
59
+ root_command.run(args)
60
60
  end
61
61
  end
62
62
 
@@ -71,7 +71,7 @@ module Nanoc::CLI
71
71
  #
72
72
  # @return [void]
73
73
  def self.add_command(cmd)
74
- self.root_command.add_command(cmd)
74
+ root_command.add_command(cmd)
75
75
  end
76
76
 
77
77
  protected
@@ -80,9 +80,9 @@ protected
80
80
  #
81
81
  # @return [void]
82
82
  def self.setup
83
- self.setup_cleaning_streams
84
- self.setup_commands
85
- self.load_custom_commands
83
+ setup_cleaning_streams
84
+ setup_commands
85
+ load_custom_commands
86
86
  end
87
87
 
88
88
  # Sets up the root command and base subcommands.
@@ -93,19 +93,19 @@ protected
93
93
  @root_command = nil
94
94
 
95
95
  # Add root command
96
- filename = File.dirname(__FILE__) + "/cli/commands/nanoc.rb"
97
- @root_command = self.load_command_at(filename)
96
+ filename = File.dirname(__FILE__) + '/cli/commands/nanoc.rb'
97
+ @root_command = load_command_at(filename)
98
98
 
99
99
  # Add help command
100
100
  help_cmd = Cri::Command.new_basic_help
101
- self.add_command(help_cmd)
101
+ add_command(help_cmd)
102
102
 
103
103
  # Add other commands
104
104
  cmd_filenames = Dir[File.dirname(__FILE__) + '/cli/commands/*.rb']
105
- cmd_filenames.each do |filename|
106
- next if File.basename(filename, '.rb') == 'nanoc'
107
- cmd = self.load_command_at(filename)
108
- self.add_command(cmd)
105
+ cmd_filenames.each do |cmd_filename|
106
+ next if File.basename(cmd_filename, '.rb') == 'nanoc'
107
+ cmd = load_command_at(cmd_filename)
108
+ add_command(cmd)
109
109
  end
110
110
  end
111
111
 
@@ -113,15 +113,15 @@ protected
113
113
  #
114
114
  # @return [void]
115
115
  def self.load_custom_commands
116
- self.recursive_contents_of('commands').each do |filename|
116
+ recursive_contents_of('commands').each do |filename|
117
117
  # Create command
118
118
  command = Nanoc::CLI.load_command_at(filename)
119
119
 
120
120
  # Get supercommand
121
121
  pieces = filename.gsub(/^commands\/|\.rb$/, '').split('/')
122
- pieces = pieces[0, pieces.size-1] || []
122
+ pieces = pieces[0, pieces.size - 1] || []
123
123
  root = Nanoc::CLI.root_command
124
- supercommand = pieces.inject(root) do |cmd, piece|
124
+ supercommand = pieces.reduce(root) do |cmd, piece|
125
125
  cmd.nil? ? nil : cmd.command_named(piece)
126
126
  end
127
127
 
@@ -138,7 +138,7 @@ protected
138
138
  # @param [String] filename The name of the file that contains the command
139
139
  #
140
140
  # @return [Cri::Command] The loaded command
141
- def self.load_command_at(filename, command_name=nil)
141
+ def self.load_command_at(filename, command_name = nil)
142
142
  # Load
143
143
  code = File.read(filename)
144
144
  cmd = Cri::Command.define(code, filename)
@@ -155,7 +155,7 @@ protected
155
155
  def self.recursive_contents_of(path)
156
156
  return [] unless File.directory?(path)
157
157
  files, dirs = *Dir[path + '/*'].sort.partition { |e| File.file?(e) }
158
- dirs.each { |d| files.concat self.recursive_contents_of(d) }
158
+ dirs.each { |d| files.concat recursive_contents_of(d) }
159
159
  files
160
160
  end
161
161
 
@@ -183,8 +183,8 @@ protected
183
183
  #
184
184
  # @return [void]
185
185
  def self.setup_cleaning_streams
186
- $stdout = self.wrap_in_cleaning_stream($stdout)
187
- $stderr = self.wrap_in_cleaning_stream($stderr)
186
+ $stdout = wrap_in_cleaning_stream($stdout)
187
+ $stderr = wrap_in_cleaning_stream($stderr)
188
188
  end
189
189
 
190
190
  # @return [Boolean] true if UTF-8 support is present, false if not
@@ -196,13 +196,15 @@ protected
196
196
 
197
197
  # @return [Boolean] true if color support is present, false if not
198
198
  def self.enable_ansi_colors?(io)
199
- return false if !io.tty?
199
+ if !io.tty?
200
+ return false
201
+ end
200
202
 
201
203
  if Nanoc.on_windows?
202
204
  return defined?(::Win32::Console::ANSI)
203
205
  end
204
206
 
205
- return true
207
+ true
206
208
  end
207
209
 
208
210
  end
@@ -11,7 +11,7 @@ module Nanoc::DataSources
11
11
 
12
12
  # Get data
13
13
  @http_client ||= Nanoc::Extra::CHiCk::Client.new
14
- status, headers, data = *@http_client.get("http://feeds.delicious.com/v2/json/#{self.config[:username]}")
14
+ _status, _headers, data = *@http_client.get("http://feeds.delicious.com/v2/json/#{config[:username]}")
15
15
 
16
16
  # Parse as JSON
17
17
  raw_items = JSON.parse(data)
@@ -11,21 +11,21 @@ module Nanoc::DataSources
11
11
  require 'uri'
12
12
 
13
13
  # Check configuration
14
- if self.config[:username].nil?
15
- raise RuntimeError, "LastFM data source requires a username in the configuration"
14
+ if config[:username].nil?
15
+ raise 'LastFM data source requires a username in the configuration'
16
16
  end
17
- if self.config[:api_key].nil?
18
- raise RuntimeError, "LastFM data source requires an API key in the configuration"
17
+ if config[:api_key].nil?
18
+ raise 'LastFM data source requires an API key in the configuration'
19
19
  end
20
20
 
21
21
  # Get data
22
22
  @http_client ||= Nanoc::Extra::CHiCk::Client.new
23
- status, headers, data = *@http_client.get(
23
+ _status, _headers, data = *@http_client.get(
24
24
  'http://ws.audioscrobbler.com/2.0/' +
25
25
  '?method=user.getRecentTracks' +
26
26
  '&format=json' +
27
- '&user=' + URI.escape(self.config[:username]) +
28
- '&api_key=' + URI.escape(self.config[:api_key])
27
+ '&user=' + URI.escape(config[:username]) +
28
+ '&api_key=' + URI.escape(config[:api_key])
29
29
  )
30
30
 
31
31
  # Parse as JSON
@@ -35,16 +35,18 @@ module Nanoc::DataSources
35
35
  # Convert to items
36
36
  raw_items.enum_with_index.map do |raw_item, i|
37
37
  # Get artist data
38
- artist_status, artist_headers, artist_data = *@http_client.get(
38
+ _artist_status, _artist_headers, artist_data = *@http_client.get(
39
39
  'http://ws.audioscrobbler.com/2.0/' +
40
40
  '?method=artist.getInfo' +
41
41
  '&format=json' +
42
42
  (
43
- raw_item['artist']['mbid'].empty? ?
44
- '&artist=' + URI.escape(raw_item['artist']['#text']) :
45
- '&mbid=' + URI.escape(raw_item['artist']['mbid'])
43
+ if raw_item['artist']['mbid'].empty?
44
+ '&artist=' + URI.escape(raw_item['artist']['#text'])
45
+ else
46
+ '&mbid=' + URI.escape(raw_item['artist']['mbid'])
47
+ end
46
48
  ) +
47
- '&api_key=' + URI.escape(self.config[:api_key])
49
+ '&api_key=' + URI.escape(config[:api_key])
48
50
  )
49
51
 
50
52
  # Parse as JSON
@@ -59,10 +61,10 @@ module Nanoc::DataSources
59
61
  track_played_at = Time.now
60
62
  now_playing = true
61
63
  else
62
- played_at = Time.parse(raw_item['date']['#text'])
64
+ track_played_at = Time.parse(raw_item['date']['#text'])
63
65
  now_playing = false
64
66
  end
65
-
67
+
66
68
  attributes = {
67
69
  :name => raw_item['name'],
68
70
  :artist => {
@@ -11,7 +11,7 @@ module Nanoc::DataSources
11
11
 
12
12
  # Get data
13
13
  @http_client ||= Nanoc::Extra::CHiCk::Client.new
14
- status, headers, data = *@http_client.get("http://twitter.com/statuses/user_timeline/#{self.config[:username]}.json")
14
+ _status, _headers, data = *@http_client.get("http://twitter.com/statuses/user_timeline/#{config[:username]}.json")
15
15
 
16
16
  # Parse as JSON
17
17
  raw_items = JSON.parse(data)
@@ -43,12 +43,12 @@ module Nanoc::DataSources
43
43
  end
44
44
 
45
45
  # See {Nanoc::DataSource#create_item}.
46
- def create_item(content, attributes, identifier, params={})
46
+ def create_item(content, attributes, identifier, params = {})
47
47
  create_object('content', content, attributes, identifier, params)
48
48
  end
49
49
 
50
50
  # See {Nanoc::DataSource#create_layout}.
51
- def create_layout(content, attributes, identifier, params={})
51
+ def create_layout(content, attributes, identifier, params = {})
52
52
  create_object('layouts', content, attributes, identifier, params)
53
53
  end
54
54
 
@@ -57,7 +57,7 @@ module Nanoc::DataSources
57
57
  # Creates a new object (item or layout) on disk in dir_name according to
58
58
  # the given identifier. The file will have its attributes taken from the
59
59
  # attributes hash argument and its content from the content argument.
60
- def create_object(dir_name, content, attributes, identifier, params={})
60
+ def create_object(dir_name, content, attributes, identifier, params = {})
61
61
  raise NotImplementedError.new(
62
62
  "#{self.class} does not implement ##{name}"
63
63
  )
@@ -103,11 +103,11 @@ module Nanoc::DataSources
103
103
 
104
104
  # Get identifier
105
105
  if meta_filename
106
- identifier = identifier_for_filename(meta_filename[(dir_name.length+1)..-1])
106
+ identifier = identifier_for_filename(meta_filename[(dir_name.length + 1)..-1])
107
107
  elsif content_filename
108
- identifier = identifier_for_filename(content_filename[(dir_name.length+1)..-1])
108
+ identifier = identifier_for_filename(content_filename[(dir_name.length + 1)..-1])
109
109
  else
110
- raise RuntimeError, "meta_filename and content_filename are both nil"
110
+ raise 'meta_filename and content_filename are both nil'
111
111
  end
112
112
 
113
113
  # Get modification times
@@ -120,7 +120,7 @@ module Nanoc::DataSources
120
120
  elsif content_mtime
121
121
  mtime = content_mtime
122
122
  else
123
- raise RuntimeError, "meta_mtime and content_mtime are both nil"
123
+ raise 'meta_mtime and content_mtime are both nil'
124
124
  end
125
125
 
126
126
  # Create layout object
@@ -143,14 +143,10 @@ module Nanoc::DataSources
143
143
  # 'content/qux' => [ nil, 'html' ]
144
144
  # }
145
145
  def all_split_files_in(dir_name)
146
- # Get all good file names
147
- filenames = self.all_files_in(dir_name)
148
- filenames.reject! { |fn| fn =~ /(~|\.orig|\.rej|\.bak)$/ }
146
+ grouped_filenames = all_files_in(dir_name).
147
+ reject { |fn| fn =~ /(~|\.orig|\.rej|\.bak)$/ }.
148
+ group_by { |fn| basename_of(fn) }
149
149
 
150
- # Group by identifier
151
- grouped_filenames = filenames.group_by { |fn| basename_of(fn) }
152
-
153
- # Convert values into metafile/content file extension tuple
154
150
  grouped_filenames.each_pair do |key, filenames|
155
151
  # Divide
156
152
  meta_filenames = filenames.select { |fn| ext_of(fn) == '.yaml' }
@@ -158,18 +154,17 @@ module Nanoc::DataSources
158
154
 
159
155
  # Check number of files per type
160
156
  if ![ 0, 1 ].include?(meta_filenames.size)
161
- raise RuntimeError, "Found #{meta_filenames.size} meta files for #{key}; expected 0 or 1"
157
+ raise "Found #{meta_filenames.size} meta files for #{key}; expected 0 or 1"
162
158
  end
163
159
  if ![ 0, 1 ].include?(content_filenames.size)
164
- raise RuntimeError, "Found #{content_filenames.size} content files for #{key}; expected 0 or 1"
160
+ raise "Found #{content_filenames.size} content files for #{key}; expected 0 or 1"
165
161
  end
166
162
 
167
163
  # Reorder elements and convert to extnames
168
164
  filenames[0] = meta_filenames[0] ? 'yaml' : nil
169
- filenames[1] = content_filenames[0] ? ext_of(content_filenames[0])[1..-1] || '': nil
165
+ filenames[1] = content_filenames[0] ? ext_of(content_filenames[0])[1..-1] || '' : nil
170
166
  end
171
167
 
172
- # Done
173
168
  grouped_filenames
174
169
  end
175
170
 
@@ -292,8 +287,15 @@ module Nanoc::DataSources
292
287
  original_encoding = data.encoding
293
288
  end
294
289
 
295
- data.encode!('UTF-8') rescue raise_encoding_error(filename, original_encoding)
296
- raise_encoding_error(filename, original_encoding) if !data.valid_encoding?
290
+ begin
291
+ data.encode!('UTF-8')
292
+ rescue
293
+ raise_encoding_error(filename, original_encoding)
294
+ end
295
+
296
+ if !data.valid_encoding?
297
+ raise_encoding_error(filename, original_encoding)
298
+ end
297
299
  end
298
300
 
299
301
  # Remove UTF-8 BOM (ugly)
@@ -67,11 +67,10 @@ module Nanoc::DataSources
67
67
  private
68
68
 
69
69
  # See {Nanoc::DataSources::Filesystem#create_object}.
70
- def create_object(dir_name, content, attributes, identifier, params={})
70
+ def create_object(dir_name, content, attributes, identifier, params = {})
71
71
  # Check for periods
72
72
  if (@config.nil? || !@config[:allow_periods_in_identifiers]) && identifier.include?('.')
73
- raise RuntimeError,
74
- "Attempted to create an object in #{dir_name} with identifier #{identifier} containing a period, but allow_periods_in_identifiers is not enabled in the site configuration. (Enabling allow_periods_in_identifiers may cause the site to break, though.)"
73
+ raise "Attempted to create an object in #{dir_name} with identifier #{identifier} containing a period, but allow_periods_in_identifiers is not enabled in the site configuration. (Enabling allow_periods_in_identifiers may cause the site to break, though.)"
75
74
  end
76
75
 
77
76
  # Determine path
@@ -109,9 +108,9 @@ module Nanoc::DataSources
109
108
  # the given directory name off the filename.
110
109
  def identifier_for_filename(filename)
111
110
  if filename =~ /(^|\/)index(\.[^\/]+)?$/
112
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\/?(index)?(\.[^\/\.]+)?$/ : /\/?index(\.[^\/]+)?$/)
111
+ regex = @config && @config[:allow_periods_in_identifiers] ? /\/?(index)?(\.[^\/\.]+)?$/ : /\/?index(\.[^\/]+)?$/
113
112
  else
114
- regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
113
+ regex = @config && @config[:allow_periods_in_identifiers] ? /\.[^\/\.]+$/ : /\.[^\/]+$/
115
114
  end
116
115
  filename.sub(regex, '').cleaned_identifier
117
116
  end
@@ -46,17 +46,16 @@ module Nanoc::DataSources
46
46
  private
47
47
 
48
48
  # See {Nanoc::DataSources::Filesystem#create_object}.
49
- def create_object(dir_name, content, attributes, identifier, params={})
49
+ def create_object(dir_name, content, attributes, identifier, params = {})
50
50
  # Determine base path
51
51
  last_component = identifier.split('/')[-1] || dir_name
52
- base_path = dir_name + identifier + last_component
53
52
 
54
53
  # Get filenames
55
54
  ext = params[:extension] || '.html'
56
55
  dir_path = dir_name + identifier
57
56
  meta_filename = dir_name + identifier + last_component + '.yaml'
58
57
  content_filename = dir_name + identifier + last_component + ext
59
-
58
+
60
59
  # Notify
61
60
  Nanoc::NotificationCenter.post(:file_created, meta_filename)
62
61
  Nanoc::NotificationCenter.post(:file_created, content_filename)
@@ -34,13 +34,13 @@ module Nanoc::DataSources
34
34
  prefix = config[:prefix] || 'static'
35
35
 
36
36
  # Convert filenames to items
37
- self.all_files_in(prefix).map do |filename|
37
+ all_files_in(prefix).map do |filename|
38
38
  attributes = {
39
39
  :extension => File.extname(filename)[1..-1],
40
40
  :filename => filename,
41
41
  }
42
42
  attributes[:is_hidden] = true unless config[:hide_items] == false
43
- identifier = filename[(prefix.length+1)..-1] + '/'
43
+ identifier = filename[(prefix.length + 1)..-1] + '/'
44
44
  mtime = File.mtime(filename)
45
45
  checksum = Pathname.new(filename).checksum
46
46
 
@@ -25,7 +25,7 @@ module Nanoc::Extra
25
25
  end
26
26
 
27
27
  # Calls the autocompiler. The behaviour of this method is defined by the
28
- # [Rack specification](http://rack.rubyforge.org/doc/files/SPEC.html).
28
+ # [Rack specification](http://rack.rubyforge.org/doc/SPEC.html).
29
29
  #
30
30
  # @param [Hash] env The environment, as defined by the Rack specification
31
31
  #
@@ -37,7 +37,7 @@ module Nanoc::Extra
37
37
  build_site
38
38
 
39
39
  # Find rep
40
- path = Rack::Utils::unescape(env['PATH_INFO'])
40
+ path = Rack::Utils.unescape(env['PATH_INFO'])
41
41
  reps = site.items.map { |i| i.reps }.flatten
42
42
  rep = reps.find do |r|
43
43
  r.path == path ||
@@ -87,7 +87,7 @@ module Nanoc::Extra
87
87
 
88
88
  def mime_type_of(path, fallback)
89
89
  mime_type = MIME::Types.of(path).first
90
- mime_type = mime_type.nil? ? fallback : mime_type.simplified
90
+ mime_type.nil? ? fallback : mime_type.simplified
91
91
  end
92
92
 
93
93
  def file_server
@@ -15,17 +15,17 @@ module Nanoc::Extra::Checking
15
15
  end
16
16
 
17
17
  def run
18
- raise NotImplementedError.new("Nanoc::Extra::Checking::Check subclasses must implement #run")
18
+ raise NotImplementedError.new('Nanoc::Extra::Checking::Check subclasses must implement #run')
19
19
  end
20
20
 
21
- def add_issue(desc, params={})
21
+ def add_issue(desc, params = {})
22
22
  subject = params.fetch(:subject, nil)
23
23
 
24
24
  @issues << Issue.new(desc, subject, self.class)
25
25
  end
26
26
 
27
27
  def output_filenames
28
- Dir[@site.config[:output_dir] + '/**/*'].select{ |f| File.file?(f) }
28
+ Dir[@site.config[:output_dir] + '/**/*'].select { |f| File.file?(f) }
29
29
  end
30
30
 
31
31
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  module ::Nanoc::Extra::Checking::Checks
4
4
 
@@ -13,7 +13,7 @@ module ::Nanoc::Extra::Checking::Checks
13
13
  results = ::W3CValidators::CSSValidator.new.validate_file(filename)
14
14
  results.errors.each do |e|
15
15
  desc = e.message.gsub(%r{\s+}, ' ').strip
16
- self.add_issue(desc, :subject => filename)
16
+ add_issue(desc, :subject => filename)
17
17
  end
18
18
  end
19
19
  end
@@ -16,16 +16,16 @@ module ::Nanoc::Extra::Checking::Checks
16
16
  def run
17
17
  # Find all broken external hrefs
18
18
  # TODO de-duplicate this (duplicated in internal links check)
19
- filenames = self.output_filenames.select { |f| File.extname(f) == '.html' }
19
+ filenames = output_filenames.select { |f| File.extname(f) == '.html' }
20
20
  hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :external).filenames_per_href
21
- results = self.select_invalid(hrefs_with_filenames.keys)
21
+ results = select_invalid(hrefs_with_filenames.keys)
22
22
 
23
23
  # Report them
24
24
  results.each do |res|
25
25
  filenames = hrefs_with_filenames[res.href]
26
26
  filenames.each do |filename|
27
- self.add_issue(
28
- "reference to #{res.href}: #{res.explanation}",
27
+ add_issue(
28
+ "broken reference to #{res.href}: #{res.explanation}",
29
29
  :subject => filename)
30
30
  end
31
31
  end
@@ -54,7 +54,7 @@ module ::Nanoc::Extra::Checking::Checks
54
54
  def next
55
55
  @mutex.synchronize do
56
56
  @index += 1
57
- return @array[@index-1]
57
+ return @array[@index - 1]
58
58
  end
59
59
  end
60
60
 
@@ -71,7 +71,7 @@ module ::Nanoc::Extra::Checking::Checks
71
71
  loop do
72
72
  href = enum.next
73
73
  break if href.nil?
74
- res = self.validate(href)
74
+ res = validate(href)
75
75
  if res
76
76
  mutex.synchronize do
77
77
  invalid << res
@@ -101,7 +101,7 @@ module ::Nanoc::Extra::Checking::Checks
101
101
  res = nil
102
102
  5.times do |i|
103
103
  begin
104
- Timeout::timeout(10) do
104
+ Timeout.timeout(10) do
105
105
  res = request_url_once(url)
106
106
  if res.code == '405'
107
107
  res = request_url_once(url, Net::HTTP::Get)
@@ -151,13 +151,13 @@ module ::Nanoc::Extra::Checking::Checks
151
151
  end
152
152
 
153
153
  def request_url_once(url, req_method = Net::HTTP::Head)
154
- req = req_method.new(self.path_for_url(url))
154
+ req = req_method.new(path_for_url(url))
155
155
  http = Net::HTTP.new(url.host, url.port)
156
156
  if url.instance_of? URI::HTTPS
157
157
  http.use_ssl = true
158
158
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
159
159
  end
160
- res = http.request(req)
160
+ http.request(req)
161
161
  end
162
162
 
163
163
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  module ::Nanoc::Extra::Checking::Checks
4
4
 
@@ -13,7 +13,7 @@ module ::Nanoc::Extra::Checking::Checks
13
13
  results = ::W3CValidators::MarkupValidator.new.validate_file(filename)
14
14
  results.errors.each do |e|
15
15
  desc = e.message.gsub(%r{\s+}, ' ').strip
16
- self.add_issue(desc, :subject => filename)
16
+ add_issue(desc, :subject => filename)
17
17
  end
18
18
  end
19
19
  end
@@ -21,4 +21,3 @@ module ::Nanoc::Extra::Checking::Checks
21
21
  end
22
22
 
23
23
  end
24
-
@@ -12,13 +12,13 @@ module Nanoc::Extra::Checking::Checks
12
12
  # @return [void]
13
13
  def run
14
14
  # TODO de-duplicate this (duplicated in external links check)
15
- filenames = self.output_filenames.select { |f| File.extname(f) == '.html' }
15
+ filenames = output_filenames.select { |f| File.extname(f) == '.html' }
16
16
  hrefs_with_filenames = ::Nanoc::Extra::LinkCollector.new(filenames, :internal).filenames_per_href
17
- hrefs_with_filenames.each_pair do |href, filenames|
18
- filenames.each do |filename|
17
+ hrefs_with_filenames.each_pair do |href, fns|
18
+ fns.each do |filename|
19
19
  unless valid?(href, filename)
20
- self.add_issue(
21
- "reference to #{href}",
20
+ add_issue(
21
+ "broken reference to #{href}",
22
22
  :subject => filename)
23
23
  end
24
24
  end
@@ -57,10 +57,9 @@ module Nanoc::Extra::Checking::Checks
57
57
  return true if File.directory?(path) && @site.config[:index_filenames].any? { |fn| File.file?(File.join(path, fn)) }
58
58
 
59
59
  # Nope :(
60
- return false
60
+ false
61
61
  end
62
62
 
63
63
  end
64
64
 
65
65
  end
66
-
@@ -7,19 +7,19 @@ module Nanoc::Extra::Checking::Checks
7
7
  def run
8
8
  require 'set'
9
9
 
10
- item_rep_paths = Set.new(@site.items.collect { |i| i.reps }.flatten.collect { |r| r.raw_path })
10
+ item_rep_paths = Set.new(@site.items.map { |i| i.reps }.flatten.map { |r| r.raw_path })
11
11
 
12
- self.output_filenames.each do |f|
13
- next if self.pruner.filename_excluded?(f)
12
+ output_filenames.each do |f|
13
+ next if pruner.filename_excluded?(f)
14
14
  if !item_rep_paths.include?(f)
15
- self.add_issue(
16
- "file without matching item",
15
+ add_issue(
16
+ 'file without matching item',
17
17
  :subject => f)
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
- protected
22
+ protected
23
23
 
24
24
  def pruner
25
25
  exclude_config = @site.config.fetch(:prune, {}).fetch(:exclude, [])
@@ -7,7 +7,7 @@ module Nanoc::Extra::Checking
7
7
  attr_reader :deploy_checks
8
8
 
9
9
  def self.from_file(filename)
10
- dsl = self.new
10
+ dsl = new
11
11
  dsl.instance_eval File.read(filename)
12
12
  dsl
13
13
  end