nanoc 2.2.2 → 3.0.0a1

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.
Files changed (116) hide show
  1. data/bin/nanoc +29 -11
  2. data/bin/nanoc-select +85 -0
  3. metadata +27 -161
  4. data/ChangeLog +0 -3
  5. data/LICENSE +0 -19
  6. data/README +0 -75
  7. data/Rakefile +0 -76
  8. data/lib/nanoc.rb +0 -73
  9. data/lib/nanoc/base.rb +0 -26
  10. data/lib/nanoc/base/asset.rb +0 -117
  11. data/lib/nanoc/base/asset_defaults.rb +0 -21
  12. data/lib/nanoc/base/asset_rep.rb +0 -282
  13. data/lib/nanoc/base/binary_filter.rb +0 -44
  14. data/lib/nanoc/base/code.rb +0 -41
  15. data/lib/nanoc/base/compiler.rb +0 -67
  16. data/lib/nanoc/base/core_ext.rb +0 -2
  17. data/lib/nanoc/base/core_ext/hash.rb +0 -78
  18. data/lib/nanoc/base/core_ext/string.rb +0 -8
  19. data/lib/nanoc/base/data_source.rb +0 -286
  20. data/lib/nanoc/base/defaults.rb +0 -30
  21. data/lib/nanoc/base/filter.rb +0 -93
  22. data/lib/nanoc/base/layout.rb +0 -91
  23. data/lib/nanoc/base/notification_center.rb +0 -66
  24. data/lib/nanoc/base/page.rb +0 -132
  25. data/lib/nanoc/base/page_defaults.rb +0 -20
  26. data/lib/nanoc/base/page_rep.rb +0 -324
  27. data/lib/nanoc/base/plugin.rb +0 -71
  28. data/lib/nanoc/base/proxies.rb +0 -5
  29. data/lib/nanoc/base/proxies/asset_proxy.rb +0 -29
  30. data/lib/nanoc/base/proxies/asset_rep_proxy.rb +0 -26
  31. data/lib/nanoc/base/proxies/layout_proxy.rb +0 -25
  32. data/lib/nanoc/base/proxies/page_proxy.rb +0 -35
  33. data/lib/nanoc/base/proxies/page_rep_proxy.rb +0 -28
  34. data/lib/nanoc/base/proxy.rb +0 -37
  35. data/lib/nanoc/base/router.rb +0 -72
  36. data/lib/nanoc/base/site.rb +0 -274
  37. data/lib/nanoc/base/template.rb +0 -64
  38. data/lib/nanoc/binary_filters.rb +0 -1
  39. data/lib/nanoc/binary_filters/image_science_thumbnail.rb +0 -28
  40. data/lib/nanoc/cli.rb +0 -9
  41. data/lib/nanoc/cli/base.rb +0 -132
  42. data/lib/nanoc/cli/commands.rb +0 -10
  43. data/lib/nanoc/cli/commands/autocompile.rb +0 -80
  44. data/lib/nanoc/cli/commands/compile.rb +0 -311
  45. data/lib/nanoc/cli/commands/create_layout.rb +0 -85
  46. data/lib/nanoc/cli/commands/create_page.rb +0 -85
  47. data/lib/nanoc/cli/commands/create_site.rb +0 -323
  48. data/lib/nanoc/cli/commands/create_template.rb +0 -76
  49. data/lib/nanoc/cli/commands/help.rb +0 -69
  50. data/lib/nanoc/cli/commands/info.rb +0 -125
  51. data/lib/nanoc/cli/commands/switch.rb +0 -141
  52. data/lib/nanoc/cli/commands/update.rb +0 -91
  53. data/lib/nanoc/cli/logger.rb +0 -72
  54. data/lib/nanoc/data_sources.rb +0 -2
  55. data/lib/nanoc/data_sources/filesystem.rb +0 -707
  56. data/lib/nanoc/data_sources/filesystem_combined.rb +0 -495
  57. data/lib/nanoc/extra.rb +0 -6
  58. data/lib/nanoc/extra/auto_compiler.rb +0 -285
  59. data/lib/nanoc/extra/context.rb +0 -22
  60. data/lib/nanoc/extra/core_ext.rb +0 -2
  61. data/lib/nanoc/extra/core_ext/hash.rb +0 -54
  62. data/lib/nanoc/extra/core_ext/time.rb +0 -13
  63. data/lib/nanoc/extra/file_proxy.rb +0 -29
  64. data/lib/nanoc/extra/vcs.rb +0 -48
  65. data/lib/nanoc/extra/vcses.rb +0 -5
  66. data/lib/nanoc/extra/vcses/bazaar.rb +0 -21
  67. data/lib/nanoc/extra/vcses/dummy.rb +0 -20
  68. data/lib/nanoc/extra/vcses/git.rb +0 -21
  69. data/lib/nanoc/extra/vcses/mercurial.rb +0 -21
  70. data/lib/nanoc/extra/vcses/subversion.rb +0 -21
  71. data/lib/nanoc/filters.rb +0 -16
  72. data/lib/nanoc/filters/bluecloth.rb +0 -13
  73. data/lib/nanoc/filters/erb.rb +0 -19
  74. data/lib/nanoc/filters/erubis.rb +0 -14
  75. data/lib/nanoc/filters/haml.rb +0 -21
  76. data/lib/nanoc/filters/markaby.rb +0 -14
  77. data/lib/nanoc/filters/maruku.rb +0 -14
  78. data/lib/nanoc/filters/old.rb +0 -19
  79. data/lib/nanoc/filters/rainpress.rb +0 -13
  80. data/lib/nanoc/filters/rdiscount.rb +0 -13
  81. data/lib/nanoc/filters/rdoc.rb +0 -23
  82. data/lib/nanoc/filters/redcloth.rb +0 -14
  83. data/lib/nanoc/filters/relativize_paths.rb +0 -16
  84. data/lib/nanoc/filters/relativize_paths_in_css.rb +0 -16
  85. data/lib/nanoc/filters/relativize_paths_in_html.rb +0 -16
  86. data/lib/nanoc/filters/rubypants.rb +0 -14
  87. data/lib/nanoc/filters/sass.rb +0 -18
  88. data/lib/nanoc/helpers.rb +0 -9
  89. data/lib/nanoc/helpers/blogging.rb +0 -217
  90. data/lib/nanoc/helpers/capturing.rb +0 -63
  91. data/lib/nanoc/helpers/filtering.rb +0 -54
  92. data/lib/nanoc/helpers/html_escape.rb +0 -25
  93. data/lib/nanoc/helpers/link_to.rb +0 -113
  94. data/lib/nanoc/helpers/render.rb +0 -49
  95. data/lib/nanoc/helpers/tagging.rb +0 -56
  96. data/lib/nanoc/helpers/text.rb +0 -38
  97. data/lib/nanoc/helpers/xml_sitemap.rb +0 -63
  98. data/lib/nanoc/routers.rb +0 -3
  99. data/lib/nanoc/routers/default.rb +0 -54
  100. data/lib/nanoc/routers/no_dirs.rb +0 -66
  101. data/lib/nanoc/routers/versioned.rb +0 -79
  102. data/vendor/cri/ChangeLog +0 -0
  103. data/vendor/cri/LICENSE +0 -19
  104. data/vendor/cri/NEWS +0 -0
  105. data/vendor/cri/README +0 -4
  106. data/vendor/cri/Rakefile +0 -25
  107. data/vendor/cri/lib/cri.rb +0 -12
  108. data/vendor/cri/lib/cri/base.rb +0 -153
  109. data/vendor/cri/lib/cri/command.rb +0 -104
  110. data/vendor/cri/lib/cri/core_ext.rb +0 -8
  111. data/vendor/cri/lib/cri/core_ext/string.rb +0 -41
  112. data/vendor/cri/lib/cri/option_parser.rb +0 -186
  113. data/vendor/cri/test/test_base.rb +0 -6
  114. data/vendor/cri/test/test_command.rb +0 -6
  115. data/vendor/cri/test/test_core_ext.rb +0 -21
  116. data/vendor/cri/test/test_option_parser.rb +0 -279
@@ -1,64 +0,0 @@
1
- module Nanoc
2
-
3
- # A Nanoc::Template represents a template, which can be used for creating
4
- # new pages. Pages don't necessary have to be created using templates, but
5
- # they can be useful for generating pages where you only have to "fill in
6
- # the blanks".
7
- class Template
8
-
9
- # The Nanoc::Site this template belongs to.
10
- attr_accessor :site
11
-
12
- # The name of this template.
13
- attr_reader :name
14
-
15
- # The raw content a page created using this template will have.
16
- attr_reader :page_content
17
-
18
- # A hash containing the attributes a page created using this template will
19
- # have.
20
- attr_reader :page_attributes
21
-
22
- # Creates a new template.
23
- #
24
- # +name+:: The name of this template.
25
- #
26
- # +page_content+:: The raw content a page created using this template will
27
- # have.
28
- #
29
- # +page_attributes+:: A hash containing the attributes a page created
30
- # using this template will have.
31
- def initialize(page_content, page_attributes, name)
32
- @page_content = page_content
33
- @page_attributes = page_attributes.clean
34
- @name = name
35
- end
36
-
37
- # Saves the template in the database, creating it if it doesn't exist yet
38
- # or updating it if it already exists. Tells the site's data source to
39
- # save the template.
40
- def save
41
- @site.data_source.loading do
42
- @site.data_source.save_template(self)
43
- end
44
- end
45
-
46
- # Renames the template. Tells the site's data source to rename the
47
- # template.
48
- def move_to(new_name)
49
- @site.data_source.loading do
50
- @site.data_source.move_template(self, new_name)
51
- end
52
- end
53
-
54
- # Deletes the template. Tells the site's data source to delete the
55
- # template.
56
- def delete
57
- @site.data_source.loading do
58
- @site.data_source.delete_template(self)
59
- end
60
- end
61
-
62
- end
63
-
64
- end
@@ -1 +0,0 @@
1
- require 'nanoc/binary_filters/image_science_thumbnail'
@@ -1,28 +0,0 @@
1
- module Nanoc::BinaryFilters
2
-
3
- class ImageScienceThumbnail < Nanoc::BinaryFilter
4
-
5
- identifier :image_science_thumbnail
6
-
7
- def run(file)
8
- require 'image_science'
9
-
10
- # Get temporary file path
11
- tmp_file = Tempfile.new('filter')
12
- tmp_path = tmp_file.path
13
- tmp_file.close
14
-
15
- # Create thumbnail
16
- ImageScience.with_image(file.path) do |img|
17
- img.thumbnail(@asset_rep.thumbnail_size || 150) do |thumbnail|
18
- thumbnail.save(tmp_path)
19
- end
20
- end
21
-
22
- # Return thumbnail file
23
- File.open(tmp_path)
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,9 +0,0 @@
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'
@@ -1,132 +0,0 @@
1
- module Nanoc::CLI
2
-
3
- # Nanoc::CLI::Base is the central class representing a commandline nanoc
4
- # tool. It has a list of commands, and is linked to a specific nanoc site.
5
- class Base < Cri::Base
6
-
7
- attr_reader :commands, :site
8
-
9
- # Creates a new instance of the commandline nanoc tool.
10
- def initialize
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)
27
- end
28
-
29
- # Helper function which can be called when a command is executed that
30
- # requires a site, such as the compile command.
31
- def require_site
32
- if site.nil?
33
- $stderr.puts 'The current working directory does not seem to be a ' +
34
- 'valid/complete nanoc site directory; aborting.'
35
- exit 1
36
- end
37
- end
38
-
39
- # Gets the site (Nanoc::Site) in the current directory and loads its data.
40
- def site
41
- # Load site if possible
42
- if File.file?('config.yaml') and @site.nil?
43
- begin
44
- @site = Nanoc::Site.new(YAML.load_file('config.yaml'))
45
- @site.load_data
46
- rescue Nanoc::Errors::UnknownDataSourceError => e
47
- $stderr.puts "Unknown data source: #{e}"
48
- exit 1
49
- rescue Nanoc::Errors::UnknownRouterError => e
50
- $stderr.puts "Unknown router: #{e}"
51
- exit 1
52
- rescue Exception => e
53
- $stderr.puts "ERROR: An exception occured while loading this site."
54
- $stderr.puts
55
- $stderr.puts "If you think this is a bug in nanoc, please do report it at " +
56
- "<http://nanoc.stoneship.org/trac/newticket> -- thanks!"
57
- $stderr.puts
58
- $stderr.puts 'Message:'
59
- $stderr.puts ' ' + e.message
60
- $stderr.puts
61
- $stderr.puts 'Backtrace:'
62
- $stderr.puts e.backtrace.map { |t| ' - ' + t }.join("\n")
63
- exit 1
64
- end
65
- end
66
-
67
- @site
68
- end
69
-
70
- # Sets the data source's VCS to the VCS with the given name. Does nothing
71
- # when the site's data source does not support VCSes (i.e. does not
72
- # implement #vcs=).
73
- def set_vcs(vcs_name)
74
- # Skip if not possible
75
- return if vcs_name.nil?
76
- return if site.nil? or !site.data_source.respond_to?(:vcs=)
77
-
78
- # Find VCS
79
- vcs_class = Nanoc::Extra::VCS.named(vcs_name.to_sym)
80
- if vcs_class.nil?
81
- $stderr.puts "A VCS named #{vcs_name} was not found; aborting."
82
- exit 1
83
- end
84
-
85
- # Set VCS
86
- site.data_source.vcs = vcs_class.new
87
- end
88
-
89
- # Returns the list of global option definitionss.
90
- def global_option_definitions
91
- [
92
- {
93
- :long => 'help', :short => 'h', :argument => :forbidden,
94
- :desc => 'show this help message and quit'
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
- },
104
- {
105
- :long => 'version', :short => 'v', :argument => :forbidden,
106
- :desc => 'show version information and quit'
107
- }
108
- ]
109
- end
110
-
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
127
- end
128
- end
129
-
130
- end
131
-
132
- end
@@ -1,10 +0,0 @@
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,80 +0,0 @@
1
- module Nanoc::CLI
2
-
3
- class AutocompileCommand < Cri::Command # :nodoc:
4
-
5
- def name
6
- 'autocompile'
7
- end
8
-
9
- def aliases
10
- [ 'aco', 'autocompile_site' ]
11
- end
12
-
13
- def short_desc
14
- 'start the autocompiler'
15
- end
16
-
17
- def long_desc
18
- handler_names = Nanoc::Extra::AutoCompiler::HANDLER_NAMES.join(', ')
19
-
20
- 'Start the autocompiler web server. Unless specified, the web ' +
21
- 'server will run on port 3000 and listen on all IP addresses. ' +
22
- 'Running the autocompiler requires \'mime/types\' and \'rack\'.' +
23
- "\n" +
24
- 'Available handlers are (in order of preference): ' + handler_names +
25
- ' (default is ' + Nanoc::Extra::AutoCompiler::HANDLER_NAMES[0].to_s + ').'
26
- end
27
-
28
- def usage
29
- "nanoc autocompile [options]"
30
- end
31
-
32
- def option_definitions
33
- [
34
- # --all
35
- {
36
- :long => 'all', :short => 'a', :argument => :forbidden,
37
- :desc => 'compile all pages, even those that aren\'t outdated'
38
- },
39
- # --port
40
- {
41
- :long => 'port', :short => 'p', :argument => :required,
42
- :desc => 'specify a port number for the autocompiler'
43
- },
44
- # --handler
45
- {
46
- :long => 'handler', :short => 'H', :argument => :required,
47
- :desc => 'specify the handler to use'
48
- }
49
- ]
50
- end
51
-
52
- def run(options, arguments)
53
- # Check arguments
54
- if arguments.size != 0
55
- $stderr.puts "usage: #{usage}"
56
- exit 1
57
- end
58
-
59
- # Make sure we are in a nanoc site directory
60
- @base.require_site
61
-
62
- # Autocompile site
63
- begin
64
- autocompiler = Nanoc::Extra::AutoCompiler.new(@base.site, options.has_key?(:all))
65
- autocompiler.start(
66
- options[:port],
67
- options[:handler]
68
- )
69
- rescue LoadError
70
- $stderr.puts "'mime/types' and 'rack' are required to autocompile sites. " +
71
- "You may want to install the 'mime-types' and 'rack' gems by " +
72
- "running 'gem install mime-types' and 'gem install rack'."
73
- rescue Nanoc::Extra::AutoCompiler::UnknownHandlerError
74
- $stderr.puts "The requested handler, #{options[:handler]}, is not available."
75
- end
76
- end
77
-
78
- end
79
-
80
- end
@@ -1,311 +0,0 @@
1
- module Nanoc::CLI
2
-
3
- class CompileCommand < Cri::Command # :nodoc:
4
-
5
- def name
6
- 'compile'
7
- end
8
-
9
- def aliases
10
- []
11
- end
12
-
13
- def short_desc
14
- 'compile pages and assets of this site'
15
- end
16
-
17
- def long_desc
18
- 'Compile all pages and all assets of the current site. If a path is ' +
19
- 'given, only the page or asset with the given path will be compiled. ' +
20
- 'Additionally, only pages and assets that are outdated will be ' +
21
- 'compiled, unless specified otherwise with the -a option.'
22
- end
23
-
24
- def usage
25
- "nanoc compile [options] [path]"
26
- end
27
-
28
- def option_definitions
29
- [
30
- # --all
31
- {
32
- :long => 'all', :short => 'a', :argument => :forbidden,
33
- :desc => 'compile all pages and assets, even those that aren\'t outdated'
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
- },
50
- ]
51
- end
52
-
53
- def run(options, arguments)
54
- # Make sure we are in a nanoc site directory
55
- @base.require_site
56
-
57
- # Find object with given path
58
- if arguments.size == 0
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
67
- else
68
- objs = arguments.map do |path|
69
- # Find object
70
- path = path.cleaned_path
71
- obj = @base.site.pages.find { |page| page.path == path }
72
- obj = @base.site.assets.find { |asset| asset.path == path } if obj.nil?
73
-
74
- # Ensure object
75
- if obj.nil?
76
- $stderr.puts "Unknown page or asset: #{path}"
77
- exit 1
78
- end
79
-
80
- obj
81
- end
82
- end
83
-
84
- # Compile site
85
- begin
86
- # Give feedback
87
- puts "Compiling #{objs.nil? ? 'site' : 'objects'}..."
88
-
89
- # Initialize profiling stuff
90
- time_before = Time.now
91
- @filter_times ||= {}
92
- @times_stack ||= []
93
- setup_notifications
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
-
103
- # Compile
104
- @base.site.compiler.run(
105
- objs,
106
- :even_when_not_outdated => compile_all
107
- )
108
-
109
- # Find reps
110
- page_reps = @base.site.pages.map { |p| p.reps }.flatten
111
- asset_reps = @base.site.assets.map { |a| a.reps }.flatten
112
- reps = page_reps + asset_reps
113
-
114
- # Show skipped reps
115
- reps.select { |r| !r.compiled? }.each do |rep|
116
- duration = @rep_times[rep.disk_path]
117
- Nanoc::CLI::Logger.instance.file(:low, :skip, rep.disk_path, duration)
118
- end
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
-
126
- # Give general feedback
127
- puts
128
- puts "No objects were modified." unless reps.any? { |r| r.modified? }
129
- puts "#{objs.nil? ? 'Site' : 'Object'} compiled in #{format('%.2f', Time.now - time_before)}s."
130
-
131
- if options.has_key?(:verbose)
132
- print_state_feedback(reps)
133
- print_profiling_feedback(reps)
134
- end
135
- rescue Interrupt => e
136
- exit
137
- rescue Exception => e
138
- print_error(e)
139
- end
140
- end
141
-
142
- private
143
-
144
- def setup_notifications
145
- Nanoc::NotificationCenter.on(:compilation_started) do |rep|
146
- rep_compilation_started(rep)
147
- end
148
- Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
149
- rep_compilation_ended(rep)
150
- end
151
- Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name|
152
- rep_filtering_started(rep, filter_name)
153
- end
154
- Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
155
- rep_filtering_ended(rep, filter_name)
156
- end
157
- end
158
-
159
- def print_state_feedback(reps)
160
- # Categorise reps
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
167
-
168
- # Print
169
- puts
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)
175
- end
176
-
177
- def print_profiling_feedback(reps)
178
- # Get max filter length
179
- max_filter_name_length = @filter_times.keys.map { |k| k.to_s.size }.max
180
- return if max_filter_name_length.nil?
181
-
182
- # Print warning if necessary
183
- if reps.any? { |r| !r.compiled? }
184
- $stderr.puts
185
- $stderr.puts "Warning: profiling information may not be accurate because " +
186
- "some objects were not compiled."
187
- end
188
-
189
- # Print header
190
- puts
191
- puts ' ' * max_filter_name_length + ' | count min avg max tot'
192
- puts '-' * max_filter_name_length + '-+-----------------------------------'
193
-
194
- @filter_times.to_a.sort_by { |r| r[1] }.each do |row|
195
- # Extract data
196
- filter_name, samples = *row
197
-
198
- # Calculate stats
199
- count = samples.size
200
- min = samples.min
201
- tot = samples.inject { |memo, i| memo + i}
202
- avg = tot/count
203
- max = samples.max
204
-
205
- # Format stats
206
- count = format('%4d', count)
207
- min = format('%4.2f', min)
208
- avg = format('%4.2f', avg)
209
- max = format('%4.2f', max)
210
- tot = format('%5.2f', tot)
211
-
212
- # Output stats
213
- filter_name = format("%#{max_filter_name_length}s", filter_name)
214
- puts "#{filter_name} | #{count} #{min}s #{avg}s #{max}s #{tot}s"
215
- end
216
- end
217
-
218
- def print_error(error)
219
- # Get rep
220
- rep = @base.site.compiler.stack.select { |i| i.is_a?(Nanoc::PageRep) || i.is_a?(Nanoc::AssetRep) }[-1]
221
- rep_name = rep.nil? ? 'the site' : "#{rep.is_a?(Nanoc::PageRep) ? rep.page.path : rep.asset.path} (rep #{rep.name})"
222
-
223
- # Build message
224
- case error
225
- when Nanoc::Errors::UnknownLayoutError
226
- message = "Unknown layout: #{error.message}"
227
- when Nanoc::Errors::UnknownFilterError
228
- message = "Unknown filter: #{error.message}"
229
- when Nanoc::Errors::CannotDetermineFilterError
230
- message = "Cannot determine filter for layout: #{error.message}"
231
- when Nanoc::Errors::RecursiveCompilationError
232
- message = "Recursive call to page content."
233
- when Nanoc::Errors::NoLongerSupportedError
234
- message = "No longer supported: #{error.message}"
235
- else
236
- message = "Error: #{error.message}"
237
- end
238
-
239
- # Print message
240
- $stderr.puts
241
- $stderr.puts "ERROR: An exception occured while compiling #{rep_name}."
242
- $stderr.puts
243
- $stderr.puts "If you think this is a bug in nanoc, please do report it at " +
244
- "<http://nanoc.stoneship.org/trac/newticket> -- thanks!"
245
- $stderr.puts
246
- $stderr.puts 'Message:'
247
- $stderr.puts ' ' + message
248
- $stderr.puts
249
- $stderr.puts 'Compilation stack:'
250
- @base.site.compiler.stack.reverse.each do |item|
251
- if item.is_a?(Nanoc::PageRep) # page rep
252
- $stderr.puts " - [page] #{item.page.path} (rep #{item.name})"
253
- elsif item.is_a?(Nanoc::AssetRep) # asset rep
254
- $stderr.puts " - [asset] #{item.asset.path} (rep #{item.name})"
255
- else # layout
256
- $stderr.puts " - [layout] #{item.path}"
257
- end
258
- end
259
- $stderr.puts
260
- $stderr.puts 'Backtrace:'
261
- $stderr.puts error.backtrace.map { |t| ' - ' + t }.join("\n")
262
- end
263
-
264
- def rep_compilation_started(rep)
265
- # Profile compilation
266
- @rep_times ||= {}
267
- @rep_times[rep.disk_path] = Time.now
268
- end
269
-
270
- def rep_compilation_ended(rep)
271
- # Profile compilation
272
- @rep_times ||= {}
273
- @rep_times[rep.disk_path] = Time.now - @rep_times[rep.disk_path]
274
-
275
- # Skip if not outputted
276
- return if rep.attribute_named(:skip_output)
277
-
278
- # Get action and level
279
- action, level = *if rep.created?
280
- [ :create, :high ]
281
- elsif rep.modified?
282
- [ :update, :high ]
283
- elsif !rep.compiled?
284
- [ nil, nil ]
285
- else
286
- [ :identical, :low ]
287
- end
288
-
289
- # Log
290
- unless action.nil?
291
- duration = @rep_times[rep.disk_path]
292
- Nanoc::CLI::Logger.instance.file(level, action, rep.disk_path, duration)
293
- end
294
- end
295
-
296
- def rep_filtering_started(rep, filter_name)
297
- @times_stack.push(Time.now)
298
- end
299
-
300
- def rep_filtering_ended(rep, filter_name)
301
- # Get last time
302
- time_start = @times_stack.pop
303
-
304
- # Update times
305
- @filter_times[filter_name.to_sym] ||= []
306
- @filter_times[filter_name.to_sym] << Time.now - time_start
307
- end
308
-
309
- end
310
-
311
- end