Sha256: 93d5dab966597465216802a7a68ffc110c4cc13cbcc4f57b34d6730206dae01d

Contents?: true

Size: 607 Bytes

Versions: 8

Compression:

Stored size: 607 Bytes

Contents

require 'cgi'

module Slippery
  module Processors
    class AddGoogleFont
      def initialize(font_name, variants = [])
        @font_name = font_name.freeze
        @variants  = variants.freeze
      end

      def call(doc)
        doc.rewrite('head', &add_font_link)
      end

      def add_font_link
        ->(head) {
          head << H[:link, {rel: 'stylesheet', type: 'text/css', href: href}]
        }
      end

      def href
        'http://fonts.googleapis.com/css?family=' +
          CGI.escape(@font_name) + (@variants.empty? ? '' : ':' + @variants.join(','))
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
slippery-0.4.2 lib/slippery/processors/add_google_font.rb
slippery-0.4.1 lib/slippery/processors/add_google_font.rb
slippery-0.4.0 lib/slippery/processors/add_google_font.rb
slippery-0.3.0 lib/slippery/processors/add_google_font.rb
slippery-0.2.0 lib/slippery/processors/add_google_font.rb
slippery-0.1.0 lib/slippery/processors/add_google_font.rb
slippery-0.0.3 lib/slippery/processors/add_google_font.rb
slippery-0.0.1 lib/slippery/processors/add_google_font.rb