class ThemeFont
Public Class Methods
all()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 33 def google_fonts @@google_fonts ||= all.select { |font| font.collection == 'google' } end
options()
click to toggle source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 15 def options @@options ||= all.map(&:name) end
Private Class Methods
source()
click to toggle source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 71 def source @@source ||= YAML.load(File.read(File.join(File.dirname(__FILE__), 'theme_fonts.yml'))) end