Class: Dugway::ThemeFont

Inherits:
Struct
  • Object
show all
Defined in:
lib/dugway/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



4
5
6
# File 'lib/dugway/theme_font.rb', line 4

def collection
  @collection
end

#familyObject

Returns the value of attribute family

Returns:

  • (Object)

    the current value of family



4
5
6
# File 'lib/dugway/theme_font.rb', line 4

def family
  @family
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/dugway/theme_font.rb', line 4

def name
  @name
end

Class Method Details

.allObject



6
7
8
9
10
11
12
13
14
# File 'lib/dugway/theme_font.rb', line 6

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



20
21
22
23
24
# File 'lib/dugway/theme_font.rb', line 20

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

.find_family_by_name(name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/dugway/theme_font.rb', line 26

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

.google_font_namesObject



34
35
36
37
38
# File 'lib/dugway/theme_font.rb', line 34

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

.google_font_url_for_all_fontsObject



44
45
46
# File 'lib/dugway/theme_font.rb', line 44

def google_font_url_for_all_fonts
  google_font_url_for_fonts(google_font_names)
end

.google_font_url_for_fonts(fonts) ⇒ Object



40
41
42
# File 'lib/dugway/theme_font.rb', line 40

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

.google_font_url_for_themeObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dugway/theme_font.rb', line 48

def google_font_url_for_theme
  theme = Dugway.theme
  fonts = theme.fonts.keys.map { |key|
    theme.customization[key] }.select { |font_name|
      google_font_names.include? font_name }.sort

  if fonts.present?
    google_font_url_for_fonts(fonts)
  else
    nil
  end
end

.optionsObject



16
17
18
# File 'lib/dugway/theme_font.rb', line 16

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