Class: ActiveMail::Tokens

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activemail/tokens.rb

Overview

Design-tokens registry: the single Ruby source of truth, bridged to SCSS by #to_scss.

Constant Summary collapse

TokenMap =
T.type_alias { T::Hash[Symbol, String] }
DEFAULT_COLORS =
T.let(
  {
    primary: '#2a9d8f',
    secondary: '#264653',
    text: '#1a1a1a',
    background: '#ffffff',
    muted: '#6b7280',
    border: '#e5e7eb',
    button_text: '#ffffff'
  }.freeze,
  TokenMap
)
SYSTEM_FONT_STACK =
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'
DEFAULT_FONTS =
T.let(
  {
    body: SYSTEM_FONT_STACK,
    heading: SYSTEM_FONT_STACK
  }.freeze,
  TokenMap
)
DEFAULT_SPACINGS =
T.let(
  {
    xs: '4px',
    sm: '8px',
    md: '16px',
    lg: '24px',
    xl: '40px'
  }.freeze,
  TokenMap
)

Instance Method Summary collapse

Constructor Details

#initializeTokens

Returns a new instance of Tokens.



48
49
50
51
52
# File 'lib/activemail/tokens.rb', line 48

def initialize
  @colors = T.let(DEFAULT_COLORS.dup, TokenMap)
  @fonts = T.let(DEFAULT_FONTS.dup, TokenMap)
  @spacings = T.let(DEFAULT_SPACINGS.dup, TokenMap)
end

Instance Method Details

#color(name, value = nil) ⇒ Object



57
58
59
# File 'lib/activemail/tokens.rb', line 57

def color(name, value = nil)
  access(@colors, name, value)
end

#color!(name) ⇒ Object



74
75
76
# File 'lib/activemail/tokens.rb', line 74

def color!(name)
  fetch!(@colors, :color, name)
end

#colorsObject



90
91
92
# File 'lib/activemail/tokens.rb', line 90

def colors
  @colors.dup.freeze
end

#font(name, value = nil) ⇒ Object



62
63
64
# File 'lib/activemail/tokens.rb', line 62

def font(name, value = nil)
  access(@fonts, name, value)
end

#font!(name) ⇒ Object



79
80
81
# File 'lib/activemail/tokens.rb', line 79

def font!(name)
  fetch!(@fonts, :font, name)
end

#fontsObject



95
96
97
# File 'lib/activemail/tokens.rb', line 95

def fonts
  @fonts.dup.freeze
end

#spacing(name, value = nil) ⇒ Object



67
68
69
# File 'lib/activemail/tokens.rb', line 67

def spacing(name, value = nil)
  access(@spacings, name, value)
end

#spacing!(name) ⇒ Object



84
85
86
# File 'lib/activemail/tokens.rb', line 84

def spacing!(name)
  fetch!(@spacings, :spacing, name)
end

#spacingsObject



100
101
102
# File 'lib/activemail/tokens.rb', line 100

def spacings
  @spacings.dup.freeze
end

#to_scssObject



107
108
109
110
# File 'lib/activemail/tokens.rb', line 107

def to_scss
  lines = scss_lines('color', @colors) + scss_lines('font', @fonts) + scss_lines('spacing', @spacings)
  "#{lines.join("\n")}\n"
end