bridgetown-builder 0.21.4 → 1.0.0.alpha4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41eb874f69d9c20d4481cb654a3147c3de796c103d3157f4d9d0eb01ea164b7c
4
- data.tar.gz: f2431292309bcc8a91657cfeab450a767c4a80c547b52b8c1e2fb614e86ac3e0
3
+ metadata.gz: 23d5a5f262d6f8aca6d45490367c468fe33cab06f6353321136418e7ab972730
4
+ data.tar.gz: 25ac5f20a634df624e7e7de78668eed4505573a939f5ca2c21adee147783f96d
5
5
  SHA512:
6
- metadata.gz: eafa21680356e54005efd268670c5a220708d92e262ed8664c61f7586760ac991d812145409e991d77232755c4cf033d877137789375d03b9f442ac2b932132f
7
- data.tar.gz: 3775b6f7e701794dcc97fbf835df2ccda4bfbc29d77be8b075e750215ee0dce264d1ac4046361adc0954d4653474d07960d0a73a1ee631069a238ad855b1f228
6
+ metadata.gz: a11a81432d73c635e2344bcdf01553c979f67333704dc3280647f2b641dc97c16f03c4c1bc31853b26801bd650b78de993fffb50adc497b9ec5607830ed52732
7
+ data.tar.gz: 9a9cb41f7c1a81eeaa807fdc3cdb356649cdb9a7900f8811e95c039911f4bdb390cfaed3eb180204dd8f37bf458331c58b9f452ac476b69c0083f1dcd3a7cf47
data/.rubocop.yml CHANGED
@@ -2,9 +2,9 @@
2
2
  inherit_from: ../.rubocop.yml
3
3
 
4
4
  AllCops:
5
- Include:
6
- - lib/**/*.rb
7
- - spec/**/*.rb
5
+ Exclude:
6
+ - "*.gemspec"
7
+ - test/**/*.rb
8
8
 
9
9
  Metrics/AbcSize:
10
10
  Exclude:
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.author = "Bridgetown Team"
9
9
  spec.email = "maintainers@bridgetownrb.com"
10
10
  spec.summary = "A Bridgetown plugin to provide a sophisticated DSL for writing plugins at a higher level of abstraction."
11
- spec.homepage = "https://github.com/bridgetownrb/bridgetown/tree/master/bridgetown-builder"
11
+ spec.homepage = "https://github.com/bridgetownrb/bridgetown/tree/main/bridgetown-builder"
12
12
  spec.license = "MIT"
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features)/!) }
@@ -4,19 +4,33 @@ module Bridgetown
4
4
  # Superclass for a website's SiteBuilder abstract class
5
5
  class Builder < Bridgetown::Builders::PluginBuilder
6
6
  extend ActiveSupport::DescendantsTracker
7
+ include ActiveSupport::Callbacks
8
+
9
+ define_callbacks :build
7
10
 
8
11
  class << self
9
12
  def register
10
13
  Bridgetown::Hooks.register_one :site, :pre_read, reloadable: false do |site|
11
- new(name, site)
14
+ new(name, site).build_with_callbacks
12
15
  end
13
16
  end
17
+
18
+ ruby2_keywords def before_build(*args, &block)
19
+ set_callback :build, :before, *args, &block
20
+ end
21
+
22
+ ruby2_keywords def after_build(*args, &block)
23
+ set_callback :build, :after, *args, &block
24
+ end
25
+
26
+ ruby2_keywords def around_build(*args, &block)
27
+ set_callback :build, :around, *args, &block
28
+ end
14
29
  end
15
30
 
16
- # Subclass is expected to implement #build
17
- def initialize(name, current_site = nil)
18
- super(name, current_site)
19
- build
31
+ def build_with_callbacks
32
+ run_callbacks(:build) { build }
33
+ self
20
34
  end
21
35
 
22
36
  def inspect
@@ -24,7 +38,8 @@ module Bridgetown
24
38
  end
25
39
 
26
40
  def self.descendants
27
- super.reject { |klass| ["SiteBuilder"].include?(klass.name) }
41
+ site_builder_name = "SiteBuilder"
42
+ super.reject { |klass| [site_builder_name].include?(klass.name) }
28
43
  end
29
44
  end
30
45
  end
@@ -10,14 +10,14 @@ module Bridgetown
10
10
  module HTTP
11
11
  def get(url, headers: {}, parse_json: true)
12
12
  body = begin
13
- connection(parse_json: parse_json).get(url, headers: headers).body
14
- rescue Faraday::ParsingError
15
- Bridgetown.logger.error(
16
- "Faraday::ParsingError",
17
- "The response from #{url} did not contain valid JSON"
18
- )
19
- nil
20
- end
13
+ connection(parse_json: parse_json).get(url, headers: headers).body
14
+ rescue Faraday::ParsingError
15
+ Bridgetown.logger.error(
16
+ "Faraday::ParsingError",
17
+ "The response from #{url} did not contain valid JSON"
18
+ )
19
+ nil
20
+ end
21
21
  yield body
22
22
  end
23
23
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Builders
5
+ module DSL
6
+ module Resources
7
+ def add_resource(collection_name, path, &block) # rubocop:todo Metrics/AbcSize
8
+ data = Bridgetown::Utils::RubyFrontMatter.new(scope: self).tap do |fm|
9
+ fm.define_singleton_method(:___) do |hsh|
10
+ hsh.each do |k, v|
11
+ fm.set k, v
12
+ end
13
+ end
14
+ fm.instance_exec(&block)
15
+ end.to_h
16
+ if data[:content]
17
+ data[:_content_] = data[:content]
18
+ data.delete :content
19
+ end
20
+
21
+ collection_name = collection_name.to_s
22
+ unless @site.collections[collection_name]
23
+ Bridgetown.logger.info(
24
+ "#{self.class.name}:",
25
+ "Creating `#{collection_name}' collection on the fly..."
26
+ )
27
+ collection = Collection.new(@site, collection_name)
28
+ collection.metadata["output"] = true
29
+ @site.collections[collection_name] = collection
30
+ end
31
+
32
+ Bridgetown::Model::Base.build(
33
+ self,
34
+ collection_name,
35
+ path,
36
+ data
37
+ ).as_resource_in_collection
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -5,6 +5,7 @@ require "bridgetown-builder/dsl/helpers"
5
5
  require "bridgetown-builder/dsl/hooks"
6
6
  require "bridgetown-builder/dsl/http"
7
7
  require "bridgetown-builder/dsl/liquid"
8
+ require "bridgetown-builder/dsl/resources"
8
9
  module Bridgetown
9
10
  module Builders
10
11
  class PluginBuilder
@@ -13,12 +14,13 @@ module Bridgetown
13
14
  include DSL::Hooks
14
15
  include DSL::HTTP
15
16
  include DSL::Liquid
17
+ include DSL::Resources
16
18
 
17
19
  attr_accessor :functions, :name, :site, :config
18
20
 
19
- def initialize(name, current_site = nil)
21
+ def initialize(name = nil, current_site = nil)
20
22
  self.functions = Set.new
21
- self.name = name
23
+ self.name = name || self.class.name
22
24
  self.site = current_site || Bridgetown.sites.first
23
25
 
24
26
  self.config = if defined?(self.class::CONFIG_DEFAULTS)
@@ -34,8 +36,9 @@ module Bridgetown
34
36
  "#{name} (Hook)"
35
37
  end
36
38
 
37
- def doc(path, &block)
38
- DocumentsGenerator.add(path, block)
39
+ def doc(*)
40
+ raise Bridgetown::Errors::FatalException,
41
+ "The `doc' method has been removed. Please use the `new_resource' builder DSL instead"
39
42
  end
40
43
  end
41
44
  end
@@ -6,8 +6,6 @@ require "bridgetown-core/version"
6
6
  module Bridgetown
7
7
  module Builders
8
8
  autoload :PluginBuilder, "bridgetown-builder/plugin"
9
- autoload :DocumentBuilder, "bridgetown-builder/document"
10
- autoload :DocumentsGenerator, "bridgetown-builder/documents_generator"
11
9
  end
12
10
 
13
11
  autoload :Builder, "bridgetown-builder/builder"
@@ -18,24 +16,13 @@ Bridgetown::Hooks.register_one :site, :pre_read, priority: :low, reloadable: fal
18
16
  # builders, but if the site hasn't defined it explicitly, this is a no-op
19
17
  if defined?(SiteBuilder)
20
18
  SiteBuilder.descendants.map do |c|
21
- c.new(c.name, site)
19
+ c.new(c.name, site).build_with_callbacks
22
20
  end
23
21
  end
24
-
25
- # If the documents generator is in use, we need to add it at the top of the
26
- # list so the site runs the generator before any others
27
- if Bridgetown::Builders.autoload?(:DocumentsGenerator).nil? &&
28
- !site.generators.first.is_a?(Bridgetown::Builders::DocumentsGenerator)
29
- site.generators.unshift Bridgetown::Builders::DocumentsGenerator.new(site.config)
30
- end
31
22
  end
32
23
 
33
24
  Bridgetown::Hooks.register_one :site, :pre_reload, reloadable: false do |site|
34
25
  # Remove all anonymous generator classes so they can later get reloaded
35
26
  site.converters.delete_if { |generator| generator.class.name.nil? }
36
27
  site.generators.delete_if { |generator| generator.class.name.nil? }
37
-
38
- unless Bridgetown::Builders.autoload? :DocumentsGenerator
39
- Bridgetown::Builders::DocumentsGenerator.clear_documents_to_generate
40
- end
41
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.4
4
+ version: 1.0.0.alpha4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-10 00:00:00.000000000 Z
11
+ date: 2021-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridgetown-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.21.4
19
+ version: 1.0.0.alpha4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.21.4
26
+ version: 1.0.0.alpha4
27
27
  description:
28
28
  email: maintainers@bridgetownrb.com
29
29
  executables: []
@@ -35,15 +35,14 @@ files:
35
35
  - bridgetown-builder.gemspec
36
36
  - lib/bridgetown-builder.rb
37
37
  - lib/bridgetown-builder/builder.rb
38
- - lib/bridgetown-builder/document.rb
39
- - lib/bridgetown-builder/documents_generator.rb
40
38
  - lib/bridgetown-builder/dsl/generators.rb
41
39
  - lib/bridgetown-builder/dsl/helpers.rb
42
40
  - lib/bridgetown-builder/dsl/hooks.rb
43
41
  - lib/bridgetown-builder/dsl/http.rb
44
42
  - lib/bridgetown-builder/dsl/liquid.rb
43
+ - lib/bridgetown-builder/dsl/resources.rb
45
44
  - lib/bridgetown-builder/plugin.rb
46
- homepage: https://github.com/bridgetownrb/bridgetown/tree/master/bridgetown-builder
45
+ homepage: https://github.com/bridgetownrb/bridgetown/tree/main/bridgetown-builder
47
46
  licenses:
48
47
  - MIT
49
48
  metadata: {}
@@ -58,9 +57,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
57
  version: '0'
59
58
  required_rubygems_version: !ruby/object:Gem::Requirement
60
59
  requirements:
61
- - - ">="
60
+ - - ">"
62
61
  - !ruby/object:Gem::Version
63
- version: '0'
62
+ version: 1.3.1
64
63
  requirements: []
65
64
  rubygems_version: 3.1.4
66
65
  signing_key:
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Builders
5
- class DocumentBuilder
6
- attr_reader :site
7
-
8
- def initialize(site, path)
9
- @site = site
10
- @path = path
11
- @data = HashWithDotAccess::Hash.new
12
- end
13
-
14
- def front_matter(data)
15
- @data.merge!(data)
16
- end
17
-
18
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
19
- def _add_document_to_site
20
- @collection = (@data[:collection] || :posts).to_s
21
- collection = @site.collections[@collection]
22
- unless collection
23
- collection = Collection.new(@site, @collection)
24
- collection.metadata["output"] = true
25
- @site.collections[@collection] = collection
26
- end
27
-
28
- doc = Document.new(
29
- File.join(collection.directory, @path),
30
- site: @site,
31
- collection: collection
32
- )
33
- doc.send(:merge_defaults)
34
- doc.content = @data[:content]
35
- @data.delete(:content)
36
-
37
- if @path.start_with?("/")
38
- pathname = Pathname.new(@path)
39
- @data[:permalink] = File.join(
40
- pathname.dirname,
41
- pathname.basename.sub(pathname.extname, "")
42
- ) + "/"
43
- end
44
-
45
- doc.merge_data!(@data)
46
- doc.send(:read_post_data)
47
-
48
- collection.docs << doc
49
- end
50
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
51
-
52
- # rubocop:disable Style/MissingRespondToMissing
53
- def method_missing(key, value = nil)
54
- if respond_to?(key)
55
- super
56
- else
57
- @data[key] = value
58
- end
59
- end
60
- # rubocop:enable Style/MissingRespondToMissing
61
- end
62
- end
63
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Builders
5
- class DocumentsGenerator < Bridgetown::Generator
6
- priority :high
7
-
8
- def self.add(path, block)
9
- @documents_to_generate ||= []
10
- @documents_to_generate << [path, block]
11
- end
12
-
13
- class << self
14
- attr_reader :documents_to_generate
15
- end
16
-
17
- def self.clear_documents_to_generate
18
- @documents_to_generate = []
19
- end
20
-
21
- def generate(site)
22
- self.class.documents_to_generate&.each do |doc_block|
23
- path, block = doc_block
24
- doc_builder = DocumentBuilder.new(site, path)
25
- doc_builder.instance_exec(&block)
26
- doc_builder._add_document_to_site
27
- end
28
- end
29
- end
30
- end
31
- end