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,130 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3
4
-
5
- # Represents a layout in a nanoc site. It has content, attributes, an
6
- # identifier and a modification time (to speed up compilation).
7
- class Layout
8
-
9
- extend Nanoc3::Memoization
10
-
11
- # @return [String] The raw content of this layout
12
- attr_reader :raw_content
13
-
14
- # @return [Hash] This layout's attributes
15
- attr_reader :attributes
16
-
17
- # @return [String] This layout's identifier, starting and ending with a
18
- # slash
19
- attr_accessor :identifier
20
-
21
- # Creates a new layout.
22
- #
23
- # @param [String] raw_content The raw content of this layout.
24
- #
25
- # @param [Hash] attributes A hash containing this layout's attributes.
26
- #
27
- # @param [String] identifier This layout's identifier.
28
- #
29
- # @param [Time, Hash] params Extra parameters. For backwards
30
- # compatibility, this can be a Time instance indicating the time when
31
- # this layout was last modified (mtime).
32
- #
33
- # @option params [Time, nil] :mtime (nil) The time when this layout was
34
- # last modified. Deprecated; pass the modification time as the `:mtime`
35
- # attribute instead.
36
- def initialize(raw_content, attributes, identifier, params=nil)
37
- @raw_content = raw_content
38
- @attributes = attributes.symbolize_keys
39
- @identifier = identifier.cleaned_identifier.freeze
40
-
41
- # Set mtime
42
- params ||= {}
43
- params = { :mtime => params } if params.is_a?(Time)
44
- @attributes.merge(:mtime => params[:mtime]) if params[:mtime]
45
- end
46
-
47
- # Requests the attribute with the given key.
48
- #
49
- # @param [Symbol] key The name of the attribute to fetch.
50
- #
51
- # @return [Object] The value of the requested attribute.
52
- def [](key)
53
- @attributes[key]
54
- end
55
-
56
- # Returns the type of this object. Will always return `:layout`, because
57
- # this is a layout. For items, this method returns `:item`.
58
- #
59
- # @api private
60
- #
61
- # @return [Symbol] :layout
62
- def type
63
- :layout
64
- end
65
-
66
- # Prevents all further modifications to the layout.
67
- #
68
- # @return [void]
69
- def freeze
70
- attributes.freeze_recursively
71
- identifier.freeze
72
- raw_content.freeze
73
- end
74
-
75
- # Returns an object that can be used for uniquely identifying objects.
76
- #
77
- # @api private
78
- #
79
- # @return [Object] An unique reference to this object
80
- def reference
81
- [ type, self.identifier ]
82
- end
83
-
84
- def inspect
85
- "<#{self.class}:0x#{self.object_id.to_s(16)} identifier=#{self.identifier}>"
86
- end
87
-
88
- # @return [String] The checksum for this object. If its contents change,
89
- # the checksum will change as well.
90
- def checksum
91
- attributes = @attributes.dup
92
- attributes.delete(:file)
93
- @raw_content.checksum + ',' + attributes.checksum
94
- end
95
- memoize :checksum
96
-
97
- def hash
98
- self.class.hash ^ self.identifier.hash
99
- end
100
-
101
- def eql?(other)
102
- self.class == other.class && self.identifier == other.identifier
103
- end
104
-
105
- def ==(other)
106
- self.eql?(other)
107
- end
108
-
109
- def marshal_dump
110
- [
111
- @raw_content,
112
- @attributes,
113
- @identifier
114
- ]
115
- end
116
-
117
- def marshal_load(source)
118
- @raw_content,
119
- @attributes,
120
- @identifier = *source
121
- end
122
-
123
- # @deprecated Access the modification time using `layout[:mtime]` instead.
124
- def mtime
125
- self[:mtime]
126
- end
127
-
128
- end
129
-
130
- end
@@ -1,361 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Nanoc3
4
-
5
- # The in-memory representation of a nanoc site. It holds references to the
6
- # following site data:
7
- #
8
- # * {#items} — the list of items ({Nanoc3::Item})
9
- # * {#layouts} — the list of layouts ({Nanoc3::Layout})
10
- # * {#code_snippets} — the list of code snippets ({Nanoc3::CodeSnippet})
11
- # * {#data_sources} — the list of data sources ({Nanoc3::DataSource})
12
- #
13
- # In addition, each site has a {#config} hash which stores the site
14
- # configuration.
15
- #
16
- # The physical representation of a {Nanoc3::Site} is usually a directory
17
- # that contains a configuration file, site data, a rakefile, a rules file,
18
- # etc. The way site data is stored depends on the data source.
19
- class Site
20
-
21
- # The default configuration for a data source. A data source's
22
- # configuration overrides these options.
23
- DEFAULT_DATA_SOURCE_CONFIG = {
24
- :type => 'filesystem_unified',
25
- :items_root => '/',
26
- :layouts_root => '/',
27
- :config => {}
28
- }
29
-
30
- # The default configuration for a site. A site's configuration overrides
31
- # these options: when a {Nanoc3::Site} is created with a configuration
32
- # that lacks some options, the default value will be taken from
33
- # `DEFAULT_CONFIG`.
34
- DEFAULT_CONFIG = {
35
- :text_extensions => %w( css erb haml htm html js less markdown md php rb sass scss txt xhtml xml ),
36
- :output_dir => 'output',
37
- :data_sources => [ {} ],
38
- :index_filenames => [ 'index.html' ],
39
- :enable_output_diff => false
40
- }
41
-
42
- # Creates a site object for the site specified by the given
43
- # `dir_or_config_hash` argument.
44
- #
45
- # @param [Hash, String] dir_or_config_hash If a string, contains the path
46
- # to the site directory; if a hash, contains the site configuration.
47
- def initialize(dir_or_config_hash)
48
- build_config(dir_or_config_hash)
49
- end
50
-
51
- # Compiles the site.
52
- #
53
- # @return [void]
54
- #
55
- # @since 3.2.0
56
- def compile
57
- compiler.run
58
- end
59
-
60
- # Returns the compiler for this site. Will create a new compiler if none
61
- # exists yet.
62
- #
63
- # @return [Nanoc3::Compiler] The compiler for this site
64
- def compiler
65
- @compiler ||= Compiler.new(self)
66
- end
67
-
68
- # Returns the data sources for this site. Will create a new data source if
69
- # none exists yet.
70
- #
71
- # @return [Array<Nanoc3::DataSource>] The list of data sources for this
72
- # site
73
- #
74
- # @raise [Nanoc3::Errors::UnknownDataSource] if the site configuration
75
- # specifies an unknown data source
76
- def data_sources
77
- load_code_snippets
78
-
79
- @data_sources ||= begin
80
- @config[:data_sources].map do |data_source_hash|
81
- # Get data source class
82
- data_source_class = Nanoc3::DataSource.named(data_source_hash[:type])
83
- raise Nanoc3::Errors::UnknownDataSource.new(data_source_hash[:type]) if data_source_class.nil?
84
-
85
- # Warn about deprecated data sources
86
- # TODO [in nanoc 4.0] remove me
87
- case data_source_hash[:type]
88
- when 'filesystem'
89
- warn "Warning: the 'filesystem' data source has been renamed to 'filesystem_verbose'. Using 'filesystem' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem' with 'filesystem_verbose'."
90
- when 'filesystem_combined', 'filesystem_compact'
91
- warn "Warning: the 'filesystem_combined' and 'filesystem_compact' data source has been merged into the new 'filesystem_unified' data source. Using 'filesystem_combined' and 'filesystem_compact' will work in nanoc 3.1.x, but it will likely not work anymore in a future release of nanoc. Please update your data source configuration and replace 'filesystem_combined' and 'filesystem_compact with 'filesystem_unified'."
92
- end
93
-
94
- # Create data source
95
- data_source_class.new(
96
- self,
97
- data_source_hash[:items_root],
98
- data_source_hash[:layouts_root],
99
- data_source_hash.merge(data_source_hash[:config] || {})
100
- )
101
- end
102
- end
103
- end
104
-
105
- # Returns this site’s code snippets.
106
- #
107
- # @return [Array<Nanoc3::CodeSnippet>] The list of code snippets in this
108
- # site
109
- def code_snippets
110
- load
111
- @code_snippets
112
- end
113
-
114
- # Returns this site’s items.
115
- #
116
- # @return [Array<Nanoc3::Item>] The list of items in this site
117
- def items
118
- load
119
- @items
120
- end
121
-
122
- # Returns this site’s layouts.
123
- #
124
- # @return [Array<Nanoc3::Layouts>] The list of layout in this site
125
- def layouts
126
- load
127
- @layouts
128
- end
129
-
130
- # Returns the site configuration. It has the following keys:
131
- #
132
- # * `text_extensions` (`Array<String>`) - A list of file extensions that
133
- # will cause nanoc to threat the file as textual instead of binary. When
134
- # the data source finds a content file with an extension that is
135
- # included in this list, it will be marked as textual.
136
- #
137
- # * `output_dir` (`String`) - The directory to which compiled items will
138
- # be written. This path is relative to the current working directory,
139
- # but can also be an absolute path.
140
- #
141
- # * `data_sources` (`Array<Hash>`) - A list of data sources for this site.
142
- # See below for documentation on the structure of this list. By default,
143
- # there is only one data source of the filesystem type mounted at `/`.
144
- #
145
- # * `index_filenames` (`Array<String>`) - A list of filenames that will be
146
- # stripped off full item paths to create cleaner URLs. For example,
147
- # `/about/` will be used instead of `/about/index.html`). The default
148
- # value should be okay in most cases.
149
- #
150
- # * `enable_output_diff` (`Boolean`) - True when diffs should be generated
151
- # for the compiled content of this site; false otherwise.
152
- #
153
- # The list of data sources consists of hashes with the following keys:
154
- #
155
- # * `:type` (`String`) - The type of data source, i.e. its identifier.
156
- #
157
- # * `:items_root` (`String`) - The prefix that should be given to all
158
- # items returned by the {#items} method (comparable to mount points
159
- # for filesystems in Unix-ish OSes).
160
- #
161
- # * `:layouts_root` (`String`) - The prefix that should be given to all
162
- # layouts returned by the {#layouts} method (comparable to mount
163
- # points for filesystems in Unix-ish OSes).
164
- #
165
- # * `:config` (`Hash`) - A hash containing the configuration for this data
166
- # source. nanoc itself does not use this hash. This is especially
167
- # useful for online data sources; for example, a Twitter data source
168
- # would need the username of the account from which to fetch tweets.
169
- #
170
- # @return [Hash] The site configuration
171
- def config
172
- @config
173
- end
174
-
175
- # Fills each item's parent reference and children array with the
176
- # appropriate items. It is probably not necessary to call this method
177
- # manually; it will be called when appropriate.
178
- #
179
- # @return [void]
180
- def setup_child_parent_links
181
- teardown_child_parent_links
182
-
183
- items = @items.sort_by { |i| i.identifier }
184
- items.each_with_index do |item, index|
185
- # Get parent
186
- next if index == 0
187
- parent_identifier = item.identifier.sub(/[^\/]+\/$/, '')
188
- parent = nil
189
- (0..index-1).reverse_each do |candidate_index|
190
- candidate = items[candidate_index]
191
- if candidate.identifier == parent_identifier
192
- parent = candidate
193
- elsif candidate.identifier[0..parent_identifier.size-1] != parent_identifier
194
- break
195
- end
196
- end
197
- next if parent.nil?
198
-
199
- # Link
200
- item.parent = parent
201
- parent.children << item
202
- end
203
- end
204
-
205
- # Removes all child-parent links.
206
- #
207
- # @api private
208
- #
209
- # @return [void]
210
- def teardown_child_parent_links
211
- @items.each do |item|
212
- item.parent = nil
213
- item.children = []
214
- end
215
- end
216
-
217
- # Prevents all further modifications to itself, its items, its layouts etc.
218
- #
219
- # @return [void]
220
- def freeze
221
- config.freeze_recursively
222
- items.each { |i| i.freeze }
223
- layouts.each { |l| l.freeze }
224
- code_snippets.each { |cs| cs.freeze }
225
- end
226
-
227
- # @deprecated It is no longer necessary to explicitly load site data. It
228
- # is safe to remove all {#load_data} calls.
229
- def load_data(force=false)
230
- warn 'It is no longer necessary to call Nanoc3::Site#load_data. This method no longer has any effect. All calls to this method can be safely removed.'
231
- end
232
-
233
- # Loads the site data. It is not necessary to call this method explicitly;
234
- # it will be called when it is necessary.
235
- #
236
- # @api private
237
- #
238
- # @return [void]
239
- def load
240
- return if @loaded || @loading
241
- @loading = true
242
-
243
- # Load all data
244
- load_code_snippets
245
- data_sources.each { |ds| ds.use }
246
- load_items
247
- load_layouts
248
- data_sources.each { |ds| ds.unuse }
249
- setup_child_parent_links
250
-
251
- # Load compiler too
252
- # FIXME this should not be necessary
253
- compiler.load
254
-
255
- @loaded = true
256
- rescue => e
257
- unload
258
- raise e
259
- ensure
260
- @loading = false
261
- end
262
-
263
- # Undoes the effects of {#load}. Used when {#load} raises an exception.
264
- #
265
- # @api private
266
- def unload
267
- return if @unloading
268
- @unloading = true
269
-
270
- @items_loaded = false
271
- @items = []
272
- @layouts_loaded = false
273
- @layouts = []
274
- @code_snippets_loaded = false
275
- @code_snippets = []
276
-
277
- compiler.unload
278
-
279
- @loaded = false
280
- @unloading = false
281
- end
282
-
283
- private
284
-
285
- # Loads this site’s code and executes it.
286
- def load_code_snippets
287
- @code_snippets_loaded ||= false
288
- return if @code_snippets_loaded
289
- @code_snippets_loaded = true
290
-
291
- # Get code snippets
292
- @code_snippets = Dir['lib/**/*.rb'].sort.map do |filename|
293
- Nanoc3::CodeSnippet.new(
294
- File.read(filename),
295
- filename
296
- )
297
- end
298
-
299
- # Execute code snippets
300
- @code_snippets.each { |cs| cs.load }
301
- end
302
-
303
- # Loads this site’s items, sets up item child-parent relationships and
304
- # builds each item's list of item representations.
305
- def load_items
306
- @items_loaded ||= false
307
- return if @items_loaded
308
- @items_loaded = true
309
-
310
- # Get items
311
- @items = []
312
- data_sources.each do |ds|
313
- items_in_ds = ds.items
314
- items_in_ds.each { |i| i.identifier = File.join(ds.items_root, i.identifier) }
315
- @items.concat(items_in_ds)
316
- end
317
- end
318
-
319
- # Loads this site’s layouts.
320
- def load_layouts
321
- @layouts_loaded ||= false
322
- return if @layouts_loaded
323
- @layouts_loaded = true
324
-
325
- # Get layouts
326
- @layouts = []
327
- data_sources.each do |ds|
328
- layouts_in_ds = ds.layouts
329
- layouts_in_ds.each { |i| i.identifier = File.join(ds.layouts_root, i.identifier) }
330
- @layouts.concat(layouts_in_ds)
331
- end
332
- end
333
-
334
- # Builds the configuration hash based on the given argument. Also see
335
- # {#initialize} for details.
336
- def build_config(dir_or_config_hash)
337
- if dir_or_config_hash.is_a? String
338
- # Check whether it is supported
339
- if dir_or_config_hash != '.'
340
- warn 'WARNING: Calling Nanoc3::Site.new with a directory that is not the current working directory is not supported. It is recommended to change the directory before calling Nanoc3::Site.new. For example, instead of Nanoc3::Site.new(\'abc\'), use Dir.chdir(\'abc\') { Nanoc3::Site.new(\'.\') }.'
341
- end
342
-
343
- # Read config from config.yaml in given dir
344
- config_path = File.join(dir_or_config_hash, 'config.yaml')
345
- @config = DEFAULT_CONFIG.merge(YAML.load_file(config_path).symbolize_keys)
346
- @config[:data_sources].map! { |ds| ds.symbolize_keys }
347
- else
348
- # Use passed config hash
349
- @config = DEFAULT_CONFIG.merge(dir_or_config_hash)
350
- end
351
-
352
- # Merge data sources with default data source config
353
- @config[:data_sources] = @config[:data_sources].map { |ds| DEFAULT_DATA_SOURCE_CONFIG.merge(ds) }
354
-
355
- # Convert to proper configuration
356
- @config = Nanoc3::Configuration.new(@config)
357
- end
358
-
359
- end
360
-
361
- end