nanoc3 3.1.9 → 3.2.0a1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/NEWS.md +0 -50
- data/README.md +3 -15
- data/bin/nanoc3 +2 -0
- data/lib/nanoc3/base/checksummer.rb +40 -0
- data/lib/nanoc3/base/code_snippet.rb +30 -12
- data/lib/nanoc3/base/compiled_content_cache.rb +86 -0
- data/lib/nanoc3/base/compiler.rb +134 -95
- data/lib/nanoc3/base/compiler_dsl.rb +12 -11
- data/lib/nanoc3/base/core_ext/string.rb +2 -2
- data/lib/nanoc3/base/data_source.rb +17 -16
- data/lib/nanoc3/base/dependency_tracker.rb +102 -121
- data/lib/nanoc3/base/directed_graph.rb +65 -3
- data/lib/nanoc3/base/errors.rb +20 -16
- data/lib/nanoc3/base/item.rb +58 -50
- data/lib/nanoc3/base/item_rep.rb +177 -150
- data/lib/nanoc3/base/layout.rb +51 -18
- data/lib/nanoc3/base/notification_center.rb +8 -8
- data/lib/nanoc3/base/plugin_registry.rb +9 -9
- data/lib/nanoc3/base/rule.rb +18 -9
- data/lib/nanoc3/base/rule_context.rb +5 -5
- data/lib/nanoc3/base/site.rb +135 -47
- data/lib/nanoc3/base.rb +21 -19
- data/lib/nanoc3/cli/base.rb +51 -74
- data/lib/nanoc3/cli/commands/autocompile.rb +3 -0
- data/lib/nanoc3/cli/commands/compile.rb +35 -74
- data/lib/nanoc3/cli/commands/create_site.rb +17 -5
- data/lib/nanoc3/cli/commands/debug.rb +11 -4
- data/lib/nanoc3/cli/commands/view.rb +0 -1
- data/lib/nanoc3/cli/commands/watch.rb +148 -0
- data/lib/nanoc3/cli/commands.rb +1 -0
- data/lib/nanoc3/cli/logger.rb +15 -21
- data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -1
- data/lib/nanoc3/data_sources/filesystem.rb +11 -40
- data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -22
- data/lib/nanoc3/extra/auto_compiler.rb +1 -1
- data/lib/nanoc3/extra/chick.rb +8 -8
- data/lib/nanoc3/extra/deployers/rsync.rb +2 -3
- data/lib/nanoc3/extra/validators/links.rb +32 -51
- data/lib/nanoc3/extra/validators/w3c.rb +2 -2
- data/lib/nanoc3/extra/vcs.rb +1 -1
- data/lib/nanoc3/filters/colorize_syntax.rb +15 -19
- data/lib/nanoc3/filters/erb.rb +1 -5
- data/lib/nanoc3/filters/erubis.rb +1 -5
- data/lib/nanoc3/filters/haml.rb +1 -2
- data/lib/nanoc3/filters/less.rb +2 -51
- data/lib/nanoc3/filters/mustache.rb +21 -0
- data/lib/nanoc3/filters/rdiscount.rb +1 -2
- data/lib/nanoc3/filters/relativize_paths.rb +3 -2
- data/lib/nanoc3/filters/sass.rb +50 -56
- data/lib/nanoc3/filters.rb +2 -0
- data/lib/nanoc3/helpers/blogging.rb +22 -29
- data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
- data/lib/nanoc3/helpers/capturing.rb +1 -1
- data/lib/nanoc3/helpers/filtering.rb +1 -1
- data/lib/nanoc3/helpers/link_to.rb +10 -21
- data/lib/nanoc3/helpers/rendering.rb +5 -24
- data/lib/nanoc3/helpers/tagging.rb +6 -6
- data/lib/nanoc3/helpers/text.rb +2 -2
- data/lib/nanoc3.rb +1 -1
- metadata +35 -93
- data/.gemtest +0 -0
- data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
- data/nanoc3.gemspec +0 -41
- data/tasks/clean.rake +0 -11
- data/tasks/doc.rake +0 -14
- data/tasks/gem.rake +0 -13
- data/tasks/test.rake +0 -38
- data/test/base/core_ext/array_spec.rb +0 -23
- data/test/base/core_ext/hash_spec.rb +0 -41
- data/test/base/core_ext/string_spec.rb +0 -27
- data/test/base/test_code_snippet.rb +0 -33
- data/test/base/test_compiler.rb +0 -410
- data/test/base/test_compiler_dsl.rb +0 -121
- data/test/base/test_context.rb +0 -33
- data/test/base/test_data_source.rb +0 -48
- data/test/base/test_dependency_tracker.rb +0 -510
- data/test/base/test_directed_graph.rb +0 -91
- data/test/base/test_filter.rb +0 -85
- data/test/base/test_item.rb +0 -141
- data/test/base/test_item_rep.rb +0 -953
- data/test/base/test_layout.rb +0 -44
- data/test/base/test_notification_center.rb +0 -36
- data/test/base/test_plugin.rb +0 -32
- data/test/base/test_rule.rb +0 -21
- data/test/base/test_rule_context.rb +0 -63
- data/test/base/test_site.rb +0 -366
- data/test/cli/commands/test_compile.rb +0 -12
- data/test/cli/commands/test_create_item.rb +0 -12
- data/test/cli/commands/test_create_layout.rb +0 -28
- data/test/cli/commands/test_create_site.rb +0 -24
- data/test/cli/commands/test_help.rb +0 -12
- data/test/cli/commands/test_info.rb +0 -12
- data/test/cli/commands/test_update.rb +0 -12
- data/test/cli/test_logger.rb +0 -12
- data/test/data_sources/test_filesystem.rb +0 -420
- data/test/data_sources/test_filesystem_unified.rb +0 -538
- data/test/data_sources/test_filesystem_verbose.rb +0 -359
- data/test/extra/core_ext/test_enumerable.rb +0 -32
- data/test/extra/core_ext/test_time.rb +0 -17
- data/test/extra/deployers/test_rsync.rb +0 -234
- data/test/extra/test_auto_compiler.rb +0 -482
- data/test/extra/test_file_proxy.rb +0 -21
- data/test/extra/test_vcs.rb +0 -24
- data/test/extra/validators/test_links.rb +0 -53
- data/test/extra/validators/test_w3c.rb +0 -49
- data/test/filters/test_bluecloth.rb +0 -20
- data/test/filters/test_coderay.rb +0 -46
- data/test/filters/test_colorize_syntax.rb +0 -84
- data/test/filters/test_erb.rb +0 -72
- data/test/filters/test_erubis.rb +0 -72
- data/test/filters/test_haml.rb +0 -98
- data/test/filters/test_kramdown.rb +0 -20
- data/test/filters/test_less.rb +0 -118
- data/test/filters/test_markaby.rb +0 -26
- data/test/filters/test_maruku.rb +0 -20
- data/test/filters/test_rainpress.rb +0 -31
- data/test/filters/test_rdiscount.rb +0 -33
- data/test/filters/test_rdoc.rb +0 -18
- data/test/filters/test_redcloth.rb +0 -20
- data/test/filters/test_relativize_paths.rb +0 -231
- data/test/filters/test_rubypants.rb +0 -20
- data/test/filters/test_sass.rb +0 -235
- data/test/gem_loader.rb +0 -11
- data/test/helper.rb +0 -99
- data/test/helpers/test_blogging.rb +0 -808
- data/test/helpers/test_breadcrumbs.rb +0 -83
- data/test/helpers/test_capturing.rb +0 -42
- data/test/helpers/test_filtering.rb +0 -108
- data/test/helpers/test_html_escape.rb +0 -18
- data/test/helpers/test_link_to.rb +0 -251
- data/test/helpers/test_rendering.rb +0 -109
- data/test/helpers/test_tagging.rb +0 -89
- data/test/helpers/test_text.rb +0 -26
- data/test/helpers/test_xml_sitemap.rb +0 -69
- data/test/tasks/test_clean.rb +0 -71
data/lib/nanoc3/cli/logger.rb
CHANGED
@@ -8,8 +8,6 @@ module Nanoc3::CLI
|
|
8
8
|
# feedback in the terminal.
|
9
9
|
class Logger
|
10
10
|
|
11
|
-
# Maps actions (`:create`, `:update`, `:identical` and `:skip`) onto their
|
12
|
-
# ANSI color codes.
|
13
11
|
ACTION_COLORS = {
|
14
12
|
:create => "\e[1m" + "\e[32m", # bold + green
|
15
13
|
:update => "\e[1m" + "\e[33m", # bold + yellow
|
@@ -19,38 +17,35 @@ module Nanoc3::CLI
|
|
19
17
|
|
20
18
|
include Singleton
|
21
19
|
|
22
|
-
#
|
23
|
-
#
|
20
|
+
# The log level, which can be :high, :low or :off (which will log all
|
21
|
+
# messages, only high-priority messages, or no messages at all,
|
24
22
|
# respectively).
|
25
|
-
#
|
26
|
-
# @return [Symbol] The log level
|
27
23
|
attr_accessor :level
|
28
24
|
|
29
|
-
#
|
25
|
+
# Whether to use color in log messages or not
|
30
26
|
attr_accessor :color
|
31
27
|
alias_method :color?, :color
|
32
28
|
|
33
29
|
def initialize
|
34
30
|
@level = :high
|
35
|
-
@color =
|
31
|
+
@color = true
|
36
32
|
|
37
33
|
# Try enabling color support on Windows
|
38
34
|
begin
|
39
35
|
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~/mswin|mingw/
|
40
36
|
rescue LoadError
|
41
|
-
|
37
|
+
warn 'The win32console gem is not available. Install it to enable color support on Windows.'
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
45
41
|
# Logs a file-related action.
|
46
42
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# @param [:create, :update, :identical] action The kind of file action
|
43
|
+
# +level+:: The importance of this action. Can be :high or :low.
|
50
44
|
#
|
51
|
-
#
|
45
|
+
# +action+:: The kind of file action. Can be :create, :update or
|
46
|
+
# :identical.
|
52
47
|
#
|
53
|
-
#
|
48
|
+
# +identifier+:: The identifier of the item the action was performed on.
|
54
49
|
def file(level, action, identifier, duration=nil)
|
55
50
|
log(
|
56
51
|
level,
|
@@ -66,19 +61,18 @@ module Nanoc3::CLI
|
|
66
61
|
|
67
62
|
# Logs a message.
|
68
63
|
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
# @param [String] message The message to be logged
|
64
|
+
# +level+:: The importance of this message. Can be :high or :low.
|
72
65
|
#
|
73
|
-
#
|
66
|
+
# +s+:: The message to be logged.
|
74
67
|
#
|
75
|
-
#
|
76
|
-
|
68
|
+
# +io+:: The IO instance to which the message will be written. Defaults to
|
69
|
+
# standard output.
|
70
|
+
def log(level, s, io=$stdout)
|
77
71
|
# Don't log when logging is disabled
|
78
72
|
return if @level == :off
|
79
73
|
|
80
74
|
# Log when level permits it
|
81
|
-
io.puts(
|
75
|
+
io.puts(s) if (@level == :low or @level == level)
|
82
76
|
end
|
83
77
|
|
84
78
|
end
|
@@ -86,8 +86,7 @@ module Nanoc3::DataSources
|
|
86
86
|
meta = (meta_filename && YAML.load_file(meta_filename)) || {}
|
87
87
|
content_or_filename = content_filename
|
88
88
|
else
|
89
|
-
meta, content_or_filename = parse(
|
90
|
-
content_filename, meta_filename, kind)
|
89
|
+
meta, content_or_filename = parse(content_filename, meta_filename, kind)
|
91
90
|
end
|
92
91
|
|
93
92
|
# Get attributes
|
@@ -124,10 +123,15 @@ module Nanoc3::DataSources
|
|
124
123
|
raise RuntimeError, "meta_mtime and content_mtime are both nil"
|
125
124
|
end
|
126
125
|
|
126
|
+
# Get checksum
|
127
|
+
meta_checksum = meta_filename ? Nanoc3::Checksummer.checksum_for(meta_filename) : nil
|
128
|
+
content_checksum = content_filename ? Nanoc3::Checksummer.checksum_for(content_filename) : nil
|
129
|
+
checksum = [ meta_checksum, content_checksum ].compact.join('-')
|
130
|
+
|
127
131
|
# Create layout object
|
128
132
|
klass.new(
|
129
133
|
content_or_filename, attributes, identifier,
|
130
|
-
:binary => is_binary, :mtime => mtime
|
134
|
+
:binary => is_binary, :mtime => mtime, :checksum => checksum
|
131
135
|
)
|
132
136
|
end
|
133
137
|
end
|
@@ -229,17 +233,17 @@ module Nanoc3::DataSources
|
|
229
233
|
def parse(content_filename, meta_filename, kind)
|
230
234
|
# Read content and metadata from separate files
|
231
235
|
if meta_filename
|
232
|
-
content = content_filename ? read(content_filename) : ''
|
233
|
-
meta = YAML.
|
236
|
+
content = content_filename ? File.read(content_filename) : ''
|
237
|
+
meta = YAML.load_file(meta_filename) || {}
|
234
238
|
|
235
239
|
return [ meta, content ]
|
236
240
|
end
|
237
241
|
|
238
242
|
# Read data
|
239
|
-
data = read(content_filename)
|
243
|
+
data = File.read(content_filename)
|
240
244
|
|
241
245
|
# Check presence of metadata section
|
242
|
-
if data
|
246
|
+
if data[0, 3] != '-'*3 && data[0, 5] != '-'*5
|
243
247
|
return [ {}, data ]
|
244
248
|
end
|
245
249
|
|
@@ -259,39 +263,6 @@ module Nanoc3::DataSources
|
|
259
263
|
[ meta, content ]
|
260
264
|
end
|
261
265
|
|
262
|
-
# Reads the content of the file with the given name and returns a string
|
263
|
-
# in UTF-8 encoding. The original encoding of the string is derived from
|
264
|
-
# the default external encoding, but this can be overridden by the
|
265
|
-
# “encoding” configuration attribute in the data source configuration.
|
266
|
-
def read(filename)
|
267
|
-
# Read
|
268
|
-
begin
|
269
|
-
data = File.read(filename)
|
270
|
-
rescue => e
|
271
|
-
raise RuntimeError.new("Could not read #{filename}: #{e.inspect}")
|
272
|
-
end
|
273
|
-
|
274
|
-
# Fix
|
275
|
-
if data.respond_to?(:encode!)
|
276
|
-
if @config && @config[:encoding]
|
277
|
-
original_encoding = Encoding.find(@config[:encoding])
|
278
|
-
data.force_encoding(@config[:encoding])
|
279
|
-
else
|
280
|
-
original_encoding = data.encoding
|
281
|
-
end
|
282
|
-
|
283
|
-
data.encode!('UTF-8') rescue raise_encoding_error(filename, original_encoding)
|
284
|
-
raise_encoding_error(filename, original_encoding) if !data.valid_encoding?
|
285
|
-
end
|
286
|
-
|
287
|
-
data
|
288
|
-
end
|
289
|
-
|
290
|
-
# Raises an invalid encoding error for the given filename and encoding.
|
291
|
-
def raise_encoding_error(filename, encoding)
|
292
|
-
raise RuntimeError.new("Could not read #{filename} because the file is not valid #{encoding}.")
|
293
|
-
end
|
294
|
-
|
295
266
|
end
|
296
267
|
|
297
268
|
end
|
@@ -14,10 +14,10 @@ module Nanoc3::DataSources
|
|
14
14
|
# itself can start with a metadata section: it can be stored at the top of
|
15
15
|
# the file, between `---` (three dashes) separators. For example:
|
16
16
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
17
|
+
# ---
|
18
|
+
# title: "Moo!"
|
19
|
+
# ---
|
20
|
+
# h1. Hello!
|
21
21
|
#
|
22
22
|
# The metadata section can be omitted. If the file does not start with
|
23
23
|
# three or five dashes, the entire file will be considered as content.
|
@@ -26,7 +26,7 @@ module Nanoc3::DataSources
|
|
26
26
|
# an `index.*` filename, such as `index.txt`, will have the filesystem path
|
27
27
|
# with the `index.*` part stripped as a identifier. For example:
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# foo/bar/index.html → /foo/bar/
|
30
30
|
#
|
31
31
|
# In other cases, the identifier is calculated by stripping the extension.
|
32
32
|
# If the `allow_periods_in_identifiers` attribute in the configuration is
|
@@ -34,24 +34,24 @@ module Nanoc3::DataSources
|
|
34
34
|
# extensions; if it is false or unset, all extensions will be stripped.
|
35
35
|
# For example:
|
36
36
|
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
37
|
+
# (`allow_periods_in_identifiers` set to true)
|
38
|
+
# foo.entry.html → /foo.entry/
|
39
|
+
#
|
40
|
+
# (`allow_periods_in_identifiers` set to false)
|
41
|
+
# foo.html.erb → /foo/
|
42
42
|
#
|
43
|
-
# Note that
|
44
|
-
#
|
43
|
+
# Note that it is possible for two different, separate files to have the
|
44
|
+
# same identifier. It is recommended to avoid such situations.
|
45
45
|
#
|
46
46
|
# Some more examples:
|
47
47
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
48
|
+
# content/index.html → /
|
49
|
+
# content/foo.html → /foo/
|
50
|
+
# content/foo/index.html → /foo/
|
51
|
+
# content/foo/bar.html → /foo/bar/
|
52
|
+
# content/foo/bar.baz.html → /foo/bar/ OR /foo/bar.baz/
|
53
|
+
# content/foo/bar/index.html → /foo/bar/
|
54
|
+
# content/foo.bar/index.html → /foo.bar/
|
55
55
|
#
|
56
56
|
# The file extension does not determine the filters to run on items; the
|
57
57
|
# Rules file is used to specify processing instructors for each item.
|
@@ -103,10 +103,10 @@ module Nanoc3::DataSources
|
|
103
103
|
# Returns the identifier derived from the given filename, first stripping
|
104
104
|
# the given directory name off the filename.
|
105
105
|
def identifier_for_filename(filename)
|
106
|
-
if filename =~ /
|
107
|
-
regex = ((@config && @config[:allow_periods_in_identifiers]) ?
|
106
|
+
if filename =~ /index\.[^\/]+$/
|
107
|
+
regex = ((@config && @config[:allow_periods_in_identifiers]) ? /index\.[^\/\.]+$/ : /index\.[^\/]+$/)
|
108
108
|
else
|
109
|
-
regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/
|
109
|
+
regex = ((@config && @config[:allow_periods_in_identifiers]) ? /\.[^\/\.]+$/ : /\.[^\/]+$/)
|
110
110
|
end
|
111
111
|
filename.sub(regex, '').cleaned_identifier
|
112
112
|
end
|
@@ -29,7 +29,7 @@ module Nanoc3::Extra
|
|
29
29
|
# @param [Hash] env The environment, as defined by the Rack specification
|
30
30
|
#
|
31
31
|
# @return [Array] An array containing the status, the headers, and the
|
32
|
-
#
|
32
|
+
# body, as defined by the Rack specification
|
33
33
|
def call(env)
|
34
34
|
@mutex.synchronize do
|
35
35
|
# Start with a new site
|
data/lib/nanoc3/extra/chick.rb
CHANGED
@@ -5,13 +5,13 @@ require 'rack/cache'
|
|
5
5
|
module Nanoc3::Extra
|
6
6
|
|
7
7
|
# @deprecated Use a HTTP library such as
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
|
9
|
+
# [Curb](http://curb.rubyforge.org/) instead.
|
10
10
|
module CHiCk
|
11
11
|
|
12
12
|
# @deprecated Use a HTTP library such as
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
|
14
|
+
# [Curb](http://curb.rubyforge.org/) instead.
|
15
15
|
class Client
|
16
16
|
|
17
17
|
DEFAULT_OPTIONS = {
|
@@ -59,8 +59,8 @@ module Nanoc3::Extra
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# @deprecated Use a HTTP library such as
|
62
|
-
#
|
63
|
-
#
|
62
|
+
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
|
63
|
+
# [Curb](http://curb.rubyforge.org/) instead.
|
64
64
|
class CacheController
|
65
65
|
|
66
66
|
def initialize(app, options={})
|
@@ -79,8 +79,8 @@ module Nanoc3::Extra
|
|
79
79
|
end
|
80
80
|
|
81
81
|
# @deprecated Use a HTTP library such as
|
82
|
-
#
|
83
|
-
#
|
82
|
+
# [Net::HTTP](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/) or
|
83
|
+
# [Curb](http://curb.rubyforge.org/) instead.
|
84
84
|
class RackClient
|
85
85
|
|
86
86
|
METHOD_TO_CLASS_MAPPING = {
|
@@ -63,10 +63,10 @@ module Nanoc3::Extra::Deployers
|
|
63
63
|
# Runs the task. Possible params:
|
64
64
|
#
|
65
65
|
# @option params [Boolean] :dry_run (false) True if the action itself
|
66
|
-
#
|
66
|
+
# should not be executed, but still printed; false otherwise.
|
67
67
|
#
|
68
68
|
# @option params [String] :config_name (:default) The name of the
|
69
|
-
#
|
69
|
+
# deployment configuration to use.
|
70
70
|
#
|
71
71
|
# @return [void]
|
72
72
|
def run(params={})
|
@@ -106,7 +106,6 @@ module Nanoc3::Extra::Deployers
|
|
106
106
|
# Runs the given shell command. This is a simple wrapper around Kernel#system.
|
107
107
|
def run_shell_cmd(args)
|
108
108
|
system(*args)
|
109
|
-
raise "command exited with a nonzero status code #{$?.exitstatus} (command: #{args.join(' ')})" if !$?.success?
|
110
109
|
end
|
111
110
|
|
112
111
|
end
|
@@ -7,17 +7,17 @@ module Nanoc3::Extra::Validators
|
|
7
7
|
class Links
|
8
8
|
|
9
9
|
# @param [String] dir The directory that will be searched for HTML files
|
10
|
-
#
|
10
|
+
# to validate
|
11
11
|
#
|
12
12
|
# @param [Array<String>] index_filenames An array of index filenames that
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# will be appended to URLs by web servers if a directory is requested
|
14
|
+
# instead of a file
|
15
15
|
#
|
16
16
|
# @option params [Boolean] :internal (false) True if internal links should
|
17
|
-
#
|
17
|
+
# be checked; false if they should not
|
18
18
|
#
|
19
19
|
# @option params [Boolean] :external (false) True if external links should
|
20
|
-
#
|
20
|
+
# be checked; false if they should not
|
21
21
|
def initialize(dir, index_filenames, params={})
|
22
22
|
@dir = dir
|
23
23
|
@index_filenames = index_filenames
|
@@ -48,36 +48,6 @@ module Nanoc3::Extra::Validators
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
# Enumerates all key-value pairs of a given hash in a thread-safe way.
|
52
|
-
#
|
53
|
-
# This class is a helper class, which means that it is not used directly
|
54
|
-
# by nanoc. Future versions of nanoc may no longer contain this class. Do
|
55
|
-
# not depend on this class to be available.
|
56
|
-
class ThreadsafeHashEnumerator
|
57
|
-
|
58
|
-
# Creates a new enumerator for the given hash.
|
59
|
-
#
|
60
|
-
# @param [Hash] hash The hash for which the enumerator should return
|
61
|
-
# key-value pairs
|
62
|
-
def initialize(hash)
|
63
|
-
@hash = hash
|
64
|
-
@unprocessed_keys = @hash.keys.dup
|
65
|
-
@mutex = Mutex.new
|
66
|
-
end
|
67
|
-
|
68
|
-
# Returns the next key-value pair in the hash.
|
69
|
-
#
|
70
|
-
# @return [Array] An array containing the key and the corresponding
|
71
|
-
# value of teh next key-value pair
|
72
|
-
def next_pair
|
73
|
-
@mutex.synchronize do
|
74
|
-
key = @unprocessed_keys.shift
|
75
|
-
return (key ? [ key, @hash[key] ] : nil)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
51
|
def all_broken_hrefs
|
82
52
|
broken_hrefs = {}
|
83
53
|
|
@@ -157,23 +127,17 @@ module Nanoc3::Extra::Validators
|
|
157
127
|
require 'uri'
|
158
128
|
|
159
129
|
# Parse
|
160
|
-
uri =
|
161
|
-
begin
|
162
|
-
uri = URI.parse(href)
|
163
|
-
rescue URI::InvalidURIError
|
164
|
-
@delegate && @delegate.send(:external_href_validated, href, false)
|
165
|
-
return false
|
166
|
-
end
|
130
|
+
uri = URI.parse(href)
|
167
131
|
|
168
132
|
# Skip non-HTTP URLs
|
169
|
-
return true if uri.scheme
|
133
|
+
return true if uri.scheme != 'http'
|
170
134
|
|
171
135
|
# Get status
|
172
136
|
status = fetch_http_status_for(uri)
|
173
|
-
is_valid =
|
137
|
+
is_valid = (status && status >= 200 && status <= 299)
|
174
138
|
|
175
139
|
# Notify
|
176
|
-
@delegate
|
140
|
+
@delegate.send(:external_href_validated, href, is_valid)
|
177
141
|
|
178
142
|
# Done
|
179
143
|
is_valid
|
@@ -189,10 +153,30 @@ module Nanoc3::Extra::Validators
|
|
189
153
|
end
|
190
154
|
end
|
191
155
|
|
156
|
+
# This class is a helper class, which means that it is not used directly
|
157
|
+
# by nanoc. Future versions of nanoc may no longer contain this class. Do
|
158
|
+
# not depend on this class to be available.
|
159
|
+
class EachPairEnumerator
|
160
|
+
|
161
|
+
def initialize(hash)
|
162
|
+
@hash = hash
|
163
|
+
@unprocessed_keys = @hash.keys.dup
|
164
|
+
@mutex = Mutex.new
|
165
|
+
end
|
166
|
+
|
167
|
+
def next_pair
|
168
|
+
@mutex.synchronize do
|
169
|
+
key = @unprocessed_keys.shift
|
170
|
+
return (key ? [ key, @hash[key] ] : nil)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
192
176
|
def validate_external_hrefs(hrefs, broken_hrefs)
|
193
177
|
@mutex = Mutex.new
|
194
178
|
|
195
|
-
enum =
|
179
|
+
enum = EachPairEnumerator.new(hrefs)
|
196
180
|
|
197
181
|
threads = []
|
198
182
|
10.times do
|
@@ -218,10 +202,7 @@ module Nanoc3::Extra::Validators
|
|
218
202
|
def fetch_http_status_for(url, params={})
|
219
203
|
5.times do |i|
|
220
204
|
begin
|
221
|
-
res =
|
222
|
-
Timeout::timeout(10) do
|
223
|
-
res = request_url_once(url)
|
224
|
-
end
|
205
|
+
res = request_url_once(url)
|
225
206
|
|
226
207
|
if res.code =~ /^3..$/
|
227
208
|
url = URI.parse(res['location'])
|
@@ -230,7 +211,7 @@ module Nanoc3::Extra::Validators
|
|
230
211
|
return res.code.to_i
|
231
212
|
end
|
232
213
|
rescue
|
233
|
-
|
214
|
+
nil
|
234
215
|
end
|
235
216
|
end
|
236
217
|
end
|
@@ -6,10 +6,10 @@ module Nanoc3::Extra::Validators
|
|
6
6
|
class W3C
|
7
7
|
|
8
8
|
# @param [String] dir The directory that will be searched for HTML and/or
|
9
|
-
#
|
9
|
+
# CSS files to validate
|
10
10
|
#
|
11
11
|
# @param [Array<Symbol>] types A list of types to check. Allowed types are
|
12
|
-
#
|
12
|
+
# `:html` and `:css`.
|
13
13
|
def initialize(dir, types)
|
14
14
|
@dir = dir
|
15
15
|
@types = types
|
data/lib/nanoc3/extra/vcs.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'open3'
|
4
|
-
|
5
3
|
module Nanoc3::Filters
|
6
4
|
class ColorizeSyntax < Nanoc3::Filter
|
7
5
|
|
@@ -38,9 +36,6 @@ module Nanoc3::Filters
|
|
38
36
|
#
|
39
37
|
# @param [String] content The content to filter
|
40
38
|
#
|
41
|
-
# @option params [Symbol] :syntax (:html) The syntax to use, which can be
|
42
|
-
# `:html`, `:xml` or `:xhtml`, the latter two being the same.
|
43
|
-
#
|
44
39
|
# @option params [Hash] :colorizers (DEFAULT_COLORIZER) A hash containing
|
45
40
|
# a mapping of programming languages (symbols, not strings) onto
|
46
41
|
# colorizers (symbols).
|
@@ -55,8 +50,19 @@ module Nanoc3::Filters
|
|
55
50
|
@colorizers[language] = colorizer
|
56
51
|
end
|
57
52
|
|
53
|
+
# Determine syntax (HTML or XML)
|
54
|
+
syntax = params[:syntax] || :html
|
55
|
+
case syntax
|
56
|
+
when :html
|
57
|
+
klass = Nokogiri::HTML
|
58
|
+
when :xml
|
59
|
+
klass = Nokogiri::XML
|
60
|
+
else
|
61
|
+
raise RuntimeError, "unknown syntax: #{syntax.inspect} (expected :html or :xml)"
|
62
|
+
end
|
63
|
+
|
58
64
|
# Colorize
|
59
|
-
doc =
|
65
|
+
doc = klass.fragment(content)
|
60
66
|
doc.css('pre > code[class*="language-"]').each do |element|
|
61
67
|
# Get language
|
62
68
|
match = element['class'].match(/(^| )language-([^ ]+)/)
|
@@ -68,7 +74,7 @@ module Nanoc3::Filters
|
|
68
74
|
element.inner_html = highlighted_code
|
69
75
|
end
|
70
76
|
|
71
|
-
doc.
|
77
|
+
doc.to_s
|
72
78
|
end
|
73
79
|
|
74
80
|
private
|
@@ -76,7 +82,7 @@ module Nanoc3::Filters
|
|
76
82
|
KNOWN_COLORIZERS = [ :coderay, :dummy, :pygmentize ]
|
77
83
|
|
78
84
|
def highlight(code, language, params={})
|
79
|
-
colorizer = @colorizers[language
|
85
|
+
colorizer = @colorizers[language]
|
80
86
|
if KNOWN_COLORIZERS.include?(colorizer)
|
81
87
|
send(colorizer, code, language, params[colorizer] || {})
|
82
88
|
else
|
@@ -95,22 +101,12 @@ module Nanoc3::Filters
|
|
95
101
|
end
|
96
102
|
|
97
103
|
def pygmentize(code, language, params={})
|
98
|
-
check_availability('pygmentize --V')
|
99
|
-
|
100
104
|
IO.popen("pygmentize -l #{language} -f html", "r+") do |io|
|
101
105
|
io.write(code)
|
102
106
|
io.close_write
|
103
|
-
|
104
|
-
|
105
|
-
doc = Nokogiri::HTML.fragment(highlighted_code)
|
106
|
-
return doc.xpath('./div[@class="highlight"]/pre').inner_html
|
107
|
+
return io.read
|
107
108
|
end
|
108
109
|
end
|
109
110
|
|
110
|
-
def check_availability(cmd)
|
111
|
-
# Will raise on error
|
112
|
-
Open3.popen3('highlight --version') { |stdin, stdout, stderr| }
|
113
|
-
end
|
114
|
-
|
115
111
|
end
|
116
112
|
end
|
data/lib/nanoc3/filters/erb.rb
CHANGED
@@ -15,14 +15,10 @@ module Nanoc3::Filters
|
|
15
15
|
# Create context
|
16
16
|
context = ::Nanoc3::Context.new(assigns)
|
17
17
|
|
18
|
-
# Get binding
|
19
|
-
proc = assigns[:content] ? lambda { assigns[:content] } : nil
|
20
|
-
assigns_binding = context.get_binding(&proc)
|
21
|
-
|
22
18
|
# Get result
|
23
19
|
erb = ::ERB.new(content)
|
24
20
|
erb.filename = filename
|
25
|
-
erb.result(
|
21
|
+
erb.result(context.get_binding { assigns[:content] })
|
26
22
|
end
|
27
23
|
|
28
24
|
end
|
@@ -15,12 +15,8 @@ module Nanoc3::Filters
|
|
15
15
|
# Create context
|
16
16
|
context = ::Nanoc3::Context.new(assigns)
|
17
17
|
|
18
|
-
# Get binding
|
19
|
-
proc = assigns[:content] ? lambda { assigns[:content] } : nil
|
20
|
-
assigns_binding = context.get_binding(&proc)
|
21
|
-
|
22
18
|
# Get result
|
23
|
-
::Erubis::Eruby.new(content, :filename => filename).result(
|
19
|
+
::Erubis::Eruby.new(content, :filename => filename).result(context.get_binding { assigns[:content] })
|
24
20
|
end
|
25
21
|
|
26
22
|
end
|
data/lib/nanoc3/filters/haml.rb
CHANGED
@@ -19,8 +19,7 @@ module Nanoc3::Filters
|
|
19
19
|
context = ::Nanoc3::Context.new(assigns)
|
20
20
|
|
21
21
|
# Get result
|
22
|
-
|
23
|
-
::Haml::Engine.new(content, options).render(context, assigns, &proc)
|
22
|
+
::Haml::Engine.new(content, options).render(context, assigns) { assigns[:content] }
|
24
23
|
end
|
25
24
|
|
26
25
|
end
|