Class: ThemeFont

Inherits:
Struct
  • Object
show all
Defined in:
lib/bigcartel/theme/fonts/theme_font.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#collectionObject

Returns the value of attribute collection

Returns:

  • (Object)

    the current value of collection



3
4
5
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3

def collection
  @collection
end

#familyObject

Returns the value of attribute family

Returns:

  • (Object)

    the current value of family



3
4
5
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3

def family
  @family
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3

def name
  @name
end

Class Method Details

.allObject



5
6
7
8
9
10
11
12
13
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 5

def all
  @@all ||= Array.new.tap { |fonts|
    source.each_pair { |collection, collection_fonts|
      collection_fonts.values.each { |font|
        fonts << ThemeFont.new(font['name'], font['family'], collection)
      }
    }
  }.sort_by { |font| font.name }
end

.find_by_name(name) ⇒ Object



19
20
21
22
23
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 19

def find_by_name(name)
  all.find { |font|
    name.downcase == font.name.downcase
  }
end

.find_family_by_name(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 25

def find_family_by_name(name)
  if font = find_by_name(name)
    font.family
  else
    name
  end
end

.google_font_namesObject



33
34
35
36
37
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 33

def google_font_names
  @@google_font_names ||= all.select { |font|
    font.collection == 'google'
  }.map(&:name)
end

.google_font_url_for_all_fontsObject



43
44
45
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 43

def google_font_url_for_all_fonts
  google_font_url_for_fonts(google_font_names)
end

.google_font_url_for_fonts(fonts) ⇒ Object



39
40
41
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 39

def google_font_url_for_fonts(fonts)
  "//fonts.googleapis.com/css?family=#{ fonts.uniq.map { |font| font.gsub(' ', '+') }.join('|') }"
end

.google_font_url_for_theme(fonts, settings) ⇒ Object



47
48
49
50
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 47

def google_font_url_for_theme(fonts, settings)
  google_fonts = fonts.keys.map { |key| settings[key] }.select { |font_name| google_font_names.include? font_name }.sort
  google_fonts.empty? ? nil : google_font_url_for_fonts(google_fonts)
end

.optionsObject



15
16
17
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 15

def options
  @@options ||= all.map(&:name)
end