bridgetown-builder 1.0.0 → 1.1.0.beta1

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: 57644330313669593a0ef79303b8bb692fd2ea7d69fbed8c878d5d33918d4bed
4
- data.tar.gz: 3a79d7726250d9c477b1afb214a6b1aff3fd45b5d400467ba73844d9b608bdc6
3
+ metadata.gz: 60efa769d64aab272bb16517ea5d4411312943547b5031ea104930fbafd425d1
4
+ data.tar.gz: f78876a42486103772f292a57689a2f32cfdb520c2d5900b098b3a04a967a990
5
5
  SHA512:
6
- metadata.gz: b31cae7e13054287b31cc4eaac0246370bd366ce8c8537d5a220ebde1daaf0ad27204ab40e9e09b8e47361cd06b4f6e646acc14da00833eea8ac84e3c4223d8c
7
- data.tar.gz: a165e07527cf5c2302e66729648445ec7cd84a030c9fa06bb89ca97e57a7a6c3c96981a8fb9838adcb1e5b1dacabf7c193ec8c58afeea3994a71d55b6b3c65b4
6
+ metadata.gz: cd8890f49fc3132664fdf22392bed9ea43ae1756979e85922baee85dd455ded4bd9cb01ac6ecb0c0bfdcdca8ddd882db4acb0fb1b3d9415f1906453bf7f23466
7
+ data.tar.gz: 78d07a7e500fe002a3299edb0da04d75a7ba55c42d2f26406d3144a3be18f1ac5223f21ef8b8e9abf5700b70f4d5b7bc5b4767a9ec486227a0dd259a9e3a2df7
@@ -7,13 +7,16 @@ module Bridgetown
7
7
  def generator(method_name = nil, &block)
8
8
  block = method(method_name) if method_name.is_a?(Symbol)
9
9
  local_name = name # pull the name method into a local variable
10
+ builder_priority = self.class.instance_variable_get(:@priority)
10
11
 
11
- new_gen = Class.new(Bridgetown::Generator) do
12
+ anon_generator = Class.new(Bridgetown::Generator) do
12
13
  define_method(:_builder_block) { block }
13
14
  define_singleton_method(:custom_name) { local_name }
14
15
 
15
16
  attr_reader :site
16
17
 
18
+ priority builder_priority || :low
19
+
17
20
  def inspect
18
21
  "#<#{self.class.custom_name} (Generator)>"
19
22
  end
@@ -23,10 +26,10 @@ module Bridgetown
23
26
  end
24
27
  end
25
28
 
26
- first_low_priority_index = site.generators.find_index { |gen| gen.class.priority == :low }
27
- site.generators.insert(first_low_priority_index || 0, new_gen.new(site.config))
29
+ site.generators << anon_generator.new(site.config)
30
+ site.generators.sort!
28
31
 
29
- functions << { name: name, generator: new_gen }
32
+ functions << { name: name, generator: anon_generator }
30
33
  end
31
34
  end
32
35
  end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Builders
5
+ module DSL
6
+ module Inspectors
7
+ # Add a couple familar DOM API features
8
+ module QuerySelection
9
+ def query_selector(selector)
10
+ css(selector).first
11
+ end
12
+
13
+ def query_selector_all(selector)
14
+ css(selector)
15
+ end
16
+ end
17
+
18
+ # HTML inspector type
19
+ module HTML
20
+ # Are there inspectors available? Is it an .htm* file?
21
+ def self.can_run?(resource, inspectors)
22
+ inspectors &&
23
+ resource.destination&.output_ext&.starts_with?(".htm") &&
24
+ !resource.data.bypass_inspectors
25
+ end
26
+
27
+ # Process the resource with the available inspectors and return the output HTML
28
+ #
29
+ # @return [String] transformed HTML
30
+ def self.call(resource, inspectors)
31
+ doc = Nokogiri.HTML5(resource.output)
32
+
33
+ inspectors.each do |block|
34
+ block.call(doc, resource)
35
+ end
36
+
37
+ doc.to_html
38
+ end
39
+ end
40
+
41
+ # XML inspector type
42
+ module XML
43
+ # Strip the resource's initial extension dot. `.rss` => `rss`
44
+ def self.resource_ext(resource)
45
+ resource.destination&.output_ext&.delete_prefix(".")
46
+ end
47
+
48
+ # Are there any inspectors available which match the resource extension?
49
+ def self.can_run?(resource, inspectors)
50
+ inspectors &&
51
+ inspectors[resource_ext(resource)] &&
52
+ !resource.data.bypass_inspectors
53
+ end
54
+
55
+ # Process the resource with the available inspectors and return the output XML
56
+ #
57
+ # @return [String] transformed XML
58
+ def self.call(resource, inspectors)
59
+ doc = Nokogiri::XML(resource.output)
60
+
61
+ inspectors[resource_ext(resource)].each do |block|
62
+ block.call(doc, resource)
63
+ end
64
+
65
+ doc.to_xml
66
+ end
67
+ end
68
+
69
+ class << self
70
+ # Require the Nokogiri gem if necessary and add the `QuerySelection` mixin
71
+ def setup_nokogiri
72
+ unless defined?(Nokogiri)
73
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail "nokogiri"
74
+ end
75
+
76
+ return if Nokogiri::XML::Node <= QuerySelection
77
+
78
+ Nokogiri::XML::Node.include QuerySelection
79
+ end
80
+
81
+ # Shorthand for `HTML.call`
82
+ def process_html(...)
83
+ HTML.call(...)
84
+ end
85
+
86
+ # Shorthand for `XML.call`
87
+ def process_xml(...)
88
+ XML.call(...)
89
+ end
90
+ end
91
+
92
+ # Set up an inspector to review or manipulate HTML resources
93
+ # @yield the block to be called after the resource has been rendered
94
+ # @yieldparam [Nokogiri::HTML5::Document] the Nokogiri document
95
+ def inspect_html(&block)
96
+ unless @_html_inspectors
97
+ @_html_inspectors = []
98
+
99
+ Inspectors.setup_nokogiri
100
+
101
+ hook :resources, :post_render do |resource|
102
+ next unless HTML.can_run?(resource, @_html_inspectors)
103
+
104
+ resource.output = Inspectors.process_html(resource, @_html_inspectors)
105
+ end
106
+ end
107
+
108
+ @_html_inspectors << block
109
+ end
110
+
111
+ # Set up an inspector to review or manipulate XML resources
112
+ # @param extension [String] defaults to `xml`
113
+ # @yield the block to be called after the resource has been rendered
114
+ # @yieldparam [Nokogiri::XML::Document] the Nokogiri document
115
+ def inspect_xml(extension = "xml", &block)
116
+ unless @_xml_inspectors
117
+ @_xml_inspectors = {}
118
+
119
+ Inspectors.setup_nokogiri
120
+
121
+ hook :resources, :post_render do |resource|
122
+ next unless Inspectors::XML.can_run?(resource, @_xml_inspectors)
123
+
124
+ resource.output = Inspectors.process_xml(resource, @_xml_inspectors)
125
+ end
126
+ end
127
+
128
+ (@_xml_inspectors[extension.to_s] ||= []).tap do |arr|
129
+ arr << block
130
+ end
131
+
132
+ @_xml_inspectors
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -3,15 +3,28 @@
3
3
  require "bridgetown-builder/dsl/generators"
4
4
  require "bridgetown-builder/dsl/helpers"
5
5
  require "bridgetown-builder/dsl/hooks"
6
+ require "bridgetown-builder/dsl/inspectors"
6
7
  require "bridgetown-builder/dsl/http"
7
8
  require "bridgetown-builder/dsl/liquid"
8
9
  require "bridgetown-builder/dsl/resources"
10
+
9
11
  module Bridgetown
10
12
  module Builders
11
13
  class PluginBuilder
14
+ include Bridgetown::Prioritizable
15
+
16
+ self.priorities = {
17
+ highest: 100,
18
+ high: 10,
19
+ normal: 0,
20
+ low: -10,
21
+ lowest: -100,
22
+ }.freeze
23
+
12
24
  include DSL::Generators
13
25
  include DSL::Helpers
14
26
  include DSL::Hooks
27
+ include DSL::Inspectors
15
28
  include DSL::HTTP
16
29
  include DSL::Liquid
17
30
  include DSL::Resources
@@ -15,7 +15,7 @@ Bridgetown::Hooks.register_one :site, :pre_read, priority: :low, reloadable: fal
15
15
  # SiteBuilder is the superclass sites can subclass to create any number of
16
16
  # builders, but if the site hasn't defined it explicitly, this is a no-op
17
17
  if defined?(SiteBuilder)
18
- SiteBuilder.descendants.map do |c|
18
+ SiteBuilder.descendants.sort.map do |c|
19
19
  c.new(c.name, site).build_with_callbacks
20
20
  end
21
21
  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: 1.0.0
4
+ version: 1.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-07 00:00:00.000000000 Z
11
+ date: 2022-06-02 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: 1.0.0
19
+ version: 1.1.0.beta1
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: 1.0.0
26
+ version: 1.1.0.beta1
27
27
  description:
28
28
  email: maintainers@bridgetownrb.com
29
29
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/bridgetown-builder/dsl/helpers.rb
40
40
  - lib/bridgetown-builder/dsl/hooks.rb
41
41
  - lib/bridgetown-builder/dsl/http.rb
42
+ - lib/bridgetown-builder/dsl/inspectors.rb
42
43
  - lib/bridgetown-builder/dsl/liquid.rb
43
44
  - lib/bridgetown-builder/dsl/resources.rb
44
45
  - lib/bridgetown-builder/plugin.rb
@@ -57,9 +58,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
58
  version: '0'
58
59
  required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  requirements:
60
- - - ">="
61
+ - - ">"
61
62
  - !ruby/object:Gem::Version
62
- version: '0'
63
+ version: 1.3.1
63
64
  requirements: []
64
65
  rubygems_version: 3.1.4
65
66
  signing_key: