Class: Slippery::Processors::AddGoogleFont
- Inherits:
-
Object
- Object
- Slippery::Processors::AddGoogleFont
- Defined in:
- lib/slippery/processors/add_google_font.rb
Instance Method Summary collapse
- #add_font_link ⇒ Object
- #call(doc) ⇒ Object
- #href ⇒ Object
-
#initialize(font_name, variants = []) ⇒ AddGoogleFont
constructor
A new instance of AddGoogleFont.
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
#add_font_link ⇒ Object
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 |
#href ⇒ Object
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 |