bridgetown-core 0.16.0 → 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/bridgetown-core.gemspec +2 -1
  4. data/lib/bridgetown-core.rb +45 -29
  5. data/lib/bridgetown-core/collection.rb +5 -1
  6. data/lib/bridgetown-core/commands/apply.rb +2 -2
  7. data/lib/bridgetown-core/commands/console.rb +4 -4
  8. data/lib/bridgetown-core/commands/new.rb +1 -1
  9. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  10. data/lib/bridgetown-core/concerns/liquid_renderable.rb +10 -0
  11. data/lib/bridgetown-core/concerns/site/configurable.rb +24 -22
  12. data/lib/bridgetown-core/concerns/site/content.rb +46 -33
  13. data/lib/bridgetown-core/concerns/site/extensible.rb +14 -13
  14. data/lib/bridgetown-core/concerns/site/localizable.rb +24 -0
  15. data/lib/bridgetown-core/concerns/site/processable.rb +12 -15
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +35 -28
  17. data/lib/bridgetown-core/concerns/site/writable.rb +7 -15
  18. data/lib/bridgetown-core/concerns/validatable.rb +2 -2
  19. data/lib/bridgetown-core/configuration.rb +14 -6
  20. data/lib/bridgetown-core/converter.rb +0 -42
  21. data/lib/bridgetown-core/converters/erb_templates.rb +75 -16
  22. data/lib/bridgetown-core/converters/liquid_templates.rb +96 -0
  23. data/lib/bridgetown-core/converters/markdown.rb +0 -3
  24. data/lib/bridgetown-core/document.rb +34 -21
  25. data/lib/bridgetown-core/drops/site_drop.rb +5 -1
  26. data/lib/bridgetown-core/drops/unified_payload_drop.rb +0 -1
  27. data/lib/bridgetown-core/drops/url_drop.rb +19 -3
  28. data/lib/bridgetown-core/excerpt.rb +1 -1
  29. data/lib/bridgetown-core/filters.rb +37 -55
  30. data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
  31. data/lib/bridgetown-core/frontmatter_defaults.rb +17 -0
  32. data/lib/bridgetown-core/generators/prototype_generator.rb +42 -25
  33. data/lib/bridgetown-core/helpers.rb +84 -0
  34. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  35. data/lib/bridgetown-core/log_writer.rb +2 -2
  36. data/lib/bridgetown-core/page.rb +8 -2
  37. data/lib/bridgetown-core/plugin_manager.rb +34 -1
  38. data/lib/bridgetown-core/reader.rb +2 -4
  39. data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
  40. data/lib/bridgetown-core/readers/data_reader.rb +4 -3
  41. data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
  42. data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
  43. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  44. data/lib/bridgetown-core/readers/post_reader.rb +29 -15
  45. data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
  46. data/lib/bridgetown-core/renderer.rb +42 -162
  47. data/lib/bridgetown-core/ruby_template_view.rb +26 -22
  48. data/lib/bridgetown-core/site.rb +14 -2
  49. data/lib/bridgetown-core/tags/find.rb +86 -0
  50. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  51. data/lib/bridgetown-core/tags/t.rb +14 -0
  52. data/lib/bridgetown-core/utils.rb +16 -2
  53. data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
  54. data/lib/bridgetown-core/version.rb +2 -2
  55. data/lib/bridgetown-core/watcher.rb +1 -0
  56. data/lib/site_template/src/images/.keep +1 -0
  57. metadata +29 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d35a1d7fa1834831d59b4b7dfd072d3cddfb8d152416b63686aa1bf477567394
4
- data.tar.gz: c3b2f423702f55e433709d11de4219f7ed76736f707b39aed0b22f09048b2804
3
+ metadata.gz: 306a26e30d93c885f8e9580f31df3f10757b8d686337ac851a33c354689be225
4
+ data.tar.gz: 2e258edc76ea89224865c9cbc48d9ae5fcd9dacd2070d99953c6f567644237ac
5
5
  SHA512:
6
- metadata.gz: 9c7799ef500f1d6b519e4f0ede9487c37bde860b12250c1bd39bfe66a348729e73aa7256e04f84fa310e6a82f5b0fcd6041026d4f1f16c8528808ea5331cd4d8
7
- data.tar.gz: 040dcffce2be2cdf189fd7dc1d5585f14a24975e5ee19b2e2d1aa88a09b4e011725727c127c3c2b690e09a79415e0d8edc9e5ce471d87b13b5cc3f4007cbbc50
6
+ metadata.gz: 9a03b2aaabcf0066e0cb634c95f9b5819db23b472887e1048b78e589c9815615986ed8bb943b77f8d272221448608a95f489d6db21508703dbf3123ec31623a1
7
+ data.tar.gz: 2fc8d22203172c03db70520f430292833360c0eb39c91dde1a8d17d498c726295a8bc7183310468f981e5d236fa31a26fc3a564beb6e8179922d3975db6f876e
@@ -0,0 +1 @@
1
+ -m markdown
@@ -33,11 +33,12 @@ Gem::Specification.new do |s|
33
33
 
34
34
  s.add_runtime_dependency("activesupport", "~> 6.0")
35
35
  s.add_runtime_dependency("addressable", "~> 2.4")
36
- s.add_runtime_dependency("awesome_print", "~> 1.8")
36
+ s.add_runtime_dependency("amazing_print", "~> 1.2")
37
37
  s.add_runtime_dependency("colorator", "~> 1.0")
38
38
  s.add_runtime_dependency("erubi", "~> 1.9")
39
39
  s.add_runtime_dependency("faraday", "~> 1.0")
40
40
  s.add_runtime_dependency("faraday_middleware", "~> 1.0")
41
+ s.add_runtime_dependency("hash_with_dot_access", "~> 1.0")
41
42
  s.add_runtime_dependency("i18n", "~> 1.0")
42
43
  s.add_runtime_dependency("kramdown", "~> 2.1")
43
44
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
@@ -29,8 +29,9 @@ require "csv"
29
29
  require "json"
30
30
 
31
31
  # 3rd party
32
- require "active_support/core_ext/hash/indifferent_access"
32
+ require "active_support/core_ext/object/blank"
33
33
  require "active_support/core_ext/string/inflections"
34
+ require "hash_with_dot_access"
34
35
  require "pathutil"
35
36
  require "addressable/uri"
36
37
  require "safe_yaml/load"
@@ -68,6 +69,7 @@ module Bridgetown
68
69
  autoload :Cache, "bridgetown-core/cache"
69
70
  autoload :CollectionReader, "bridgetown-core/readers/collection_reader"
70
71
  autoload :DataReader, "bridgetown-core/readers/data_reader"
72
+ autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
71
73
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
72
74
  autoload :PostReader, "bridgetown-core/readers/post_reader"
73
75
  autoload :PageReader, "bridgetown-core/readers/page_reader"
@@ -113,24 +115,23 @@ module Bridgetown
113
115
  require_all "bridgetown-core/tags"
114
116
 
115
117
  class << self
116
- # Public: Tells you which Bridgetown environment you are building in so
117
- # you can skip tasks if you need to.
118
-
118
+ # Tells you which Bridgetown environment you are building in so
119
+ # you can skip tasks if you need to.
119
120
  def environment
120
121
  ENV["BRIDGETOWN_ENV"] || "development"
121
122
  end
122
123
  alias_method :env, :environment
123
124
 
124
- # Public: Generate a Bridgetown configuration Hash by merging the default
125
- # options with anything in bridgetown.config.yml, and adding the given
126
- # options on top.
125
+ # Generate a Bridgetown configuration hash by merging the default
126
+ # options with anything in bridgetown.config.yml, and adding the given
127
+ # options on top.
127
128
  #
128
- # override - A Hash of config directives that override any options in both
129
- # the defaults and the config file.
130
- # See Bridgetown::Configuration::DEFAULTS for a
131
- # list of option names and their defaults.
129
+ # @param override [Hash] - A an optional hash of config directives that override
130
+ # any options in both the defaults and the config file. See
131
+ # {Bridgetown::Configuration::DEFAULTS} for a list of option names and their
132
+ # defaults.
132
133
  #
133
- # Returns the final configuration Hash.
134
+ # @return [Hash] The final configuration hash.
134
135
  def configuration(override = {})
135
136
  config = Configuration.new
136
137
  override = Configuration[override].stringify_keys
@@ -145,15 +146,29 @@ module Bridgetown
145
146
  end
146
147
 
147
148
  # Conveinence method to register a new Thor command
149
+ #
150
+ # @see Bridgetown::Commands::Registrations.register
148
151
  def register_command(&block)
149
152
  Bridgetown::Commands::Registrations.register(&block)
150
153
  end
151
154
 
152
- # Public: Set the TZ environment variable to use the timezone specified
155
+ # Determines the correct Bundler environment block method to use and passes
156
+ # the block on to it.
157
+ #
158
+ # @return [void]
159
+ def with_unbundled_env(&block)
160
+ if Bundler.bundler_major_version >= 2
161
+ Bundler.method(:with_unbundled_env).call(&block)
162
+ else
163
+ Bundler.method(:with_clean_env).call(&block)
164
+ end
165
+ end
166
+
167
+ # Set the TZ environment variable to use the timezone specified
153
168
  #
154
- # timezone - the IANA Time Zone
169
+ # @param timezone [String] the IANA Time Zone
155
170
  #
156
- # Returns nothing
171
+ # @return [void]
157
172
  # rubocop:disable Naming/AccessorMethodName
158
173
  def set_timezone(timezone)
159
174
  ENV["TZ"] = if Utils::Platforms.really_windows?
@@ -164,38 +179,39 @@ module Bridgetown
164
179
  end
165
180
  # rubocop:enable Naming/AccessorMethodName
166
181
 
167
- # Public: Fetch the logger instance for this Bridgetown process.
182
+ # Fetch the logger instance for this Bridgetown process.
168
183
  #
169
- # Returns the LogAdapter instance.
184
+ # @return [LogAdapter]
170
185
  def logger
171
186
  @logger ||= LogAdapter.new(LogWriter.new, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
172
187
  end
173
188
 
174
- # Public: Set the log writer.
175
- # New log writer must respond to the same methods
176
- # as Ruby's interal Logger.
189
+ # Set the log writer. New log writer must respond to the same methods as Ruby's
190
+ # internal Logger.
177
191
  #
178
- # writer - the new Logger-compatible log transport
192
+ # @param writer [Object] the new Logger-compatible log transport
179
193
  #
180
- # Returns the new logger.
194
+ # @return [LogAdapter]
181
195
  def logger=(writer)
182
196
  @logger = LogAdapter.new(writer, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
183
197
  end
184
198
 
185
- # Public: An array of sites
199
+ # An array of sites. Currently only ever a single entry.
186
200
  #
187
- # Returns the Bridgetown sites created.
201
+ # @return [Array<Bridgetown::Site>] the Bridgetown sites created.
188
202
  def sites
189
203
  @sites ||= []
190
204
  end
191
205
 
192
- # Public: Ensures the questionable path is prefixed with the base directory
193
- # and prepends the questionable path with the base directory if false.
206
+ # Ensures the questionable path is prefixed with the base directory
207
+ # and prepends the questionable path with the base directory if false.
194
208
  #
195
- # base_directory - the directory with which to prefix the questionable path
196
- # questionable_path - the path we're unsure about, and want prefixed
209
+ # @param base_directory [String] the directory with which to prefix the
210
+ # questionable path
211
+ # @param questionable_path [String] the path we're unsure about, and want
212
+ # prefixed
197
213
  #
198
- # Returns the sanitized path.
214
+ # @return [String] the sanitized path
199
215
  def sanitized_path(base_directory, questionable_path)
200
216
  return base_directory if base_directory.eql?(questionable_path)
201
217
 
@@ -2,7 +2,10 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Collection
5
- attr_reader :site, :label, :metadata
5
+ # @return [Bridgetown::Site]
6
+ attr_reader :site
7
+
8
+ attr_reader :label, :metadata
6
9
  attr_writer :docs
7
10
 
8
11
  # Create a new Collection.
@@ -65,6 +68,7 @@ module Bridgetown
65
68
  read_static_file(file_path, full_path)
66
69
  end
67
70
  end
71
+ site.static_files.concat(files)
68
72
  sort_docs!
69
73
  end
70
74
 
@@ -44,7 +44,7 @@ module Bridgetown
44
44
 
45
45
  def apply_after_new_command
46
46
  # Coming from the new command, so set up proper bundler env
47
- Bundler.with_clean_env do
47
+ Bridgetown.with_unbundled_env do
48
48
  self.destination_root = New.created_site_dir
49
49
  inside(New.created_site_dir) do
50
50
  apply_from_url options[:apply]
@@ -62,7 +62,7 @@ module Bridgetown
62
62
  " current folder."
63
63
  end
64
64
 
65
- Bundler.with_clean_env do
65
+ Bridgetown.with_unbundled_env do
66
66
  apply_from_url automation_command
67
67
  end
68
68
  rescue ArgumentError => e
@@ -21,14 +21,14 @@ module Bridgetown
21
21
  desc: "Custom configuration file(s)"
22
22
  class_option :"bypass-ap",
23
23
  type: :boolean,
24
- desc: "Don't load AwesomePrint when IRB opens"
24
+ desc: "Don't load AmazingPrint when IRB opens"
25
25
  class_option :blank,
26
26
  type: :boolean,
27
27
  desc: "Skip reading content and running generators before opening console"
28
28
 
29
29
  def console
30
30
  require "irb"
31
- require "awesome_print" unless options[:"bypass-ap"]
31
+ require "amazing_print" unless options[:"bypass-ap"]
32
32
 
33
33
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
34
34
  " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
@@ -61,10 +61,10 @@ module Bridgetown
61
61
  begin
62
62
  catch(:IRB_EXIT) do
63
63
  unless options[:"bypass-ap"]
64
- AwesomePrint.defaults = {
64
+ AmazingPrint.defaults = {
65
65
  indent: 2,
66
66
  }
67
- AwesomePrint.irb!
67
+ AmazingPrint.irb!
68
68
  end
69
69
  irb.eval_input
70
70
  end
@@ -115,7 +115,7 @@ module Bridgetown
115
115
  def bundle_install(path)
116
116
  unless Bridgetown.environment == "test"
117
117
  require "bundler"
118
- Bundler.with_clean_env do
118
+ Bridgetown.with_unbundled_env do
119
119
  inside(path) do
120
120
  run "bundle install", abort_on_failure: true
121
121
  end
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  end
12
12
 
13
13
  def no_layout?
14
- data["layout"] == "none"
14
+ data["layout"] == "none" || data["layout"] == false
15
15
  end
16
16
  end
17
17
  end
@@ -8,10 +8,20 @@ module Bridgetown
8
8
  # contain any Liquid Tags or Variables, true otherwise.
9
9
  def render_with_liquid?
10
10
  return false if data["render_with_liquid"] == false
11
+ return false unless liquid_engine_configured?
11
12
 
12
13
  !(yaml_file? || !Utils.has_liquid_construct?(content))
13
14
  end
14
15
 
16
+ def liquid_engine_configured?
17
+ data["template_engine"] == "liquid" ||
18
+ (
19
+ data["template_engine"].nil? && (
20
+ site.config[:template_engine].nil? || site.config[:template_engine] == "liquid"
21
+ )
22
+ )
23
+ end
24
+
15
25
  # Override in individual classes
16
26
  def yaml_file?
17
27
  false
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Bridgetown
4
- module Site::Configurable
3
+ class Bridgetown::Site
4
+ module Configurable
5
5
  # Set the site's configuration. This handles side-effects caused by
6
- # changing values in the configuration.
6
+ # changing values in the configuration.
7
7
  #
8
- # @param config [Bridgetown::Configuration]
9
- # An instance of {Bridgetown::Configuration},
8
+ # @param config [Configuration]
9
+ # An instance of {Configuration},
10
10
  # containing the new configuration.
11
11
  #
12
- # @return [Bridgetown::Configuration]
13
- # A new instance of {Bridgetown::Configuration}
14
- #
15
- # @see Bridgetown::Configuration
12
+ # @return [Configuration]
13
+ # The processed instance of {Configuration}
16
14
  def config=(config)
17
15
  @config = config.clone
18
16
 
@@ -37,18 +35,22 @@ module Bridgetown
37
35
  @config
38
36
  end
39
37
 
38
+ def defaults_reader
39
+ @defaults_reader ||= Bridgetown::DefaultsReader.new(self)
40
+ end
41
+
40
42
  # Returns the current instance of {FrontmatterDefaults} or
41
- # creates a new instance {FrontmatterDefaults} if it doesn't already exist.
43
+ # creates a new instance {FrontmatterDefaults} if it doesn't already exist.
42
44
  #
43
45
  # @return [FrontmatterDefaults]
44
46
  # Returns an instance of {FrontmatterDefaults}
45
47
  def frontmatter_defaults
46
- @frontmatter_defaults ||= FrontmatterDefaults.new(self)
48
+ @frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
47
49
  end
48
50
 
49
51
  # Whether to perform a full rebuild without incremental regeneration.
50
- # If either +override+["incremental"] or +config+["incremental"] are true,
51
- # fully rebuild the site. If not, incrementally build the site.
52
+ # If either `override["incremental"]` or `config["incremental"]` are true,
53
+ # fully rebuild the site. If not, incrementally build the site.
52
54
  #
53
55
  # @param [Hash] override
54
56
  # An override hash to override the current config value
@@ -59,11 +61,11 @@ module Bridgetown
59
61
  end
60
62
 
61
63
  # Returns the current instance of {Publisher} or creates a new instance of
62
- # {Publisher} if one doesn't exist.
64
+ # {Publisher} if one doesn't exist.
63
65
  #
64
66
  # @return [Publisher] Returns an instance of {Publisher}
65
67
  def publisher
66
- @publisher ||= Publisher.new(self)
68
+ @publisher ||= Bridgetown::Publisher.new(self)
67
69
  end
68
70
 
69
71
  # Prefix a path or paths with the {#root_dir} directory.
@@ -122,16 +124,16 @@ module Bridgetown
122
124
  end
123
125
 
124
126
  # The full path to the directory that houses all the registered collections
125
- # for the current site.
127
+ # for the current site.
126
128
  #
127
- # If +@collections_path+ is specified use its value.
129
+ # If `@collections_path` is specified use its value.
128
130
  #
129
- # If +@collections+ is not specified and +config+["collections_dir"] is
130
- # specified, prepend it with {#source} and assign it to
131
- # {#collections_path}.
131
+ # If `@collections` is not specified and `config["collections_dir"]` is
132
+ # specified, prepend it with {#source} and assign it to
133
+ # {#collections_path}.
132
134
  #
133
- # If +@collections+ is not specified and +config+["collections_dir"] is not
134
- # specified, assign {#source} to +@collections_path+
135
+ # If `@collections` is not specified and `config["collections_dir"]` is not
136
+ # specified, assign {#source} to `@collections_path`
135
137
  #
136
138
  # @return [String] Returns the full path to the collections directory
137
139
  # @see #config
@@ -1,27 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Bridgetown
4
- module Site::Content
3
+ class Bridgetown::Site
4
+ # Content is king!
5
+ module Content
5
6
  # Construct a Hash of Posts indexed by the specified Post attribute.
6
7
  #
7
- # @param post_attr [String] The String name of the Post attribute.
8
- #
9
- # @example
10
- # Returns a hash like so: { attr => posts } where
8
+ # Returns a hash like so: `{ attr => posts }` where:
11
9
  #
12
- # attr - One of the values for the requested attribute.
10
+ # * `attr` - One of the values for the requested attribute.
11
+ # * `posts` - The array of Posts with the given attr value.
13
12
  #
14
- # posts - The Array of Posts with the given attr value.
13
+ # @param post_attr [String] The String name of the Post attribute.
15
14
  #
16
15
  # @example
17
- #
18
16
  # post_attr_hash('categories')
19
17
  # # => { 'tech' => [<Post A>, <Post B>],
20
18
  # # 'ruby' => [<Post B>] }
21
19
  #
22
20
  # @return [Hash{String, Symbol => Array<Post>}]
23
21
  # Returns a hash of !{attr => posts}
24
- #
25
22
  def post_attr_hash(post_attr)
26
23
  # Build a hash map based on the specified post attribute ( post attr =>
27
24
  # array of posts ) then sort each array in reverse order.
@@ -36,7 +33,7 @@ module Bridgetown
36
33
  end
37
34
 
38
35
  # Returns a hash of "tags" using {#post_attr_hash} where each tag is a key
39
- # and each value is a post which contains the key.
36
+ # and each value is a post which contains the key.
40
37
  # @example
41
38
  # tags
42
39
  # # => { 'tech': [<Post A>, <Post B>],
@@ -48,7 +45,7 @@ module Bridgetown
48
45
  end
49
46
 
50
47
  # Returns a hash of "categories" using {#post_attr_hash} where each tag is
51
- # a key and each value is a post which contains the key.
48
+ # a key and each value is a post which contains the key.
52
49
  # @example
53
50
  # categories
54
51
  # # => { 'tech': [<Post A>, <Post B>],
@@ -60,11 +57,11 @@ module Bridgetown
60
57
  post_attr_hash("categories")
61
58
  end
62
59
 
63
- # Returns the value of +data+["site_metadata"] or creates a new instance of
64
- # +ActiveSupport::HashWithIndifferentAccess+
60
+ # Returns the value of `data["site_metadata"]` or creates a new instance of
61
+ # `HashWithDotAccess::Hash`
65
62
  # @return [Hash] Returns a hash of site metadata
66
63
  def metadata
67
- data["site_metadata"] ||= ActiveSupport::HashWithIndifferentAccess.new
64
+ data["site_metadata"] ||= HashWithDotAccess::Hash.new
68
65
  end
69
66
 
70
67
  # The Hash payload containing site-wide data.
@@ -98,34 +95,33 @@ module Bridgetown
98
95
  #
99
96
  # @see #post_attr_hash
100
97
  def site_payload
101
- Drops::UnifiedPayloadDrop.new self
98
+ Bridgetown::Drops::UnifiedPayloadDrop.new self
102
99
  end
103
100
  alias_method :to_liquid, :site_payload
104
101
 
105
- # The list of {#collections} and their corresponding {Bridgetown::Collection} instances.
102
+ # The list of collections labels and their corresponding {Collection} instances.
106
103
  #
107
- # If +config+['collections'] is set, a new instance of {Bridgetown::Collection} is created
108
- # for each entry in the collections configuration.
104
+ # If `config['collections']` is set, a new instance of {Collection} is created
105
+ # for each entry in the collections configuration.
109
106
  #
110
- # If +config+["collections"] is not specified, a blank hash is returned.
107
+ # If `config["collections"]` is not specified, a blank hash is returned.
111
108
  #
112
- # @return [Hash{String, Symbol => Bridgetown::Collection}] A Hash
109
+ # @return [Hash{String, Symbol => Collection}] A Hash
113
110
  # containing a collection name-to-instance pairs.
114
111
  #
115
112
  # @return [Hash] Returns a blank hash if no items found
116
- # @see Collection
117
113
  def collections
118
114
  @collections ||= collection_names.each_with_object(
119
- ActiveSupport::HashWithIndifferentAccess.new
115
+ HashWithDotAccess::Hash.new
120
116
  ) do |name, hsh|
121
117
  hsh[name] = Bridgetown::Collection.new(self, name)
122
118
  end
123
119
  end
124
120
 
125
121
  # An array of collection names.
126
- # @return [Array<Collection>] an array of collection names from the configuration,
127
- # or an empty array if the +config+["collections"] key is not set.
128
- # @raise ArgumentError Raise an error if +config+["collections"] is not
122
+ # @return [Array<String>] an array of collection names from the configuration,
123
+ # or an empty array if the `config["collections"]` key is not set.
124
+ # @raise ArgumentError Raise an error if `config["collections"]` is not
129
125
  # an Array or a Hash
130
126
  def collection_names
131
127
  case config["collections"]
@@ -141,17 +137,18 @@ module Bridgetown
141
137
  end
142
138
 
143
139
  # Get all documents.
144
- # @return [Array<String>] an array of documents from the configuration
140
+ # @return [Array<Document>] an array of documents from the
141
+ # configuration
145
142
  def documents
146
143
  collections.each_with_object(Set.new) do |(_, collection), set|
147
- set.merge(collection.docs).merge(collection.files)
144
+ set.merge(collection.docs)
148
145
  end.to_a
149
146
  end
150
147
 
151
148
  # Get the documents to be written
152
149
  #
153
- # @return [Array<String, File>] an Array of Documents which should be written and
154
- # that +respond_to :write?+
150
+ # @return [Array<Document>] an array of documents which should be
151
+ # written and that `respond_to :write?`
155
152
  # @see #documents
156
153
  # @see Collection
157
154
  def docs_to_write
@@ -160,11 +157,27 @@ module Bridgetown
160
157
 
161
158
  # Get all posts.
162
159
  #
163
- # @return [Collection] A #Collection of posts. Returns +#collections+["posts"]
164
- # @return [Collection] Return a new #Collection if +#collections+["posts"] is nil
160
+ # @return [Collection] Returns {#collections}`["posts"]`, creating it if need be
165
161
  # @see Collection
166
162
  def posts
167
- collections["posts"] ||= Collection.new(self, "posts")
163
+ collections["posts"] ||= Bridgetown::Collection.new(self, "posts")
164
+ end
165
+
166
+ # Get the static files to be written
167
+ #
168
+ # @return [Array<StaticFile>] an array of files which should be
169
+ # written and that `respond_to :write?`
170
+ # @see #static_files
171
+ # @see StaticFile
172
+ def static_files_to_write
173
+ static_files.select(&:write?)
174
+ end
175
+
176
+ # Get all pages and documents (posts and collection items) in a single array.
177
+ #
178
+ # @return [Array]
179
+ def contents
180
+ pages + documents
168
181
  end
169
182
  end
170
183
  end