nanoc3 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. metadata +14 -313
  2. data/.gemtest +0 -0
  3. data/ChangeLog +0 -3
  4. data/Gemfile +0 -29
  5. data/LICENSE +0 -19
  6. data/NEWS.md +0 -449
  7. data/README.md +0 -108
  8. data/Rakefile +0 -14
  9. data/bin/nanoc3 +0 -12
  10. data/doc/yardoc_templates/default/layout/html/footer.erb +0 -10
  11. data/lib/nanoc3.rb +0 -28
  12. data/lib/nanoc3/base.rb +0 -49
  13. data/lib/nanoc3/base/compilation/checksum_store.rb +0 -57
  14. data/lib/nanoc3/base/compilation/compiled_content_cache.rb +0 -62
  15. data/lib/nanoc3/base/compilation/compiler.rb +0 -455
  16. data/lib/nanoc3/base/compilation/compiler_dsl.rb +0 -214
  17. data/lib/nanoc3/base/compilation/dependency_tracker.rb +0 -196
  18. data/lib/nanoc3/base/compilation/filter.rb +0 -165
  19. data/lib/nanoc3/base/compilation/item_rep_proxy.rb +0 -102
  20. data/lib/nanoc3/base/compilation/item_rep_recorder_proxy.rb +0 -88
  21. data/lib/nanoc3/base/compilation/outdatedness_checker.rb +0 -223
  22. data/lib/nanoc3/base/compilation/outdatedness_reasons.rb +0 -46
  23. data/lib/nanoc3/base/compilation/rule.rb +0 -73
  24. data/lib/nanoc3/base/compilation/rule_context.rb +0 -84
  25. data/lib/nanoc3/base/compilation/rule_memory_calculator.rb +0 -40
  26. data/lib/nanoc3/base/compilation/rule_memory_store.rb +0 -53
  27. data/lib/nanoc3/base/compilation/rules_collection.rb +0 -231
  28. data/lib/nanoc3/base/context.rb +0 -47
  29. data/lib/nanoc3/base/core_ext.rb +0 -6
  30. data/lib/nanoc3/base/core_ext/array.rb +0 -62
  31. data/lib/nanoc3/base/core_ext/hash.rb +0 -63
  32. data/lib/nanoc3/base/core_ext/pathname.rb +0 -26
  33. data/lib/nanoc3/base/core_ext/string.rb +0 -46
  34. data/lib/nanoc3/base/directed_graph.rb +0 -275
  35. data/lib/nanoc3/base/errors.rb +0 -174
  36. data/lib/nanoc3/base/memoization.rb +0 -67
  37. data/lib/nanoc3/base/notification_center.rb +0 -84
  38. data/lib/nanoc3/base/ordered_hash.rb +0 -200
  39. data/lib/nanoc3/base/plugin_registry.rb +0 -165
  40. data/lib/nanoc3/base/result_data/item_rep.rb +0 -488
  41. data/lib/nanoc3/base/source_data/code_snippet.rb +0 -58
  42. data/lib/nanoc3/base/source_data/configuration.rb +0 -24
  43. data/lib/nanoc3/base/source_data/data_source.rb +0 -234
  44. data/lib/nanoc3/base/source_data/item.rb +0 -301
  45. data/lib/nanoc3/base/source_data/layout.rb +0 -130
  46. data/lib/nanoc3/base/source_data/site.rb +0 -361
  47. data/lib/nanoc3/base/store.rb +0 -135
  48. data/lib/nanoc3/cli.rb +0 -133
  49. data/lib/nanoc3/cli/command.rb +0 -139
  50. data/lib/nanoc3/cli/commands/autocompile.rb +0 -60
  51. data/lib/nanoc3/cli/commands/compile.rb +0 -280
  52. data/lib/nanoc3/cli/commands/create_item.rb +0 -62
  53. data/lib/nanoc3/cli/commands/create_layout.rb +0 -75
  54. data/lib/nanoc3/cli/commands/create_site.rb +0 -410
  55. data/lib/nanoc3/cli/commands/debug.rb +0 -119
  56. data/lib/nanoc3/cli/commands/info.rb +0 -98
  57. data/lib/nanoc3/cli/commands/nanoc.rb +0 -37
  58. data/lib/nanoc3/cli/commands/update.rb +0 -72
  59. data/lib/nanoc3/cli/commands/view.rb +0 -84
  60. data/lib/nanoc3/cli/commands/watch.rb +0 -125
  61. data/lib/nanoc3/cli/error_handler.rb +0 -193
  62. data/lib/nanoc3/cli/logger.rb +0 -91
  63. data/lib/nanoc3/data_sources.rb +0 -29
  64. data/lib/nanoc3/data_sources/deprecated/delicious.rb +0 -42
  65. data/lib/nanoc3/data_sources/deprecated/last_fm.rb +0 -87
  66. data/lib/nanoc3/data_sources/deprecated/twitter.rb +0 -38
  67. data/lib/nanoc3/data_sources/filesystem.rb +0 -299
  68. data/lib/nanoc3/data_sources/filesystem_unified.rb +0 -116
  69. data/lib/nanoc3/data_sources/filesystem_verbose.rb +0 -86
  70. data/lib/nanoc3/extra.rb +0 -22
  71. data/lib/nanoc3/extra/auto_compiler.rb +0 -103
  72. data/lib/nanoc3/extra/chick.rb +0 -125
  73. data/lib/nanoc3/extra/core_ext.rb +0 -4
  74. data/lib/nanoc3/extra/core_ext/enumerable.rb +0 -33
  75. data/lib/nanoc3/extra/core_ext/time.rb +0 -19
  76. data/lib/nanoc3/extra/deployers.rb +0 -11
  77. data/lib/nanoc3/extra/deployers/rsync.rb +0 -114
  78. data/lib/nanoc3/extra/file_proxy.rb +0 -40
  79. data/lib/nanoc3/extra/validators.rb +0 -12
  80. data/lib/nanoc3/extra/validators/links.rb +0 -264
  81. data/lib/nanoc3/extra/validators/w3c.rb +0 -95
  82. data/lib/nanoc3/extra/vcs.rb +0 -66
  83. data/lib/nanoc3/extra/vcses.rb +0 -17
  84. data/lib/nanoc3/extra/vcses/bazaar.rb +0 -25
  85. data/lib/nanoc3/extra/vcses/dummy.rb +0 -24
  86. data/lib/nanoc3/extra/vcses/git.rb +0 -25
  87. data/lib/nanoc3/extra/vcses/mercurial.rb +0 -25
  88. data/lib/nanoc3/extra/vcses/subversion.rb +0 -25
  89. data/lib/nanoc3/filters.rb +0 -53
  90. data/lib/nanoc3/filters/asciidoc.rb +0 -38
  91. data/lib/nanoc3/filters/bluecloth.rb +0 -19
  92. data/lib/nanoc3/filters/coderay.rb +0 -21
  93. data/lib/nanoc3/filters/colorize_syntax.rb +0 -261
  94. data/lib/nanoc3/filters/erb.rb +0 -35
  95. data/lib/nanoc3/filters/erubis.rb +0 -27
  96. data/lib/nanoc3/filters/haml.rb +0 -27
  97. data/lib/nanoc3/filters/kramdown.rb +0 -20
  98. data/lib/nanoc3/filters/less.rb +0 -53
  99. data/lib/nanoc3/filters/markaby.rb +0 -20
  100. data/lib/nanoc3/filters/maruku.rb +0 -20
  101. data/lib/nanoc3/filters/mustache.rb +0 -24
  102. data/lib/nanoc3/filters/rainpress.rb +0 -19
  103. data/lib/nanoc3/filters/rdiscount.rb +0 -22
  104. data/lib/nanoc3/filters/rdoc.rb +0 -33
  105. data/lib/nanoc3/filters/redcarpet.rb +0 -27
  106. data/lib/nanoc3/filters/redcloth.rb +0 -47
  107. data/lib/nanoc3/filters/relativize_paths.rb +0 -45
  108. data/lib/nanoc3/filters/rubypants.rb +0 -20
  109. data/lib/nanoc3/filters/sass.rb +0 -66
  110. data/lib/nanoc3/filters/slim.rb +0 -25
  111. data/lib/nanoc3/filters/typogruby.rb +0 -23
  112. data/lib/nanoc3/filters/uglify_js.rb +0 -42
  113. data/lib/nanoc3/helpers.rb +0 -16
  114. data/lib/nanoc3/helpers/blogging.rb +0 -319
  115. data/lib/nanoc3/helpers/breadcrumbs.rb +0 -40
  116. data/lib/nanoc3/helpers/capturing.rb +0 -138
  117. data/lib/nanoc3/helpers/filtering.rb +0 -50
  118. data/lib/nanoc3/helpers/html_escape.rb +0 -55
  119. data/lib/nanoc3/helpers/link_to.rb +0 -151
  120. data/lib/nanoc3/helpers/rendering.rb +0 -140
  121. data/lib/nanoc3/helpers/tagging.rb +0 -71
  122. data/lib/nanoc3/helpers/text.rb +0 -44
  123. data/lib/nanoc3/helpers/xml_sitemap.rb +0 -76
  124. data/lib/nanoc3/tasks.rb +0 -10
  125. data/lib/nanoc3/tasks/clean.rake +0 -16
  126. data/lib/nanoc3/tasks/clean.rb +0 -29
  127. data/lib/nanoc3/tasks/deploy/rsync.rake +0 -14
  128. data/lib/nanoc3/tasks/validate.rake +0 -92
  129. data/nanoc3.gemspec +0 -49
  130. data/tasks/doc.rake +0 -16
  131. data/tasks/test.rake +0 -44
  132. data/test/base/core_ext/array_spec.rb +0 -73
  133. data/test/base/core_ext/hash_spec.rb +0 -98
  134. data/test/base/core_ext/pathname_spec.rb +0 -27
  135. data/test/base/core_ext/string_spec.rb +0 -37
  136. data/test/base/test_checksum_store.rb +0 -35
  137. data/test/base/test_code_snippet.rb +0 -31
  138. data/test/base/test_compiler.rb +0 -316
  139. data/test/base/test_compiler_dsl.rb +0 -161
  140. data/test/base/test_context.rb +0 -31
  141. data/test/base/test_data_source.rb +0 -46
  142. data/test/base/test_dependency_tracker.rb +0 -262
  143. data/test/base/test_directed_graph.rb +0 -283
  144. data/test/base/test_filter.rb +0 -83
  145. data/test/base/test_item.rb +0 -179
  146. data/test/base/test_item_rep.rb +0 -553
  147. data/test/base/test_layout.rb +0 -59
  148. data/test/base/test_memoization.rb +0 -90
  149. data/test/base/test_notification_center.rb +0 -34
  150. data/test/base/test_outdatedness_checker.rb +0 -394
  151. data/test/base/test_plugin.rb +0 -30
  152. data/test/base/test_rule.rb +0 -19
  153. data/test/base/test_rule_context.rb +0 -65
  154. data/test/base/test_site.rb +0 -190
  155. data/test/cli/commands/test_compile.rb +0 -33
  156. data/test/cli/commands/test_create_item.rb +0 -14
  157. data/test/cli/commands/test_create_layout.rb +0 -28
  158. data/test/cli/commands/test_create_site.rb +0 -24
  159. data/test/cli/commands/test_help.rb +0 -12
  160. data/test/cli/commands/test_info.rb +0 -11
  161. data/test/cli/commands/test_update.rb +0 -10
  162. data/test/cli/test_cli.rb +0 -102
  163. data/test/cli/test_error_handler.rb +0 -29
  164. data/test/cli/test_logger.rb +0 -10
  165. data/test/data_sources/test_filesystem.rb +0 -433
  166. data/test/data_sources/test_filesystem_unified.rb +0 -536
  167. data/test/data_sources/test_filesystem_verbose.rb +0 -357
  168. data/test/extra/core_ext/test_enumerable.rb +0 -30
  169. data/test/extra/core_ext/test_time.rb +0 -15
  170. data/test/extra/deployers/test_rsync.rb +0 -232
  171. data/test/extra/test_auto_compiler.rb +0 -417
  172. data/test/extra/test_file_proxy.rb +0 -19
  173. data/test/extra/test_vcs.rb +0 -22
  174. data/test/extra/validators/test_links.rb +0 -51
  175. data/test/extra/validators/test_w3c.rb +0 -47
  176. data/test/filters/test_asciidoc.rb +0 -22
  177. data/test/filters/test_bluecloth.rb +0 -18
  178. data/test/filters/test_coderay.rb +0 -44
  179. data/test/filters/test_colorize_syntax.rb +0 -283
  180. data/test/filters/test_erb.rb +0 -99
  181. data/test/filters/test_erubis.rb +0 -70
  182. data/test/filters/test_haml.rb +0 -96
  183. data/test/filters/test_kramdown.rb +0 -18
  184. data/test/filters/test_less.rb +0 -113
  185. data/test/filters/test_markaby.rb +0 -24
  186. data/test/filters/test_maruku.rb +0 -18
  187. data/test/filters/test_mustache.rb +0 -25
  188. data/test/filters/test_rainpress.rb +0 -29
  189. data/test/filters/test_rdiscount.rb +0 -31
  190. data/test/filters/test_rdoc.rb +0 -18
  191. data/test/filters/test_redcarpet.rb +0 -63
  192. data/test/filters/test_redcloth.rb +0 -33
  193. data/test/filters/test_relativize_paths.rb +0 -332
  194. data/test/filters/test_rubypants.rb +0 -18
  195. data/test/filters/test_sass.rb +0 -229
  196. data/test/filters/test_slim.rb +0 -35
  197. data/test/filters/test_typogruby.rb +0 -21
  198. data/test/filters/test_uglify_js.rb +0 -30
  199. data/test/gem_loader.rb +0 -11
  200. data/test/helper.rb +0 -179
  201. data/test/helpers/test_blogging.rb +0 -754
  202. data/test/helpers/test_breadcrumbs.rb +0 -81
  203. data/test/helpers/test_capturing.rb +0 -41
  204. data/test/helpers/test_filtering.rb +0 -106
  205. data/test/helpers/test_html_escape.rb +0 -32
  206. data/test/helpers/test_link_to.rb +0 -249
  207. data/test/helpers/test_rendering.rb +0 -89
  208. data/test/helpers/test_tagging.rb +0 -87
  209. data/test/helpers/test_text.rb +0 -24
  210. data/test/helpers/test_xml_sitemap.rb +0 -103
  211. data/test/tasks/test_clean.rb +0 -67
@@ -1,66 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'sass'
4
- require 'set'
5
-
6
- module Nanoc3::Filters
7
- class Sass < Nanoc3::Filter
8
-
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
- # Runs the content through [Sass](http://sass-lang.com/).
37
- # Parameters passed to this filter will be passed on to Sass.
38
- #
39
- # @param [String] content The content to filter
40
- #
41
- # @return [String] The filtered content
42
- 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
50
-
51
- # Render
52
- engine = ::Sass::Engine.new(content, options)
53
- self.class.current = self
54
- engine.render
55
- end
56
-
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
62
- end
63
- end
64
-
65
- end
66
- end
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'slim'
4
-
5
- module Nanoc3::Filters
6
-
7
- # @since 3.2.0
8
- class Slim < Nanoc3::Filter
9
-
10
- # Runs the content through [Slim](http://slim-lang.com/)
11
- # This method takes no options.
12
- #
13
- # @param [String] content The content to filter
14
- #
15
- # @return [String] The filtered content
16
- def run(content, params={})
17
- # Create context
18
- context = ::Nanoc3::Context.new(assigns)
19
-
20
- ::Slim::Template.new { content }.render(context) { assigns[:content] }
21
- end
22
-
23
- end
24
-
25
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'typogruby'
4
-
5
- module Nanoc3::Filters
6
-
7
- # @since 3.2.0
8
- class Typogruby < Nanoc3::Filter
9
-
10
- # Runs the content through [Typogruby](http://avdgaag.github.com/typogruby/).
11
- # This method takes no options.
12
- #
13
- # @param [String] content The content to filter
14
- #
15
- # @return [String] The filtered content
16
- def run(content, params={})
17
- # Get result
18
- ::Typogruby.improve(content)
19
- end
20
-
21
- end
22
-
23
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'uglifier'
4
-
5
- module Nanoc3::Filters
6
- class UglifyJS < Nanoc3::Filter
7
-
8
- # Runs the content through [UglifyJS](https://github.com/mishoo/UglifyJS/).
9
- # This method optionally takes options to pass directly to Uglifier:
10
- #
11
- # {
12
- # :mangle => true, # Mangle variables names
13
- # :toplevel => false, # Mangle top-level variable names
14
- # :except => [], # Variable names to be excluded from mangling
15
- # :max_line_length => 32 * 1024, # Maximum line length
16
- # :squeeze => true, # Squeeze code resulting in smaller, but less-readable code
17
- # :seqs => true, # Reduce consecutive statements in blocks into single statement
18
- # :dead_code => true, # Remove dead code (e.g. after return)
19
- # :unsafe => false, # Optimizations known to be unsafe in some situations
20
- # :copyright => true, # Show copyright message
21
- # :beautify => false, # Ouput indented code
22
- # :beautify_options => {
23
- # :indent_level => 4,
24
- # :indent_start => 0,
25
- # :quote_keys => false,
26
- # :space_colon => 0,
27
- # :ascii_only => false
28
- # }
29
- # }
30
- #
31
- # @param [String] content The content to filter
32
- #
33
- # @option params [Array] :options ([]) A list of options to pass on to Uglifier
34
- #
35
- # @return [String] The filtered content
36
- def run(content, params={})
37
- # Add filename to load path
38
- Uglifier.new(params).compile(content)
39
- end
40
-
41
- end
42
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3::Helpers
4
-
5
- autoload 'Blogging', 'nanoc3/helpers/blogging'
6
- autoload 'Breadcrumbs', 'nanoc3/helpers/breadcrumbs'
7
- autoload 'Capturing', 'nanoc3/helpers/capturing'
8
- autoload 'Filtering', 'nanoc3/helpers/filtering'
9
- autoload 'HTMLEscape', 'nanoc3/helpers/html_escape'
10
- autoload 'LinkTo', 'nanoc3/helpers/link_to'
11
- autoload 'Rendering', 'nanoc3/helpers/rendering'
12
- autoload 'Tagging', 'nanoc3/helpers/tagging'
13
- autoload 'Text', 'nanoc3/helpers/text'
14
- autoload 'XMLSitemap', 'nanoc3/helpers/xml_sitemap'
15
-
16
- end
@@ -1,319 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3::Helpers
4
-
5
- # Provides functionality for building blogs, such as finding articles and
6
- # constructing feeds.
7
- #
8
- # This helper has a few requirements. First, all blog articles should have
9
- # the following attributes:
10
- #
11
- # * `kind` - Set to `"article"`
12
- #
13
- # * `created_at` - The article's publication timestamp
14
- #
15
- # Some functions in this blogging helper, such as the {#atom_feed} function,
16
- # require additional attributes to be set; these attributes are described in
17
- # the documentation for these functions.
18
- #
19
- # All "time" item attributes, site configuration attributes or method
20
- # parameters can either be a `Time` instance or a string in any format
21
- # parseable by `Time.parse`.
22
- #
23
- # The two main functions are {#sorted_articles} and {#atom_feed}.
24
- module Blogging
25
-
26
- # Returns an unsorted list of articles, i.e. items where the `kind`
27
- # attribute is set to `"article"`.
28
- #
29
- # @return [Array] An array containing all articles
30
- def articles
31
- @items.select { |item| item[:kind] == 'article' }
32
- end
33
-
34
- # Returns a sorted list of articles, i.e. items where the `kind`
35
- # attribute is set to `"article"`. Articles are sorted by descending
36
- # creation date, so newer articles appear before older articles.
37
- #
38
- # @return [Array] A sorted array containing all articles
39
- def sorted_articles
40
- articles.sort_by do |a|
41
- attribute_to_time(a[:created_at])
42
- end.reverse
43
- end
44
-
45
- # Returns a string representing the atom feed containing recent articles,
46
- # sorted by descending creation date.
47
- #
48
- # The following attributes must be set on blog articles:
49
- #
50
- # * `title` - The title of the blog post
51
- #
52
- # * `kind` and `created_at` (described above)
53
- #
54
- # The following attributes can optionally be set on blog articles to
55
- # change the behaviour of the Atom feed:
56
- #
57
- # * `excerpt` - An excerpt of the article, which is usually only a few
58
- # lines long.
59
- #
60
- # * `custom_path_in_feed` - The path that will be used instead of the
61
- # normal path in the feed. This can be useful when including
62
- # non-outputted items in a feed; such items could have their custom feed
63
- # path set to the blog path instead, for example.
64
- #
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
68
- # URL of article is a remote location.
69
- #
70
- # * `updated_at` - The time when the article was last modified. If this
71
- # attribute is not present, the `created_at` attribute will be used as
72
- # the time when the article was last modified.
73
- #
74
- # The site configuration will need to have the following attributes:
75
- #
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".
79
- #
80
- # The feed item will need to know about the feed title, the feed author
81
- # name, and the URI corresponding to the author. These can be specified
82
- # using parameters, as attributes in the feed item, or in the site
83
- # configuration.
84
- #
85
- # * `title` - The title of the feed, which is usually also the title of
86
- # the blog.
87
- #
88
- # * `author_name` - The name of the item's author.
89
- #
90
- # * `author_uri` - The URI for the item's author, such as the author's
91
- # web site URL.
92
- #
93
- # The feed item can have the following optional attributes:
94
- #
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
97
- # FeedBurner this would be set to the public FeedBurner URL.
98
- #
99
- # To construct a feed, create a new item and make sure that it is
100
- # filtered with `:erb` or `:erubis`; it should not be laid out. Ensure
101
- # that it is routed to the proper path, e.g. `/blog.xml`. It may also be
102
- # useful to set the `is_hidden` attribute to true, so that helpers such
103
- # as the sitemap helper will ignore the item. The content of the feed
104
- # item should be `<%= atom_feed %>`.
105
- #
106
- # @example Defining compilation and routing rules for a feed item
107
- #
108
- # compile '/blog/feed/' do
109
- # filter :erb
110
- # end
111
- #
112
- # route '/blog/feed/' do
113
- # '/blog.xml'
114
- # end
115
- #
116
- # @example Limiting the number of items in a feed
117
- #
118
- # <%= atom_feed :limit => 5 %>
119
- #
120
- # @option params [Number] :limit (5) The maximum number of articles to
121
- # show
122
- #
123
- # @option params [Array] :articles (sorted_articles) A list of articles to
124
- # include in the feed
125
- #
126
- # @option params [Proc] :content_proc (->{ |article|
127
- # article.compiled_content(:snapshot => :pre) }) A proc that returns the
128
- # content of the given article, which is passed as a parameter. This
129
- # function may not return nil.
130
- #
131
- # @option params [proc] :excerpt_proc (->{ |article| article[:excerpt] })
132
- # A proc that returns the excerpt of the given article, passed as a
133
- # parameter. This function should return nil if there is no excerpt.
134
- #
135
- # @option params [String] :title The feed's title, if it is not given in
136
- # the item attributes.
137
- #
138
- # @option params [String] :author_name The name of the feed's author, if
139
- # it is not given in the item attributes.
140
- #
141
- # @option params [String] :author_uri The URI of the feed's author, if it
142
- # is not given in the item attributes.
143
- #
144
- # @return [String] The generated feed content
145
- def atom_feed(params={})
146
- require 'builder'
147
-
148
- # Extract parameters
149
- limit = params[:limit] || 5
150
- relevant_articles = params[:articles] || articles || []
151
- content_proc = params[:content_proc] || lambda { |a| a.compiled_content(:snapshot => :pre) }
152
- excerpt_proc = params[:excerpt_proc] || lambda { |a| a[:excerpt] }
153
-
154
- # Check config attributes
155
- if @site.config[:base_url].nil?
156
- raise RuntimeError.new('Cannot build Atom feed: site configuration has no base_url')
157
- end
158
-
159
- # Check feed item attributes
160
- title = params[:title] || @item[:title] || @site.config[:title]
161
- if title.nil?
162
- raise RuntimeError.new('Cannot build Atom feed: no title in params, item or site config')
163
- end
164
- author_name = params[:author_name] || @item[:author_name] || @site.config[:author_name]
165
- if author_name.nil?
166
- raise RuntimeError.new('Cannot build Atom feed: no author_name in params, item or site config')
167
- end
168
- author_uri = params[:author_uri] || @item[:author_uri] || @site.config[:author_uri]
169
- if author_uri.nil?
170
- raise RuntimeError.new('Cannot build Atom feed: no author_uri in params, item or site config')
171
- end
172
-
173
- # Check article attributes
174
- if relevant_articles.empty?
175
- raise RuntimeError.new('Cannot build Atom feed: no articles')
176
- end
177
- if relevant_articles.any? { |a| a[:created_at].nil? }
178
- raise RuntimeError.new('Cannot build Atom feed: one or more articles lack created_at')
179
- end
180
-
181
- # Get sorted relevant articles
182
- sorted_relevant_articles = relevant_articles.sort_by do |a|
183
- attribute_to_time(a[:created_at])
184
- end.reverse.first(limit)
185
-
186
- # Get most recent article
187
- last_article = sorted_relevant_articles.first
188
-
189
- # Create builder
190
- buffer = ''
191
- xml = Builder::XmlMarkup.new(:target => buffer, :indent => 2)
192
-
193
- # Build feed
194
- xml.instruct!
195
- xml.feed(:xmlns => 'http://www.w3.org/2005/Atom') do
196
- root_url = @site.config[:base_url] + '/'
197
-
198
- # Add primary attributes
199
- xml.id root_url
200
- xml.title title
201
-
202
- # Add date
203
- xml.updated(attribute_to_time(last_article[:created_at]).to_iso8601_time)
204
-
205
- # Add links
206
- xml.link(:rel => 'alternate', :href => root_url)
207
- xml.link(:rel => 'self', :href => feed_url)
208
-
209
- # Add author information
210
- xml.author do
211
- xml.name author_name
212
- xml.uri author_uri
213
- end
214
-
215
- # Add articles
216
- sorted_relevant_articles.each do |a|
217
- # Get URL
218
- url = url_for(a)
219
- next if url.nil?
220
-
221
- xml.entry do
222
- # Add primary attributes
223
- xml.id atom_tag_for(a)
224
- xml.title a[:title], :type => 'html'
225
-
226
- # Add dates
227
- xml.published attribute_to_time(a[:created_at]).to_iso8601_time
228
- xml.updated attribute_to_time(a[:updated_at] || a[:created_at]).to_iso8601_time
229
-
230
- # Add specific author information
231
- if a[:author_name] || a[:author_uri]
232
- xml.author do
233
- xml.name a[:author_name] || author_name
234
- xml.uri a[:author_uri] || author_uri
235
- end
236
- end
237
-
238
- # Add link
239
- xml.link(:rel => 'alternate', :href => url)
240
-
241
- # Add content
242
- summary = excerpt_proc.call(a)
243
- xml.content content_proc.call(a), :type => 'html'
244
- xml.summary summary, :type => 'html' unless summary.nil?
245
- end
246
- end
247
- end
248
-
249
- buffer
250
- end
251
-
252
- # Returns the URL for the given item. It will return the URL containing
253
- # the custom path in the feed if possible, otherwise the normal path.
254
- #
255
- # @param [Nanoc3::Item] item The item for which to fetch the URL.
256
- #
257
- # @return [String] The URL of the given item
258
- def url_for(item)
259
- # Check attributes
260
- if @site.config[:base_url].nil?
261
- raise RuntimeError.new('Cannot build Atom feed: site configuration has no base_url')
262
- end
263
-
264
- # Build URL
265
- if item[:custom_url_in_feed]
266
- item[:custom_url_in_feed]
267
- elsif item[:custom_path_in_feed]
268
- @site.config[:base_url] + item[:custom_path_in_feed]
269
- elsif item.path
270
- @site.config[:base_url] + item.path
271
- end
272
- end
273
-
274
- # Returns the URL of the feed. It will return the custom feed URL if set,
275
- # or otherwise the normal feed URL.
276
- #
277
- # @return [String] The URL of the feed
278
- def feed_url
279
- # Check attributes
280
- if @site.config[:base_url].nil?
281
- raise RuntimeError.new('Cannot build Atom feed: site configuration has no base_url')
282
- end
283
-
284
- @item[:feed_url] || @site.config[:base_url] + @item.path
285
- end
286
-
287
- # Returns an URI containing an unique ID for the given item. This will be
288
- # used in the Atom feed to uniquely identify articles. These IDs are
289
- # created using a procedure suggested by Mark Pilgrim and described in his
290
- # ["How to make a good ID in Atom" blog post]
291
- # (http://diveintomark.org/archives/2004/05/28/howto-atom-id).
292
- #
293
- # @param [Nanoc3::Item] item The item for which to create an atom tag
294
- #
295
- # @return [String] The atom tag for the given item
296
- def atom_tag_for(item)
297
- hostname, base_dir = %r{^.+?://([^/]+)(.*)$}.match(@site.config[:base_url])[1..2]
298
-
299
- formatted_date = attribute_to_time(item[:created_at]).to_iso8601_date
300
-
301
- 'tag:' + hostname + ',' + formatted_date + ':' + base_dir + (item.path || item.identifier)
302
- end
303
-
304
- # Converts the given attribute (which can be a string, a Time or a Date)
305
- # into a Time.
306
- #
307
- # @param [String, Time, Date] time Something that contains time
308
- # information but is not necessarily a Time instance yet
309
- #
310
- # @return [Time] The Time instance corresponding to the given input
311
- def attribute_to_time(time)
312
- time = Time.local(time.year, time.month, time.day) if time.is_a?(Date)
313
- time = Time.parse(time) if time.is_a?(String)
314
- time
315
- end
316
-
317
- end
318
-
319
- end