nanoc3 3.2.0a4 → 3.2.0b1
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +20 -2
- data/README.md +7 -3
- data/bin/nanoc3 +1 -3
- data/lib/nanoc3.rb +1 -13
- data/lib/nanoc3/base/compilation/filter.rb +21 -0
- data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +1 -3
- data/lib/nanoc3/base/compilation/outdatedness_checker.rb +1 -1
- data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -2
- data/lib/nanoc3/base/compilation/rules_collection.rb +37 -13
- data/lib/nanoc3/base/directed_graph.rb +3 -3
- data/lib/nanoc3/base/memoization.rb +6 -9
- data/lib/nanoc3/base/source_data/code_snippet.rb +2 -1
- data/lib/nanoc3/base/source_data/configuration.rb +7 -3
- data/lib/nanoc3/base/source_data/item.rb +52 -10
- data/lib/nanoc3/base/source_data/layout.rb +28 -1
- data/lib/nanoc3/base/source_data/site.rb +14 -3
- data/lib/nanoc3/cli.rb +98 -6
- data/lib/nanoc3/cli/{base.rb → command.rb} +117 -153
- data/lib/nanoc3/cli/commands/autocompile.rb +20 -48
- data/lib/nanoc3/cli/commands/compile.rb +32 -48
- data/lib/nanoc3/cli/commands/create_item.rb +21 -37
- data/lib/nanoc3/cli/commands/create_layout.rb +18 -36
- data/lib/nanoc3/cli/commands/create_site.rb +15 -34
- data/lib/nanoc3/cli/commands/debug.rb +17 -31
- data/lib/nanoc3/cli/commands/info.rb +14 -29
- data/lib/nanoc3/cli/commands/nanoc.rb +37 -0
- data/lib/nanoc3/cli/commands/update.rb +21 -44
- data/lib/nanoc3/cli/commands/view.rb +18 -44
- data/lib/nanoc3/cli/commands/watch.rb +16 -31
- data/lib/nanoc3/data_sources/filesystem.rb +25 -6
- data/lib/nanoc3/data_sources/filesystem_unified.rb +5 -5
- data/lib/nanoc3/extra/auto_compiler.rb +1 -0
- data/lib/nanoc3/extra/file_proxy.rb +0 -1
- data/lib/nanoc3/filters.rb +2 -0
- data/lib/nanoc3/filters/asciidoc.rb +16 -36
- data/lib/nanoc3/filters/bluecloth.rb +2 -2
- data/lib/nanoc3/filters/coderay.rb +2 -2
- data/lib/nanoc3/filters/colorize_syntax.rb +18 -5
- data/lib/nanoc3/filters/erb.rb +2 -2
- data/lib/nanoc3/filters/erubis.rb +2 -2
- data/lib/nanoc3/filters/haml.rb +2 -2
- data/lib/nanoc3/filters/kramdown.rb +2 -2
- data/lib/nanoc3/filters/less.rb +32 -1
- data/lib/nanoc3/filters/markaby.rb +2 -2
- data/lib/nanoc3/filters/maruku.rb +2 -2
- data/lib/nanoc3/filters/mustache.rb +2 -2
- data/lib/nanoc3/filters/rainpress.rb +2 -2
- data/lib/nanoc3/filters/rdiscount.rb +4 -3
- data/lib/nanoc3/filters/rdoc.rb +10 -6
- data/lib/nanoc3/filters/redcarpet.rb +2 -2
- data/lib/nanoc3/filters/redcloth.rb +2 -2
- data/lib/nanoc3/filters/rubypants.rb +2 -2
- data/lib/nanoc3/filters/sass.rb +44 -52
- data/lib/nanoc3/filters/slim.rb +2 -2
- data/lib/nanoc3/filters/typogruby.rb +2 -2
- data/lib/nanoc3/filters/uglify_js.rb +42 -0
- data/nanoc3.gemspec +1 -1
- data/tasks/test.rake +6 -0
- data/test/base/core_ext/array_spec.rb +0 -2
- data/test/base/core_ext/hash_spec.rb +0 -2
- data/test/base/core_ext/pathname_spec.rb +0 -2
- data/test/base/core_ext/string_spec.rb +0 -2
- data/test/base/test_checksum_store.rb +0 -2
- data/test/base/test_code_snippet.rb +0 -2
- data/test/base/test_compiler.rb +2 -4
- data/test/base/test_compiler_dsl.rb +1 -3
- data/test/base/test_context.rb +0 -2
- data/test/base/test_data_source.rb +0 -2
- data/test/base/test_dependency_tracker.rb +0 -2
- data/test/base/test_directed_graph.rb +0 -2
- data/test/base/test_filter.rb +0 -2
- data/test/base/test_item.rb +19 -4
- data/test/base/test_item_rep.rb +0 -2
- data/test/base/test_layout.rb +19 -4
- data/test/base/test_memoization.rb +39 -2
- data/test/base/test_notification_center.rb +0 -2
- data/test/base/test_outdatedness_checker.rb +31 -2
- data/test/base/test_plugin.rb +0 -2
- data/test/base/test_rule.rb +0 -2
- data/test/base/test_rule_context.rb +0 -2
- data/test/base/test_site.rb +30 -3
- data/test/cli/commands/test_compile.rb +24 -3
- data/test/cli/commands/test_create_item.rb +5 -3
- data/test/cli/commands/test_create_layout.rb +4 -4
- data/test/cli/commands/test_create_site.rb +5 -5
- data/test/cli/commands/test_help.rb +3 -3
- data/test/cli/commands/test_info.rb +2 -3
- data/test/cli/commands/test_update.rb +0 -2
- data/test/cli/test_cli.rb +40 -0
- data/test/cli/test_logger.rb +0 -2
- data/test/data_sources/test_filesystem.rb +0 -2
- data/test/data_sources/test_filesystem_unified.rb +32 -58
- data/test/data_sources/test_filesystem_verbose.rb +0 -2
- data/test/extra/core_ext/test_enumerable.rb +0 -2
- data/test/extra/core_ext/test_time.rb +0 -2
- data/test/extra/deployers/test_rsync.rb +0 -2
- data/test/extra/test_auto_compiler.rb +5 -7
- data/test/extra/test_file_proxy.rb +0 -2
- data/test/extra/test_vcs.rb +0 -2
- data/test/extra/validators/test_links.rb +0 -2
- data/test/extra/validators/test_w3c.rb +0 -2
- data/test/filters/test_asciidoc.rb +0 -2
- data/test/filters/test_bluecloth.rb +0 -2
- data/test/filters/test_coderay.rb +0 -2
- data/test/filters/test_colorize_syntax.rb +49 -2
- data/test/filters/test_erb.rb +0 -2
- data/test/filters/test_erubis.rb +0 -2
- data/test/filters/test_haml.rb +0 -2
- data/test/filters/test_kramdown.rb +0 -2
- data/test/filters/test_less.rb +59 -5
- data/test/filters/test_markaby.rb +0 -2
- data/test/filters/test_maruku.rb +0 -2
- data/test/filters/test_mustache.rb +0 -2
- data/test/filters/test_rainpress.rb +0 -2
- data/test/filters/test_rdiscount.rb +0 -2
- data/test/filters/test_rdoc.rb +0 -2
- data/test/filters/test_redcarpet.rb +0 -2
- data/test/filters/test_redcloth.rb +0 -2
- data/test/filters/test_relativize_paths.rb +77 -24
- data/test/filters/test_rubypants.rb +0 -2
- data/test/filters/test_sass.rb +136 -10
- data/test/filters/test_slim.rb +0 -2
- data/test/filters/test_typogruby.rb +0 -2
- data/test/filters/test_uglify_js.rb +30 -0
- data/test/gem_loader.rb +11 -0
- data/test/helper.rb +3 -0
- data/test/helpers/test_blogging.rb +0 -2
- data/test/helpers/test_breadcrumbs.rb +0 -2
- data/test/helpers/test_capturing.rb +0 -2
- data/test/helpers/test_filtering.rb +0 -2
- data/test/helpers/test_html_escape.rb +0 -2
- data/test/helpers/test_link_to.rb +0 -2
- data/test/helpers/test_rendering.rb +0 -2
- data/test/helpers/test_tagging.rb +0 -2
- data/test/helpers/test_text.rb +0 -2
- data/test/helpers/test_xml_sitemap.rb +0 -2
- data/test/tasks/test_clean.rb +0 -2
- metadata +11 -9
- data/lib/nanoc3/cli/commands.rb +0 -16
- data/lib/nanoc3/cli/commands/help.rb +0 -71
- data/tasks/clean.rake +0 -11
@@ -85,7 +85,8 @@ module Nanoc3
|
|
85
85
|
"<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>"
|
86
86
|
end
|
87
87
|
|
88
|
-
#
|
88
|
+
# @return [String] The checksum for this object. If its contents change,
|
89
|
+
# the checksum will change as well.
|
89
90
|
def checksum
|
90
91
|
attributes = @attributes.dup
|
91
92
|
attributes.delete(:file)
|
@@ -93,6 +94,32 @@ module Nanoc3
|
|
93
94
|
end
|
94
95
|
memoize :checksum
|
95
96
|
|
97
|
+
def hash
|
98
|
+
self.class.hash ^ self.identifier.hash
|
99
|
+
end
|
100
|
+
|
101
|
+
def eql?(other)
|
102
|
+
self.class == other.class && self.identifier == other.identifier
|
103
|
+
end
|
104
|
+
|
105
|
+
def ==(other)
|
106
|
+
self.eql?(other)
|
107
|
+
end
|
108
|
+
|
109
|
+
def marshal_dump
|
110
|
+
[
|
111
|
+
@raw_content,
|
112
|
+
@attributes,
|
113
|
+
@identifier
|
114
|
+
]
|
115
|
+
end
|
116
|
+
|
117
|
+
def marshal_load(source)
|
118
|
+
@raw_content,
|
119
|
+
@attributes,
|
120
|
+
@identifier = *source
|
121
|
+
end
|
122
|
+
|
96
123
|
# @deprecated Access the modification time using `layout[:mtime]` instead.
|
97
124
|
def mtime
|
98
125
|
self[:mtime]
|
@@ -179,11 +179,22 @@ module Nanoc3
|
|
179
179
|
# @return [void]
|
180
180
|
def setup_child_parent_links
|
181
181
|
teardown_child_parent_links
|
182
|
-
|
182
|
+
|
183
|
+
items = @items.sort_by { |i| i.identifier }
|
184
|
+
items.each_with_index do |item, index|
|
183
185
|
# Get parent
|
186
|
+
next if index == 0
|
184
187
|
parent_identifier = item.identifier.sub(/[^\/]+\/$/, '')
|
185
|
-
parent =
|
186
|
-
|
188
|
+
parent = nil
|
189
|
+
(0..index-1).reverse_each do |candidate_index|
|
190
|
+
candidate = items[candidate_index]
|
191
|
+
if candidate.identifier == parent_identifier
|
192
|
+
parent = candidate
|
193
|
+
elsif candidate.identifier[0..parent_identifier.size-1] != parent_identifier
|
194
|
+
break
|
195
|
+
end
|
196
|
+
end
|
197
|
+
next if parent.nil?
|
187
198
|
|
188
199
|
# Link
|
189
200
|
item.parent = parent
|
data/lib/nanoc3/cli.rb
CHANGED
@@ -1,12 +1,104 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# Load Cri
|
4
3
|
require 'cri'
|
5
4
|
|
6
5
|
module Nanoc3::CLI
|
7
|
-
end
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
module Commands
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Boolean] true if debug output is enabled, false if not
|
11
|
+
#
|
12
|
+
# @since 3.2.0
|
13
|
+
def self.debug?
|
14
|
+
@debug || false
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [Boolean] boolean true if debug output should be enabled,
|
18
|
+
# false if it should not
|
19
|
+
#
|
20
|
+
# @return [void]
|
21
|
+
#
|
22
|
+
# @since 3.2.0
|
23
|
+
def self.debug=(boolean)
|
24
|
+
@debug = boolean
|
25
|
+
end
|
26
|
+
|
27
|
+
autoload 'Logger', 'nanoc3/cli/logger'
|
28
|
+
autoload 'Command', 'nanoc3/cli/command'
|
29
|
+
|
30
|
+
# Invokes the nanoc commandline tool with the given arguments.
|
31
|
+
#
|
32
|
+
# @param [Array<String>] args An array of commandline arguments
|
33
|
+
#
|
34
|
+
# @return [void]
|
35
|
+
def self.run(args)
|
36
|
+
self.setup
|
37
|
+
self.load_custom_commands
|
38
|
+
self.root_command.run(args)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Adds the given command to the collection of available commands.
|
42
|
+
#
|
43
|
+
# @param [Cri::Command] cmd The command to add
|
44
|
+
#
|
45
|
+
# @return [void]
|
46
|
+
def self.add_command(cmd)
|
47
|
+
self.root_command.add_command(cmd)
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
# Makes the commandline interface ready for using by loading the commands.
|
53
|
+
#
|
54
|
+
# @return [void]
|
55
|
+
def self.setup
|
56
|
+
# Don’t set up twice
|
57
|
+
return if @setup
|
58
|
+
|
59
|
+
# Add help command
|
60
|
+
help_cmd = Cri::Command.new_basic_help
|
61
|
+
self.add_command(help_cmd)
|
62
|
+
|
63
|
+
# Add other commands
|
64
|
+
cmd_filenames = Dir[File.dirname(__FILE__) + '/cli/commands/*.rb']
|
65
|
+
cmd_filenames.each do |filename|
|
66
|
+
next if File.basename(filename, '.rb') == 'nanoc'
|
67
|
+
cmd = self.load_command_at(filename)
|
68
|
+
self.add_command(cmd)
|
69
|
+
end
|
70
|
+
|
71
|
+
@setup = true
|
72
|
+
end
|
73
|
+
|
74
|
+
# Loads the commands in `commands/`.
|
75
|
+
#
|
76
|
+
# @return [void]
|
77
|
+
def self.load_custom_commands
|
78
|
+
Dir['commands/*.rb'].each do |filename|
|
79
|
+
cmd = Nanoc3::CLI.load_command_at(filename)
|
80
|
+
Nanoc3::CLI.root_command.add_command(cmd)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Loads the command in the file with the given filename.
|
85
|
+
#
|
86
|
+
# @param [String] filename The name of the file that contains the command
|
87
|
+
#
|
88
|
+
# @return [Cri::Command] The loaded command
|
89
|
+
def self.load_command_at(filename)
|
90
|
+
code = File.read(filename)
|
91
|
+
cmd = Cri::Command.define(code)
|
92
|
+
cmd.modify { name File.basename(filename, '.rb') }
|
93
|
+
cmd
|
94
|
+
end
|
95
|
+
|
96
|
+
# @return [Cri::Command] The root command, i.e. the commandline tool itself
|
97
|
+
def self.root_command
|
98
|
+
@root_command ||= begin
|
99
|
+
filename = File.dirname(__FILE__) + "/cli/commands/nanoc.rb"
|
100
|
+
self.load_command_at(filename)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -2,7 +2,86 @@
|
|
2
2
|
|
3
3
|
module Nanoc3::CLI
|
4
4
|
|
5
|
-
|
5
|
+
# An abstract superclass for commands that can be executed. These are not
|
6
|
+
# the same as Cri commands, but are used in conjuction with Cri commands.
|
7
|
+
# nanoc commands will be called by Cri commands and will perform the actual
|
8
|
+
# execution of the command, as well as perform error handling if necessary.
|
9
|
+
class Command
|
10
|
+
|
11
|
+
# @return [Hash] A hash contain the options and their values
|
12
|
+
attr_reader :options
|
13
|
+
|
14
|
+
# @return [Array] The list of arguments
|
15
|
+
attr_reader :arguments
|
16
|
+
|
17
|
+
# @return [Cri::Command] The Cri command
|
18
|
+
attr_reader :command
|
19
|
+
|
20
|
+
# @param [Hash] options A hash contain the options and their values
|
21
|
+
#
|
22
|
+
# @param [Array] arguments The list of arguments
|
23
|
+
#
|
24
|
+
# @param [Cri::Command] command The Cri command
|
25
|
+
def initialize(options, arguments, command)
|
26
|
+
@options = options
|
27
|
+
@arguments = arguments
|
28
|
+
@command = command
|
29
|
+
end
|
30
|
+
|
31
|
+
# Runs the command with the given options, arguments and Cri command. This
|
32
|
+
# is a convenience method so that no individual command needs to be
|
33
|
+
# created.
|
34
|
+
#
|
35
|
+
# @param [Hash] options A hash contain the options and their values
|
36
|
+
#
|
37
|
+
# @param [Array] arguments The list of arguments
|
38
|
+
#
|
39
|
+
# @param [Cri::Command] command The Cri command
|
40
|
+
#
|
41
|
+
# @return [void]
|
42
|
+
def self.call(options, arguments, command)
|
43
|
+
self.new(options, arguments, command).call
|
44
|
+
end
|
45
|
+
|
46
|
+
# Runs the command.
|
47
|
+
#
|
48
|
+
# @return [void]
|
49
|
+
def call
|
50
|
+
# Set exit handler
|
51
|
+
[ 'INT', 'TERM' ].each do |signal|
|
52
|
+
Signal.trap(signal) do
|
53
|
+
puts
|
54
|
+
exit!(0)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Set attributes
|
59
|
+
|
60
|
+
# Run
|
61
|
+
self.run
|
62
|
+
rescue Interrupt => e
|
63
|
+
exit(1)
|
64
|
+
rescue StandardError, ScriptError => e
|
65
|
+
self.print_error(e)
|
66
|
+
exit(1)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Performs the actual execution of the command.
|
70
|
+
#
|
71
|
+
# @return [void]
|
72
|
+
#
|
73
|
+
# @abstract
|
74
|
+
def run
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
# @return [Boolean] true if debug output is enabled, false if not
|
80
|
+
#
|
81
|
+
# @see Nanoc3::CLI.debug?
|
82
|
+
def debug?
|
83
|
+
Nanoc3::CLI.debug?
|
84
|
+
end
|
6
85
|
|
7
86
|
# A hash that contains the name of the gem for a given required file. If a
|
8
87
|
# `#require` fails, the gem name is looked up in this hash.
|
@@ -35,93 +114,6 @@ module Nanoc3::CLI
|
|
35
114
|
'w3c_validators' => 'w3c_validators'
|
36
115
|
}
|
37
116
|
|
38
|
-
def initialize
|
39
|
-
super('nanoc3')
|
40
|
-
|
41
|
-
@debug = false
|
42
|
-
|
43
|
-
# Add help command
|
44
|
-
self.help_command = Nanoc3::CLI::Commands::Help.new
|
45
|
-
add_command(self.help_command)
|
46
|
-
|
47
|
-
# Add other commands
|
48
|
-
add_command(Nanoc3::CLI::Commands::Autocompile.new)
|
49
|
-
add_command(Nanoc3::CLI::Commands::Compile.new)
|
50
|
-
add_command(Nanoc3::CLI::Commands::CreateLayout.new)
|
51
|
-
add_command(Nanoc3::CLI::Commands::CreateItem.new)
|
52
|
-
add_command(Nanoc3::CLI::Commands::CreateSite.new)
|
53
|
-
add_command(Nanoc3::CLI::Commands::Debug.new)
|
54
|
-
add_command(Nanoc3::CLI::Commands::Info.new)
|
55
|
-
add_command(Nanoc3::CLI::Commands::Update.new)
|
56
|
-
add_command(Nanoc3::CLI::Commands::View.new)
|
57
|
-
add_command(Nanoc3::CLI::Commands::Watch.new)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Returns a fully initialised base instance. It is recommended to use this
|
61
|
-
# shared instance than to create new ones, as this will be the instance
|
62
|
-
# that will be used when reading all code from the `lib/` directory.
|
63
|
-
#
|
64
|
-
# @return [Nanoc3::CLI::Base]
|
65
|
-
def self.shared_base
|
66
|
-
@shared_base ||= Nanoc3::CLI::Base.new
|
67
|
-
end
|
68
|
-
|
69
|
-
# @return [Boolean] true if debug output is enabled, false if not
|
70
|
-
#
|
71
|
-
# @since 3.2.0
|
72
|
-
def debug?
|
73
|
-
@debug
|
74
|
-
end
|
75
|
-
|
76
|
-
# Asserts that the current working directory contains a site
|
77
|
-
# ({Nanoc3::Site} instance). If no site is present, prints an error
|
78
|
-
# message and exits.
|
79
|
-
#
|
80
|
-
# @return [void]
|
81
|
-
def require_site
|
82
|
-
if site.nil?
|
83
|
-
$stderr.puts 'The current working directory does not seem to be a ' +
|
84
|
-
'valid/complete nanoc site directory; aborting.'
|
85
|
-
exit 1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Gets the site ({Nanoc3::Site} instance) in the current directory and
|
90
|
-
# loads its data.
|
91
|
-
#
|
92
|
-
# @return [Nanoc3::Site] The site in the current working directory
|
93
|
-
def site
|
94
|
-
# Load site if possible
|
95
|
-
if File.file?('config.yaml') && (!self.instance_variable_defined?(:@site) || @site.nil?)
|
96
|
-
begin
|
97
|
-
@site = Nanoc3::Site.new('.')
|
98
|
-
rescue Nanoc3::Errors::UnknownDataSource => e
|
99
|
-
$stderr.puts "Unknown data source: #{e}"
|
100
|
-
exit 1
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
@site
|
105
|
-
end
|
106
|
-
|
107
|
-
# @see ::Cri::Base#run
|
108
|
-
def run(args)
|
109
|
-
# Set exit handler
|
110
|
-
[ 'INT', 'TERM' ].each do |signal|
|
111
|
-
Signal.trap(signal) do
|
112
|
-
puts
|
113
|
-
exit!(0)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
super(args)
|
118
|
-
rescue Interrupt => e
|
119
|
-
exit(1)
|
120
|
-
rescue StandardError, ScriptError => e
|
121
|
-
print_error(e)
|
122
|
-
exit(1)
|
123
|
-
end
|
124
|
-
|
125
117
|
# Prints the given error to stderr. Includes message, possible resolution
|
126
118
|
# (see {#resolution_for}), compilation stack, backtrace, etc.
|
127
119
|
#
|
@@ -151,10 +143,10 @@ module Nanoc3::CLI
|
|
151
143
|
$stderr.puts
|
152
144
|
$stderr.puts '=== COMPILATION STACK:'
|
153
145
|
$stderr.puts
|
154
|
-
if stack.empty?
|
146
|
+
if self.stack.empty?
|
155
147
|
$stderr.puts " (empty)"
|
156
148
|
else
|
157
|
-
stack.reverse.each do |obj|
|
149
|
+
self.stack.reverse.each do |obj|
|
158
150
|
if obj.is_a?(Nanoc3::ItemRep)
|
159
151
|
$stderr.puts " - [item] #{obj.item.identifier} (rep #{obj.name})"
|
160
152
|
else # layout
|
@@ -181,7 +173,7 @@ module Nanoc3::CLI
|
|
181
173
|
when LoadError
|
182
174
|
# Get gem name
|
183
175
|
matches = error.message.match(/no such file to load -- ([^\s]+)/)
|
184
|
-
return nil if matches.
|
176
|
+
return nil if matches.size == 0
|
185
177
|
lib_name = matches[1]
|
186
178
|
gem_name = GEM_NAMES[$1]
|
187
179
|
|
@@ -200,6 +192,39 @@ module Nanoc3::CLI
|
|
200
192
|
end
|
201
193
|
end
|
202
194
|
|
195
|
+
# Asserts that the current working directory contains a site
|
196
|
+
# ({Nanoc3::Site} instance). If no site is present, prints an error
|
197
|
+
# message and exits.
|
198
|
+
#
|
199
|
+
# @return [void]
|
200
|
+
def require_site
|
201
|
+
@site = nil
|
202
|
+
if site.nil?
|
203
|
+
$stderr.puts 'The current working directory does not seem to be a ' +
|
204
|
+
'valid/complete nanoc site directory; aborting.'
|
205
|
+
exit 1
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Gets the site ({Nanoc3::Site} instance) in the current directory and
|
210
|
+
# loads its data.
|
211
|
+
#
|
212
|
+
# @return [Nanoc3::Site] The site in the current working directory
|
213
|
+
def site
|
214
|
+
# Load site if possible
|
215
|
+
@site ||= nil
|
216
|
+
if File.file?('config.yaml') && @site.nil?
|
217
|
+
begin
|
218
|
+
@site = Nanoc3::Site.new('.')
|
219
|
+
rescue Nanoc3::Errors::UnknownDataSource => e
|
220
|
+
$stderr.puts "Unknown data source: #{e}"
|
221
|
+
exit 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
@site
|
226
|
+
end
|
227
|
+
|
203
228
|
# Sets the data source's VCS to the VCS with the given name. Does nothing
|
204
229
|
# when the site's data source does not support VCSes (i.e. does not
|
205
230
|
# implement #vcs=).
|
@@ -227,68 +252,7 @@ module Nanoc3::CLI
|
|
227
252
|
end
|
228
253
|
end
|
229
254
|
|
230
|
-
# @return [Array] The
|
231
|
-
def global_option_definitions
|
232
|
-
[
|
233
|
-
{
|
234
|
-
:long => 'help', :short => 'h', :argument => :forbidden,
|
235
|
-
:desc => 'show this help message and quit'
|
236
|
-
},
|
237
|
-
{
|
238
|
-
:long => 'color', :short => 'l', :argument => :forbidden,
|
239
|
-
:desc => 'enable color'
|
240
|
-
},
|
241
|
-
{
|
242
|
-
:long => 'no-color', :short => 'C', :argument => :forbidden,
|
243
|
-
:desc => 'disable color'
|
244
|
-
},
|
245
|
-
{
|
246
|
-
:long => 'version', :short => 'v', :argument => :forbidden,
|
247
|
-
:desc => 'show version information and quit'
|
248
|
-
},
|
249
|
-
{
|
250
|
-
:long => 'verbose', :short => 'V', :argument => :forbidden,
|
251
|
-
:desc => 'make nanoc output more detailed'
|
252
|
-
},
|
253
|
-
{
|
254
|
-
:long => 'debug', :short => 'd', :argument => :forbidden,
|
255
|
-
:desc => 'enable debugging'
|
256
|
-
},
|
257
|
-
{
|
258
|
-
:long => 'warn', :short => 'w', :argument => :forbidden,
|
259
|
-
:desc => 'enable warnings'
|
260
|
-
}
|
261
|
-
]
|
262
|
-
end
|
263
|
-
|
264
|
-
# @see Cri::Base#handle_option
|
265
|
-
def handle_option(option)
|
266
|
-
case option
|
267
|
-
when :version
|
268
|
-
gem_info = defined?(Gem) ? "with RubyGems #{Gem::VERSION}" : "without RubyGems"
|
269
|
-
engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"
|
270
|
-
|
271
|
-
puts "nanoc #{Nanoc3::VERSION} (c) 2007-2011 Denis Defreyne."
|
272
|
-
puts "Running #{engine} #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) on #{RUBY_PLATFORM} #{gem_info}"
|
273
|
-
exit 0
|
274
|
-
when :verbose
|
275
|
-
Nanoc3::CLI::Logger.instance.level = :low
|
276
|
-
when :debug
|
277
|
-
@debug = true
|
278
|
-
when :warn
|
279
|
-
$-w = true
|
280
|
-
when :color
|
281
|
-
Nanoc3::CLI::Logger.instance.color = true
|
282
|
-
when :'no-color'
|
283
|
-
Nanoc3::CLI::Logger.instance.color = false
|
284
|
-
when :help
|
285
|
-
show_help
|
286
|
-
exit 0
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
protected
|
291
|
-
|
255
|
+
# @return [Array] The compilation stack.
|
292
256
|
def stack
|
293
257
|
(self.site && self.site.compiler.stack) || []
|
294
258
|
end
|