Module: Bridgetown::Builders::DSL::Inspectors
- Included in:
- PluginBuilder
- Defined in:
- lib/bridgetown-builder/dsl/inspectors.rb
Defined Under Namespace
Modules: HTML, QuerySelection, XML
Class Method Summary collapse
-
.process_html ⇒ Object
Shorthand for ‘HTML.call`.
-
.process_xml ⇒ Object
Shorthand for ‘XML.call`.
-
.setup_nokogiri ⇒ Object
Require the Nokogiri gem if necessary and add the ‘QuerySelection` mixin.
-
.setup_nokolexbor ⇒ Object
Require the Nokolexbor gem if necessary and add the ‘QuerySelection` mixin.
Instance Method Summary collapse
-
#inspect_html {|the| ... } ⇒ Object
Set up an inspector to review or manipulate HTML resources.
-
#inspect_xml(extension = "xml") {|the| ... } ⇒ Object
Set up an inspector to review or manipulate XML resources.
Class Method Details
.process_html ⇒ Object
Shorthand for ‘HTML.call`
93 94 95 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 93 def process_html(...) HTML.call(...) end |
.process_xml ⇒ Object
Shorthand for ‘XML.call`
98 99 100 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 98 def process_xml(...) XML.call(...) end |
.setup_nokogiri ⇒ Object
Require the Nokogiri gem if necessary and add the ‘QuerySelection` mixin
75 76 77 78 79 80 81 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 75 def setup_nokogiri unless defined?(Nokogiri) Bridgetown::Utils::RequireGems.require_with_graceful_fail "nokogiri" end Nokogiri::XML::Node.include QuerySelection unless Nokogiri::XML::Node <= QuerySelection end |
.setup_nokolexbor ⇒ Object
Require the Nokolexbor gem if necessary and add the ‘QuerySelection` mixin
84 85 86 87 88 89 90 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 84 def setup_nokolexbor unless defined?(Nokolexbor) Bridgetown::Utils::RequireGems.require_with_graceful_fail "nokolexbor" end Nokolexbor::Node.include QuerySelection unless Nokolexbor::Node <= QuerySelection end |
Instance Method Details
#inspect_html {|the| ... } ⇒ Object
Set up an inspector to review or manipulate HTML resources
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 107 def inspect_html(&block) unless @_html_inspectors @_html_inspectors = [] if site.config.html_inspector_parser == "nokolexbor" Inspectors.setup_nokolexbor else Inspectors.setup_nokogiri end hook :resources, :post_render do |resource| next unless HTML.can_run?(resource, @_html_inspectors) resource.output = Inspectors.process_html(resource, @_html_inspectors) end hook :generated_pages, :post_render do |page| next unless HTML.can_run?(page, @_html_inspectors) page.output = Inspectors.process_html(page, @_html_inspectors) end end @_html_inspectors << block end |
#inspect_xml(extension = "xml") {|the| ... } ⇒ Object
Set up an inspector to review or manipulate XML resources
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/bridgetown-builder/dsl/inspectors.rb', line 137 def inspect_xml(extension = "xml", &block) unless @_xml_inspectors @_xml_inspectors = {} Inspectors.setup_nokogiri hook :resources, :post_render do |resource| next unless Inspectors::XML.can_run?(resource, @_xml_inspectors) resource.output = Inspectors.process_xml(resource, @_xml_inspectors) end hook :generated_pages, :post_render do |page| next unless Inspectors::XML.can_run?(page, @_xml_inspectors) page.output = Inspectors.process_xml(page, @_xml_inspectors) end end (@_xml_inspectors[extension.to_s] ||= []).tap do |arr| arr << block end @_xml_inspectors end |