Class: TNS::Output::Tailwind

Inherits:
Object
  • Object
show all
Defined in:
lib/tns/output/tailwind.rb

Overview

Output a given color palette as Tailwind JSON.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tailwind

Returns a new instance of Tailwind.



9
10
11
# File 'lib/tns/output/tailwind.rb', line 9

def initialize(name)
  @name = name
end

Instance Method Details

#format(palette) ⇒ Object



13
14
15
16
# File 'lib/tns/output/tailwind.rb', line 13

def format(palette)
  colors = palette.map { |variant| format_variant(variant) }
  JSON.pretty_generate({ @name.to_s => colors.reduce({}, :merge) })
end

#format_variant(variant) ⇒ Object



18
19
20
# File 'lib/tns/output/tailwind.rb', line 18

def format_variant(variant)
  { (variant.index * 100).to_s => variant.to_css.to_s }
end