Class: Mxrb::Dsl::DesignSystemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/dsl/builder.rb

Constant Summary collapse

TOKEN_KINDS =
%i[color spacing radius typography breakpoint].freeze

Instance Method Summary collapse

Constructor Details

#initializeDesignSystemBuilder

Returns a new instance of DesignSystemBuilder.



649
650
651
652
653
654
655
656
657
# File 'lib/mxrb/dsl/builder.rb', line 649

def initialize
  @tokens = []
  @themes = []
  @layouts = []
  @components = []
  @accessibility = []
  @contrast_pairs = []
  @forbid_literal_colors = false
end

Instance Method Details

#accessibility(rule) ⇒ Object



673
674
675
# File 'lib/mxrb/dsl/builder.rb', line 673

def accessibility(rule)
  @accessibility << rule.to_s
end

#component(name) ⇒ Object



669
670
671
# File 'lib/mxrb/dsl/builder.rb', line 669

def component(name)
  @components << name.to_s
end

#contrast(foreground:, background:, level: :aa) ⇒ Object



683
684
685
686
687
# File 'lib/mxrb/dsl/builder.rb', line 683

def contrast(foreground:, background:, level: :aa)
  @contrast_pairs << {
    foreground: foreground.to_s, background: background.to_s, level: level.to_s
  }
end

#forbid_literal_colors(value = true) ⇒ Object



689
690
691
# File 'lib/mxrb/dsl/builder.rb', line 689

def forbid_literal_colors(value = true)
  @forbid_literal_colors = value == true
end

#layout(name) ⇒ Object



665
666
667
# File 'lib/mxrb/dsl/builder.rb', line 665

def layout(name)
  @layouts << name.to_s
end

#theme(name, inherits: nil, &block) ⇒ Object



677
678
679
680
681
# File 'lib/mxrb/dsl/builder.rb', line 677

def theme(name, inherits: nil, &block)
  builder = DesignThemeBuilder.new(name, inherits:)
  builder.instance_eval(&block) if block
  @themes << builder.to_h
end

#to_hObject



693
694
695
696
697
698
699
700
# File 'lib/mxrb/dsl/builder.rb', line 693

def to_h
  {
    tokens: @tokens, layouts: @layouts,
    components: @components, accessibility: @accessibility,
    themes: @themes, contrast_pairs: @contrast_pairs,
    forbid_literal_colors: @forbid_literal_colors
  }
end