bridgetown-builder 0.21.4 → 1.0.0.alpha1

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: 3670da54487f5fb5c550eeeb4ce89d7437cfc2641e8557ed04636ba1853dcc37
4
+ data.tar.gz: 3a699187328b8e8e508ac269b63e35f92e85c0d1017784783268d40df5a97736
5
5
  SHA512:
6
- metadata.gz: eafa21680356e54005efd268670c5a220708d92e262ed8664c61f7586760ac991d812145409e991d77232755c4cf033d877137789375d03b9f442ac2b932132f
7
- data.tar.gz: 3775b6f7e701794dcc97fbf835df2ccda4bfbc29d77be8b075e750215ee0dce264d1ac4046361adc0954d4653474d07960d0a73a1ee631069a238ad855b1f228
6
+ metadata.gz: a21fc74c5433d45562505f4b1b300579f0c568546abd7d5b1355071936a8f7c4ee04c722499dde5ce9f0fd5601d307d60b181ed07004f21bfe3c4908cb906c8c
7
+ data.tar.gz: ac73d8a594532014055ca161a4bcae5094eb5829088b520eb98abd2b7d2057f99431f699b38ead83cef2a081723379574e03368e01ced3c6268a6b374f4ff006
data/.rubocop.yml CHANGED
@@ -4,7 +4,6 @@ inherit_from: ../.rubocop.yml
4
4
  AllCops:
5
5
  Include:
6
6
  - lib/**/*.rb
7
- - spec/**/*.rb
8
7
 
9
8
  Metrics/AbcSize:
10
9
  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)/!) }
@@ -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)
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,6 +14,7 @@ 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
 
@@ -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"
@@ -21,21 +19,10 @@ Bridgetown::Hooks.register_one :site, :pre_read, priority: :low, reloadable: fal
21
19
  c.new(c.name, site)
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.alpha1
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-16 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.alpha1
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.alpha1
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