Class: ThemeFont
- Inherits:
-
Struct
- Object
- Struct
- ThemeFont
- Defined in:
- lib/bigcartel/theme/fonts/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.
-
#weights ⇒ Object
Returns the value of attribute weights.
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(fonts, settings) ⇒ Object
- .google_fonts ⇒ Object
- .options ⇒ Object
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection
3 4 5 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3 def collection @collection end |
#family ⇒ Object
Returns the value of attribute family
3 4 5 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3 def family @family end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3 def name @name end |
#weights ⇒ Object
Returns the value of attribute weights
3 4 5 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 3 def weights @weights end |
Class Method Details
.all ⇒ Object
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'], font['weights'], 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_names ⇒ Object
39 40 41 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 39 def google_font_names google_fonts.map(&:name) end |
.google_font_url_for_all_fonts ⇒ Object
55 56 57 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 55 def google_font_url_for_all_fonts google_font_url_for_fonts(google_fonts) end |
.google_font_url_for_fonts(fonts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 43 def google_font_url_for_fonts(fonts) fonts = fonts.map do |font| if font.kind_of? ThemeFont font.weights ? "#{font.name}:#{font.weights}" : font.name else font end end "//fonts.googleapis.com/css?family=#{ fonts.uniq.map { |font| font.gsub(' ', '+') }.join('|') }&display=swap" end |
.google_font_url_for_theme(fonts, settings) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 59 def google_font_url_for_theme(fonts, settings) google_fonts = fonts.keys.map { |key| settings[key] }.compact. map { |font_name| find_by_name font_name }. compact. select { |font| font.collection == 'google' }. sort_by { |font| font.name } google_fonts.empty? ? nil : google_font_url_for_fonts(google_fonts) end |
.google_fonts ⇒ Object
33 34 35 36 37 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 33 def google_fonts @@google_fonts ||= all.select { |font| font.collection == 'google' } end |
.options ⇒ Object
15 16 17 |
# File 'lib/bigcartel/theme/fonts/theme_font.rb', line 15 def @@options ||= all.map(&:name) end |