bridgetown-builder 1.2.0 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bridgetown-builder/dsl/http.rb +7 -7
- data/lib/bridgetown-builder/dsl/inspectors.rb +21 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd4294dca6d4f9998eaad39cf9f871b26fd3e027f592aeb744795b30264c06f
|
4
|
+
data.tar.gz: fbe83235997f06379f455ec5e8f9329fc6b75b8d3df0d3db797656d94f504e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d742094bbc288aae967da7c5e47a7d7cfdb56ae41fbc5b6b5d5c728447c076e76ad98a070100aa01c2d1df8b5c3742189472e3247dc490eb05ae0350f88da48f
|
7
|
+
data.tar.gz: 33c455986f6405e237632d58035af6a11ede56b1deec2525bbd944c30eb4edaec16766703a26c90be3b8c82fa116d08a7802f8a935e62bb45afc9839c0b591f2
|
@@ -1,16 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
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,
|
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.
|
26
|
+
faraday.response :follow_redirects
|
27
|
+
|
29
28
|
if parse_json
|
30
|
-
faraday.
|
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 =
|
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
|
-
|
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
|
-
|
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]
|
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
|
-
|
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.
|
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
|
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.
|
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.
|
26
|
+
version: 1.3.0.beta1
|
27
27
|
description:
|
28
28
|
email: maintainers@bridgetownrb.com
|
29
29
|
executables: []
|
@@ -62,9 +62,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - ">"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 1.3.1
|
68
68
|
requirements: []
|
69
69
|
rubygems_version: 3.1.4
|
70
70
|
signing_key:
|