bridgetown-builder 1.2.0.beta5 → 1.3.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: 3adba1ab83a39cc41f730c0578c9a8c8055234131b936c5062126100812940f5
4
- data.tar.gz: 33b00e3983ad093f16eec8e8036c320af59545d8bdbee8a96e20b495dca4385c
3
+ metadata.gz: 3bd4294dca6d4f9998eaad39cf9f871b26fd3e027f592aeb744795b30264c06f
4
+ data.tar.gz: fbe83235997f06379f455ec5e8f9329fc6b75b8d3df0d3db797656d94f504e80
5
5
  SHA512:
6
- metadata.gz: ce99a17248739c698cac7629d574b3ac2d4777092bb30e72f73391b68ac8ea5c177961f8e5ba8f8242860ef5bb7c01e89634f6d423ef29bba8a41e06ce6dd158
7
- data.tar.gz: 492cd212fa8d17770e77d8343617b3b2308688c5b37b596f99437e42b518ff8cacbd061c06eb07c66814e4a7cb226bfb6bd5c82f1e0480c256805fe76834a7fd
6
+ metadata.gz: d742094bbc288aae967da7c5e47a7d7cfdb56ae41fbc5b6b5d5c728447c076e76ad98a070100aa01c2d1df8b5c3742189472e3247dc490eb05ae0350f88da48f
7
+ data.tar.gz: 33c455986f6405e237632d58035af6a11ede56b1deec2525bbd944c30eb4edaec16766703a26c90be3b8c82fa116d08a7802f8a935e62bb45afc9839c0b591f2
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday_middleware/redirect_limit_reached"
4
- require "faraday_middleware/response/follow_redirects"
5
- require "faraday_middleware/response/parse_json"
3
+ require "faraday/follow_redirects"
6
4
 
7
5
  module Bridgetown
8
6
  module Builders
9
7
  module DSL
10
8
  module HTTP
11
- def get(url, headers: {}, parse_json: true)
9
+ def get(url, headers: {}, parse_json: true, **params)
12
10
  body = begin
13
- connection(parse_json: parse_json).get(url, headers: headers).body
11
+ connection(parse_json: parse_json).get(url, params, headers).body
14
12
  rescue Faraday::ParsingError
15
13
  Bridgetown.logger.error(
16
14
  "Faraday::ParsingError",
@@ -25,12 +23,14 @@ module Bridgetown
25
23
  headers["Content-Type"] = "application/json" if parse_json
26
24
 
27
25
  Faraday.new(headers: headers) do |faraday|
28
- faraday.use FaradayMiddleware::FollowRedirects
26
+ faraday.response :follow_redirects
27
+
29
28
  if parse_json
30
- faraday.use FaradayMiddleware::ParseJson, parser_options: {
29
+ faraday.response :json, parser_options: {
31
30
  object_class: HashWithDotAccess::Hash,
32
31
  }
33
32
  end
33
+
34
34
  yield faraday if block_given?
35
35
  end
36
36
  end
@@ -28,7 +28,11 @@ module Bridgetown
28
28
  #
29
29
  # @return [String] transformed HTML
30
30
  def self.call(resource, inspectors)
31
- doc = Nokogiri.HTML5(resource.output)
31
+ doc = if resource.site.config.html_inspector_parser == "nokolexbor"
32
+ Nokolexbor::HTML(resource.output)
33
+ else
34
+ Nokogiri.HTML5(resource.output)
35
+ end
32
36
 
33
37
  inspectors.each do |block|
34
38
  block.call(doc, resource)
@@ -73,9 +77,16 @@ module Bridgetown
73
77
  Bridgetown::Utils::RequireGems.require_with_graceful_fail "nokogiri"
74
78
  end
75
79
 
76
- return if Nokogiri::XML::Node <= QuerySelection
80
+ Nokogiri::XML::Node.include QuerySelection unless Nokogiri::XML::Node <= QuerySelection
81
+ end
82
+
83
+ # Require the Nokolexbor gem if necessary and add the `QuerySelection` mixin
84
+ def setup_nokolexbor
85
+ unless defined?(Nokolexbor)
86
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail "nokolexbor"
87
+ end
77
88
 
78
- Nokogiri::XML::Node.include QuerySelection
89
+ Nokolexbor::Node.include QuerySelection unless Nokolexbor::Node <= QuerySelection
79
90
  end
80
91
 
81
92
  # Shorthand for `HTML.call`
@@ -91,12 +102,17 @@ module Bridgetown
91
102
 
92
103
  # Set up an inspector to review or manipulate HTML resources
93
104
  # @yield the block to be called after the resource has been rendered
94
- # @yieldparam [Nokogiri::HTML5::Document] the Nokogiri document
105
+ # @yieldparam [Nokogiri::HTML5::Document, Nokolexbor::Document]
106
+ # the Nokogiri or Nokolexbor document
95
107
  def inspect_html(&block)
96
108
  unless @_html_inspectors
97
109
  @_html_inspectors = []
98
110
 
99
- Inspectors.setup_nokogiri
111
+ if site.config.html_inspector_parser == "nokolexbor"
112
+ Inspectors.setup_nokolexbor
113
+ else
114
+ Inspectors.setup_nokogiri
115
+ end
100
116
 
101
117
  hook :resources, :post_render do |resource|
102
118
  next unless HTML.can_run?(resource, @_html_inspectors)
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.2.0.beta5
4
+ version: 1.3.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: 2023-01-02 00:00:00.000000000 Z
11
+ date: 2023-05-01 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.2.0.beta5
19
+ version: 1.3.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.2.0.beta5
26
+ version: 1.3.0.beta1
27
27
  description:
28
28
  email: maintainers@bridgetownrb.com
29
29
  executables: []