class ThemeFont
Public Class Methods
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
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
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
Source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 39 def google_font_names google_fonts.map(&:name) end
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
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
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
Source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 69 def google_font_url_for_theme_json(account_theme) return {} if account_theme.theme&.name.nil? # Cosmos and Lunch Break use the secondary font for the primary text font font_setting = if ["cosmos", "lunch break"].include?(account_theme.theme.name.downcase) account_theme.settings[:secondary_font] else account_theme.settings[:primary_font] || account_theme.settings[:text_font] || account_theme.settings[:font] || account_theme.settings[:serif_font] end font = find_by_name(font_setting) return {} if font.nil? || font.collection != 'google' { "primary_text_font" => { "name" => font.name, "url" => "https://fonts.googleapis.com/css?family=#{font.name.gsub(' ', '+')}" } } end
Source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 33 def google_fonts @@google_fonts ||= all.select { |font| font.collection == 'google' } end
Source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 15 def options @@options ||= all.map(&:name) end
Private Class Methods
Source
# File lib/bigcartel/theme/fonts/theme_font.rb, line 95 def source @@source ||= YAML.load(File.read(File.join(File.dirname(__FILE__), 'theme_fonts.yml'))) end