nanoc 2.1.6 → 2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/ChangeLog +3 -221
  2. data/Rakefile +9 -51
  3. data/bin/nanoc +5 -2
  4. data/lib/nanoc.rb +9 -31
  5. data/lib/nanoc/base.rb +26 -0
  6. data/lib/nanoc/base/core_ext.rb +2 -0
  7. data/lib/nanoc/base/filter.rb +11 -41
  8. data/lib/nanoc/base/layout.rb +1 -5
  9. data/lib/nanoc/base/page_rep.rb +1 -1
  10. data/lib/nanoc/base/proxies.rb +5 -0
  11. data/lib/nanoc/base/site.rb +4 -2
  12. data/lib/nanoc/binary_filters.rb +1 -0
  13. data/lib/nanoc/cli.rb +9 -1
  14. data/lib/nanoc/cli/base.rb +41 -129
  15. data/lib/nanoc/cli/commands.rb +10 -0
  16. data/lib/nanoc/cli/commands/autocompile.rb +1 -1
  17. data/lib/nanoc/cli/commands/compile.rb +51 -13
  18. data/lib/nanoc/cli/commands/create_layout.rb +1 -1
  19. data/lib/nanoc/cli/commands/create_page.rb +1 -1
  20. data/lib/nanoc/cli/commands/create_site.rb +1 -1
  21. data/lib/nanoc/cli/commands/create_template.rb +1 -1
  22. data/lib/nanoc/cli/commands/help.rb +1 -1
  23. data/lib/nanoc/cli/commands/info.rb +1 -1
  24. data/lib/nanoc/cli/commands/switch.rb +1 -1
  25. data/lib/nanoc/cli/commands/update.rb +1 -1
  26. data/lib/nanoc/cli/logger.rb +13 -7
  27. data/lib/nanoc/data_sources.rb +2 -0
  28. data/lib/nanoc/data_sources/filesystem.rb +3 -38
  29. data/lib/nanoc/extra.rb +6 -0
  30. data/lib/nanoc/extra/core_ext.rb +2 -0
  31. data/lib/nanoc/extra/vcses.rb +5 -0
  32. data/lib/nanoc/filters.rb +14 -0
  33. data/lib/nanoc/filters/erb.rb +3 -2
  34. data/lib/nanoc/filters/haml.rb +1 -1
  35. data/lib/nanoc/filters/markaby.rb +0 -1
  36. data/lib/nanoc/filters/rainpress.rb +13 -0
  37. data/lib/nanoc/filters/relativize_paths.rb +25 -0
  38. data/lib/nanoc/filters/sass.rb +1 -0
  39. data/lib/nanoc/helpers.rb +9 -0
  40. data/lib/nanoc/helpers/blogging.rb +55 -12
  41. data/lib/nanoc/helpers/filtering.rb +54 -0
  42. data/lib/nanoc/helpers/link_to.rb +40 -0
  43. data/lib/nanoc/helpers/text.rb +38 -0
  44. data/lib/nanoc/helpers/xml_sitemap.rb +3 -2
  45. data/lib/nanoc/routers.rb +3 -0
  46. data/vendor/cri/ChangeLog +0 -0
  47. data/vendor/cri/LICENSE +19 -0
  48. data/vendor/cri/NEWS +0 -0
  49. data/vendor/cri/README +4 -0
  50. data/vendor/cri/Rakefile +25 -0
  51. data/vendor/cri/lib/cri.rb +12 -0
  52. data/vendor/cri/lib/cri/base.rb +153 -0
  53. data/{lib/nanoc/cli → vendor/cri/lib/cri}/command.rb +5 -6
  54. data/vendor/cri/lib/cri/core_ext.rb +8 -0
  55. data/vendor/cri/lib/cri/core_ext/string.rb +41 -0
  56. data/{lib/nanoc/cli → vendor/cri/lib/cri}/option_parser.rb +35 -17
  57. data/vendor/cri/test/test_base.rb +6 -0
  58. data/vendor/cri/test/test_command.rb +6 -0
  59. data/vendor/cri/test/test_core_ext.rb +21 -0
  60. data/vendor/cri/test/test_option_parser.rb +279 -0
  61. data/vendor/mime-types/lib/mime/types.rb +1558 -0
  62. metadata +45 -9
  63. data/lib/nanoc/base/enhancements.rb +0 -14
  64. data/lib/nanoc/cli/cli.rb +0 -16
  65. data/lib/nanoc/cli/ext.rb +0 -37
@@ -55,11 +55,7 @@ module Nanoc
55
55
 
56
56
  # Returns the filter class needed for this layout.
57
57
  def filter_class
58
- if attribute_named(:extension).nil?
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
@@ -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)
@@ -0,0 +1,5 @@
1
+ require 'nanoc/base/proxies/asset_proxy'
2
+ require 'nanoc/base/proxies/asset_rep_proxy'
3
+ require 'nanoc/base/proxies/layout_proxy'
4
+ require 'nanoc/base/proxies/page_proxy'
5
+ require 'nanoc/base/proxies/page_rep_proxy'
@@ -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} should return #{is_array ? 'an array of' : 'a' } Nanoc::#{class_name} object#{is_array ? 's' : ''}. Future versions will not support these outdated data sources.",
266
- 'DEPRECATION WARNING'
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'
@@ -1 +1,9 @@
1
- Nanoc.load('cli', '*.rb')
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../../vendor/cri/lib'))
2
+ require 'cri'
3
+
4
+ module Nanoc::CLI # :nodoc:
5
+ end
6
+
7
+ require 'nanoc/cli/base'
8
+ require 'nanoc/cli/commands'
9
+ require 'nanoc/cli/logger'
@@ -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
- create_commands
12
- end
13
-
14
- # Parses the given commandline arguments and executes the requested
15
- # command.
16
- def run(args)
17
- # Check arguments
18
- if args.length == 0
19
- @help_command.run([], [])
20
- exit 1
21
- end
22
-
23
- # Find version or help options
24
- if args.length == 1
25
- # Parse arguments
26
- begin
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
- protected
194
-
195
- def create_commands
196
- @commands = []
197
-
198
- # Find all command classes
199
- command_classes = []
200
- ObjectSpace.each_object(Class) do |klass|
201
- command_classes << klass if klass < Nanoc::CLI::Command
202
- end
203
-
204
- # Create commands
205
- command_classes.each do |klass|
206
- if klass.to_s == 'Nanoc::CLI::HelpCommand'
207
- @help_command = HelpCommand.new
208
- @commands << @help_command
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 AutocompileCommand < Command # :nodoc:
3
+ class AutocompileCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'autocompile'
@@ -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
- objs = nil
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 => options.has_key?(:all)
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 = reps
126
- created, rest = *rest.partition { |r| r.created? }
127
- modified, rest = *rest.partition { |r| r.modified? }
128
- skipped, rest = *rest.partition { |r| !r.compiled? }
129
- identical = rest
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', created.size)
134
- puts format(' %4d modified', modified.size)
135
- puts format(' %4d skipped', skipped.size)
136
- puts format(' %4d identical', identical.size)
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)
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class CreateLayoutCommand < Command # :nodoc:
3
+ class CreateLayoutCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'create_layout'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class CreatePageCommand < Command # :nodoc:
3
+ class CreatePageCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'create_page'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class CreateSiteCommand < Command # :nodoc:
3
+ class CreateSiteCommand < Cri::Command # :nodoc:
4
4
 
5
5
  DEFAULT_PAGE = <<EOS
6
6
  <h1>A Brand New nanoc Site</h1>
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class CreateTemplateCommand < Command # :nodoc:
3
+ class CreateTemplateCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'create_template'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class HelpCommand < Command # :nodoc:
3
+ class HelpCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'help'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class InfoCommand < Command # :nodoc:
3
+ class InfoCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'info'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class SwitchCommand < Command # :nodoc:
3
+ class SwitchCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'switch'
@@ -1,6 +1,6 @@
1
1
  module Nanoc::CLI
2
2
 
3
- class UpdateCommand < Command # :nodoc:
3
+ class UpdateCommand < Cri::Command # :nodoc:
4
4
 
5
5
  def name
6
6
  'update'