nanoc 3.6.7 → 3.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CONTRIBUTING.md +9 -13
- data/Gemfile +5 -1
- data/Gemfile.lock +70 -45
- data/NEWS.md +15 -1
- data/README.md +12 -119
- data/doc/yardoc_handlers/identifier.rb +34 -0
- data/lib/nanoc/base/compilation/checksum_store.rb +2 -2
- data/lib/nanoc/base/compilation/compiler.rb +3 -3
- data/lib/nanoc/base/compilation/compiler_dsl.rb +20 -15
- data/lib/nanoc/base/compilation/dependency_tracker.rb +4 -4
- data/lib/nanoc/base/compilation/filter.rb +5 -5
- data/lib/nanoc/base/compilation/item_rep_proxy.rb +2 -2
- data/lib/nanoc/base/compilation/item_rep_recorder_proxy.rb +3 -3
- data/lib/nanoc/base/compilation/outdatedness_checker.rb +49 -46
- data/lib/nanoc/base/compilation/rule.rb +6 -4
- data/lib/nanoc/base/compilation/rule_context.rb +10 -4
- data/lib/nanoc/base/compilation/rule_memory_calculator.rb +8 -7
- data/lib/nanoc/base/compilation/rule_memory_store.rb +2 -2
- data/lib/nanoc/base/compilation/rules_collection.rb +2 -2
- data/lib/nanoc/base/core_ext/array.rb +2 -2
- data/lib/nanoc/base/core_ext/date.rb +4 -2
- data/lib/nanoc/base/core_ext/hash.rb +3 -3
- data/lib/nanoc/base/core_ext/pathname.rb +1 -1
- data/lib/nanoc/base/directed_graph.rb +6 -6
- data/lib/nanoc/base/errors.rb +1 -1
- data/lib/nanoc/base/memoization.rb +4 -4
- data/lib/nanoc/base/notification_center.rb +1 -1
- data/lib/nanoc/base/ordered_hash.rb +207 -179
- data/lib/nanoc/base/plugin_registry.rb +7 -7
- data/lib/nanoc/base/result_data/item_rep.rb +25 -26
- data/lib/nanoc/base/source_data/code_snippet.rb +2 -2
- data/lib/nanoc/base/source_data/configuration.rb +1 -1
- data/lib/nanoc/base/source_data/data_source.rb +2 -2
- data/lib/nanoc/base/source_data/item.rb +16 -15
- data/lib/nanoc/base/source_data/item_array.rb +4 -4
- data/lib/nanoc/base/source_data/layout.rb +5 -5
- data/lib/nanoc/base/source_data/site.rb +6 -6
- data/lib/nanoc/base/store.rb +8 -8
- data/lib/nanoc/cli/cleaning_stream.rb +11 -12
- data/lib/nanoc/cli/command_runner.rb +8 -8
- data/lib/nanoc/cli/commands/autocompile.rb +5 -4
- data/lib/nanoc/cli/commands/check.rb +12 -11
- data/lib/nanoc/cli/commands/compile.rb +50 -52
- data/lib/nanoc/cli/commands/create-item.rb +6 -6
- data/lib/nanoc/cli/commands/create-layout.rb +6 -6
- data/lib/nanoc/cli/commands/create-site.rb +10 -13
- data/lib/nanoc/cli/commands/deploy.rb +11 -11
- data/lib/nanoc/cli/commands/prune.rb +10 -10
- data/lib/nanoc/cli/commands/shell.rb +7 -7
- data/lib/nanoc/cli/commands/show-data.rb +22 -23
- data/lib/nanoc/cli/commands/show-plugins.rb +3 -3
- data/lib/nanoc/cli/commands/show-rules.rb +8 -8
- data/lib/nanoc/cli/commands/sync.rb +4 -2
- data/lib/nanoc/cli/commands/update.rb +4 -4
- data/lib/nanoc/cli/commands/validate-css.rb +3 -3
- data/lib/nanoc/cli/commands/validate-html.rb +3 -3
- data/lib/nanoc/cli/commands/validate-links.rb +3 -3
- data/lib/nanoc/cli/commands/view.rb +5 -3
- data/lib/nanoc/cli/commands/watch.rb +12 -12
- data/lib/nanoc/cli/error_handler.rb +58 -58
- data/lib/nanoc/cli/logger.rb +6 -6
- data/lib/nanoc/cli/stream_cleaners/abstract.rb +1 -1
- data/lib/nanoc/cli/stream_cleaners.rb +0 -1
- data/lib/nanoc/cli.rb +24 -22
- data/lib/nanoc/data_sources/deprecated/delicious.rb +1 -1
- data/lib/nanoc/data_sources/deprecated/last_fm.rb +16 -14
- data/lib/nanoc/data_sources/deprecated/twitter.rb +1 -1
- data/lib/nanoc/data_sources/filesystem.rb +22 -20
- data/lib/nanoc/data_sources/filesystem_unified.rb +4 -5
- data/lib/nanoc/data_sources/filesystem_verbose.rb +2 -3
- data/lib/nanoc/data_sources/static.rb +2 -2
- data/lib/nanoc/extra/auto_compiler.rb +3 -3
- data/lib/nanoc/extra/checking/check.rb +3 -3
- data/lib/nanoc/extra/checking/checks/css.rb +2 -2
- data/lib/nanoc/extra/checking/checks/external_links.rb +9 -9
- data/lib/nanoc/extra/checking/checks/html.rb +2 -3
- data/lib/nanoc/extra/checking/checks/internal_links.rb +6 -7
- data/lib/nanoc/extra/checking/checks/stale.rb +6 -6
- data/lib/nanoc/extra/checking/dsl.rb +1 -1
- data/lib/nanoc/extra/checking/runner.rb +19 -19
- data/lib/nanoc/extra/chick.rb +11 -9
- data/lib/nanoc/extra/core_ext/pathname.rb +1 -2
- data/lib/nanoc/extra/core_ext/time.rb +2 -2
- data/lib/nanoc/extra/core_ext.rb +0 -1
- data/lib/nanoc/extra/deployer.rb +2 -2
- data/lib/nanoc/extra/deployers/fog.rb +12 -12
- data/lib/nanoc/extra/deployers/rsync.rb +6 -6
- data/lib/nanoc/extra/file_proxy.rb +1 -1
- data/lib/nanoc/extra/filesystem_tools.rb +5 -5
- data/lib/nanoc/extra/link_collector.rb +4 -3
- data/lib/nanoc/extra/pruner.rb +5 -5
- data/lib/nanoc/extra/validators/links.rb +3 -3
- data/lib/nanoc/extra/vcs.rb +1 -1
- data/lib/nanoc/filters/asciidoc.rb +3 -3
- data/lib/nanoc/filters/bluecloth.rb +1 -1
- data/lib/nanoc/filters/coderay.rb +2 -2
- data/lib/nanoc/filters/coffeescript.rb +2 -0
- data/lib/nanoc/filters/colorize_syntax.rb +16 -16
- data/lib/nanoc/filters/erb.rb +5 -5
- data/lib/nanoc/filters/erubis.rb +1 -1
- data/lib/nanoc/filters/haml.rb +1 -1
- data/lib/nanoc/filters/handlebars.rb +2 -2
- data/lib/nanoc/filters/kramdown.rb +1 -1
- data/lib/nanoc/filters/less.rb +1 -1
- data/lib/nanoc/filters/markaby.rb +1 -1
- data/lib/nanoc/filters/maruku.rb +1 -1
- data/lib/nanoc/filters/mustache.rb +1 -1
- data/lib/nanoc/filters/pandoc.rb +1 -1
- data/lib/nanoc/filters/rainpress.rb +1 -1
- data/lib/nanoc/filters/rdiscount.rb +1 -1
- data/lib/nanoc/filters/rdoc.rb +1 -1
- data/lib/nanoc/filters/redcarpet.rb +2 -2
- data/lib/nanoc/filters/redcloth.rb +9 -9
- data/lib/nanoc/filters/relativize_paths.rb +7 -8
- data/lib/nanoc/filters/rubypants.rb +1 -1
- data/lib/nanoc/filters/sass/sass_filesystem_importer.rb +1 -1
- data/lib/nanoc/filters/sass.rb +1 -1
- data/lib/nanoc/filters/slim.rb +1 -1
- data/lib/nanoc/filters/typogruby.rb +1 -1
- data/lib/nanoc/filters/uglify_js.rb +1 -1
- data/lib/nanoc/filters/xsl.rb +9 -7
- data/lib/nanoc/filters/yui_compressor.rb +2 -0
- data/lib/nanoc/helpers/blogging.rb +6 -6
- data/lib/nanoc/helpers/breadcrumbs.rb +1 -1
- data/lib/nanoc/helpers/capturing.rb +2 -2
- data/lib/nanoc/helpers/filtering.rb +1 -1
- data/lib/nanoc/helpers/html_escape.rb +3 -3
- data/lib/nanoc/helpers/link_to.rb +6 -6
- data/lib/nanoc/helpers/rendering.rb +2 -2
- data/lib/nanoc/helpers/tagging.rb +2 -2
- data/lib/nanoc/helpers/text.rb +1 -1
- data/lib/nanoc/helpers/xml_sitemap.rb +2 -2
- data/lib/nanoc/version.rb +1 -1
- data/lib/nanoc.rb +3 -2
- data/nanoc.gemspec +2 -6
- data/tasks/rubocop.rake +5 -0
- data/test/base/test_compiler_dsl.rb +20 -1
- data/test/cli/commands/test_compile.rb +4 -3
- data/test/cli/test_error_handler.rb +32 -0
- data/test/filters/test_erb.rb +1 -1
- data/test/filters/test_less.rb +1 -1
- data/test/filters/test_xsl.rb +95 -8
- metadata +30 -84
@@ -21,37 +21,37 @@ module Nanoc::Extra::Checking
|
|
21
21
|
|
22
22
|
# @return [Boolean] true if a Checks file exists, false otherwise
|
23
23
|
def has_dsl?
|
24
|
-
|
24
|
+
checks_filename && File.file?(checks_filename)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Lists all available checks on stdout.
|
28
28
|
#
|
29
29
|
# @return [void]
|
30
30
|
def list_checks
|
31
|
-
|
31
|
+
load_dsl_if_available
|
32
32
|
|
33
|
-
puts
|
33
|
+
puts 'Available checks:'
|
34
34
|
puts
|
35
|
-
puts all_check_classes.map { |i|
|
35
|
+
puts all_check_classes.map { |i| ' ' + i.identifier.to_s }.sort.join("\n")
|
36
36
|
end
|
37
37
|
|
38
38
|
# Runs all checks.
|
39
39
|
#
|
40
40
|
# @return [Boolean] true if successful, false otherwise
|
41
41
|
def run_all
|
42
|
-
|
42
|
+
load_dsl_if_available
|
43
43
|
|
44
|
-
|
44
|
+
run_check_classes(all_check_classes)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Runs the checks marked for deployment.
|
48
48
|
#
|
49
49
|
# @return [Boolean] true if successful, false otherwise
|
50
50
|
def run_for_deploy
|
51
|
-
|
51
|
+
require_dsl
|
52
52
|
|
53
|
-
return true if
|
54
|
-
|
53
|
+
return true if dsl.nil?
|
54
|
+
run_check_classes(check_classes_named(dsl.deploy_checks))
|
55
55
|
end
|
56
56
|
|
57
57
|
# Runs the checks with the given names.
|
@@ -60,9 +60,9 @@ module Nanoc::Extra::Checking
|
|
60
60
|
#
|
61
61
|
# @return [Boolean] true if successful, false otherwise
|
62
62
|
def run_specific(check_class_names)
|
63
|
-
|
63
|
+
load_dsl_if_available
|
64
64
|
|
65
|
-
|
65
|
+
run_check_classes(check_classes_named(check_class_names))
|
66
66
|
end
|
67
67
|
|
68
68
|
protected
|
@@ -71,7 +71,7 @@ module Nanoc::Extra::Checking
|
|
71
71
|
@dsl_loaded ||= false
|
72
72
|
if !@dsl_loaded
|
73
73
|
if self.has_dsl?
|
74
|
-
@dsl = Nanoc::Extra::Checking::DSL.from_file(
|
74
|
+
@dsl = Nanoc::Extra::Checking::DSL.from_file(checks_filename)
|
75
75
|
else
|
76
76
|
@dsl = nil
|
77
77
|
end
|
@@ -80,8 +80,8 @@ module Nanoc::Extra::Checking
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def require_dsl
|
83
|
-
|
84
|
-
if
|
83
|
+
load_dsl_if_available
|
84
|
+
if dsl.nil?
|
85
85
|
raise Nanoc::Errors::GenericTrivial, "No checks defined (no #{CHECKS_FILENAMES.first} file present)"
|
86
86
|
end
|
87
87
|
end
|
@@ -91,8 +91,8 @@ module Nanoc::Extra::Checking
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def run_check_classes(classes)
|
94
|
-
issues =
|
95
|
-
|
94
|
+
issues = run_checks(classes)
|
95
|
+
print_issues(issues)
|
96
96
|
issues.empty? ? true : false
|
97
97
|
end
|
98
98
|
|
@@ -101,7 +101,7 @@ module Nanoc::Extra::Checking
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def check_classes_named(n)
|
104
|
-
|
104
|
+
n.map do |a|
|
105
105
|
klass = Nanoc::Extra::Checking::Check.named(a)
|
106
106
|
raise Nanoc::Errors::GenericTrivial, "Unknown check: #{a}" if klass.nil?
|
107
107
|
klass
|
@@ -115,7 +115,7 @@ module Nanoc::Extra::Checking
|
|
115
115
|
issues = Set.new
|
116
116
|
length = classes.map { |c| c.identifier.to_s.length }.max + 18
|
117
117
|
classes.each do |klass|
|
118
|
-
print format(" %-#{length}s", "Running #{klass.identifier}
|
118
|
+
print format(" %-#{length}s", "Running check #{klass.identifier}… ")
|
119
119
|
|
120
120
|
check = klass.new(@site)
|
121
121
|
check.run
|
@@ -134,7 +134,7 @@ module Nanoc::Extra::Checking
|
|
134
134
|
require 'colored'
|
135
135
|
|
136
136
|
return if issues.empty?
|
137
|
-
puts
|
137
|
+
puts 'Issues found!'
|
138
138
|
issues.group_by { |i| i.subject }.to_a.sort_by { |p| p.first }.each do |pair|
|
139
139
|
subject = pair.first
|
140
140
|
issues = pair.last
|
data/lib/nanoc/extra/chick.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'rack'
|
3
5
|
require 'rack/cache'
|
@@ -16,7 +18,7 @@ module Nanoc::Extra
|
|
16
18
|
|
17
19
|
DEFAULT_OPTIONS = {
|
18
20
|
:cache => {
|
19
|
-
:metastore => 'file:tmp/rack/cache.meta',
|
21
|
+
:metastore => 'file:tmp/rack/cache.meta',
|
20
22
|
:entitystore => 'file:tmp/rack/cache.body'
|
21
23
|
},
|
22
24
|
:cache_controller => {
|
@@ -24,7 +26,7 @@ module Nanoc::Extra
|
|
24
26
|
}
|
25
27
|
}
|
26
28
|
|
27
|
-
def initialize(options={})
|
29
|
+
def initialize(options = {})
|
28
30
|
# Get options
|
29
31
|
@options = DEFAULT_OPTIONS.merge(options)
|
30
32
|
@options[:cache] = DEFAULT_OPTIONS[:cache].merge(@options[:cache])
|
@@ -34,11 +36,11 @@ module Nanoc::Extra
|
|
34
36
|
def get(url)
|
35
37
|
# Build app
|
36
38
|
options = @options
|
37
|
-
@app ||= Rack::Builder.new
|
39
|
+
@app ||= Rack::Builder.new do
|
38
40
|
use Rack::Cache, options[:cache].merge(:verbose => true)
|
39
41
|
use Nanoc::Extra::CHiCk::CacheController, options[:cache_controller]
|
40
42
|
run Nanoc::Extra::CHiCk::RackClient
|
41
|
-
|
43
|
+
end
|
42
44
|
|
43
45
|
# Build environment for request
|
44
46
|
env = Rack::MockRequest.env_for(url, :method => 'GET')
|
@@ -63,14 +65,14 @@ module Nanoc::Extra
|
|
63
65
|
# [Curb](http://curb.rubyforge.org/) instead.
|
64
66
|
class CacheController
|
65
67
|
|
66
|
-
def initialize(app, options={})
|
68
|
+
def initialize(app, options = {})
|
67
69
|
@app = app
|
68
70
|
@options = options
|
69
71
|
end
|
70
72
|
|
71
73
|
def call(env)
|
72
74
|
res = @app.call(env)
|
73
|
-
unless res[1].
|
75
|
+
unless res[1].key?('Cache-Control') || res[1].key?('Expires')
|
74
76
|
res[1]['Cache-Control'] = "max-age=#{@options[:max_age]}"
|
75
77
|
end
|
76
78
|
res
|
@@ -96,7 +98,7 @@ module Nanoc::Extra
|
|
96
98
|
request = Rack::Request.new(env)
|
97
99
|
|
98
100
|
# Build headers and strip HTTP_
|
99
|
-
request_headers = env.
|
101
|
+
request_headers = env.reduce({}) do |m, (k, v)|
|
100
102
|
k =~ /^HTTP_(.*)$/ && v ? m.merge($1.gsub(/_/, '-') => v) : m
|
101
103
|
end
|
102
104
|
|
@@ -105,14 +107,14 @@ module Nanoc::Extra
|
|
105
107
|
net_http_request_class = METHOD_TO_CLASS_MAPPING[request.request_method]
|
106
108
|
raise ArgumentError, "Unsupported method: #{request.request_method}" if net_http_request_class.nil?
|
107
109
|
net_http_request = net_http_request_class.new(request.fullpath, request_headers)
|
108
|
-
net_http_request.body = env['rack.input'].read if
|
110
|
+
net_http_request.body = env['rack.input'].read if %w( POST PUT ).include?(request.request_method)
|
109
111
|
|
110
112
|
# Perform request
|
111
113
|
http.request(net_http_request) do |response|
|
112
114
|
# Build Rack response triplet
|
113
115
|
return [
|
114
116
|
response.code.to_i,
|
115
|
-
response.to_hash.
|
117
|
+
response.to_hash.reduce({}) { |m, (k, v)| m.merge(k => v[0]) },
|
116
118
|
[ response.body ]
|
117
119
|
]
|
118
120
|
end
|
@@ -17,7 +17,7 @@ module Nanoc::Extra
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def include_component?(component)
|
20
|
-
|
20
|
+
components.include?(component)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -27,4 +27,3 @@ end
|
|
27
27
|
class ::Pathname
|
28
28
|
include ::Nanoc::Extra::PathnameExtensions
|
29
29
|
end
|
30
|
-
|
@@ -4,12 +4,12 @@ module Nanoc::Extra::TimeExtensions
|
|
4
4
|
|
5
5
|
# @return [String] The time in an ISO-8601 date format.
|
6
6
|
def to_iso8601_date
|
7
|
-
|
7
|
+
strftime('%Y-%m-%d')
|
8
8
|
end
|
9
9
|
|
10
10
|
# @return [String] The time in an ISO-8601 time format.
|
11
11
|
def to_iso8601_time
|
12
|
-
|
12
|
+
getutc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
data/lib/nanoc/extra/core_ext.rb
CHANGED
data/lib/nanoc/extra/deployer.rb
CHANGED
@@ -29,7 +29,7 @@ module Nanoc::Extra
|
|
29
29
|
#
|
30
30
|
# @option params [Boolean] :dry_run (false) true if the deployer should
|
31
31
|
# only show what would be deployed instead actually deploying
|
32
|
-
def initialize(source_path, config, params={})
|
32
|
+
def initialize(source_path, config, params = {})
|
33
33
|
@source_path = source_path
|
34
34
|
@config = config
|
35
35
|
@dry_run = params.fetch(:dry_run) { false }
|
@@ -39,7 +39,7 @@ module Nanoc::Extra
|
|
39
39
|
#
|
40
40
|
# @abstract
|
41
41
|
def run
|
42
|
-
raise NotImplementedError.new(
|
42
|
+
raise NotImplementedError.new('Nanoc::Extra::Deployer subclasses must implement #run')
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
@@ -24,14 +24,14 @@ module Nanoc::Extra::Deployers
|
|
24
24
|
require 'fog'
|
25
25
|
|
26
26
|
# Get params, unsetting anything we don't want to pass through to fog.
|
27
|
-
src = File.expand_path(
|
28
|
-
bucket =
|
29
|
-
path =
|
27
|
+
src = File.expand_path(source_path)
|
28
|
+
bucket = config.delete(:bucket) || config.delete(:bucket_name)
|
29
|
+
path = config.delete(:path)
|
30
30
|
|
31
|
-
|
31
|
+
config.delete(:kind)
|
32
32
|
|
33
33
|
# Validate params
|
34
|
-
error 'The path requires no trailing slash' if path && path[-1,1] == '/'
|
34
|
+
error 'The path requires no trailing slash' if path && path[-1, 1] == '/'
|
35
35
|
|
36
36
|
# Mock if necessary
|
37
37
|
if self.dry_run?
|
@@ -39,11 +39,11 @@ module Nanoc::Extra::Deployers
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Get connection
|
42
|
-
puts
|
43
|
-
connection = ::Fog::Storage.new(
|
42
|
+
puts 'Connecting'
|
43
|
+
connection = ::Fog::Storage.new(config)
|
44
44
|
|
45
45
|
# Get bucket
|
46
|
-
puts
|
46
|
+
puts 'Getting bucket'
|
47
47
|
begin
|
48
48
|
directory = connection.directories.get(bucket, :prefix => path)
|
49
49
|
rescue ::Excon::Errors::NotFound
|
@@ -64,10 +64,10 @@ module Nanoc::Extra::Deployers
|
|
64
64
|
truncated = set.is_truncated
|
65
65
|
files = files + set
|
66
66
|
end
|
67
|
-
keys_to_destroy = files.all.map {|file| file.key}
|
67
|
+
keys_to_destroy = files.all.map { |file| file.key }
|
68
68
|
|
69
69
|
# Upload all the files in the output folder to the clouds
|
70
|
-
puts
|
70
|
+
puts 'Uploading local files'
|
71
71
|
FileUtils.cd(src) do
|
72
72
|
files = Dir['**/*'].select { |f| File.file?(f) }
|
73
73
|
files.each do |file_path|
|
@@ -81,12 +81,12 @@ module Nanoc::Extra::Deployers
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# delete extraneous remote files
|
84
|
-
puts
|
84
|
+
puts 'Removing remote files'
|
85
85
|
keys_to_destroy.each do |key|
|
86
86
|
directory.files.get(key).destroy
|
87
87
|
end
|
88
88
|
|
89
|
-
puts
|
89
|
+
puts 'Done!'
|
90
90
|
end
|
91
91
|
|
92
92
|
private
|
@@ -34,13 +34,13 @@ module Nanoc::Extra::Deployers
|
|
34
34
|
require 'systemu'
|
35
35
|
|
36
36
|
# Get params
|
37
|
-
src =
|
38
|
-
dst =
|
39
|
-
options =
|
37
|
+
src = source_path + '/'
|
38
|
+
dst = config[:dst]
|
39
|
+
options = config[:options] || DEFAULT_OPTIONS
|
40
40
|
|
41
41
|
# Validate
|
42
42
|
raise 'No dst found in deployment configuration' if dst.nil?
|
43
|
-
raise 'dst requires no trailing slash' if dst[-1,1] == '/'
|
43
|
+
raise 'dst requires no trailing slash' if dst[-1, 1] == '/'
|
44
44
|
|
45
45
|
# Run
|
46
46
|
if dry_run
|
@@ -53,11 +53,11 @@ module Nanoc::Extra::Deployers
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
# Runs the given shell command. It will raise an error if execution fails
|
56
|
+
# Runs the given shell command. It will raise an error if execution fails
|
57
57
|
# (results in a nonzero exit code).
|
58
58
|
def run_shell_cmd(args)
|
59
59
|
status = systemu(args, 'stdout' => $stdout, 'stderr' => $stderr)
|
60
|
-
raise "command exited with a nonzero status code #{
|
60
|
+
raise "command exited with a nonzero status code #{$CHILD_STATUS.exitstatus} (command: #{args.join(' ')})" if !status.success?
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
@@ -59,18 +59,18 @@ module Nanoc::Extra
|
|
59
59
|
#
|
60
60
|
# @raise [UnsupportedFileTypeError] if a file of an unsupported type is
|
61
61
|
# detected (something other than file, directory or link)
|
62
|
-
def all_files_in(dir_name, recursion_limit=10)
|
62
|
+
def all_files_in(dir_name, recursion_limit = 10)
|
63
63
|
Dir[dir_name + '/**/*'].map do |fn|
|
64
64
|
case File.ftype(fn)
|
65
65
|
when 'link'
|
66
66
|
if 0 == recursion_limit
|
67
67
|
raise MaxSymlinkDepthExceededError.new(fn)
|
68
68
|
else
|
69
|
-
absolute_target =
|
69
|
+
absolute_target = resolve_symlink(fn)
|
70
70
|
if File.file?(absolute_target)
|
71
71
|
fn
|
72
72
|
else
|
73
|
-
all_files_in(absolute_target, recursion_limit-1).map do |sfn|
|
73
|
+
all_files_in(absolute_target, recursion_limit - 1).map do |sfn|
|
74
74
|
fn + sfn[absolute_target.size..-1]
|
75
75
|
end
|
76
76
|
end
|
@@ -100,7 +100,7 @@ module Nanoc::Extra
|
|
100
100
|
#
|
101
101
|
# @raise [UnsupportedFileTypeError] if a file of an unsupported type is
|
102
102
|
# detected (something other than file, directory or link)
|
103
|
-
def resolve_symlink(filename, recursion_limit=5)
|
103
|
+
def resolve_symlink(filename, recursion_limit = 5)
|
104
104
|
target = File.readlink(filename)
|
105
105
|
absolute_target = File.expand_path(target, File.dirname(filename))
|
106
106
|
|
@@ -109,7 +109,7 @@ module Nanoc::Extra
|
|
109
109
|
if 0 == recursion_limit
|
110
110
|
raise MaxSymlinkDepthExceededError.new(absolute_target)
|
111
111
|
else
|
112
|
-
|
112
|
+
resolve_symlink(absolute_target, recursion_limit - 1)
|
113
113
|
end
|
114
114
|
when 'file', 'directory'
|
115
115
|
absolute_target
|
@@ -6,9 +6,10 @@ module ::Nanoc::Extra
|
|
6
6
|
|
7
7
|
class LinkCollector
|
8
8
|
|
9
|
-
def initialize(filenames, mode=nil)
|
9
|
+
def initialize(filenames, mode = nil)
|
10
10
|
@filenames = filenames
|
11
|
-
@filter =
|
11
|
+
@filter =
|
12
|
+
case mode
|
12
13
|
when nil
|
13
14
|
lambda { |h| true }
|
14
15
|
when :external
|
@@ -17,7 +18,7 @@ module ::Nanoc::Extra
|
|
17
18
|
lambda { |h| !external_href?(h) }
|
18
19
|
else
|
19
20
|
raise ArgumentError, 'Expected mode argument to be :internal, :external or nil'
|
20
|
-
end
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
def filenames_per_href
|
data/lib/nanoc/extra/pruner.rb
CHANGED
@@ -14,7 +14,7 @@ module Nanoc::Extra
|
|
14
14
|
# @option params [Boolean] :dry_run (false) true if the files to be deleted
|
15
15
|
# should only be printed instead of actually deleted, false if the files
|
16
16
|
# should actually be deleted.
|
17
|
-
def initialize(site, params={})
|
17
|
+
def initialize(site, params = {})
|
18
18
|
@site = site
|
19
19
|
@dry_run = params.fetch(:dry_run) { false }
|
20
20
|
@exclude = params.fetch(:exclude) { [] }
|
@@ -27,7 +27,7 @@ module Nanoc::Extra
|
|
27
27
|
require 'find'
|
28
28
|
|
29
29
|
# Get compiled files
|
30
|
-
compiled_files =
|
30
|
+
compiled_files = site.items.map do |item|
|
31
31
|
item.reps.map do |rep|
|
32
32
|
rep.raw_path
|
33
33
|
end
|
@@ -36,7 +36,7 @@ module Nanoc::Extra
|
|
36
36
|
# Get present files and dirs
|
37
37
|
present_files = []
|
38
38
|
present_dirs = []
|
39
|
-
Find.find(
|
39
|
+
Find.find(site.config[:output_dir] + '/') do |f|
|
40
40
|
present_files << f if File.file?(f)
|
41
41
|
present_dirs << f if File.directory?(f)
|
42
42
|
end
|
@@ -45,14 +45,14 @@ module Nanoc::Extra
|
|
45
45
|
stray_files = (present_files - compiled_files)
|
46
46
|
stray_files.each do |f|
|
47
47
|
next if filename_excluded?(f)
|
48
|
-
|
48
|
+
delete_file(f)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Remove empty directories
|
52
52
|
present_dirs.reverse_each do |dir|
|
53
53
|
next if Dir.foreach(dir) { |n| break true if n !~ /\A\.\.?\z/ }
|
54
54
|
next if filename_excluded?(dir)
|
55
|
-
|
55
|
+
delete_dir(dir)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -5,9 +5,9 @@ module Nanoc::Extra::Validators
|
|
5
5
|
# @deprecated Use the Checking API or the `check` command instead
|
6
6
|
class Links
|
7
7
|
|
8
|
-
def initialize(dir, index_filenames, params={})
|
9
|
-
@include_internal = params.
|
10
|
-
@include_external = params.
|
8
|
+
def initialize(dir, index_filenames, params = {})
|
9
|
+
@include_internal = params.key?(:internal) && params[:internal]
|
10
|
+
@include_external = params.key?(:external) && params[:external]
|
11
11
|
end
|
12
12
|
|
13
13
|
def run
|
data/lib/nanoc/extra/vcs.rb
CHANGED
@@ -13,12 +13,12 @@ module Nanoc::Filters
|
|
13
13
|
# @param [String] content The content to filter
|
14
14
|
#
|
15
15
|
# @return [String] The filtered content
|
16
|
-
def run(content, params={})
|
16
|
+
def run(content, params = {})
|
17
17
|
# Run command
|
18
18
|
stdout = ''
|
19
19
|
stderr = ''
|
20
20
|
status = systemu(
|
21
|
-
|
21
|
+
%w( asciidoc -o - - ),
|
22
22
|
'stdin' => content,
|
23
23
|
'stdout' => stdout,
|
24
24
|
'stderr' => stderr)
|
@@ -26,7 +26,7 @@ module Nanoc::Filters
|
|
26
26
|
# Show errors
|
27
27
|
unless status.success?
|
28
28
|
$stderr.puts stderr
|
29
|
-
raise
|
29
|
+
raise "AsciiDoc filter failed with status #{status}"
|
30
30
|
end
|
31
31
|
|
32
32
|
# Get result
|
@@ -6,12 +6,12 @@ module Nanoc::Filters
|
|
6
6
|
requires 'coderay'
|
7
7
|
|
8
8
|
# @deprecated Use the `:colorize_syntax` filter instead.
|
9
|
-
def run(content, params={})
|
9
|
+
def run(content, params = {})
|
10
10
|
# Warn
|
11
11
|
warn 'The :coderay filter is deprecated; consider using the :colorize_syntax filter instead.'
|
12
12
|
|
13
13
|
# Check params
|
14
|
-
raise ArgumentError,
|
14
|
+
raise ArgumentError, 'CodeRay filter requires a :language argument which is missing' if params[:language].nil?
|
15
15
|
|
16
16
|
# Get result
|
17
17
|
::CodeRay.scan(content, params[:language]).html
|
@@ -82,7 +82,7 @@ module Nanoc::Filters
|
|
82
82
|
# such as the doctype, `html`, `head` and `body` elements will be added.
|
83
83
|
#
|
84
84
|
# @return [String] The filtered content
|
85
|
-
def run(content, params={})
|
85
|
+
def run(content, params = {})
|
86
86
|
# Take colorizers from parameters
|
87
87
|
@colorizers = Hash.new(params[:default_colorizer] || DEFAULT_COLORIZER)
|
88
88
|
(params[:colorizers] || {}).each_pair do |language, colorizer|
|
@@ -97,7 +97,7 @@ module Nanoc::Filters
|
|
97
97
|
when :xml, :xhtml
|
98
98
|
klass = Nokogiri::XML
|
99
99
|
else
|
100
|
-
raise
|
100
|
+
raise "unknown syntax: #{syntax.inspect} (expected :html or :xml)"
|
101
101
|
end
|
102
102
|
|
103
103
|
# Colorize
|
@@ -131,12 +131,12 @@ module Nanoc::Filters
|
|
131
131
|
# Add language-something class
|
132
132
|
unless has_class
|
133
133
|
klass = element['class'] || ''
|
134
|
-
klass << ' ' unless [' ', nil].include?(klass[-1,1])
|
134
|
+
klass << ' ' unless [' ', nil].include?(klass[-1, 1])
|
135
135
|
klass << "language-#{language}"
|
136
136
|
element['class'] = klass
|
137
137
|
end
|
138
138
|
|
139
|
-
|
139
|
+
highlight_postprocess(language, element.parent)
|
140
140
|
end
|
141
141
|
|
142
142
|
method = "to_#{syntax}".to_sym
|
@@ -154,7 +154,7 @@ module Nanoc::Filters
|
|
154
154
|
# @param [Hash] params Parameters to pass on to CodeRay
|
155
155
|
#
|
156
156
|
# @return [String] The colorized output
|
157
|
-
def coderay(code, language, params={})
|
157
|
+
def coderay(code, language, params = {})
|
158
158
|
require 'coderay'
|
159
159
|
|
160
160
|
::CodeRay.scan(code, language).html(params)
|
@@ -168,7 +168,7 @@ module Nanoc::Filters
|
|
168
168
|
#
|
169
169
|
# @return [String] The colorized output, which is identical to the input
|
170
170
|
# in this case
|
171
|
-
def dummy(code, language, params={})
|
171
|
+
def dummy(code, language, params = {})
|
172
172
|
code
|
173
173
|
end
|
174
174
|
|
@@ -184,7 +184,7 @@ module Nanoc::Filters
|
|
184
184
|
# @option params [String, Symbol] :encoding The encoding of the code block
|
185
185
|
#
|
186
186
|
# @return [String] The colorized output
|
187
|
-
def pygmentize(code, language, params={})
|
187
|
+
def pygmentize(code, language, params = {})
|
188
188
|
require 'systemu'
|
189
189
|
check_availability('pygmentize', '-V')
|
190
190
|
|
@@ -193,7 +193,7 @@ module Nanoc::Filters
|
|
193
193
|
|
194
194
|
# Build command
|
195
195
|
cmd = [ 'pygmentize', '-l', language, '-f', 'html' ]
|
196
|
-
cmd << '-O' << params.map { |k,v| "#{k}=#{v}" }.join(',') unless params.empty?
|
196
|
+
cmd << '-O' << params.map { |k, v| "#{k}=#{v}" }.join(',') unless params.empty?
|
197
197
|
|
198
198
|
# Run command
|
199
199
|
stdout = StringIO.new
|
@@ -214,7 +214,7 @@ module Nanoc::Filters
|
|
214
214
|
# @param [String] language The language the code is written in
|
215
215
|
#
|
216
216
|
# @return [String] The colorized output
|
217
|
-
def pygmentsrb(code, language, params={})
|
217
|
+
def pygmentsrb(code, language, params = {})
|
218
218
|
require 'pygments'
|
219
219
|
|
220
220
|
args = params.dup
|
@@ -245,7 +245,7 @@ module Nanoc::Filters
|
|
245
245
|
# @option params [String] :style The style to use
|
246
246
|
#
|
247
247
|
# @return [String] The colorized output
|
248
|
-
def simon_highlight(code, language, params={})
|
248
|
+
def simon_highlight(code, language, params = {})
|
249
249
|
require 'systemu'
|
250
250
|
|
251
251
|
check_availability('highlight', '--version')
|
@@ -277,7 +277,7 @@ module Nanoc::Filters
|
|
277
277
|
def coderay_postprocess(language, element)
|
278
278
|
# Skip if we're a free <code>
|
279
279
|
return if element.parent.nil?
|
280
|
-
|
280
|
+
|
281
281
|
# <div class="code">
|
282
282
|
div_inner = Nokogiri::XML::Node.new('div', element.document)
|
283
283
|
div_inner['class'] = 'code'
|
@@ -301,12 +301,12 @@ module Nanoc::Filters
|
|
301
301
|
s.lines.drop_while { |line| line.strip.empty? }.join.rstrip
|
302
302
|
end
|
303
303
|
|
304
|
-
def highlight(code, language, params={})
|
304
|
+
def highlight(code, language, params = {})
|
305
305
|
colorizer = @colorizers[language.to_sym]
|
306
306
|
if KNOWN_COLORIZERS.include?(colorizer)
|
307
307
|
send(colorizer, code, language, params[colorizer] || {})
|
308
308
|
else
|
309
|
-
raise
|
309
|
+
raise "I don’t know how to highlight code using the “#{colorizer}” colorizer"
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -315,16 +315,16 @@ module Nanoc::Filters
|
|
315
315
|
if KNOWN_COLORIZERS.include?(colorizer)
|
316
316
|
sym = (colorizer.to_s + '_postprocess').to_sym
|
317
317
|
if self.respond_to?(sym)
|
318
|
-
|
318
|
+
send(sym, language, element)
|
319
319
|
end
|
320
320
|
else
|
321
|
-
raise
|
321
|
+
raise "I don’t know how to highlight code using the “#{colorizer}” colorizer"
|
322
322
|
end
|
323
323
|
end
|
324
324
|
|
325
325
|
def check_availability(*cmd)
|
326
326
|
systemu cmd
|
327
|
-
raise "Could not spawn #{cmd.join(' ')}" if
|
327
|
+
raise "Could not spawn #{cmd.join(' ')}" if $CHILD_STATUS.exitstatus != 0
|
328
328
|
end
|
329
329
|
|
330
330
|
end
|