Class: Typie

Inherits:
Object
  • Object
show all
Defined in:
lib/typie.rb

Class Method Summary collapse

Class Method Details

.add_domains(*domains) ⇒ Object (private) Also known as: add_domain

Add domains for Typekit to serve this Kit to

Parameters:

  • domains (Array)

    An array of the domains to allow



40
41
42
43
# File 'lib/typie.rb', line 40

def add_domains(*domains)
  @settings[:domains] << domains
  @settings[:domains].flatten!
end

.add_font(name, options = {}) ⇒ Object (private)

Add a Family to the Kit

Parameters:

  • name (String)

    The Family name (must match Typekit exactly)

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :include_variations (Array)

    An array of Font Variation Descriptions to be included



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/typie.rb', line 50

def add_font(name, options = {})
  font = @typekit.family_by_name(name)
  
  if options[:include_variations]
    # We're silently ignoring invalid variations
    variations = options[:include_variations] & font.variations.map(&:to_fvd)
  else
    # Add all variations available by default
    variations = font.variations.map(&:to_fvd)
  end
  
  @fonts << { :id => font.id, :variations => variations }
end

.call_it(name) ⇒ Object (private)

Set the name of the Kit

Parameters:

  • name (String)

    The desired name



34
35
36
# File 'lib/typie.rb', line 34

def call_it(name)
  @settings[:name] = name
end

.new_kit(options = {}, &block) ⇒ String

Add a Kit to Typekit

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :token (String)

    Required: Your Typekit API Token

Returns:

  • (String)

    Typekit Kit ID of the resulting Kit



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/typie.rb', line 10

def new_kit(options = {}, &block)
  raise 'Token required' unless options[:token]
  
  # Setup Typie
  @typekit = Typekit::Client.new(options[:token])
  @settings = { :name => 'Unnamed', :domains => [] }
  @fonts = []
  
  # Wreak havoc
  instance_eval &block
  
  # Handle it all
  kit = @typekit.create_kit @settings
  @fonts.each do |font|
    kit.add_family(font[:id], :variations => font[:variations])
  end
  
  kit.id
end