Sha256: 039f5d94af44d05332ca2326dd43849d2323a2602d719a26289af351fecf70af

Contents?: true

Size: 1.28 KB

Versions: 7

Compression:

Stored size: 1.28 KB

Contents

require 'rake/tasklib'

require 'web_font'

module WebFont
  class CacheTask < Rake::TaskLib
    attr_accessor :name, :verbose

    def self.define_tasks!
      new
    end

    def initialize
      define_tasks
    end

    private

      def define_tasks
        namespace :web_font do
          desc 'Download google fonts'
          task :cache_fonts do
            WebFont::Index.download

            downloader = WebFont::Downloader.new
            cache_path = WebFont::LocalCache.cache_path

            unless WebFont::LocalCache.cache
              raise 'WebFont::LocalCache.cache is false.'
            end

            if cache_path
              FileUtils.mkdir_p(cache_path) if !Dir.exist?(cache_path)
            else
              raise 'WebFont::LocalCache.cache_path is empty.'
            end

            file_path  = "#{WebFont::Index.path}/fonts.json"
            hash       = JSON.parse(File.open(file_path).read)

            hash['items'].each_with_index do |item, index|
              family = item['family']

              puts family

              downloader.download(family, cache_path, false)
            end

            puts "\n"
            puts '=' * 50
            puts 'ALL FONTS ARE DOWNLOADED...'
            puts '=' * 50
          end
        end
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
web_font-0.2.0 lib/web_font/cache_task.rb
web_font-0.1.14 lib/web_font/cache_task.rb
web_font-0.1.13 lib/web_font/cache_task.rb
web_font-0.1.12 lib/web_font/cache_task.rb
web_font-0.1.11 lib/web_font/cache_task.rb
web_font-0.1.10 lib/web_font/cache_task.rb
web_font-0.1.9 lib/web_font/cache_task.rb