nanoc3 3.1.9 → 3.2.0a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/LICENSE +1 -1
  2. data/NEWS.md +0 -50
  3. data/README.md +3 -15
  4. data/bin/nanoc3 +2 -0
  5. data/lib/nanoc3/base/checksummer.rb +40 -0
  6. data/lib/nanoc3/base/code_snippet.rb +30 -12
  7. data/lib/nanoc3/base/compiled_content_cache.rb +86 -0
  8. data/lib/nanoc3/base/compiler.rb +134 -95
  9. data/lib/nanoc3/base/compiler_dsl.rb +12 -11
  10. data/lib/nanoc3/base/core_ext/string.rb +2 -2
  11. data/lib/nanoc3/base/data_source.rb +17 -16
  12. data/lib/nanoc3/base/dependency_tracker.rb +102 -121
  13. data/lib/nanoc3/base/directed_graph.rb +65 -3
  14. data/lib/nanoc3/base/errors.rb +20 -16
  15. data/lib/nanoc3/base/item.rb +58 -50
  16. data/lib/nanoc3/base/item_rep.rb +177 -150
  17. data/lib/nanoc3/base/layout.rb +51 -18
  18. data/lib/nanoc3/base/notification_center.rb +8 -8
  19. data/lib/nanoc3/base/plugin_registry.rb +9 -9
  20. data/lib/nanoc3/base/rule.rb +18 -9
  21. data/lib/nanoc3/base/rule_context.rb +5 -5
  22. data/lib/nanoc3/base/site.rb +135 -47
  23. data/lib/nanoc3/base.rb +21 -19
  24. data/lib/nanoc3/cli/base.rb +51 -74
  25. data/lib/nanoc3/cli/commands/autocompile.rb +3 -0
  26. data/lib/nanoc3/cli/commands/compile.rb +35 -74
  27. data/lib/nanoc3/cli/commands/create_site.rb +17 -5
  28. data/lib/nanoc3/cli/commands/debug.rb +11 -4
  29. data/lib/nanoc3/cli/commands/view.rb +0 -1
  30. data/lib/nanoc3/cli/commands/watch.rb +148 -0
  31. data/lib/nanoc3/cli/commands.rb +1 -0
  32. data/lib/nanoc3/cli/logger.rb +15 -21
  33. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -1
  34. data/lib/nanoc3/data_sources/filesystem.rb +11 -40
  35. data/lib/nanoc3/data_sources/filesystem_unified.rb +22 -22
  36. data/lib/nanoc3/extra/auto_compiler.rb +1 -1
  37. data/lib/nanoc3/extra/chick.rb +8 -8
  38. data/lib/nanoc3/extra/deployers/rsync.rb +2 -3
  39. data/lib/nanoc3/extra/validators/links.rb +32 -51
  40. data/lib/nanoc3/extra/validators/w3c.rb +2 -2
  41. data/lib/nanoc3/extra/vcs.rb +1 -1
  42. data/lib/nanoc3/filters/colorize_syntax.rb +15 -19
  43. data/lib/nanoc3/filters/erb.rb +1 -5
  44. data/lib/nanoc3/filters/erubis.rb +1 -5
  45. data/lib/nanoc3/filters/haml.rb +1 -2
  46. data/lib/nanoc3/filters/less.rb +2 -51
  47. data/lib/nanoc3/filters/mustache.rb +21 -0
  48. data/lib/nanoc3/filters/rdiscount.rb +1 -2
  49. data/lib/nanoc3/filters/relativize_paths.rb +3 -2
  50. data/lib/nanoc3/filters/sass.rb +50 -56
  51. data/lib/nanoc3/filters.rb +2 -0
  52. data/lib/nanoc3/helpers/blogging.rb +22 -29
  53. data/lib/nanoc3/helpers/breadcrumbs.rb +1 -1
  54. data/lib/nanoc3/helpers/capturing.rb +1 -1
  55. data/lib/nanoc3/helpers/filtering.rb +1 -1
  56. data/lib/nanoc3/helpers/link_to.rb +10 -21
  57. data/lib/nanoc3/helpers/rendering.rb +5 -24
  58. data/lib/nanoc3/helpers/tagging.rb +6 -6
  59. data/lib/nanoc3/helpers/text.rb +2 -2
  60. data/lib/nanoc3.rb +1 -1
  61. metadata +35 -93
  62. data/.gemtest +0 -0
  63. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  64. data/nanoc3.gemspec +0 -41
  65. data/tasks/clean.rake +0 -11
  66. data/tasks/doc.rake +0 -14
  67. data/tasks/gem.rake +0 -13
  68. data/tasks/test.rake +0 -38
  69. data/test/base/core_ext/array_spec.rb +0 -23
  70. data/test/base/core_ext/hash_spec.rb +0 -41
  71. data/test/base/core_ext/string_spec.rb +0 -27
  72. data/test/base/test_code_snippet.rb +0 -33
  73. data/test/base/test_compiler.rb +0 -410
  74. data/test/base/test_compiler_dsl.rb +0 -121
  75. data/test/base/test_context.rb +0 -33
  76. data/test/base/test_data_source.rb +0 -48
  77. data/test/base/test_dependency_tracker.rb +0 -510
  78. data/test/base/test_directed_graph.rb +0 -91
  79. data/test/base/test_filter.rb +0 -85
  80. data/test/base/test_item.rb +0 -141
  81. data/test/base/test_item_rep.rb +0 -953
  82. data/test/base/test_layout.rb +0 -44
  83. data/test/base/test_notification_center.rb +0 -36
  84. data/test/base/test_plugin.rb +0 -32
  85. data/test/base/test_rule.rb +0 -21
  86. data/test/base/test_rule_context.rb +0 -63
  87. data/test/base/test_site.rb +0 -366
  88. data/test/cli/commands/test_compile.rb +0 -12
  89. data/test/cli/commands/test_create_item.rb +0 -12
  90. data/test/cli/commands/test_create_layout.rb +0 -28
  91. data/test/cli/commands/test_create_site.rb +0 -24
  92. data/test/cli/commands/test_help.rb +0 -12
  93. data/test/cli/commands/test_info.rb +0 -12
  94. data/test/cli/commands/test_update.rb +0 -12
  95. data/test/cli/test_logger.rb +0 -12
  96. data/test/data_sources/test_filesystem.rb +0 -420
  97. data/test/data_sources/test_filesystem_unified.rb +0 -538
  98. data/test/data_sources/test_filesystem_verbose.rb +0 -359
  99. data/test/extra/core_ext/test_enumerable.rb +0 -32
  100. data/test/extra/core_ext/test_time.rb +0 -17
  101. data/test/extra/deployers/test_rsync.rb +0 -234
  102. data/test/extra/test_auto_compiler.rb +0 -482
  103. data/test/extra/test_file_proxy.rb +0 -21
  104. data/test/extra/test_vcs.rb +0 -24
  105. data/test/extra/validators/test_links.rb +0 -53
  106. data/test/extra/validators/test_w3c.rb +0 -49
  107. data/test/filters/test_bluecloth.rb +0 -20
  108. data/test/filters/test_coderay.rb +0 -46
  109. data/test/filters/test_colorize_syntax.rb +0 -84
  110. data/test/filters/test_erb.rb +0 -72
  111. data/test/filters/test_erubis.rb +0 -72
  112. data/test/filters/test_haml.rb +0 -98
  113. data/test/filters/test_kramdown.rb +0 -20
  114. data/test/filters/test_less.rb +0 -118
  115. data/test/filters/test_markaby.rb +0 -26
  116. data/test/filters/test_maruku.rb +0 -20
  117. data/test/filters/test_rainpress.rb +0 -31
  118. data/test/filters/test_rdiscount.rb +0 -33
  119. data/test/filters/test_rdoc.rb +0 -18
  120. data/test/filters/test_redcloth.rb +0 -20
  121. data/test/filters/test_relativize_paths.rb +0 -231
  122. data/test/filters/test_rubypants.rb +0 -20
  123. data/test/filters/test_sass.rb +0 -235
  124. data/test/gem_loader.rb +0 -11
  125. data/test/helper.rb +0 -99
  126. data/test/helpers/test_blogging.rb +0 -808
  127. data/test/helpers/test_breadcrumbs.rb +0 -83
  128. data/test/helpers/test_capturing.rb +0 -42
  129. data/test/helpers/test_filtering.rb +0 -108
  130. data/test/helpers/test_html_escape.rb +0 -18
  131. data/test/helpers/test_link_to.rb +0 -251
  132. data/test/helpers/test_rendering.rb +0 -109
  133. data/test/helpers/test_tagging.rb +0 -89
  134. data/test/helpers/test_text.rb +0 -26
  135. data/test/helpers/test_xml_sitemap.rb +0 -69
  136. data/test/tasks/test_clean.rb +0 -71
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'less'
4
-
5
3
  module Nanoc3::Filters
6
4
  class Less < Nanoc3::Filter
7
5
 
@@ -12,56 +10,9 @@ module Nanoc3::Filters
12
10
  #
13
11
  # @return [String] The filtered content
14
12
  def run(content, params={})
15
- # Find imports (hacky)
16
- imports = []
17
- imports.concat(content.scan(/^@import\s+(["'])([^\1]+?)\1;/))
18
- imports.concat(content.scan(/^@import\s+url\((["']?)([^)]+?)\1\);/))
19
- imported_filenames = imports.map do |i|
20
- i[1].match(/\.(less|css)$/) ? i[1] : i[1] + '.less'
21
- end
22
-
23
- # Convert to items
24
- imported_items = imported_filenames.map do |filename|
25
- # Find directory for this item
26
- current_dir_pathname = Pathname.new(@item[:content_filename]).dirname.realpath
27
-
28
- # Find absolute pathname for imported item
29
- imported_pathname = Pathname.new(filename)
30
- if imported_pathname.relative?
31
- imported_pathname = current_dir_pathname + imported_pathname
32
- end
33
- next if !imported_pathname.exist?
34
- imported_filename = imported_pathname.realpath
35
-
36
- # Find matching item
37
- @items.find do |i|
38
- next if i[:content_filename].nil?
39
- Pathname.new(i[:content_filename]).realpath == imported_filename
40
- end
41
- end.compact
42
-
43
- # Create dependencies
44
- depend_on(imported_items)
45
-
46
- # Add filename to load path
47
- paths = [ File.dirname(@item[:content_filename]) ]
48
- parser = ::Less::Parser.new(:paths => paths)
49
- parser.parse(content).to_css
50
- end
51
-
52
- # @todo Remove me in nanoc 3.2.x
53
- def depend_on(items)
54
- # Notify
55
- items.each do |item|
56
- Nanoc3::NotificationCenter.post(:visit_started, item)
57
- Nanoc3::NotificationCenter.post(:visit_ended, item)
58
- end
13
+ require 'less'
59
14
 
60
- # Raise unmet dependency error if necessary
61
- items.each do |item|
62
- rep = item.reps.find { |r| !r.compiled? }
63
- raise Nanoc3::Errors::UnmetDependency.new(rep) if rep
64
- end
15
+ ::Less::Engine.new(content).to_css
65
16
  end
66
17
 
67
18
  end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module Nanoc3::Filters
4
+ class Mustache < Nanoc3::Filter
5
+
6
+ # Runs the content through
7
+ # [Mustache](http://github.com/defunkt/mustache). This method takes no
8
+ # options.
9
+ #
10
+ # @param [String] content The content to filter
11
+ #
12
+ # @return [String] The filtered content
13
+ def run(content, params={})
14
+ require 'mustache'
15
+
16
+ # Get result
17
+ ::Mustache.render(content, item.attributes)
18
+ end
19
+
20
+ end
21
+ end
@@ -4,8 +4,7 @@ module Nanoc3::Filters
4
4
  class RDiscount < Nanoc3::Filter
5
5
 
6
6
  # Runs the content through [RDiscount](http://github.com/rtomayko/rdiscount).
7
- #
8
- # @option params [Array] symbol ([]) A list of RDiscount extensions
7
+ # This method takes no options.
9
8
  #
10
9
  # @param [String] content The content to filter
11
10
  #
@@ -14,7 +14,8 @@ module Nanoc3::Filters
14
14
  #
15
15
  # @param [String] content The content to filter
16
16
  #
17
- # @option params [Symbol] :type The type of content to filter; can be either `:html` or `:css`.
17
+ # @option params [Symbol] :type The type of content to filter; can be
18
+ # either `:html` or `:css`.
18
19
  #
19
20
  # @return [String] The filtered content
20
21
  def run(content, params={})
@@ -22,7 +23,7 @@ module Nanoc3::Filters
22
23
  @item_rep = assigns[:item_rep] if @item_rep.nil?
23
24
 
24
25
  # Filter
25
- # TODO use nokogiri or csspool instead of regular expressions
26
+ # FIXME use nokogiri or csspool instead of regular expressions
26
27
  case params[:type]
27
28
  when :html
28
29
  content.gsub(/(<[^>]+\s+(src|href))=(['"]?)(\/.*?)\3([ >])/) do
@@ -1,38 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'sass'
4
- require 'set'
5
-
6
3
  module Nanoc3::Filters
7
4
  class Sass < Nanoc3::Filter
8
5
 
9
- class << self
10
- # The current filter. This is definitely going to bite me if I ever get
11
- # to multithreading nanoc.
12
- attr_accessor :current
13
- end
14
-
15
- # Essentially the {Sass::Importers::Filesystem} but registering each
16
- # import file path.
17
- class SassFilesystemImporter < ::Sass::Importers::Filesystem
18
-
19
- private
20
-
21
- def _find(dir, name, options)
22
- full_filename, syntax = find_real_file(dir, name)
23
- return unless full_filename && File.readable?(full_filename)
24
-
25
- filter = Nanoc3::Filters::Sass.current
26
- item = filter.imported_filename_to_item(full_filename)
27
- filter.depend_on([ item ]) unless item.nil?
28
-
29
- options[:syntax] = syntax
30
- options[:filename] = full_filename
31
- options[:importer] = self
32
- ::Sass::Engine.new(File.read(full_filename), options)
33
- end
34
- end
35
-
36
6
  # Runs the content through [Sass](http://sass-lang.com/).
37
7
  # Parameters passed to this filter will be passed on to Sass.
38
8
  #
@@ -40,41 +10,65 @@ module Nanoc3::Filters
40
10
  #
41
11
  # @return [String] The filtered content
42
12
  def run(content, params={})
43
- # Build options
44
- options = params.dup
45
- sass_filename = options[:filename] ||
46
- (@item && @item[:content_filename])
47
- options[:filename] ||= sass_filename
48
- options[:filesystem_importer] ||=
49
- Nanoc3::Filters::Sass::SassFilesystemImporter
13
+ require 'sass'
14
+
15
+ # Add imported_filename read accessor to ImportNode
16
+ # but… but… nex3 said I could monkey patch it! :(
17
+ methods = ::Sass::Tree::ImportNode.instance_methods
18
+ if !methods.include?(:import_filename) && !methods.include?('import_filename')
19
+ ::Sass::Tree::ImportNode.send(:attr_reader, :imported_filename)
20
+ end
21
+
22
+ # Get options
23
+ options = params.merge(:filename => filename)
50
24
 
51
- # Render
25
+ # Build engine
52
26
  engine = ::Sass::Engine.new(content, options)
53
- self.class.current = self
54
- engine.render
55
- end
56
27
 
57
- def imported_filename_to_item(filename)
58
- path = Pathname.new(filename).realpath
59
- @items.find do |i|
60
- next if i[:content_filename].nil?
61
- Pathname.new(i[:content_filename]).realpath == path
28
+ # Get import nodes
29
+ require 'set'
30
+ imported_nodes = []
31
+ unprocessed_nodes = Set.new([ engine.to_tree ])
32
+ until unprocessed_nodes.empty?
33
+ # Get an unprocessed node
34
+ node = unprocessed_nodes.each { |n| break n }
35
+ unprocessed_nodes.delete(node)
36
+
37
+ # Add to list of import nodes if necessary
38
+ imported_nodes << node if node.is_a?(::Sass::Tree::ImportNode)
39
+
40
+ # Mark children of this node for processing
41
+ node.children.each { |c| unprocessed_nodes << c }
62
42
  end
63
- end
64
43
 
65
- # @todo Remove me in nanoc 3.2.x
66
- def depend_on(items)
67
- # Notify
68
- items.each do |item|
44
+ # Get import paths
45
+ import_paths = (options[:load_paths] || []).dup
46
+ import_paths.unshift(File.dirname(options[:filename])) if options[:filename]
47
+
48
+ # Get imported filenames
49
+ imported_filenames = imported_nodes.map do |node|
50
+ ::Sass::Files.find_file_to_import(node.imported_filename, import_paths)
51
+ end
52
+
53
+ # Convert to items
54
+ imported_items = imported_filenames.map do |filename|
55
+ normalized_filename = Pathname.new(filename).realpath
56
+ @items.find { |i| i[:filename] && Pathname.new(i[:filename]).realpath == normalized_filename }
57
+ end.compact
58
+
59
+ # Require compilation of each item
60
+ imported_items.each do |item|
61
+ # Notify
69
62
  Nanoc3::NotificationCenter.post(:visit_started, item)
70
63
  Nanoc3::NotificationCenter.post(:visit_ended, item)
71
- end
72
64
 
73
- # Raise unmet dependency error if necessary
74
- items.each do |item|
75
- rep = item.reps.find { |r| !r.compiled? }
76
- raise Nanoc3::Errors::UnmetDependency.new(rep) if rep
65
+ # Raise unmet dependency error if item is not yet compiled
66
+ any_uncompiled_rep = item.reps.find { |r| !r.compiled? }
67
+ raise Nanoc3::Errors::UnmetDependency.new(any_uncompiled_rep) if any_uncompiled_rep
77
68
  end
69
+
70
+ # Done
71
+ engine.render
78
72
  end
79
73
 
80
74
  end
@@ -12,6 +12,7 @@ module Nanoc3::Filters
12
12
  autoload 'Less', 'nanoc3/filters/less'
13
13
  autoload 'Markaby', 'nanoc3/filters/markaby'
14
14
  autoload 'Maruku', 'nanoc3/filters/maruku'
15
+ autoload 'Mustache', 'nanoc3/filters/mustache'
15
16
  autoload 'Rainpress', 'nanoc3/filters/rainpress'
16
17
  autoload 'RDiscount', 'nanoc3/filters/rdiscount'
17
18
  autoload 'RDoc', 'nanoc3/filters/rdoc'
@@ -30,6 +31,7 @@ module Nanoc3::Filters
30
31
  Nanoc3::Filter.register '::Nanoc3::Filters::Less', :less
31
32
  Nanoc3::Filter.register '::Nanoc3::Filters::Markaby', :markaby
32
33
  Nanoc3::Filter.register '::Nanoc3::Filters::Maruku', :maruku
34
+ Nanoc3::Filter.register '::Nanoc3::Filters::Mustache', :mustache
33
35
  Nanoc3::Filter.register '::Nanoc3::Filters::Rainpress', :rainpress
34
36
  Nanoc3::Filter.register '::Nanoc3::Filters::RDiscount', :rdiscount
35
37
  Nanoc3::Filter.register '::Nanoc3::Filters::RDoc', :rdoc
@@ -39,7 +39,8 @@ module Nanoc3::Helpers
39
39
  def sorted_articles
40
40
  require 'time'
41
41
  articles.sort_by do |a|
42
- attribute_to_time(a[:created_at])
42
+ time = a[:created_at]
43
+ time.is_a?(String) ? Time.parse(time) : time
43
44
  end.reverse
44
45
  end
45
46
 
@@ -119,28 +120,28 @@ module Nanoc3::Helpers
119
120
  # <%= atom_feed :limit => 5 %>
120
121
  #
121
122
  # @option params [Number] :limit (5) The maximum number of articles to
122
- # show
123
+ # show
123
124
  #
124
125
  # @option params [Array] :articles (sorted_articles) A list of articles to
125
- # include in the feed
126
+ # include in the feed
126
127
  #
127
128
  # @option params [Proc] :content_proc (->{ |article|
128
- # article.compiled_content(:snapshot => :pre) }) A proc that returns the
129
- # content of the given article, which is passed as a parameter. This
130
- # function may not return nil.
129
+ # article.compiled_content(:snapshot => :pre) }) A proc that returns the
130
+ # content of the given article, which is passed as a parameter. This
131
+ # function may not return nil.
131
132
  #
132
133
  # @option params [proc] :excerpt_proc (->{ |article| article[:excerpt] })
133
- # A proc that returns the excerpt of the given article, passed as a
134
- # parameter. This function should return nil if there is no excerpt.
134
+ # A proc that returns the excerpt of the given article, passed as a
135
+ # parameter. This function should return nil if there is no excerpt.
135
136
  #
136
137
  # @option params [String] :title The feed’s title, if it is not given in
137
- # the item attributes.
138
+ # the item attributes.
138
139
  #
139
140
  # @option params [String] :author_name The name of the feed’s author, if
140
- # it is not given in the item attributes.
141
+ # it is not given in the item attributes.
141
142
  #
142
143
  # @option params [String] :author_uri The URI of the feed’s author, if it
143
- # is not given in the item attributes.
144
+ # is not given in the item attributes.
144
145
  #
145
146
  # @return [String] The generated feed content
146
147
  def atom_feed(params={})
@@ -182,7 +183,8 @@ module Nanoc3::Helpers
182
183
 
183
184
  # Get sorted relevant articles
184
185
  sorted_relevant_articles = relevant_articles.sort_by do |a|
185
- attribute_to_time(a[:created_at])
186
+ time = a[:created_at]
187
+ time.is_a?(String) ? Time.parse(time) : time
186
188
  end.reverse.first(limit)
187
189
 
188
190
  # Get most recent article
@@ -202,7 +204,8 @@ module Nanoc3::Helpers
202
204
  xml.title title
203
205
 
204
206
  # Add date
205
- xml.updated(attribute_to_time(last_article[:created_at]).to_iso8601_time)
207
+ time = last_article[:created_at]
208
+ xml.updated((time.is_a?(String) ? Time.parse(time) : time).to_iso8601_time)
206
209
 
207
210
  # Add links
208
211
  xml.link(:rel => 'alternate', :href => root_url)
@@ -226,8 +229,10 @@ module Nanoc3::Helpers
226
229
  xml.title a[:title], :type => 'html'
227
230
 
228
231
  # Add dates
229
- xml.published attribute_to_time(a[:created_at]).to_iso8601_time
230
- xml.updated attribute_to_time(a[:updated_at] || a[:created_at]).to_iso8601_time
232
+ create_time = a[:created_at]
233
+ update_time = a[:updated_at] || a[:created_at]
234
+ xml.published((create_time.is_a?(String) ? Time.parse(create_time) : create_time).to_iso8601_time)
235
+ xml.updated( (update_time.is_a?(String) ? Time.parse(update_time) : update_time).to_iso8601_time)
231
236
 
232
237
  # Add link
233
238
  xml.link(:rel => 'alternate', :href => url)
@@ -292,24 +297,12 @@ module Nanoc3::Helpers
292
297
 
293
298
  hostname, base_dir = %r{^.+?://([^/]+)(.*)$}.match(@site.config[:base_url])[1..2]
294
299
 
295
- formatted_date = attribute_to_time(item[:created_at]).to_iso8601_date
300
+ time = item[:created_at]
301
+ formatted_date = (time.is_a?(String) ? Time.parse(time) : time).to_iso8601_date
296
302
 
297
303
  'tag:' + hostname + ',' + formatted_date + ':' + base_dir + (item.path || item.identifier)
298
304
  end
299
305
 
300
- # Converts the given attribute (which can be a string, a Time or a Date)
301
- # into a Time.
302
- #
303
- # @param [String, Time, Date] time Something that contains time
304
- # information but is not necessarily a Time instance yet
305
- #
306
- # @return [Time] The Time instance corresponding to the given input
307
- def attribute_to_time(time)
308
- time = Time.local(time.year, time.month, time.day) if time.is_a?(Date)
309
- time = Time.parse(time) if time.is_a?(String)
310
- time
311
- end
312
-
313
306
  end
314
307
 
315
308
  end
@@ -13,7 +13,7 @@ module Nanoc3::Helpers
13
13
  # will contain a `nil` element.
14
14
  #
15
15
  # @return [Array] The breadcrumbs, starting with the root item and ending
16
- # with the item itself
16
+ # with the item itself
17
17
  def breadcrumbs_trail
18
18
  breadcrumbs_for_identifier(@item.identifier)
19
19
  end
@@ -31,7 +31,7 @@ module Nanoc3::Helpers
31
31
  # content of the block itself will not be outputted.
32
32
  #
33
33
  # @param [Symbol, String] The base name of the attribute into which the
34
- # content should be stored
34
+ # content should be stored
35
35
  #
36
36
  # @return [void]
37
37
  def content_for(name, &block)
@@ -23,7 +23,7 @@ module Nanoc3::Helpers
23
23
  # <% end %>
24
24
  #
25
25
  # @param [Symbol] filter_name The name of the filter to run on the
26
- # contents of the block
26
+ # contents of the block
27
27
  #
28
28
  # @param [Hash] argument Arguments to pass to the filter
29
29
  #
@@ -17,10 +17,10 @@ module Nanoc3::Helpers
17
17
  # @param [String] text The visible link text
18
18
  #
19
19
  # @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
20
- # item or item representation that should be linked to
20
+ # item or item representation that should be linked to
21
21
  #
22
22
  # @param [Hash] attributes A hash containing HTML attributes (e.g.
23
- # `rel`, `title`, …) that will be added to the link.
23
+ # `rel`, `title`, …) that will be added to the link.
24
24
  #
25
25
  # @return [String] The link text
26
26
  #
@@ -47,12 +47,7 @@ module Nanoc3::Helpers
47
47
  # # => '<a title="My super cool blog" href="/blog/">Blog</a>'
48
48
  def link_to(text, target, attributes={})
49
49
  # Find path
50
- if target.is_a?(String)
51
- path = target
52
- else
53
- path = target.path
54
- raise RuntimeError, "Cannot create a link to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil?
55
- end
50
+ path = target.is_a?(String) ? target : target.path
56
51
 
57
52
  # Join attributes
58
53
  attributes = attributes.inject('') do |memo, (key, value)|
@@ -71,10 +66,10 @@ module Nanoc3::Helpers
71
66
  # @param [String] text The visible link text
72
67
  #
73
68
  # @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
74
- # item or item representation that should be linked to
69
+ # item or item representation that should be linked to
75
70
  #
76
71
  # @param [Hash] attributes A hash containing HTML attributes (e.g.
77
- # `rel`, `title`, …) that will be added to the link.
72
+ # `rel`, `title`, …) that will be added to the link.
78
73
  #
79
74
  # @return [String] The link text
80
75
  #
@@ -103,8 +98,8 @@ module Nanoc3::Helpers
103
98
  # item representation. The returned path will not be HTML-escaped.
104
99
  #
105
100
  # @param [String, Nanoc3::Item, Nanoc3::ItemRep] target The path/URL,
106
- # item or item representation to which the relative path should be
107
- # generated
101
+ # item or item representation to which the relative path should be
102
+ # generated
108
103
  #
109
104
  # @return [String] The relative path to the target
110
105
  #
@@ -117,20 +112,14 @@ module Nanoc3::Helpers
117
112
  require 'pathname'
118
113
 
119
114
  # Find path
120
- if target.is_a?(String)
121
- path = target
122
- else
123
- path = target.path
124
- raise RuntimeError, "Cannot get the relative path to #{target.inspect} because this target is not outputted (its routing rule returns nil)" if path.nil?
125
- end
115
+ path = target.is_a?(String) ? target : target.path
126
116
 
127
117
  # Get source and destination paths
128
118
  dst_path = Pathname.new(path)
129
- raise RuntimeError, "Cannot get the relative path to #{path} because the current item representation, #{@item_rep.inspect}, is not outputted (its routing rule returns nil)" if @item_rep.path.nil?
130
119
  src_path = Pathname.new(@item_rep.path)
131
120
 
132
- # Calculate the relative path (method depends on whether destination is
133
- # a directory or not).
121
+ # Calculate elative path (method depends on whether destination is a
122
+ # directory or not).
134
123
  if src_path.to_s[-1,1] != '/'
135
124
  relative_path = dst_path.relative_path_from(src_path.dirname).to_s
136
125
  else
@@ -7,18 +7,7 @@ module Nanoc3::Helpers
7
7
 
8
8
  include Nanoc3::Helpers::Capturing
9
9
 
10
- # Returns a string containing the rendered given layout. The given layout
11
- # will first be run through the matching layout rule.
12
- #
13
- # The assigns (`@item`, `@config`, …) will not be available in the
14
- # partial, but it is possible to pass custom assigns to the method. These
15
- # assigns will be made available as instance variables inside the partial.
16
- #
17
- # The method can also take a block. In this case, the content of the block
18
- # will be captured (using the {Nanoc3::Helpers::Capturing} helper) and
19
- # this content will be made available with `yield`. In other words, a
20
- # `yield` inside the partial will output the content of the block passed
21
- # to the method.
10
+ # Returns a string containing the rendered given layout.
22
11
  #
23
12
  # @param [String] identifier The identifier of the layout that should be
24
13
  # rendered
@@ -40,18 +29,6 @@ module Nanoc3::Helpers
40
29
  # <%= render 'head', :title => 'Foo' %>
41
30
  # # => "<h1>Foo</h1>"
42
31
  #
43
- # @example Yielding inside a partial
44
- #
45
- # # The 'box' partial
46
- # <div class="box">
47
- # <%= yield %>
48
- # </div>
49
- #
50
- # # The item/layout where the partial is rendered
51
- # <% render 'box' do %>
52
- # I'm boxy! Luvz!
53
- # <% end %>
54
- #
55
32
  # @raise [Nanoc3::Errors::UnknownLayout] if the given layout does not
56
33
  # exist
57
34
  #
@@ -61,6 +38,10 @@ module Nanoc3::Helpers
61
38
  layout = @site.layouts.find { |l| l.identifier == identifier.cleaned_identifier }
62
39
  raise Nanoc3::Errors::UnknownLayout.new(identifier.cleaned_identifier) if layout.nil?
63
40
 
41
+ # Visit
42
+ Nanoc3::NotificationCenter.post(:visit_started, layout)
43
+ Nanoc3::NotificationCenter.post(:visit_ended, layout)
44
+
64
45
  # Capture content, if any
65
46
  captured_content = block_given? ? capture(&block) : nil
66
47
 
@@ -20,14 +20,14 @@ module Nanoc3::Helpers
20
20
  # HTML-escaping rules for {#link_for_tag} apply here as well.
21
21
  #
22
22
  # @option params [String] base_url ("http://technorati.com/tag/") The URL
23
- # to which the tag will be appended to construct the link URL. This URL
24
- # must have a trailing slash.
23
+ # to which the tag will be appended to construct the link URL. This URL
24
+ # must have a trailing slash.
25
25
  #
26
26
  # @option params [String] none_text ("(none)") The text to display when
27
- # the item has no tags
27
+ # the item has no tags
28
28
  #
29
29
  # @option params [String] separator (", ") The separator to put between
30
- # tags
30
+ # tags
31
31
  #
32
32
  # @return [String] A hyperlinked list of tags for the given item
33
33
  def tags_for(item, params={})
@@ -56,10 +56,10 @@ module Nanoc3::Helpers
56
56
  # escaped, as will the content of the `a` element.
57
57
  #
58
58
  # @param [String] tag The name of the tag, which should consist of letters
59
- # and numbers (no spaces, slashes, or other special characters).
59
+ # and numbers (no spaces, slashes, or other special characters).
60
60
  #
61
61
  # @param [String] base_url The URL to which the tag will be appended to
62
- # construct the link URL. This URL must have a trailing slash.
62
+ # construct the link URL. This URL must have a trailing slash.
63
63
  #
64
64
  # @return [String] A link for the given tag and the given base URL
65
65
  def link_for_tag(tag, base_url)
@@ -12,10 +12,10 @@ module Nanoc3::Helpers
12
12
  # @param [String] string The string for which to build an excerpt
13
13
  #
14
14
  # @option params [Number] length (25) The maximum number of characters
15
- # this excerpt can contain, including the omission.
15
+ # this excerpt can contain, including the omission.
16
16
  #
17
17
  # @option params [String] omission ("...") The string to append to the
18
- # excerpt when the excerpt is shorter than the original string
18
+ # excerpt when the excerpt is shorter than the original string
19
19
  #
20
20
  # @return [String] The excerpt of the given string
21
21
  def excerptize(string, params={})
data/lib/nanoc3.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Nanoc3
4
4
 
5
5
  # The current nanoc version.
6
- VERSION = '3.1.9'
6
+ VERSION = '3.2.0a1'
7
7
 
8
8
  end
9
9