Module: Google::Webfonts::Helper

Defined in:
lib/google/webfonts/helper.rb

Overview

Provides a helper method for creating HTML link tags for fonts hosted on Google’s Webfonts CDN.

Instance Method Summary collapse

Instance Method Details

Generates a Google Webfonts link tag.

Examples:

Fonts without options.

google_webfonts_link_tag :droid_sans, :open_sans

Strings can be used for font names.

# :pt_sans would be converted to 'Pt+Sans' (lower-case t), which is
# an invalid font name. Strings do not get titleized, so this font
# name would require a string instead of a Symbol.
google_webfonts_link_tag 'PT Sans'

Specifying font weights.

google_webfonts_link_tag droid_sans: %w[400 500 bold bolditalic]

Parameters:

  • options (Array<String, Symbol, Hash{String, Symbol => Array<String>}>)

    Options for the fonts.

Returns:

  • (String)

    HTML with the <link> tag.



23
24
25
26
27
28
29
# File 'lib/google/webfonts/helper.rb', line 23

def google_webfonts_link_tag(*options)
  # Do not create the link tag unless at least one font was given.
  fail ArgumentError, 'expected at least one font' unless options.any?

  # Create the HTML for the link tag.
  Google::Webfonts::LinkTag.new(*options).to_s
end