Class: Middleman::ImgLoadingAttribute

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-img_loading_attribute/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ ImgLoadingAttribute



7
8
9
10
11
12
13
14
15
16
# File 'lib/middleman-img_loading_attribute/extension.rb', line 7

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

Instance Method Details

#after_build(builder) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/middleman-img_loading_attribute/extension.rb', line 22

def after_build(builder)
  files = Dir.glob(File.join(app.config[:build_dir], "**", "*.html"))
  files.each do |file|
    contents = File.read(file)
    replaced = contents.gsub(%r[<img], "<img loading=\"#{options[:loading]}\"")
    File.open(file, 'w') do |f|
      f.write replaced
    end
  end
end

#after_configurationObject



18
19
20
# File 'lib/middleman-img_loading_attribute/extension.rb', line 18

def after_configuration
  # Do something
end