Class: Slippery::Processors::AddGoogleFont

Inherits:
Object
  • Object
show all
Defined in:
lib/slippery/processors/add_google_font.rb

Instance Method Summary collapse

Constructor Details

#initialize(font_name, variants = []) ⇒ AddGoogleFont

Returns a new instance of AddGoogleFont.



6
7
8
9
# File 'lib/slippery/processors/add_google_font.rb', line 6

def initialize(font_name, variants = [])
  @font_name = font_name.freeze
  @variants  = variants.freeze
end

Instance Method Details



15
16
17
18
19
# File 'lib/slippery/processors/add_google_font.rb', line 15

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

#call(doc) ⇒ Object



11
12
13
# File 'lib/slippery/processors/add_google_font.rb', line 11

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

#hrefObject



21
22
23
24
# File 'lib/slippery/processors/add_google_font.rb', line 21

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