Class: Dugway::ThemeFont
- Inherits:
-
Struct
- Object
- Struct
- Dugway::ThemeFont
- Defined in:
- lib/dugway/theme_font.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#family ⇒ Object
Returns the value of attribute family.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .all ⇒ Object
- .find_by_name(name) ⇒ Object
- .find_family_by_name(name) ⇒ Object
- .google_font_names ⇒ Object
- .google_font_url_for_all_fonts ⇒ Object
- .google_font_url_for_fonts(fonts) ⇒ Object
- .google_font_url_for_theme ⇒ Object
- .options ⇒ Object
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection
4 5 6 |
# File 'lib/dugway/theme_font.rb', line 4 def collection @collection end |
#family ⇒ Object
Returns the value of attribute family
4 5 6 |
# File 'lib/dugway/theme_font.rb', line 4 def family @family end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/dugway/theme_font.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
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_names ⇒ Object
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_fonts ⇒ Object
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_theme ⇒ Object
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 |
.options ⇒ Object
16 17 18 |
# File 'lib/dugway/theme_font.rb', line 16 def ||= all.map(&:name) end |