vstheme2scss 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/vstheme2scss.rb +68 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a4e8fb0695bee76bc6b1a71391a4cd5cd3f34ae862871d40e8a5799fff57975
4
+ data.tar.gz: 35af05f2b3c256b947c74d173a64e6a8a919d813eed1a94fb7d1564a79a56e18
5
+ SHA512:
6
+ metadata.gz: c0d27484b5c2b4ef018b0c7d7af35d95dfc59595f510d95f0313cd6b5ccf6bbb5cc9c1ed2aa7142a19b2270a688daf2fe2d8e570c675b6157c9c8c5fb45f2ab4
7
+ data.tar.gz: 2da4b37d4e83e63b430761fea6f32a671e0989d25577a4e2c4aaad772a6d4c0d035587a8333b64516bf784113ba382e284d916960cf1d6d0d3be3335e97e9892
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ require "json"
3
+ require "pathname"
4
+ require "optparse"
5
+ require "ostruct"
6
+
7
+ def build_tokens_scss(tokens)
8
+ tokens.select{ |token|
9
+ token.key?("name")
10
+ }.uniq{ |token|
11
+ token["name"]
12
+ }.select{ |token|
13
+ not token["name"].include? "[" and not token["name"].include? "]" and not token["name"].include? "/"
14
+ }.select{ |token|
15
+ token["settings"].key?("foreground")
16
+ }.map{ |token|
17
+ "\t\t#{token["name"].downcase.gsub(/ /, "-")}-color: #{token["settings"]["foreground"]},"
18
+ }.join("\n")
19
+ end
20
+
21
+ def build_scss_theme(theme)
22
+ colors = theme["colors"]
23
+ tokens = theme["tokenColors"]
24
+ [
25
+ "\t#{theme["name"].downcase.gsub(/ /, "-")}: (",
26
+ "\t\tbackground-color: #{colors["editor.background"]},",
27
+ "\t\tforeground-color: #{colors["editor.foreground"]},",
28
+ "#{build_tokens_scss(tokens)}",
29
+ ].join("\n") + "\n\t),"
30
+ end
31
+
32
+ options = OpenStruct.new
33
+ OptionParser.new do |parser|
34
+ parser.banner = "Usage: vstheme2scss [options] <files>"
35
+ parser.on("-j", "--json-list=JSONFILE", "File to output theme names to"){ |o| options[:json_list] = o }
36
+ parser.on("-o", "--out-file=OUTFILE", "Output destionation file"){ |o| options[:out_file] = o }
37
+ end.parse!
38
+
39
+ if not options[:out_file]
40
+ puts "Error: Missing output file"
41
+ exit
42
+ end
43
+
44
+
45
+ out_path = Pathname.new(options[:out_file]);
46
+ json_res = ARGV.map{ |theme_file|
47
+ theme_path = Pathname.new(theme_file)
48
+ if not theme_path.directory?
49
+ theme = JSON.parse(theme_path.read)
50
+ scss_stub = build_scss_theme(theme)
51
+ else
52
+ puts "Error: #{theme_path.dirname}#{theme_path.basename} was not a file."
53
+ end
54
+ theme_path.directory? ? nil : JSON.parse(theme_path.read)
55
+ }.select{ |theme| theme != nil }
56
+
57
+ out_res = json_res.map{ |theme| build_scss_theme(theme) }.join("\n")
58
+ out_path.write("$themes: (\n#{out_res}\n);\n")
59
+
60
+ if options[:json_list]
61
+ json_out_path = Pathname.new(options[:json_list])
62
+ if json_out_path.directory?
63
+ puts "Error #{json_out_path.dirname}#{json_out_path.basename} is not a file"
64
+ else
65
+ names = json_res.map{ |theme| "#{theme["name"].downcase.gsub(/ /, "-")}" }
66
+ json_out_path.write(names)
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vstheme2scss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Kruhlmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: ''
14
+ email: kruhlmann@protonmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/vstheme2scss.rb
20
+ homepage: https://rubygems.org/gems/hola
21
+ licenses:
22
+ - GPLv3-or-later
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Converts VS Code themes into SCSS themes.
43
+ test_files: []