Class: UtilityColors::Exports

Inherits:
Object
  • Object
show all
Defined in:
lib/utility_colors/exports.rb

Class Method Summary collapse

Class Method Details

.append_alpha(alpha) ⇒ Object



50
51
52
# File 'lib/utility_colors/exports.rb', line 50

def self.append_alpha(alpha)
  "/ #{alpha * 100}"
end

.append_percentage(value) ⇒ Object



46
47
48
# File 'lib/utility_colors/exports.rb', line 46

def self.append_percentage(value)
  "#{value}%"
end

.css(filename, output_classes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/utility_colors/exports.rb', line 32

def self.css(filename, output_classes)
  # TODO: add root for variables at top? Leave for now as this is all based off a palette file where they should exist (easy copy and paste for devs)
  # TODO: determine if the style value should use the syntax variable or be converted to hardcoded value
  content = output_classes.collect { |class_name, class_content| "#{class_name} {\n\t#{class_content.gsub('£$', 'var(--').gsub('', ')')}\n}" }.join("\n\n")
  filepath = "#{filename}.css"

  # Create directory if it doesn't exist
  FileUtils.mkdir_p(File.dirname(filepath))
  File.write(filepath, content)

  puts 'Exporting utility colour classes CSS...'
  true
end

.json(filename, output_classes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/utility_colors/exports.rb', line 5

def self.json(filename, output_classes)
  # TODO: determine if they imported scss or css and return the variables keys in that way
  # TODO: determine if the style value should use a syntax variable or be converted to hardcoded value
  content = JSON.pretty_generate(output_classes.transform_values { |class_content| class_content.gsub('£$', '$').gsub('', '') })
  filepath = "#{filename}.json"

  # Create directory if it doesn't exist
  FileUtils.mkdir_p(File.dirname(filepath))
  File.write(filepath, content)

  puts 'Exporting utility colour classes JSON...'
  true
end

.scss(filename, output_classes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/utility_colors/exports.rb', line 19

def self.scss(filename, output_classes)
  # TODO: determine if the style value should use the syntax variable or be converted to hardcoded value
  content = output_classes.collect { |class_name, class_content| "#{class_name} {\n\t#{class_content.gsub('£$', '$').gsub('', '')}\n}" }.join("\n\n")
  filepath = "#{filename}.scss"

  # Create directory if it doesn't exist
  FileUtils.mkdir_p(File.dirname(filepath))
  File.write(filepath, content)

  puts 'Exporting utility colour classes SCSS...'
  true
end