class Middleman::ImgLoadingAttribute

Public Class Methods

new(app, options_hash={}, &block) click to toggle source
Calls superclass method
# File lib/middleman-img_loading_attribute/extension.rb, line 8
def initialize(app, options_hash={}, &block)
  # Call super to build options from the options_hash
  super

  # Require libraries only when activated
  # require 'necessary/library'

  # set up your extension
  # puts options.my_option
end

Public Instance Methods

after_build(builder) click to toggle source
# File lib/middleman-img_loading_attribute/extension.rb, line 23
def after_build(builder)
  files = Dir.glob(File.join(app.config[:build_dir], "**", "*.html"))
  files.each do |file|
    doc = Nokogiri::HTML(File.read(file))
    doc.css('img').each do |elem|
      next if elem.path.include?('pre') || elem.path.include?('code') || elem.path.include?('blockquote')

      elem['loading'] = options[:loading]
    end
    File.open(file, 'w') do |f|
      f.write doc.to_html
    end
  end
end
after_configuration() click to toggle source
# File lib/middleman-img_loading_attribute/extension.rb, line 19
def after_configuration
  # Do something
end