nanoc3 3.2.0a3 → 3.2.0a4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.gemtest +0 -0
  2. data/LICENSE +1 -1
  3. data/NEWS.md +23 -4
  4. data/README.md +7 -0
  5. data/lib/nanoc3/base/compilation/checksum_store.rb +17 -90
  6. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +5 -0
  7. data/lib/nanoc3/base/compilation/compiler.rb +112 -175
  8. data/lib/nanoc3/base/compilation/compiler_dsl.rb +54 -11
  9. data/lib/nanoc3/base/compilation/dependency_tracker.rb +32 -65
  10. data/lib/nanoc3/base/compilation/filter.rb +4 -3
  11. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +19 -4
  12. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +90 -0
  13. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +152 -15
  14. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +12 -9
  15. data/lib/nanoc3/base/compilation/rule.rb +3 -1
  16. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +42 -0
  17. data/lib/nanoc3/base/compilation/rule_memory_store.rb +53 -0
  18. data/lib/nanoc3/base/compilation/rules_collection.rb +205 -0
  19. data/lib/nanoc3/base/core_ext/array.rb +20 -0
  20. data/lib/nanoc3/base/core_ext/hash.rb +30 -0
  21. data/lib/nanoc3/base/core_ext/pathname.rb +26 -0
  22. data/lib/nanoc3/base/core_ext/string.rb +12 -0
  23. data/lib/nanoc3/base/core_ext.rb +1 -0
  24. data/lib/nanoc3/base/directed_graph.rb +11 -3
  25. data/lib/nanoc3/base/errors.rb +0 -4
  26. data/lib/nanoc3/base/memoization.rb +72 -0
  27. data/lib/nanoc3/base/result_data/item_rep.rb +64 -25
  28. data/lib/nanoc3/base/source_data/code_snippet.rb +9 -0
  29. data/lib/nanoc3/base/source_data/configuration.rb +20 -0
  30. data/lib/nanoc3/base/source_data/item.rb +29 -4
  31. data/lib/nanoc3/base/source_data/layout.rb +20 -1
  32. data/lib/nanoc3/base/source_data/site.rb +49 -26
  33. data/lib/nanoc3/base/store.rb +10 -1
  34. data/lib/nanoc3/base.rb +6 -1
  35. data/lib/nanoc3/cli/base.rb +20 -7
  36. data/lib/nanoc3/cli/commands/compile.rb +0 -2
  37. data/lib/nanoc3/cli/commands/create_site.rb +16 -7
  38. data/lib/nanoc3/cli/commands/debug.rb +3 -3
  39. data/lib/nanoc3/cli/commands/view.rb +1 -0
  40. data/lib/nanoc3/cli/commands/watch.rb +2 -1
  41. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -2
  42. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -2
  43. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -2
  44. data/lib/nanoc3/data_sources/filesystem.rb +17 -3
  45. data/lib/nanoc3/data_sources/filesystem_unified.rb +17 -17
  46. data/lib/nanoc3/extra/auto_compiler.rb +5 -1
  47. data/lib/nanoc3/extra/core_ext/time.rb +1 -1
  48. data/lib/nanoc3/extra/file_proxy.rb +11 -1
  49. data/lib/nanoc3/extra/validators/links.rb +1 -1
  50. data/lib/nanoc3/filters/asciidoc.rb +3 -3
  51. data/lib/nanoc3/filters/colorize_syntax.rb +106 -27
  52. data/lib/nanoc3/filters/erb.rb +16 -6
  53. data/lib/nanoc3/filters/erubis.rb +5 -1
  54. data/lib/nanoc3/filters/haml.rb +2 -1
  55. data/lib/nanoc3/filters/less.rb +3 -6
  56. data/lib/nanoc3/filters/mustache.rb +3 -0
  57. data/lib/nanoc3/filters/redcarpet.rb +27 -0
  58. data/lib/nanoc3/filters/sass.rb +1 -5
  59. data/lib/nanoc3/filters/slim.rb +25 -0
  60. data/lib/nanoc3/filters/typogruby.rb +23 -0
  61. data/lib/nanoc3/filters.rb +6 -0
  62. data/lib/nanoc3/helpers/blogging.rb +22 -26
  63. data/lib/nanoc3/helpers/rendering.rb +1 -1
  64. data/lib/nanoc3/helpers/xml_sitemap.rb +11 -2
  65. data/lib/nanoc3.rb +24 -3
  66. data/nanoc3.gemspec +4 -3
  67. data/tasks/clean.rake +11 -0
  68. data/tasks/doc.rake +14 -0
  69. data/tasks/test.rake +38 -0
  70. data/test/base/core_ext/array_spec.rb +55 -0
  71. data/test/base/core_ext/hash_spec.rb +82 -0
  72. data/test/base/core_ext/pathname_spec.rb +29 -0
  73. data/test/base/core_ext/string_spec.rb +39 -0
  74. data/test/base/test_checksum_store.rb +37 -0
  75. data/test/base/test_code_snippet.rb +33 -0
  76. data/test/base/test_compiler.rb +303 -0
  77. data/test/base/test_compiler_dsl.rb +156 -0
  78. data/test/base/test_context.rb +33 -0
  79. data/test/base/test_data_source.rb +48 -0
  80. data/test/base/test_dependency_tracker.rb +264 -0
  81. data/test/base/test_directed_graph.rb +285 -0
  82. data/test/base/test_filter.rb +85 -0
  83. data/test/base/test_item.rb +164 -0
  84. data/test/base/test_item_rep.rb +555 -0
  85. data/test/base/test_layout.rb +44 -0
  86. data/test/base/test_memoization.rb +53 -0
  87. data/test/base/test_notification_center.rb +36 -0
  88. data/test/base/test_outdatedness_checker.rb +365 -0
  89. data/test/base/test_plugin.rb +32 -0
  90. data/test/base/test_rule.rb +21 -0
  91. data/test/base/test_rule_context.rb +67 -0
  92. data/test/base/test_site.rb +144 -0
  93. data/test/cli/commands/test_compile.rb +12 -0
  94. data/test/cli/commands/test_create_item.rb +12 -0
  95. data/test/cli/commands/test_create_layout.rb +28 -0
  96. data/test/cli/commands/test_create_site.rb +24 -0
  97. data/test/cli/commands/test_help.rb +12 -0
  98. data/test/cli/commands/test_info.rb +12 -0
  99. data/test/cli/commands/test_update.rb +12 -0
  100. data/test/cli/test_logger.rb +12 -0
  101. data/test/data_sources/test_filesystem.rb +420 -0
  102. data/test/data_sources/test_filesystem_unified.rb +562 -0
  103. data/test/data_sources/test_filesystem_verbose.rb +359 -0
  104. data/test/extra/core_ext/test_enumerable.rb +32 -0
  105. data/test/extra/core_ext/test_time.rb +17 -0
  106. data/test/extra/deployers/test_rsync.rb +234 -0
  107. data/test/extra/test_auto_compiler.rb +417 -0
  108. data/test/extra/test_file_proxy.rb +21 -0
  109. data/test/extra/test_vcs.rb +24 -0
  110. data/test/extra/validators/test_links.rb +53 -0
  111. data/test/extra/validators/test_w3c.rb +49 -0
  112. data/test/filters/test_asciidoc.rb +22 -0
  113. data/test/filters/test_bluecloth.rb +20 -0
  114. data/test/filters/test_coderay.rb +46 -0
  115. data/test/filters/test_colorize_syntax.rb +149 -0
  116. data/test/filters/test_erb.rb +101 -0
  117. data/test/filters/test_erubis.rb +72 -0
  118. data/test/filters/test_haml.rb +98 -0
  119. data/test/filters/test_kramdown.rb +20 -0
  120. data/test/filters/test_less.rb +59 -0
  121. data/test/filters/test_markaby.rb +26 -0
  122. data/test/filters/test_maruku.rb +20 -0
  123. data/test/filters/test_mustache.rb +27 -0
  124. data/test/filters/test_rainpress.rb +31 -0
  125. data/test/filters/test_rdiscount.rb +33 -0
  126. data/test/filters/test_rdoc.rb +18 -0
  127. data/test/filters/test_redcarpet.rb +63 -0
  128. data/test/filters/test_redcloth.rb +35 -0
  129. data/test/filters/test_relativize_paths.rb +231 -0
  130. data/test/filters/test_rubypants.rb +20 -0
  131. data/test/filters/test_sass.rb +103 -0
  132. data/test/filters/test_slim.rb +37 -0
  133. data/test/filters/test_typogruby.rb +23 -0
  134. data/test/helper.rb +161 -0
  135. data/test/helpers/test_blogging.rb +756 -0
  136. data/test/helpers/test_breadcrumbs.rb +83 -0
  137. data/test/helpers/test_capturing.rb +43 -0
  138. data/test/helpers/test_filtering.rb +108 -0
  139. data/test/helpers/test_html_escape.rb +34 -0
  140. data/test/helpers/test_link_to.rb +251 -0
  141. data/test/helpers/test_rendering.rb +90 -0
  142. data/test/helpers/test_tagging.rb +89 -0
  143. data/test/helpers/test_text.rb +26 -0
  144. data/test/helpers/test_xml_sitemap.rb +105 -0
  145. data/test/tasks/test_clean.rb +69 -0
  146. metadata +96 -27
  147. data/lib/nanoc3/base/compilation/checksummer.rb +0 -68
@@ -17,10 +17,13 @@ module Nanoc3::Filters
17
17
  autoload 'Rainpress', 'nanoc3/filters/rainpress'
18
18
  autoload 'RDiscount', 'nanoc3/filters/rdiscount'
19
19
  autoload 'RDoc', 'nanoc3/filters/rdoc'
20
+ autoload 'Redcarpet', 'nanoc3/filters/redcarpet'
20
21
  autoload 'RedCloth', 'nanoc3/filters/redcloth'
21
22
  autoload 'RelativizePaths', 'nanoc3/filters/relativize_paths'
22
23
  autoload 'RubyPants', 'nanoc3/filters/rubypants'
23
24
  autoload 'Sass', 'nanoc3/filters/sass'
25
+ autoload 'Slim', 'nanoc3/filters/slim'
26
+ autoload 'Typogruby', 'nanoc3/filters/typogruby'
24
27
 
25
28
  Nanoc3::Filter.register '::Nanoc3::Filters::AsciiDoc', :asciidoc
26
29
  Nanoc3::Filter.register '::Nanoc3::Filters::BlueCloth', :bluecloth
@@ -37,9 +40,12 @@ module Nanoc3::Filters
37
40
  Nanoc3::Filter.register '::Nanoc3::Filters::Rainpress', :rainpress
38
41
  Nanoc3::Filter.register '::Nanoc3::Filters::RDiscount', :rdiscount
39
42
  Nanoc3::Filter.register '::Nanoc3::Filters::RDoc', :rdoc
43
+ Nanoc3::Filter.register '::Nanoc3::Filters::Redcarpet', :redcarpet
40
44
  Nanoc3::Filter.register '::Nanoc3::Filters::RedCloth', :redcloth
41
45
  Nanoc3::Filter.register '::Nanoc3::Filters::RelativizePaths', :relativize_paths
42
46
  Nanoc3::Filter.register '::Nanoc3::Filters::RubyPants', :rubypants
43
47
  Nanoc3::Filter.register '::Nanoc3::Filters::Sass', :sass
48
+ Nanoc3::Filter.register '::Nanoc3::Filters::Slim', :slim
49
+ Nanoc3::Filter.register '::Nanoc3::Filters::Typogruby', :typogruby
44
50
 
45
51
  end
@@ -8,15 +8,15 @@ module Nanoc3::Helpers
8
8
  # This helper has a few requirements. First, all blog articles should have
9
9
  # the following attributes:
10
10
  #
11
- # * `kind` Set to `"article"`
11
+ # * `kind` - Set to `"article"`
12
12
  #
13
- # * `created_at` The articles publication timestamp
13
+ # * `created_at` - The article's publication timestamp
14
14
  #
15
15
  # Some functions in this blogging helper, such as the {#atom_feed} function,
16
16
  # require additional attributes to be set; these attributes are described in
17
17
  # the documentation for these functions.
18
18
  #
19
- # All time item attributes, site configuration attributes or method
19
+ # All "time" item attributes, site configuration attributes or method
20
20
  # parameters can either be a `Time` instance or a string in any format
21
21
  # parseable by `Time.parse`.
22
22
  #
@@ -37,7 +37,6 @@ module Nanoc3::Helpers
37
37
  #
38
38
  # @return [Array] A sorted array containing all articles
39
39
  def sorted_articles
40
- require 'time'
41
40
  articles.sort_by do |a|
42
41
  attribute_to_time(a[:created_at])
43
42
  end.reverse
@@ -48,53 +47,53 @@ module Nanoc3::Helpers
48
47
  #
49
48
  # The following attributes must be set on blog articles:
50
49
  #
51
- # * `title` The title of the blog post
50
+ # * `title` - The title of the blog post
52
51
  #
53
52
  # * `kind` and `created_at` (described above)
54
53
  #
55
54
  # The following attributes can optionally be set on blog articles to
56
55
  # change the behaviour of the Atom feed:
57
56
  #
58
- # * `excerpt` An excerpt of the article, which is usually only a few
57
+ # * `excerpt` - An excerpt of the article, which is usually only a few
59
58
  # lines long.
60
59
  #
61
- # * `custom_path_in_feed` The path that will be used instead of the
60
+ # * `custom_path_in_feed` - The path that will be used instead of the
62
61
  # normal path in the feed. This can be useful when including
63
62
  # non-outputted items in a feed; such items could have their custom feed
64
63
  # path set to the blog path instead, for example.
65
64
  #
66
- # * `custom_url_in_feed` The url that will be used instead of the
67
- # normal url in the feed (generated from the sites base url + the item
68
- # reps path). This can be useful when building a link-blog where the
65
+ # * `custom_url_in_feed` - The url that will be used instead of the
66
+ # normal url in the feed (generated from the site's base url + the item
67
+ # rep's path). This can be useful when building a link-blog where the
69
68
  # URL of article is a remote location.
70
69
  #
71
- # * `updated_at` The time when the article was last modified. If this
70
+ # * `updated_at` - The time when the article was last modified. If this
72
71
  # attribute is not present, the `created_at` attribute will be used as
73
72
  # the time when the article was last modified.
74
73
  #
75
74
  # The site configuration will need to have the following attributes:
76
75
  #
77
- # * `base_url` The URL to the site, without trailing slash. For
78
- # example, if the site is at http://example.com/”, the `base_url`
79
- # would be http://example.com”.
76
+ # * `base_url` - The URL to the site, without trailing slash. For
77
+ # example, if the site is at "http://example.com/", the `base_url`
78
+ # would be "http://example.com".
80
79
  #
81
80
  # The feed item will need to know about the feed title, the feed author
82
81
  # name, and the URI corresponding to the author. These can be specified
83
82
  # using parameters, as attributes in the feed item, or in the site
84
83
  # configuration.
85
84
  #
86
- # * `title` — The title of the feed, which is usually also the title of
85
+ # * `title` - The title of the feed, which is usually also the title of
87
86
  # the blog.
88
87
  #
89
- # * `author_name` The name of the items author.
88
+ # * `author_name` - The name of the item's author.
90
89
  #
91
- # * `author_uri` The URI for the items author, such as the authors
90
+ # * `author_uri` - The URI for the item's author, such as the author's
92
91
  # web site URL.
93
92
  #
94
93
  # The feed item can have the following optional attributes:
95
94
  #
96
- # * `feed_url` The custom URL of the feed. This can be useful when the
97
- # private feed URL shouldnt be exposed; for example, when using
95
+ # * `feed_url` - The custom URL of the feed. This can be useful when the
96
+ # private feed URL shouldn't be exposed; for example, when using
98
97
  # FeedBurner this would be set to the public FeedBurner URL.
99
98
  #
100
99
  # To construct a feed, create a new item and make sure that it is
@@ -133,19 +132,18 @@ module Nanoc3::Helpers
133
132
  # A proc that returns the excerpt of the given article, passed as a
134
133
  # parameter. This function should return nil if there is no excerpt.
135
134
  #
136
- # @option params [String] :title The feeds title, if it is not given in
135
+ # @option params [String] :title The feed's title, if it is not given in
137
136
  # the item attributes.
138
137
  #
139
- # @option params [String] :author_name The name of the feeds author, if
138
+ # @option params [String] :author_name The name of the feed's author, if
140
139
  # it is not given in the item attributes.
141
140
  #
142
- # @option params [String] :author_uri The URI of the feeds author, if it
141
+ # @option params [String] :author_uri The URI of the feed's author, if it
143
142
  # is not given in the item attributes.
144
143
  #
145
144
  # @return [String] The generated feed content
146
145
  def atom_feed(params={})
147
146
  require 'builder'
148
- require 'time'
149
147
 
150
148
  # Extract parameters
151
149
  limit = params[:limit] || 5
@@ -289,15 +287,13 @@ module Nanoc3::Helpers
289
287
  # Returns an URI containing an unique ID for the given item. This will be
290
288
  # used in the Atom feed to uniquely identify articles. These IDs are
291
289
  # created using a procedure suggested by Mark Pilgrim and described in his
292
- # [How to make a good ID in Atom blog post]
290
+ # ["How to make a good ID in Atom" blog post]
293
291
  # (http://diveintomark.org/archives/2004/05/28/howto-atom-id).
294
292
  #
295
293
  # @param [Nanoc3::Item] item The item for which to create an atom tag
296
294
  #
297
295
  # @return [String] The atom tag for the given item
298
296
  def atom_tag_for(item)
299
- require 'time'
300
-
301
297
  hostname, base_dir = %r{^.+?://([^/]+)(.*)$}.match(@site.config[:base_url])[1..2]
302
298
 
303
299
  formatted_date = attribute_to_time(item[:created_at]).to_iso8601_date
@@ -81,7 +81,7 @@ module Nanoc3::Helpers
81
81
  }.merge(other_assigns)
82
82
 
83
83
  # Get filter name
84
- filter_name, filter_args = @site.compiler.filter_for_layout(layout)
84
+ filter_name, filter_args = @site.compiler.rules_collection.filter_for_layout(layout)
85
85
  raise Nanoc3::Errors::CannotDetermineFilter.new(layout.identifier) if filter_name.nil?
86
86
 
87
87
  # Get filter class
@@ -29,10 +29,19 @@ module Nanoc3::Helpers
29
29
  # if the site is at "http://example.com/", the `base_url` would be
30
30
  # "http://example.com".
31
31
  #
32
+ # @example Excluding binary items from the sitemap
33
+ #
34
+ # <%= xml_sitemap :items => @items.reject{ |i| i[:is_hidden] || i[:binary] } %>
35
+ #
36
+ # @option params [Array] :items A list of items to include in the sitemap
37
+ #
32
38
  # @return [String] The XML sitemap
33
- def xml_sitemap
39
+ def xml_sitemap(params={})
34
40
  require 'builder'
35
41
 
42
+ # Extract parameters
43
+ items = params[:items] || @items.reject { |i| i[:is_hidden] }
44
+
36
45
  # Create builder
37
46
  buffer = ''
38
47
  xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
@@ -46,7 +55,7 @@ module Nanoc3::Helpers
46
55
  xml.instruct!
47
56
  xml.urlset(:xmlns => 'http://www.google.com/schemas/sitemap/0.84') do
48
57
  # Add item
49
- @items.reject { |i| i[:is_hidden] }.each do |item|
58
+ items.each do |item|
50
59
  item.reps.reject { |r| r.raw_path.nil? }.each do |rep|
51
60
  xml.url do
52
61
  xml.loc @site.config[:base_url] + rep.path
data/lib/nanoc3.rb CHANGED
@@ -3,13 +3,34 @@
3
3
  module Nanoc3
4
4
 
5
5
  # The current nanoc version.
6
- VERSION = '3.2.0a3'
6
+ VERSION = '3.2.0a4'
7
7
 
8
8
  end
9
9
 
10
- # Load requirements
11
- require 'yaml'
10
+ # Switch #require for a faster variant
11
+ require 'set'
12
+ $_nanoc_requires ||= Set.new
13
+ module Kernel
14
+ alias_method :nanoc_original_require, :require
15
+ def require(r)
16
+ return if $_nanoc_requires.include?(r)
17
+ nanoc_original_require(r)
18
+ $_nanoc_requires << r
19
+ end
20
+ end
21
+
22
+ # Load general requirements
23
+ require 'digest'
24
+ require 'enumerator'
12
25
  require 'fileutils'
26
+ require 'forwardable'
27
+ require 'pathname'
28
+ require 'pstore'
29
+ require 'set'
30
+ require 'tempfile'
31
+ require 'thread'
32
+ require 'time'
33
+ require 'yaml'
13
34
 
14
35
  # Load nanoc
15
36
  require 'nanoc3/base'
data/nanoc3.gemspec CHANGED
@@ -13,12 +13,13 @@ Gem::Specification.new do |s|
13
13
  s.author = 'Denis Defreyne'
14
14
  s.email = 'denis.defreyne@stoneship.org'
15
15
 
16
- s.files = Dir['[A-Z]*'] + Dir['lib/**/*'] + Dir['doc/yardoc_templates/**/*'] + [ 'nanoc3.gemspec' ]
17
- s.default_executable = 'nanoc3'
16
+ s.files = Dir['[A-Z]*'] +
17
+ Dir['doc/yardoc_templates/**/*'] +
18
+ Dir['{bin,lib,tasks,test}/**/*'] +
19
+ [ 'nanoc3.gemspec', '.gemtest' ]
18
20
  s.executables = [ 'nanoc3' ]
19
21
  s.require_paths = [ 'lib' ]
20
22
 
21
- s.has_rdoc = 'yard'
22
23
  s.rdoc_options = [ '--main', 'README.md' ]
23
24
  s.extra_rdoc_files = [ 'ChangeLog', 'LICENSE', 'README.md', 'NEWS.md' ]
24
25
 
data/tasks/clean.rake ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include([
6
+ 'coverage',
7
+ 'doc',
8
+ 'tmp'
9
+ ])
10
+
11
+ CLOBBER.include([ 'pkg' ])
data/tasks/doc.rake ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yard'
4
+
5
+ YARD::Rake::YardocTask.new(:doc) do |yard|
6
+ yard.files = Dir['lib/**/*.rb']
7
+ yard.options = [
8
+ '--markup', 'markdown',
9
+ '--readme', 'README.md',
10
+ '--files', 'NEWS.md,LICENSE',
11
+ '--output-dir', 'doc/yardoc',
12
+ '--template-path', 'doc/yardoc_templates'
13
+ ]
14
+ end
data/tasks/test.rake ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'minitest/unit'
4
+
5
+ test = namespace :test do
6
+
7
+ # test:all
8
+ desc 'Run all tests'
9
+ task :all do
10
+ ENV['QUIET'] ||= 'true'
11
+
12
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
13
+
14
+ MiniTest::Unit.autorun
15
+
16
+ test_files = Dir['test/**/*_spec.rb'] + Dir['test/**/test_*.rb']
17
+ test_files.each { |f| require f }
18
+ end
19
+
20
+ # test:...
21
+ %w( base cli data_sources extra filters helpers tasks ).each do |dir|
22
+ desc "Run all #{dir} tests"
23
+ task dir.to_sym do |task|
24
+ ENV['QUIET'] ||= 'true'
25
+
26
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/..'))
27
+
28
+ MiniTest::Unit.autorun
29
+
30
+ test_files = Dir["test/#{dir}/**/*_spec.rb"] + Dir["test/#{dir}/**/test_*.rb"]
31
+ test_files.each { |f| require f }
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ desc 'Alias for test:all'
38
+ task :test => [ :'test:all' ]
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'Array#symbolize_keys' do
6
+
7
+ it 'should convert keys to symbols' do
8
+ array_old = [ :abc, 'xyz', { 'foo' => 'bar', :baz => :qux } ]
9
+ array_new = [ :abc, 'xyz', { :foo => 'bar', :baz => :qux } ]
10
+ array_old.symbolize_keys.must_equal array_new
11
+ end
12
+
13
+ end
14
+
15
+ describe 'Array#stringify_keys' do
16
+
17
+ it 'should convert keys to strings' do
18
+ array_old = [ :abc, 'xyz', { :foo => 'bar', 'baz' => :qux } ]
19
+ array_new = [ :abc, 'xyz', { 'foo' => 'bar', 'baz' => :qux } ]
20
+ array_old.stringify_keys.must_equal array_new
21
+ end
22
+
23
+ end
24
+
25
+ describe 'Array#freeze_recursively' do
26
+
27
+ it 'should prevent first-level elements from being modified' do
28
+ array = [ :a, [ :b, :c ], :d ]
29
+ array.freeze_recursively
30
+
31
+ raised = false
32
+ begin
33
+ array[0] = 123
34
+ rescue => e
35
+ raised = true
36
+ assert_match /^can't modify frozen /, e.message
37
+ end
38
+ assert raised
39
+ end
40
+
41
+ it 'should prevent second-level elements from being modified' do
42
+ array = [ :a, [ :b, :c ], :d ]
43
+ array.freeze_recursively
44
+
45
+ raised = false
46
+ begin
47
+ array[1][0] = 123
48
+ rescue => e
49
+ raised = true
50
+ assert_match /^can't modify frozen /, e.message
51
+ end
52
+ assert raised
53
+ end
54
+
55
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'Hash#symbolize_keys' do
6
+
7
+ it 'should convert keys to symbols' do
8
+ hash_old = { 'foo' => 'bar' }
9
+ hash_new = { :foo => 'bar' }
10
+ hash_old.symbolize_keys.must_equal hash_new
11
+ end
12
+
13
+ end
14
+
15
+ describe 'Hash#stringify_keys' do
16
+
17
+ it 'should leave strings as strings' do
18
+ hash_old = { 'foo' => 'bar' }
19
+ hash_new = { 'foo' => 'bar' }
20
+ hash_old.stringify_keys.must_equal hash_new
21
+ end
22
+
23
+ it 'should convert symbols to strings' do
24
+ hash_old = { :foo => 'bar' }
25
+ hash_new = { 'foo' => 'bar' }
26
+ hash_old.stringify_keys.must_equal hash_new
27
+ end
28
+
29
+ it 'should convert integers to strings' do
30
+ hash_old = { 123 => 'bar' }
31
+ hash_new = { '123' => 'bar' }
32
+ hash_old.stringify_keys.must_equal hash_new
33
+ end
34
+
35
+ it 'should convert nil to an empty string' do
36
+ hash_old = { nil => 'bar' }
37
+ hash_new = { '' => 'bar' }
38
+ hash_old.stringify_keys.must_equal hash_new
39
+ end
40
+
41
+ end
42
+
43
+ describe 'Hash#freeze_recursively' do
44
+
45
+ it 'should prevent first-level elements from being modified' do
46
+ hash = { :a => { :b => :c } }
47
+ hash.freeze_recursively
48
+
49
+ raised = false
50
+ begin
51
+ hash[:a] = 123
52
+ rescue => e
53
+ raised = true
54
+ assert_match /^can't modify frozen /, e.message
55
+ end
56
+ assert raised
57
+ end
58
+
59
+ it 'should prevent second-level elements from being modified' do
60
+ hash = { :a => { :b => :c } }
61
+ hash.freeze_recursively
62
+
63
+ raised = false
64
+ begin
65
+ hash[:a][:b] = 123
66
+ rescue => e
67
+ raised = true
68
+ assert_match /^can't modify frozen /, e.message
69
+ end
70
+ assert raised
71
+ end
72
+
73
+ end
74
+
75
+ describe 'Hash#checksum' do
76
+
77
+ it 'should work' do
78
+ expectation = 'fec9ae7163e8b8d57a15d51821d2c68d4a6bb169'
79
+ { :foo => 123 }.checksum.must_equal expectation
80
+ end
81
+
82
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'Pathname#checksum' do
6
+
7
+ it 'should work on empty files' do
8
+ begin
9
+ FileUtils.mkdir_p('tmp')
10
+ File.open('tmp/myfile', 'w') { |io| io.write('') }
11
+ pathname = Pathname.new('tmp/myfile')
12
+ pathname.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
13
+ ensure
14
+ FileUtils.rm_rf('tmp')
15
+ end
16
+ end
17
+
18
+ it 'should work on all files' do
19
+ begin
20
+ FileUtils.mkdir_p('tmp')
21
+ File.open('tmp/myfile', 'w') { |io| io.write('abc') }
22
+ pathname = Pathname.new('tmp/myfile')
23
+ pathname.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
24
+ ensure
25
+ FileUtils.rm_rf('tmp')
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ describe 'String#cleaned_identifier' do
6
+
7
+ it 'should not convert already clean paths' do
8
+ '/foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
9
+ end
10
+
11
+ it 'should prepend slash if necessary' do
12
+ 'foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
13
+ end
14
+
15
+ it 'should append slash if necessary' do
16
+ '/foo/bar'.cleaned_identifier.must_equal '/foo/bar/'
17
+ end
18
+
19
+ it 'should remove double slashes at start' do
20
+ '//foo/bar/'.cleaned_identifier.must_equal '/foo/bar/'
21
+ end
22
+
23
+ it 'should remove double slashes at end' do
24
+ '/foo/bar//'.cleaned_identifier.must_equal '/foo/bar/'
25
+ end
26
+
27
+ end
28
+
29
+ describe 'String#checksum' do
30
+
31
+ it 'should work on empty strings' do
32
+ ''.checksum.must_equal 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
33
+ end
34
+
35
+ it 'should work on all strings' do
36
+ 'abc'.checksum.must_equal 'a9993e364706816aba3e25717850c26c9cd0d89d'
37
+ end
38
+
39
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::ChecksumStoreTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_get_with_existing_object
10
+ require 'pstore'
11
+
12
+ # Create store
13
+ FileUtils.mkdir_p('tmp')
14
+ pstore = PStore.new('tmp/checksums')
15
+ pstore.transaction do
16
+ pstore[:data] = { [ :item, '/moo/' ] => 'zomg' }
17
+ pstore[:version] = 1
18
+ end
19
+
20
+ # Check
21
+ store = Nanoc3::ChecksumStore.new
22
+ store.load
23
+ obj = Nanoc3::Item.new('Moo?', {}, '/moo/')
24
+ assert_equal 'zomg', store[obj]
25
+ end
26
+
27
+ def test_get_with_nonexistant_object
28
+ store = Nanoc3::ChecksumStore.new
29
+ store.load
30
+
31
+ # Check
32
+ obj = Nanoc3::Item.new('Moo?', {}, '/animals/cow/')
33
+ new_checksum = 'Moo?'.checksum + '-' + {}.checksum
34
+ assert_equal nil, store[obj]
35
+ end
36
+
37
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/helper'
4
+
5
+ class Nanoc3::CodeSnippetTest < MiniTest::Unit::TestCase
6
+
7
+ include Nanoc3::TestHelpers
8
+
9
+ def test_load
10
+ # Initialize
11
+ $complete_insane_parrot = 'meow'
12
+
13
+ # Create code and load it
14
+ code_snippet = Nanoc3::CodeSnippet.new("$complete_insane_parrot = 'woof'", 'parrot.rb')
15
+ code_snippet.load
16
+
17
+ # Ensure code is loaded
18
+ assert_equal('woof', $complete_insane_parrot)
19
+ end
20
+
21
+ def test_load_with_toplevel_binding
22
+ # Initialize
23
+ @foo = 'meow'
24
+
25
+ # Create code and load it
26
+ code_snippet = Nanoc3::CodeSnippet.new("@foo = 'woof'", 'dog.rb')
27
+ code_snippet.load
28
+
29
+ # Ensure binding is correct
30
+ assert_equal('meow', @foo)
31
+ end
32
+
33
+ end