Class: JekyllMetrics::Hook
- Inherits:
-
Object
- Object
- JekyllMetrics::Hook
- Defined in:
- lib/jekyll-metrics/hook.rb
Overview
Compile metrics template and inject it into the page code
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page) {|@page, _self| ... } ⇒ Hook
constructor
A new instance of Hook.
- #inject_scripts ⇒ Object
Constructor Details
#initialize(page) {|@page, _self| ... } ⇒ Hook
Returns a new instance of Hook.
8 9 10 11 |
# File 'lib/jekyll-metrics/hook.rb', line 8 def initialize(page) @page = page yield(@page, self) if block_given? && injectable? end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
6 7 8 |
# File 'lib/jekyll-metrics/hook.rb', line 6 def page @page end |
Instance Method Details
#inject_scripts ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll-metrics/hook.rb', line 13 def inject_scripts return unless injectable? document = Nokogiri::HTML(page.output) first_head_script = find_first_script(document) if first_head_script inject_after_first_script(first_head_script, document) else inject_before_closing_head(document) end page.output.replace(document.to_html) end |