Module: Spree::FontsHelper
- Defined in:
- app/helpers/spree/fonts_helper.rb
Instance Method Summary collapse
- #font_styles ⇒ Object
- #google_fonts_link_tag ⇒ Object
- #header_font_family_styles ⇒ Object
- #normal_font_family_styles ⇒ Object
Instance Method Details
#font_styles ⇒ Object
53 54 55 56 57 58 |
# File 'app/helpers/spree/fonts_helper.rb', line 53 def font_styles <<~CSS.html_safe #{normal_font_family_styles} #{header_font_family_styles} CSS end |
#google_fonts_link_tag ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/helpers/spree/fonts_helper.rb', line 36 def google_fonts_link_tag fonts = [current_theme_or_preview.preferred_font_family, current_theme_or_preview.preferred_header_font_family].compact_blank.uniq return if fonts.blank? font_weights = (200..700).step(100).to_a imports = fonts.map do |font| "family=#{font.split.join('+')}:wght@#{font_weights.join(';')}" end.compact.join('&') return if imports.blank? return if Rails.env.test? stylesheet_link_tag "https://fonts.googleapis.com/css2?#{imports}&display=swap" end |
#header_font_family_styles ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/spree/fonts_helper.rb', line 24 def header_font_family_styles return '' if current_theme_or_preview.preferred_header_font_family.blank? font_family = current_theme_or_preview.preferred_header_font_family <<~CSS h1, h2, h3, h4, h5, h6 { font-family: '#{font_family}', sans-serif; } CSS end |
#normal_font_family_styles ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/spree/fonts_helper.rb', line 3 def normal_font_family_styles return '' if current_theme_or_preview.preferred_font_family.blank? font_family = current_theme_or_preview.preferred_font_family text_font_size = (current_theme_or_preview.preferred_font_size_scale || 100) / 100.0 <<~CSS :root { --font-body: #{font_family}; } body { font-family: '#{font_family}', sans-serif; } body { font-size: #{text_font_size}rem; } CSS end |