vstheme2scss 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vstheme2scss.rb +67 -67
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a4e8fb0695bee76bc6b1a71391a4cd5cd3f34ae862871d40e8a5799fff57975
4
- data.tar.gz: 35af05f2b3c256b947c74d173a64e6a8a919d813eed1a94fb7d1564a79a56e18
3
+ metadata.gz: 2b3a6006e59a22c723bb2e4f3bdbad812229d86d623e24b30c54e524c8ebb5e4
4
+ data.tar.gz: ffde2570141e62feddebc090f2f49da8b2e949c1ef39617f7ab7b6a6bf615966
5
5
  SHA512:
6
- metadata.gz: c0d27484b5c2b4ef018b0c7d7af35d95dfc59595f510d95f0313cd6b5ccf6bbb5cc9c1ed2aa7142a19b2270a688daf2fe2d8e570c675b6157c9c8c5fb45f2ab4
7
- data.tar.gz: 2da4b37d4e83e63b430761fea6f32a671e0989d25577a4e2c4aaad772a6d4c0d035587a8333b64516bf784113ba382e284d916960cf1d6d0d3be3335e97e9892
6
+ metadata.gz: be64256a4608a34ab1d324a8403e4f86bb9cc21f08e995c4461c0322cc52d1a6fd1fd01e392938725115529784a838147dda675639e1be44882c5e708b1486e5
7
+ data.tar.gz: f820fee0f7ce47e576a6c3559acf6f333bded5acc13e6417fe2b9336a706335dc046bea2341529d6c32c37175504f851a4e3291a5afab4a012897f88cc445d7a
data/lib/vstheme2scss.rb CHANGED
@@ -1,68 +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
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
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vstheme2scss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Kruhlmann
@@ -19,7 +19,7 @@ files:
19
19
  - lib/vstheme2scss.rb
20
20
  homepage: https://rubygems.org/gems/hola
21
21
  licenses:
22
- - GPLv3-or-later
22
+ - GPL-3.0-or-later
23
23
  metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options: []