bridgetown-core 0.15.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/bridgetown-core.gemspec +4 -1
  4. data/lib/bridgetown-core.rb +8 -2
  5. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -1
  6. data/lib/bridgetown-core/commands/console.rb +4 -4
  7. data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
  8. data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
  9. data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
  10. data/lib/bridgetown-core/concerns/publishable.rb +10 -0
  11. data/lib/bridgetown-core/concerns/site/configurable.rb +66 -31
  12. data/lib/bridgetown-core/concerns/site/content.rb +90 -31
  13. data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
  14. data/lib/bridgetown-core/concerns/site/localizable.rb +20 -0
  15. data/lib/bridgetown-core/concerns/site/processable.rb +14 -12
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +21 -2
  17. data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
  18. data/lib/bridgetown-core/concerns/validatable.rb +59 -0
  19. data/lib/bridgetown-core/configuration.rb +10 -3
  20. data/lib/bridgetown-core/converter.rb +34 -0
  21. data/lib/bridgetown-core/converters/erb_templates.rb +78 -0
  22. data/lib/bridgetown-core/converters/markdown.rb +6 -23
  23. data/lib/bridgetown-core/converters/smartypants.rb +0 -10
  24. data/lib/bridgetown-core/document.rb +11 -55
  25. data/lib/bridgetown-core/drops/site_drop.rb +1 -1
  26. data/lib/bridgetown-core/errors.rb +2 -0
  27. data/lib/bridgetown-core/excerpt.rb +1 -6
  28. data/lib/bridgetown-core/filters.rb +11 -48
  29. data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
  30. data/lib/bridgetown-core/frontmatter_defaults.rb +17 -0
  31. data/lib/bridgetown-core/layout.rb +24 -1
  32. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
  33. data/lib/bridgetown-core/page.rb +41 -26
  34. data/lib/bridgetown-core/plugin_manager.rb +10 -2
  35. data/lib/bridgetown-core/reader.rb +1 -0
  36. data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
  37. data/lib/bridgetown-core/readers/data_reader.rb +4 -3
  38. data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
  39. data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
  40. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  41. data/lib/bridgetown-core/readers/post_reader.rb +1 -0
  42. data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
  43. data/lib/bridgetown-core/regenerator.rb +1 -1
  44. data/lib/bridgetown-core/renderer.rb +40 -14
  45. data/lib/bridgetown-core/ruby_template_view.rb +113 -0
  46. data/lib/bridgetown-core/site.rb +2 -0
  47. data/lib/bridgetown-core/tags/class_map.rb +90 -0
  48. data/lib/bridgetown-core/tags/find.rb +86 -0
  49. data/lib/bridgetown-core/tags/t.rb +14 -0
  50. data/lib/bridgetown-core/tags/webpack_path.rb +19 -22
  51. data/lib/bridgetown-core/utils.rb +55 -2
  52. data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
  53. data/lib/bridgetown-core/version.rb +2 -2
  54. data/lib/site_template/src/_layouts/{default.html → default.liquid} +0 -0
  55. data/lib/site_template/src/_layouts/{home.html → home.liquid} +0 -0
  56. data/lib/site_template/src/_layouts/{page.html → page.liquid} +0 -0
  57. data/lib/site_template/src/_layouts/{post.html → post.liquid} +0 -0
  58. metadata +64 -10
  59. data/lib/bridgetown-core/concerns/convertible.rb +0 -235
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97ae06ce8eba440f7fbf028094f48c4779b08245c7e2edd2641deed2ccb271b0
4
- data.tar.gz: b0680214291a6721bb43230bca4627608414fea6a6fc741b2431672dfd04a39d
3
+ metadata.gz: 7878e020dc228c491934a986395227f17fa2ca93398ae0f3961a77c4df6e1761
4
+ data.tar.gz: 73dd2ad473c8525974708393f97f0ce464241fedcc78951186b726ea3435c444
5
5
  SHA512:
6
- metadata.gz: b742ce6a54a89c48beb0f12e27cb0bb8a67630ca0e749b30919ffc8a4be2054a9de38374bde59ba2f2f2db1a436a6704dc070f6eb418e85f650bb2f66d8c3dd0
7
- data.tar.gz: 99a4bfe0ab8fb3dcf94e92423089048d9149722044b79ac698c95eda96872cfa84a25e5cc2e190d4f77f2215c80199aae01d9d7aa63669f6e21790c4279e50dc
6
+ metadata.gz: 38624e9ea2b7e604b773f2224eec18fdce5e44fc9c9e388c7cefa1ebee6fcee62aa96406ff783a7458a5b3d7a24f45c486a2cc2e925867609a26cb8e30336bb1
7
+ data.tar.gz: eb46348e312153b95b46b1b5e7fbfca154c4d39c87af62e9b77ccdfacdd43cca640b8adf216c223aeb9f47f92977df48d3550dab1a7a173dac256c92cf89f77f
data/Rakefile CHANGED
@@ -12,3 +12,17 @@ Rake::TestTask.new(:test) do |test|
12
12
  test.pattern = "test/**/test_*.rb"
13
13
  test.verbose = true
14
14
  end
15
+
16
+ require 'yard'
17
+ YARD::Rake::YardocTask.new(:yard) do |t|
18
+ t.files = ['lib/**/*.rb']
19
+ t.options = ['--no-output']
20
+ t.stats_options = ['--list-undoc']
21
+ end
22
+
23
+ namespace :yard do
24
+ task :serve do
25
+ port = ENV['YARD_PORT'] || "8808"
26
+ sh("yard server --reload -p #{port}")
27
+ end
28
+ end
@@ -33,10 +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
+ s.add_runtime_dependency("erubi", "~> 1.9")
38
39
  s.add_runtime_dependency("faraday", "~> 1.0")
39
40
  s.add_runtime_dependency("faraday_middleware", "~> 1.0")
41
+ s.add_runtime_dependency("hash_with_dot_access", "~> 1.0")
40
42
  s.add_runtime_dependency("i18n", "~> 1.0")
41
43
  s.add_runtime_dependency("kramdown", "~> 2.1")
42
44
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
@@ -49,4 +51,5 @@ Gem::Specification.new do |s|
49
51
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
50
52
  s.add_runtime_dependency("terminal-table", "~> 1.8")
51
53
  s.add_runtime_dependency("thor", "~> 1.0")
54
+ s.add_runtime_dependency("tilt", "~> 2.0")
52
55
  end
@@ -29,8 +29,8 @@ require "csv"
29
29
  require "json"
30
30
 
31
31
  # 3rd party
32
- require "active_support/core_ext/hash/indifferent_access"
33
32
  require "active_support/core_ext/string/inflections"
33
+ require "hash_with_dot_access"
34
34
  require "pathutil"
35
35
  require "addressable/uri"
36
36
  require "safe_yaml/load"
@@ -54,7 +54,7 @@ module Bridgetown
54
54
  autoload :Cleaner, "bridgetown-core/cleaner"
55
55
  autoload :Collection, "bridgetown-core/collection"
56
56
  autoload :Configuration, "bridgetown-core/configuration"
57
- autoload :Convertible, "bridgetown-core/concerns/convertible"
57
+ autoload :DataAccessible, "bridgetown-core/concerns/data_accessible"
58
58
  autoload :Deprecator, "bridgetown-core/deprecator"
59
59
  autoload :Document, "bridgetown-core/document"
60
60
  autoload :EntryFilter, "bridgetown-core/entry_filter"
@@ -64,9 +64,11 @@ module Bridgetown
64
64
  autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
65
65
  autoload :Hooks, "bridgetown-core/hooks"
66
66
  autoload :Layout, "bridgetown-core/layout"
67
+ autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
67
68
  autoload :Cache, "bridgetown-core/cache"
68
69
  autoload :CollectionReader, "bridgetown-core/readers/collection_reader"
69
70
  autoload :DataReader, "bridgetown-core/readers/data_reader"
71
+ autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
70
72
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
71
73
  autoload :PostReader, "bridgetown-core/readers/post_reader"
72
74
  autoload :PageReader, "bridgetown-core/readers/page_reader"
@@ -77,17 +79,21 @@ module Bridgetown
77
79
  autoload :PageWithoutAFile, "bridgetown-core/page_without_a_file"
78
80
  autoload :PathManager, "bridgetown-core/path_manager"
79
81
  autoload :PluginManager, "bridgetown-core/plugin_manager"
82
+ autoload :Publishable, "bridgetown-core/concerns/publishable"
80
83
  autoload :Publisher, "bridgetown-core/publisher"
81
84
  autoload :Reader, "bridgetown-core/reader"
82
85
  autoload :Regenerator, "bridgetown-core/regenerator"
83
86
  autoload :RelatedPosts, "bridgetown-core/related_posts"
84
87
  autoload :Renderer, "bridgetown-core/renderer"
88
+ autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
85
89
  autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
90
+ autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
86
91
  autoload :LogWriter, "bridgetown-core/log_writer"
87
92
  autoload :Site, "bridgetown-core/site"
88
93
  autoload :StaticFile, "bridgetown-core/static_file"
89
94
  autoload :URL, "bridgetown-core/url"
90
95
  autoload :Utils, "bridgetown-core/utils"
96
+ autoload :Validatable, "bridgetown-core/concerns/validatable"
91
97
  autoload :VERSION, "bridgetown-core/version"
92
98
  autoload :Watcher, "bridgetown-core/watcher"
93
99
 
@@ -11,6 +11,7 @@ module Bridgetown
11
11
  GITHUB_REGEX = %r!https://github\.com!.freeze
12
12
  GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!.freeze
13
13
  GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!.freeze
14
+ GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!.freeze
14
15
 
15
16
  def create_builder(filename, data = nil)
16
17
  say_status :create_builder, filename
@@ -114,7 +115,7 @@ module Bridgetown
114
115
  elsif github_blob_match
115
116
  new_url.sub("/blob/", "/")
116
117
  else
117
- "#{new_url}/master"
118
+ "#{new_url}/#{Bridgetown::Utils.default_github_branch_name(arg)}"
118
119
  end
119
120
  else
120
121
  arg
@@ -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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module DataAccessible
5
+ # Returns the contents as a String.
6
+ def to_s
7
+ output || content || ""
8
+ end
9
+
10
+ # Accessor for data properties by Liquid.
11
+ #
12
+ # property - The String name of the property to retrieve.
13
+ #
14
+ # Returns the String value or nil if the property isn't included.
15
+ def [](property)
16
+ data[property]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module LayoutPlaceable
5
+ # Determine whether the file should be placed into layouts.
6
+ #
7
+ # Returns false if the document is an asset file or if the front matter
8
+ # specifies `layout: none`
9
+ def place_in_layout?
10
+ !(yaml_file? || no_layout?)
11
+ end
12
+
13
+ def no_layout?
14
+ data["layout"] == "none"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module LiquidRenderable
5
+ # Determine whether the file should be rendered with Liquid.
6
+ #
7
+ # Returns false if the document is a yaml file or if the document doesn't
8
+ # contain any Liquid Tags or Variables, true otherwise.
9
+ def render_with_liquid?
10
+ return false if data["render_with_liquid"] == false
11
+
12
+ !(yaml_file? || !Utils.has_liquid_construct?(content))
13
+ end
14
+
15
+ # Override in individual classes
16
+ def yaml_file?
17
+ false
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Publishable
5
+ # Whether the file is published or not, as indicated in YAML front-matter
6
+ def published?
7
+ !(data.key?("published") && data["published"] == false)
8
+ end
9
+ end
10
+ end
@@ -2,12 +2,17 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Site::Configurable
5
- # Public: Set the site's configuration. This handles side-effects caused by
5
+ # Set the site's configuration. This handles side-effects caused by
6
6
  # changing values in the configuration.
7
7
  #
8
- # config - a Bridgetown::Configuration, containing the new configuration.
8
+ # @param config [Bridgetown::Configuration]
9
+ # An instance of {Bridgetown::Configuration},
10
+ # containing the new configuration.
9
11
  #
10
- # Returns the new configuration.
12
+ # @return [Bridgetown::Configuration]
13
+ # A new instance of {Bridgetown::Configuration}
14
+ #
15
+ # @see Bridgetown::Configuration
11
16
  def config=(config)
12
17
  @config = config.clone
13
18
 
@@ -32,81 +37,111 @@ module Bridgetown
32
37
  @config
33
38
  end
34
39
 
35
- # Returns the FrontmatterDefaults or creates a new FrontmatterDefaults
36
- # if it doesn't already exist.
40
+ def defaults_reader
41
+ @defaults_reader ||= DefaultsReader.new(self)
42
+ end
43
+
44
+ # Returns the current instance of {FrontmatterDefaults} or
45
+ # creates a new instance {FrontmatterDefaults} if it doesn't already exist.
37
46
  #
38
- # Returns The FrontmatterDefaults
47
+ # @return [FrontmatterDefaults]
48
+ # Returns an instance of {FrontmatterDefaults}
39
49
  def frontmatter_defaults
40
50
  @frontmatter_defaults ||= FrontmatterDefaults.new(self)
41
51
  end
42
52
 
43
- # Whether to perform a full rebuild without incremental regeneration
53
+ # Whether to perform a full rebuild without incremental regeneration.
54
+ # If either +override+["incremental"] or +config+["incremental"] are true,
55
+ # fully rebuild the site. If not, incrementally build the site.
44
56
  #
45
- # Returns a Boolean: true for a full rebuild, false for normal build
57
+ # @param [Hash] override
58
+ # An override hash to override the current config value
59
+ # @option override [Boolean] "incremental" Whether to incrementally build
60
+ # @return [Boolean] true for full rebuild, false for normal build
46
61
  def incremental?(override = {})
47
62
  override["incremental"] || config["incremental"]
48
63
  end
49
64
 
50
- # Returns the publisher or creates a new publisher if it doesn't
51
- # already exist.
65
+ # Returns the current instance of {Publisher} or creates a new instance of
66
+ # {Publisher} if one doesn't exist.
52
67
  #
53
- # Returns The Publisher
68
+ # @return [Publisher] Returns an instance of {Publisher}
54
69
  def publisher
55
70
  @publisher ||= Publisher.new(self)
56
71
  end
57
72
 
58
- # Public: Prefix a given path with the root directory.
73
+ # Prefix a path or paths with the {#root_dir} directory.
59
74
  #
60
- # paths - (optional) path elements to a file or directory within the
61
- # root directory
75
+ # @see Bridgetown.sanitized_path
76
+ # @param paths [Array<String>]
77
+ # An array of paths to prefix with the root_dir directory using the
78
+ # {Bridgetown.sanitized_path} method.
62
79
  #
63
- # Returns a path which is prefixed with the root_dir directory.
80
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
64
81
  def in_root_dir(*paths)
65
82
  paths.reduce(root_dir) do |base, path|
66
83
  Bridgetown.sanitized_path(base, path)
67
84
  end
68
85
  end
69
86
 
70
- # Public: Prefix a given path with the source directory.
71
- #
72
- # paths - (optional) path elements to a file or directory within the
73
- # source directory
87
+ # Prefix a path or paths with the {#source} directory.
74
88
  #
75
- # Returns a path which is prefixed with the source directory.
89
+ # @see Bridgetown.sanitized_path
90
+ # @param paths [Array<String>]
91
+ # An array of paths to prefix with the source directory using the
92
+ # {Bridgetown.sanitized_path} method.
93
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
76
94
  def in_source_dir(*paths)
77
95
  paths.reduce(source) do |base, path|
78
96
  Bridgetown.sanitized_path(base, path)
79
97
  end
80
98
  end
81
99
 
82
- # Public: Prefix a given path with the destination directory.
100
+ # Prefix a path or paths with the {#dest} directory.
83
101
  #
84
- # paths - (optional) path elements to a file or directory within the
85
- # destination directory
102
+ # @see Bridgetown.sanitized_path
103
+ # @param paths [Array<String>]
104
+ # An array of paths to prefix with the destination directory using the
105
+ # {Bridgetown.sanitized_path} method.
86
106
  #
87
- # Returns a path which is prefixed with the destination directory.
107
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
88
108
  def in_dest_dir(*paths)
89
109
  paths.reduce(dest) do |base, path|
90
110
  Bridgetown.sanitized_path(base, path)
91
111
  end
92
112
  end
93
113
 
94
- # Public: Prefix a given path with the cache directory.
114
+ # Prefix a path or paths with the {#cache_dir} directory.
95
115
  #
96
- # paths - (optional) path elements to a file or directory within the
97
- # cache directory
116
+ # @see Bridgetown.sanitized_path
117
+ # @param paths [Array<String>]
118
+ # An array of paths to prefix with the {#cache_dir} directory using the
119
+ # {Bridgetown.sanitized_path} method.
98
120
  #
99
- # Returns a path which is prefixed with the cache directory.
121
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
100
122
  def in_cache_dir(*paths)
101
123
  paths.reduce(cache_dir) do |base, path|
102
124
  Bridgetown.sanitized_path(base, path)
103
125
  end
104
126
  end
105
127
 
106
- # Public: The full path to the directory that houses all the collections registered
107
- # with the current site.
128
+ # The full path to the directory that houses all the registered collections
129
+ # for the current site.
130
+ #
131
+ # If +@collections_path+ is specified use its value.
132
+ #
133
+ # If +@collections+ is not specified and +config+["collections_dir"] is
134
+ # specified, prepend it with {#source} and assign it to
135
+ # {#collections_path}.
136
+ #
137
+ # If +@collections+ is not specified and +config+["collections_dir"] is not
138
+ # specified, assign {#source} to +@collections_path+
108
139
  #
109
- # Returns the source directory or the absolute path to the custom collections_dir
140
+ # @return [String] Returns the full path to the collections directory
141
+ # @see #config
142
+ # @see #source
143
+ # @see #collections_path
144
+ # @see #in_source_dir
110
145
  def collections_path
111
146
  dir_str = config["collections_dir"]
112
147
  @collections_path ||= dir_str.empty? ? source : in_source_dir(dir_str)
@@ -4,17 +4,24 @@ module Bridgetown
4
4
  module Site::Content
5
5
  # Construct a Hash of Posts indexed by the specified Post attribute.
6
6
  #
7
- # post_attr - The String name of the Post attribute.
7
+ # @param post_attr [String] The String name of the Post attribute.
8
8
  #
9
- # Examples
9
+ # @example
10
+ # Returns a hash like so: { attr => posts } where
11
+ #
12
+ # attr - One of the values for the requested attribute.
13
+ #
14
+ # posts - The Array of Posts with the given attr value.
15
+ #
16
+ # @example
10
17
  #
11
18
  # post_attr_hash('categories')
12
19
  # # => { 'tech' => [<Post A>, <Post B>],
13
20
  # # 'ruby' => [<Post B>] }
14
21
  #
15
- # Returns the Hash: { attr => posts } where
16
- # attr - One of the values for the requested attribute.
17
- # posts - The Array of Posts with the given attr value.
22
+ # @return [Hash{String, Symbol => Array<Post>}]
23
+ # Returns a hash of !{attr => posts}
24
+ #
18
25
  def post_attr_hash(post_attr)
19
26
  # Build a hash map based on the specified post attribute ( post attr =>
20
27
  # array of posts ) then sort each array in reverse order.
@@ -28,53 +35,98 @@ module Bridgetown
28
35
  end
29
36
  end
30
37
 
38
+ # 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.
40
+ # @example
41
+ # tags
42
+ # # => { 'tech': [<Post A>, <Post B>],
43
+ # # 'ruby': [<Post C> }
44
+ # @return [Hash{String, Array<Post>}] Returns a hash of all tags and their corresponding posts
45
+ # @see post_attr_hash
31
46
  def tags
32
47
  post_attr_hash("tags")
33
48
  end
34
49
 
50
+ # 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.
52
+ # @example
53
+ # categories
54
+ # # => { 'tech': [<Post A>, <Post B>],
55
+ # # 'ruby': [<Post C> }
56
+ # @return [Hash{String, Array<Post>}] Returns a hash of all categories and
57
+ # their corresponding posts
58
+ # @see post_attr_hash
35
59
  def categories
36
60
  post_attr_hash("categories")
37
61
  end
38
62
 
63
+ # Returns the value of +data+["site_metadata"] or creates a new instance of
64
+ # +HashWithDotAccess::Hash+
65
+ # @return [Hash] Returns a hash of site metadata
39
66
  def metadata
40
- data["site_metadata"] ||= ActiveSupport::HashWithIndifferentAccess.new
67
+ data["site_metadata"] ||= HashWithDotAccess::Hash.new
41
68
  end
42
69
 
43
70
  # The Hash payload containing site-wide data.
44
71
  #
45
- # Returns the Hash: { "site" => data } where data is a Hash with keys:
46
- # "time" - The Time as specified in the configuration or the
47
- # current time if none was specified.
48
- # "posts" - The Array of Posts, sorted chronologically by post date
49
- # and then title.
50
- # "pages" - The Array of all Pages.
51
- # "html_pages" - The Array of HTML Pages.
52
- # "categories" - The Hash of category values and Posts.
53
- # See Site#post_attr_hash for type info.
54
- # "tags" - The Hash of tag values and Posts.
55
- # See Site#post_attr_hash for type info.
72
+ # @example
73
+ # site_payload
74
+ # # => { "site" => data } Where data is a Hash. See example below
75
+ #
76
+ # site = site_payload["site"]
77
+ # # => Returns a Hash with the following keys:
78
+ # #
79
+ # # site["time"] - The Time as specified in the configuration or the
80
+ # # current time if none was specified.
81
+ # #
82
+ # # site["posts"] - The Array of Posts, sorted chronologically by post date
83
+ # # and then title.
84
+ # #
85
+ # # site["pages"] - The Array of all Pages.
86
+ # #
87
+ # # site["html_pages"] - The Array of HTML Pages.
88
+ # #
89
+ # # site["categories"] - The Hash of category values and Posts.
90
+ # # See Site#post_attr_hash for type info.
91
+ # #
92
+ # # site["tags"] - The Hash of tag values and Posts.
93
+ # # See Site#post_attr_hash for type info.
94
+ #
95
+ # @return [Hash] Returns a hash in the structure of { "site" => data }
96
+ #
97
+ # See above example for usage.
98
+ #
99
+ # @see #post_attr_hash
56
100
  def site_payload
57
101
  Drops::UnifiedPayloadDrop.new self
58
102
  end
59
103
  alias_method :to_liquid, :site_payload
60
104
 
61
- # The list of collections and their corresponding Bridgetown::Collection instances.
62
- # If config['collections'] is set, a new instance is created
63
- # for each item in the collection, a new hash is returned otherwise.
105
+ # The list of {#collections} and their corresponding {Bridgetown::Collection} instances.
106
+ #
107
+ # If +config+['collections'] is set, a new instance of {Bridgetown::Collection} is created
108
+ # for each entry in the collections configuration.
109
+ #
110
+ # If +config+["collections"] is not specified, a blank hash is returned.
64
111
  #
65
- # Returns a Hash containing collection name-to-instance pairs.
112
+ # @return [Hash{String, Symbol => Bridgetown::Collection}] A Hash
113
+ # containing a collection name-to-instance pairs.
114
+ #
115
+ # @return [Hash] Returns a blank hash if no items found
116
+ # @see Collection
66
117
  def collections
67
118
  @collections ||= collection_names.each_with_object(
68
- ActiveSupport::HashWithIndifferentAccess.new
119
+ HashWithDotAccess::Hash.new
69
120
  ) do |name, hsh|
70
121
  hsh[name] = Bridgetown::Collection.new(self, name)
71
122
  end
72
123
  end
73
124
 
74
- # The list of collection names.
75
- #
76
- # Returns an array of collection names from the configuration,
77
- # or an empty array if the `collections` key is not set.
125
+ # 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
129
+ # an Array or a Hash
78
130
  def collection_names
79
131
  case config["collections"]
80
132
  when Hash
@@ -88,22 +140,29 @@ module Bridgetown
88
140
  end
89
141
  end
90
142
 
91
- # Get all the documents
92
- #
93
- # Returns an Array of all Documents
143
+ # Get all documents.
144
+ # @return [Array<String>] an array of documents from the configuration
94
145
  def documents
95
146
  collections.each_with_object(Set.new) do |(_, collection), set|
96
147
  set.merge(collection.docs).merge(collection.files)
97
148
  end.to_a
98
149
  end
99
150
 
100
- # Get the to be written documents
151
+ # Get the documents to be written
101
152
  #
102
- # Returns an Array of Documents which should be written
153
+ # @return [Array<String, File>] an Array of Documents which should be written and
154
+ # that +respond_to :write?+
155
+ # @see #documents
156
+ # @see Collection
103
157
  def docs_to_write
104
158
  documents.select(&:write?)
105
159
  end
106
160
 
161
+ # Get all posts.
162
+ #
163
+ # @return [Collection] A #Collection of posts. Returns +#collections+["posts"]
164
+ # @return [Collection] Return a new #Collection if +#collections+["posts"] is nil
165
+ # @see Collection
107
166
  def posts
108
167
  collections["posts"] ||= Collection.new(self, "posts")
109
168
  end