nanoc 2.1.6 → 2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +3 -221
- data/Rakefile +9 -51
- data/bin/nanoc +5 -2
- data/lib/nanoc.rb +9 -31
- data/lib/nanoc/base.rb +26 -0
- data/lib/nanoc/base/core_ext.rb +2 -0
- data/lib/nanoc/base/filter.rb +11 -41
- data/lib/nanoc/base/layout.rb +1 -5
- data/lib/nanoc/base/page_rep.rb +1 -1
- data/lib/nanoc/base/proxies.rb +5 -0
- data/lib/nanoc/base/site.rb +4 -2
- data/lib/nanoc/binary_filters.rb +1 -0
- data/lib/nanoc/cli.rb +9 -1
- data/lib/nanoc/cli/base.rb +41 -129
- data/lib/nanoc/cli/commands.rb +10 -0
- data/lib/nanoc/cli/commands/autocompile.rb +1 -1
- data/lib/nanoc/cli/commands/compile.rb +51 -13
- data/lib/nanoc/cli/commands/create_layout.rb +1 -1
- data/lib/nanoc/cli/commands/create_page.rb +1 -1
- data/lib/nanoc/cli/commands/create_site.rb +1 -1
- data/lib/nanoc/cli/commands/create_template.rb +1 -1
- data/lib/nanoc/cli/commands/help.rb +1 -1
- data/lib/nanoc/cli/commands/info.rb +1 -1
- data/lib/nanoc/cli/commands/switch.rb +1 -1
- data/lib/nanoc/cli/commands/update.rb +1 -1
- data/lib/nanoc/cli/logger.rb +13 -7
- data/lib/nanoc/data_sources.rb +2 -0
- data/lib/nanoc/data_sources/filesystem.rb +3 -38
- data/lib/nanoc/extra.rb +6 -0
- data/lib/nanoc/extra/core_ext.rb +2 -0
- data/lib/nanoc/extra/vcses.rb +5 -0
- data/lib/nanoc/filters.rb +14 -0
- data/lib/nanoc/filters/erb.rb +3 -2
- data/lib/nanoc/filters/haml.rb +1 -1
- data/lib/nanoc/filters/markaby.rb +0 -1
- data/lib/nanoc/filters/rainpress.rb +13 -0
- data/lib/nanoc/filters/relativize_paths.rb +25 -0
- data/lib/nanoc/filters/sass.rb +1 -0
- data/lib/nanoc/helpers.rb +9 -0
- data/lib/nanoc/helpers/blogging.rb +55 -12
- data/lib/nanoc/helpers/filtering.rb +54 -0
- data/lib/nanoc/helpers/link_to.rb +40 -0
- data/lib/nanoc/helpers/text.rb +38 -0
- data/lib/nanoc/helpers/xml_sitemap.rb +3 -2
- data/lib/nanoc/routers.rb +3 -0
- data/vendor/cri/ChangeLog +0 -0
- data/vendor/cri/LICENSE +19 -0
- data/vendor/cri/NEWS +0 -0
- data/vendor/cri/README +4 -0
- data/vendor/cri/Rakefile +25 -0
- data/vendor/cri/lib/cri.rb +12 -0
- data/vendor/cri/lib/cri/base.rb +153 -0
- data/{lib/nanoc/cli → vendor/cri/lib/cri}/command.rb +5 -6
- data/vendor/cri/lib/cri/core_ext.rb +8 -0
- data/vendor/cri/lib/cri/core_ext/string.rb +41 -0
- data/{lib/nanoc/cli → vendor/cri/lib/cri}/option_parser.rb +35 -17
- data/vendor/cri/test/test_base.rb +6 -0
- data/vendor/cri/test/test_command.rb +6 -0
- data/vendor/cri/test/test_core_ext.rb +21 -0
- data/vendor/cri/test/test_option_parser.rb +279 -0
- data/vendor/mime-types/lib/mime/types.rb +1558 -0
- metadata +45 -9
- data/lib/nanoc/base/enhancements.rb +0 -14
- data/lib/nanoc/cli/cli.rb +0 -16
- data/lib/nanoc/cli/ext.rb +0 -37
data/lib/nanoc/base/layout.rb
CHANGED
@@ -55,11 +55,7 @@ module Nanoc
|
|
55
55
|
|
56
56
|
# Returns the filter class needed for this layout.
|
57
57
|
def filter_class
|
58
|
-
|
59
|
-
Nanoc::Filter.named(attribute_named(:filter))
|
60
|
-
else
|
61
|
-
Nanoc::Filter.with_extension(attribute_named(:extension))
|
62
|
-
end
|
58
|
+
Nanoc::Filter.named(attribute_named(:filter))
|
63
59
|
end
|
64
60
|
|
65
61
|
# Saves the layout in the database, creating it if it doesn't exist yet or
|
data/lib/nanoc/base/page_rep.rb
CHANGED
@@ -290,7 +290,7 @@ module Nanoc
|
|
290
290
|
# Create filter
|
291
291
|
klass = layout.filter_class
|
292
292
|
raise Nanoc::Errors::CannotDetermineFilterError.new(layout.path) if klass.nil?
|
293
|
-
filter = klass.new(self)
|
293
|
+
filter = klass.new(self, :layout => layout.to_proxy)
|
294
294
|
|
295
295
|
# Layout
|
296
296
|
Nanoc::NotificationCenter.post(:filtering_started, self, klass.identifier)
|
data/lib/nanoc/base/site.rb
CHANGED
@@ -262,8 +262,10 @@ module Nanoc
|
|
262
262
|
# Raises a warning about an outdated data source method.
|
263
263
|
def warn_data_source(class_name, method_name, is_array)
|
264
264
|
warn(
|
265
|
-
"In nanoc 2.1, DataSource##{method_name}
|
266
|
-
'
|
265
|
+
"DEPRECATION WARNING: In nanoc 2.1, DataSource##{method_name} " +
|
266
|
+
"should return #{is_array ? 'an array of' : 'a' } " +
|
267
|
+
"Nanoc::#{class_name} object#{is_array ? 's' : ''}. Future " +
|
268
|
+
"versions will not support these outdated data sources."
|
267
269
|
)
|
268
270
|
end
|
269
271
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'nanoc/binary_filters/image_science_thumbnail'
|
data/lib/nanoc/cli.rb
CHANGED
data/lib/nanoc/cli/base.rb
CHANGED
@@ -2,118 +2,28 @@ module Nanoc::CLI
|
|
2
2
|
|
3
3
|
# Nanoc::CLI::Base is the central class representing a commandline nanoc
|
4
4
|
# tool. It has a list of commands, and is linked to a specific nanoc site.
|
5
|
-
class Base
|
5
|
+
class Base < Cri::Base
|
6
6
|
|
7
7
|
attr_reader :commands, :site
|
8
8
|
|
9
9
|
# Creates a new instance of the commandline nanoc tool.
|
10
10
|
def initialize
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
parsed_arguments = Nanoc::CLI::OptionParser.parse(args[0..1], global_option_definitions)
|
28
|
-
rescue Nanoc::CLI::OptionParser::IllegalOptionError => e
|
29
|
-
$stderr.puts "illegal option -- #{e}"
|
30
|
-
exit 1
|
31
|
-
end
|
32
|
-
|
33
|
-
# Handle version option
|
34
|
-
if parsed_arguments[:options].has_key?(:version)
|
35
|
-
puts "nanoc #{Nanoc::VERSION} (c) 2007-2009 Denis Defreyne."
|
36
|
-
puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}"
|
37
|
-
exit 1
|
38
|
-
# Handle help option
|
39
|
-
elsif parsed_arguments[:options].has_key?(:help)
|
40
|
-
show_help
|
41
|
-
exit 1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Find command
|
46
|
-
command = command_named(args[0])
|
47
|
-
|
48
|
-
# Get extended option definitions (with help)
|
49
|
-
extended_option_definitions = command.option_definitions + [
|
50
|
-
# --help
|
51
|
-
{
|
52
|
-
:long => 'help', :short => 'h', :argument => :forbidden,
|
53
|
-
:desc => 'show this help message and quit'
|
54
|
-
},
|
55
|
-
# --verbose
|
56
|
-
{
|
57
|
-
:long => 'verbose', :short => 'V', :argument => :forbidden,
|
58
|
-
:desc => 'enable more detailed output'
|
59
|
-
}
|
60
|
-
]
|
61
|
-
|
62
|
-
# Parse arguments
|
63
|
-
begin
|
64
|
-
parsed_arguments = Nanoc::CLI::OptionParser.parse(args[1..-1], extended_option_definitions)
|
65
|
-
rescue Nanoc::CLI::OptionParser::IllegalOptionError => e
|
66
|
-
$stderr.puts "illegal option -- #{e}"
|
67
|
-
exit 1
|
68
|
-
rescue Nanoc::CLI::OptionParser::OptionRequiresAnArgumentError => e
|
69
|
-
$stderr.puts "option requires an argument -- #{e}"
|
70
|
-
exit 1
|
71
|
-
end
|
72
|
-
|
73
|
-
# Check help option
|
74
|
-
if parsed_arguments[:options].has_key?(:help)
|
75
|
-
show_help(command)
|
76
|
-
exit 1
|
77
|
-
end
|
78
|
-
|
79
|
-
# Check verbose option
|
80
|
-
if parsed_arguments[:options].has_key?(:verbose)
|
81
|
-
Nanoc::CLI::Logger.instance.level = :low
|
82
|
-
end
|
83
|
-
|
84
|
-
# Find and run command
|
85
|
-
command.run(parsed_arguments[:options], parsed_arguments[:arguments])
|
86
|
-
end
|
87
|
-
|
88
|
-
# Returns the command with the given name.
|
89
|
-
def command_named(name)
|
90
|
-
# Find by exact name or alias
|
91
|
-
command = @commands.find { |c| c.name == name or c.aliases.include?(name) }
|
92
|
-
return command unless command.nil?
|
93
|
-
|
94
|
-
# Find by approximation
|
95
|
-
commands = @commands.select { |c| c.name[0, name.length] == name }
|
96
|
-
if commands.length > 1
|
97
|
-
$stderr.puts "nanoc: '#{name}' is ambiguous:"
|
98
|
-
$stderr.puts " #{commands.map { |c| c.name }.join(' ') }"
|
99
|
-
exit 1
|
100
|
-
elsif commands.length == 0
|
101
|
-
$stderr.puts "nanoc: unknown command '#{name}'\n"
|
102
|
-
show_help
|
103
|
-
exit 1
|
104
|
-
else
|
105
|
-
return commands[0]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# Shows the help text for the given command, or shows the general help
|
110
|
-
# text if no command is given.
|
111
|
-
def show_help(command=nil)
|
112
|
-
if command.nil?
|
113
|
-
@help_command.run([], [])
|
114
|
-
else
|
115
|
-
@help_command.run([], [ command.name ])
|
116
|
-
end
|
11
|
+
super('nanoc')
|
12
|
+
|
13
|
+
# Add help command
|
14
|
+
self.help_command = Nanoc::CLI::HelpCommand.new
|
15
|
+
add_command(self.help_command)
|
16
|
+
|
17
|
+
# Add other commands
|
18
|
+
add_command(Nanoc::CLI::AutocompileCommand.new)
|
19
|
+
add_command(Nanoc::CLI::CompileCommand.new)
|
20
|
+
add_command(Nanoc::CLI::CreateLayoutCommand.new)
|
21
|
+
add_command(Nanoc::CLI::CreatePageCommand.new)
|
22
|
+
add_command(Nanoc::CLI::CreateSiteCommand.new)
|
23
|
+
add_command(Nanoc::CLI::CreateTemplateCommand.new)
|
24
|
+
add_command(Nanoc::CLI::InfoCommand.new)
|
25
|
+
add_command(Nanoc::CLI::SwitchCommand.new)
|
26
|
+
add_command(Nanoc::CLI::UpdateCommand.new)
|
117
27
|
end
|
118
28
|
|
119
29
|
# Helper function which can be called when a command is executed that
|
@@ -183,6 +93,14 @@ module Nanoc::CLI
|
|
183
93
|
:long => 'help', :short => 'h', :argument => :forbidden,
|
184
94
|
:desc => 'show this help message and quit'
|
185
95
|
},
|
96
|
+
{
|
97
|
+
:long => 'no-color', :short => 'C', :argument => :forbidden,
|
98
|
+
:desc => 'disable color'
|
99
|
+
},
|
100
|
+
{
|
101
|
+
:long => 'verbose', :short => 'V', :argument => :forbidden,
|
102
|
+
:desc => 'make nanoc output more detailed'
|
103
|
+
},
|
186
104
|
{
|
187
105
|
:long => 'version', :short => 'v', :argument => :forbidden,
|
188
106
|
:desc => 'show version information and quit'
|
@@ -190,29 +108,23 @@ module Nanoc::CLI
|
|
190
108
|
]
|
191
109
|
end
|
192
110
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
else
|
210
|
-
@commands << klass.new
|
211
|
-
end
|
111
|
+
def handle_option(option)
|
112
|
+
# Handle no-color option
|
113
|
+
if option == :'no-color'
|
114
|
+
Nanoc::CLI::Logger.instance.color = false
|
115
|
+
# Handle verbose option
|
116
|
+
elsif option == :verbose
|
117
|
+
Nanoc::CLI::Logger.instance.level = :low
|
118
|
+
# Handle version option
|
119
|
+
elsif option == :version
|
120
|
+
puts "nanoc #{Nanoc::VERSION} (c) 2007-2009 Denis Defreyne."
|
121
|
+
puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}"
|
122
|
+
exit 0
|
123
|
+
# Handle help option
|
124
|
+
elsif option == :help
|
125
|
+
show_help
|
126
|
+
exit 0
|
212
127
|
end
|
213
|
-
|
214
|
-
# Set base
|
215
|
-
@commands.each { |c| c.base = self }
|
216
128
|
end
|
217
129
|
|
218
130
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'nanoc/cli/commands/autocompile'
|
2
|
+
require 'nanoc/cli/commands/compile'
|
3
|
+
require 'nanoc/cli/commands/create_layout'
|
4
|
+
require 'nanoc/cli/commands/create_page'
|
5
|
+
require 'nanoc/cli/commands/create_site'
|
6
|
+
require 'nanoc/cli/commands/create_template'
|
7
|
+
require 'nanoc/cli/commands/help'
|
8
|
+
require 'nanoc/cli/commands/info'
|
9
|
+
require 'nanoc/cli/commands/switch'
|
10
|
+
require 'nanoc/cli/commands/update'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nanoc::CLI
|
2
2
|
|
3
|
-
class CompileCommand < Command # :nodoc:
|
3
|
+
class CompileCommand < Cri::Command # :nodoc:
|
4
4
|
|
5
5
|
def name
|
6
6
|
'compile'
|
@@ -31,7 +31,22 @@ module Nanoc::CLI
|
|
31
31
|
{
|
32
32
|
:long => 'all', :short => 'a', :argument => :forbidden,
|
33
33
|
:desc => 'compile all pages and assets, even those that aren\'t outdated'
|
34
|
-
}
|
34
|
+
},
|
35
|
+
# --pages
|
36
|
+
{
|
37
|
+
:long => 'pages', :short => 'P', :argument => :forbidden,
|
38
|
+
:desc => 'only compile pages (no assets)'
|
39
|
+
},
|
40
|
+
# --assets
|
41
|
+
{
|
42
|
+
:long => 'assets', :short => 'A', :argument => :forbidden,
|
43
|
+
:desc => 'only compile assets (no pages)'
|
44
|
+
},
|
45
|
+
# --only-outdated
|
46
|
+
{
|
47
|
+
:long => 'only-outdated', :short => 'o', :argument => :forbidden,
|
48
|
+
:desc => 'only compile outdated pages and assets'
|
49
|
+
},
|
35
50
|
]
|
36
51
|
end
|
37
52
|
|
@@ -41,7 +56,14 @@ module Nanoc::CLI
|
|
41
56
|
|
42
57
|
# Find object with given path
|
43
58
|
if arguments.size == 0
|
44
|
-
|
59
|
+
# Find all pages and/or assets
|
60
|
+
if options.has_key?(:pages)
|
61
|
+
objs = @base.site.pages
|
62
|
+
elsif options.has_key?(:assets)
|
63
|
+
objs = @base.site.assets
|
64
|
+
else
|
65
|
+
objs = nil
|
66
|
+
end
|
45
67
|
else
|
46
68
|
objs = arguments.map do |path|
|
47
69
|
# Find object
|
@@ -70,10 +92,18 @@ module Nanoc::CLI
|
|
70
92
|
@times_stack ||= []
|
71
93
|
setup_notifications
|
72
94
|
|
95
|
+
# Parse all/only-outdated options
|
96
|
+
if options.has_key?(:all)
|
97
|
+
warn "WARNING: The --all option is no longer necessary as nanoc " +
|
98
|
+
"2.2 compiles all pages and assets by default. To change this " +
|
99
|
+
"behaviour, use the --only-outdated option."
|
100
|
+
end
|
101
|
+
compile_all = options.has_key?(:'only-outdated') ? false : true
|
102
|
+
|
73
103
|
# Compile
|
74
104
|
@base.site.compiler.run(
|
75
105
|
objs,
|
76
|
-
:even_when_not_outdated =>
|
106
|
+
:even_when_not_outdated => compile_all
|
77
107
|
)
|
78
108
|
|
79
109
|
# Find reps
|
@@ -87,6 +117,12 @@ module Nanoc::CLI
|
|
87
117
|
Nanoc::CLI::Logger.instance.file(:low, :skip, rep.disk_path, duration)
|
88
118
|
end
|
89
119
|
|
120
|
+
# Show non-written reps
|
121
|
+
reps.select { |r| r.compiled? && r.attribute_named(:skip_output) }.each do |rep|
|
122
|
+
duration = @rep_times[rep.disk_path]
|
123
|
+
Nanoc::CLI::Logger.instance.file(:low, :'not written', rep.disk_path, duration)
|
124
|
+
end
|
125
|
+
|
90
126
|
# Give general feedback
|
91
127
|
puts
|
92
128
|
puts "No objects were modified." unless reps.any? { |r| r.modified? }
|
@@ -122,18 +158,20 @@ module Nanoc::CLI
|
|
122
158
|
|
123
159
|
def print_state_feedback(reps)
|
124
160
|
# Categorise reps
|
125
|
-
rest
|
126
|
-
created,
|
127
|
-
modified,
|
128
|
-
skipped,
|
129
|
-
|
161
|
+
rest = reps
|
162
|
+
created, rest = *rest.partition { |r| r.created? }
|
163
|
+
modified, rest = *rest.partition { |r| r.modified? }
|
164
|
+
skipped, rest = *rest.partition { |r| !r.compiled? }
|
165
|
+
not_written, rest = *rest.partition { |r| r.compiled? && r.attribute_named(:skip_output) }
|
166
|
+
identical = rest
|
130
167
|
|
131
168
|
# Print
|
132
169
|
puts
|
133
|
-
puts format(' %4d created',
|
134
|
-
puts format(' %4d modified',
|
135
|
-
puts format(' %4d skipped',
|
136
|
-
puts format(' %4d
|
170
|
+
puts format(' %4d created', created.size)
|
171
|
+
puts format(' %4d modified', modified.size)
|
172
|
+
puts format(' %4d skipped', skipped.size)
|
173
|
+
puts format(' %4d not written', not_written.size)
|
174
|
+
puts format(' %4d identical', identical.size)
|
137
175
|
end
|
138
176
|
|
139
177
|
def print_profiling_feedback(reps)
|