bridgetown-core 0.15.0 → 0.16.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/bridgetown-core.gemspec +1 -0
  4. data/lib/bridgetown-core.rb +6 -1
  5. data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
  6. data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
  7. data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
  8. data/lib/bridgetown-core/concerns/publishable.rb +10 -0
  9. data/lib/bridgetown-core/concerns/site/configurable.rb +62 -31
  10. data/lib/bridgetown-core/concerns/site/content.rb +88 -29
  11. data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
  12. data/lib/bridgetown-core/concerns/site/processable.rb +12 -10
  13. data/lib/bridgetown-core/concerns/site/renderable.rb +22 -2
  14. data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
  15. data/lib/bridgetown-core/concerns/validatable.rb +59 -0
  16. data/lib/bridgetown-core/configuration.rb +1 -0
  17. data/lib/bridgetown-core/converter.rb +34 -0
  18. data/lib/bridgetown-core/converters/erb_templates.rb +61 -0
  19. data/lib/bridgetown-core/converters/markdown.rb +6 -23
  20. data/lib/bridgetown-core/converters/smartypants.rb +0 -10
  21. data/lib/bridgetown-core/document.rb +8 -52
  22. data/lib/bridgetown-core/errors.rb +2 -0
  23. data/lib/bridgetown-core/excerpt.rb +1 -6
  24. data/lib/bridgetown-core/filters.rb +2 -0
  25. data/lib/bridgetown-core/layout.rb +24 -1
  26. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
  27. data/lib/bridgetown-core/page.rb +33 -24
  28. data/lib/bridgetown-core/regenerator.rb +1 -1
  29. data/lib/bridgetown-core/renderer.rb +38 -12
  30. data/lib/bridgetown-core/ruby_template_view.rb +84 -0
  31. data/lib/bridgetown-core/tags/class_map.rb +90 -0
  32. data/lib/bridgetown-core/tags/webpack_path.rb +48 -16
  33. data/lib/bridgetown-core/version.rb +2 -2
  34. metadata +24 -3
  35. 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: 25a57f1cf4e0a06e347edf5c97c78a168bc56f5efab6fdcf7f55a78ac491a3de
4
+ data.tar.gz: 96f00f4e411b8f46467d3f8ff6ecb153c07a34f5496f4109361afdfe8d7493c0
5
5
  SHA512:
6
- metadata.gz: b742ce6a54a89c48beb0f12e27cb0bb8a67630ca0e749b30919ffc8a4be2054a9de38374bde59ba2f2f2db1a436a6704dc070f6eb418e85f650bb2f66d8c3dd0
7
- data.tar.gz: 99a4bfe0ab8fb3dcf94e92423089048d9149722044b79ac698c95eda96872cfa84a25e5cc2e190d4f77f2215c80199aae01d9d7aa63669f6e21790c4279e50dc
6
+ metadata.gz: 378534362fb45c10c4aef9600771e10d13d07f827309ee2dd2395ff5c60a9b36c1e1b309e48274de3ef09ac9d16178ad563d49da437535961ba27844c86020d0
7
+ data.tar.gz: dda52cf9adc2768b57dc93677babdd63b5d1e500a8fbfe7c69f0dcb719701f3b986ae740d3fca703932f346b172b23e0c8561549a7f1dddad7b3b97b3605e535
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
@@ -49,4 +49,5 @@ Gem::Specification.new do |s|
49
49
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
50
50
  s.add_runtime_dependency("terminal-table", "~> 1.8")
51
51
  s.add_runtime_dependency("thor", "~> 1.0")
52
+ s.add_runtime_dependency("tilt", "~> 2.0")
52
53
  end
@@ -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,6 +64,7 @@ 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"
@@ -77,17 +78,21 @@ module Bridgetown
77
78
  autoload :PageWithoutAFile, "bridgetown-core/page_without_a_file"
78
79
  autoload :PathManager, "bridgetown-core/path_manager"
79
80
  autoload :PluginManager, "bridgetown-core/plugin_manager"
81
+ autoload :Publishable, "bridgetown-core/concerns/publishable"
80
82
  autoload :Publisher, "bridgetown-core/publisher"
81
83
  autoload :Reader, "bridgetown-core/reader"
82
84
  autoload :Regenerator, "bridgetown-core/regenerator"
83
85
  autoload :RelatedPosts, "bridgetown-core/related_posts"
84
86
  autoload :Renderer, "bridgetown-core/renderer"
87
+ autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
85
88
  autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
89
+ autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
86
90
  autoload :LogWriter, "bridgetown-core/log_writer"
87
91
  autoload :Site, "bridgetown-core/site"
88
92
  autoload :StaticFile, "bridgetown-core/static_file"
89
93
  autoload :URL, "bridgetown-core/url"
90
94
  autoload :Utils, "bridgetown-core/utils"
95
+ autoload :Validatable, "bridgetown-core/concerns/validatable"
91
96
  autoload :VERSION, "bridgetown-core/version"
92
97
  autoload :Watcher, "bridgetown-core/watcher"
93
98
 
@@ -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,107 @@ 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
+ # Returns the current instance of {FrontmatterDefaults} or
41
+ # creates a new instance {FrontmatterDefaults} if it doesn't already exist.
37
42
  #
38
- # Returns The FrontmatterDefaults
43
+ # @return [FrontmatterDefaults]
44
+ # Returns an instance of {FrontmatterDefaults}
39
45
  def frontmatter_defaults
40
46
  @frontmatter_defaults ||= FrontmatterDefaults.new(self)
41
47
  end
42
48
 
43
- # Whether to perform a full rebuild without incremental regeneration
49
+ # 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.
44
52
  #
45
- # Returns a Boolean: true for a full rebuild, false for normal build
53
+ # @param [Hash] override
54
+ # An override hash to override the current config value
55
+ # @option override [Boolean] "incremental" Whether to incrementally build
56
+ # @return [Boolean] true for full rebuild, false for normal build
46
57
  def incremental?(override = {})
47
58
  override["incremental"] || config["incremental"]
48
59
  end
49
60
 
50
- # Returns the publisher or creates a new publisher if it doesn't
51
- # already exist.
61
+ # Returns the current instance of {Publisher} or creates a new instance of
62
+ # {Publisher} if one doesn't exist.
52
63
  #
53
- # Returns The Publisher
64
+ # @return [Publisher] Returns an instance of {Publisher}
54
65
  def publisher
55
66
  @publisher ||= Publisher.new(self)
56
67
  end
57
68
 
58
- # Public: Prefix a given path with the root directory.
69
+ # Prefix a path or paths with the {#root_dir} directory.
59
70
  #
60
- # paths - (optional) path elements to a file or directory within the
61
- # root directory
71
+ # @see Bridgetown.sanitized_path
72
+ # @param paths [Array<String>]
73
+ # An array of paths to prefix with the root_dir directory using the
74
+ # {Bridgetown.sanitized_path} method.
62
75
  #
63
- # Returns a path which is prefixed with the root_dir directory.
76
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
64
77
  def in_root_dir(*paths)
65
78
  paths.reduce(root_dir) do |base, path|
66
79
  Bridgetown.sanitized_path(base, path)
67
80
  end
68
81
  end
69
82
 
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
83
+ # Prefix a path or paths with the {#source} directory.
74
84
  #
75
- # Returns a path which is prefixed with the source directory.
85
+ # @see Bridgetown.sanitized_path
86
+ # @param paths [Array<String>]
87
+ # An array of paths to prefix with the source directory using the
88
+ # {Bridgetown.sanitized_path} method.
89
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
76
90
  def in_source_dir(*paths)
77
91
  paths.reduce(source) do |base, path|
78
92
  Bridgetown.sanitized_path(base, path)
79
93
  end
80
94
  end
81
95
 
82
- # Public: Prefix a given path with the destination directory.
96
+ # Prefix a path or paths with the {#dest} directory.
83
97
  #
84
- # paths - (optional) path elements to a file or directory within the
85
- # destination directory
98
+ # @see Bridgetown.sanitized_path
99
+ # @param paths [Array<String>]
100
+ # An array of paths to prefix with the destination directory using the
101
+ # {Bridgetown.sanitized_path} method.
86
102
  #
87
- # Returns a path which is prefixed with the destination directory.
103
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
88
104
  def in_dest_dir(*paths)
89
105
  paths.reduce(dest) do |base, path|
90
106
  Bridgetown.sanitized_path(base, path)
91
107
  end
92
108
  end
93
109
 
94
- # Public: Prefix a given path with the cache directory.
110
+ # Prefix a path or paths with the {#cache_dir} directory.
95
111
  #
96
- # paths - (optional) path elements to a file or directory within the
97
- # cache directory
112
+ # @see Bridgetown.sanitized_path
113
+ # @param paths [Array<String>]
114
+ # An array of paths to prefix with the {#cache_dir} directory using the
115
+ # {Bridgetown.sanitized_path} method.
98
116
  #
99
- # Returns a path which is prefixed with the cache directory.
117
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
100
118
  def in_cache_dir(*paths)
101
119
  paths.reduce(cache_dir) do |base, path|
102
120
  Bridgetown.sanitized_path(base, path)
103
121
  end
104
122
  end
105
123
 
106
- # Public: The full path to the directory that houses all the collections registered
107
- # with the current site.
124
+ # The full path to the directory that houses all the registered collections
125
+ # for the current site.
126
+ #
127
+ # If +@collections_path+ is specified use its value.
128
+ #
129
+ # If +@collections+ is not specified and +config+["collections_dir"] is
130
+ # specified, prepend it with {#source} and assign it to
131
+ # {#collections_path}.
132
+ #
133
+ # If +@collections+ is not specified and +config+["collections_dir"] is not
134
+ # specified, assign {#source} to +@collections_path+
108
135
  #
109
- # Returns the source directory or the absolute path to the custom collections_dir
136
+ # @return [String] Returns the full path to the collections directory
137
+ # @see #config
138
+ # @see #source
139
+ # @see #collections_path
140
+ # @see #in_source_dir
110
141
  def collections_path
111
142
  dir_str = config["collections_dir"]
112
143
  @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,41 +35,85 @@ 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
+ # +ActiveSupport::HashWithIndifferentAccess+
65
+ # @return [Hash] Returns a hash of site metadata
39
66
  def metadata
40
67
  data["site_metadata"] ||= ActiveSupport::HashWithIndifferentAccess.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
119
  ActiveSupport::HashWithIndifferentAccess.new
@@ -71,10 +122,11 @@ module Bridgetown
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