Class: Middleman::FontcustomExtension

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FontcustomExtension.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/middleman-fontcustom/extension.rb', line 14

def initialize(app, options_hash={}, &block)
  super

  return unless app.environment == :development

  options_hash = options.to_h

  compile = ->(config){
    ::Fontcustom::Base.new({
      :font_name => config[:font_name],
      :input => config[:source_dir],
      :output => {
        :fonts => config[:fonts_dir],
        :css => config[:css_dir]
      },
      :templates => config[:templates].split(/\s/),
      :no_hash => config[:no_hash],
      :preprocessor_path => config[:preprocessor_path],
      :autowidth => config[:autowidth]
    }).compile
  }

  app.ready do

    files.changed do |file|
      next if files.send(:ignored?, file)
      next if options_hash[:source_dir] != File.dirname(file)

      begin
        compile.call(options_hash)
      rescue => e
        logger.info e.message
      end
    end

    files.deleted do |file|
      next if files.send(:ignored?, file)
      next if options_hash[:source_dir] != File.dirname(file)

      begin
        compile.call(options_hash)
      rescue => e
        logger.info e.message
      end
    end

  end
end