Sha256: 767ad1db5ac1c277bcc6eab201264e33aa74888ea785ffee1c5135843fa861d0

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'fontcustom'

module Middleman
  class FontcustomExtension < Extension
    option :font_name, 'fontcustom', 'Output font name'
    option :source_dir, 'assets/icons', 'Folder contains icon files'
    option :fonts_dir, 'source/fonts', 'Folder to output fonts'
    option :css_dir, 'source/stylesheets', 'Folder to output css'
    option :templates, 'scss', 'Output templates'
    option :no_hash, true, 'Create hash for no cache policy'

    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]
        }).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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-fontcustom-0.1.0 lib/middleman-fontcustom/extension.rb