victor-cli 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5310277ac8adfa21b11145be6a0ca34b198a9407e8186eb1a54ac5af7da4b685
4
- data.tar.gz: fff3d483dbf41ef774a4a3a5f30d6abc72c55919d6516c03dec8d1dfdb0f4c19
3
+ metadata.gz: afafb8c88c6da7d1af79069ad31bb509ff5888c69e659a753e0eb753004defcd
4
+ data.tar.gz: 849b54edb118a6e4a2b3c5c91c0dbb21c4067fa712aef3984e46928d3ca63696
5
5
  SHA512:
6
- metadata.gz: 1001b0a3ccd0d48944f3abf93956acf8e524c71e2dd81a9b39dd0ee415197f8ebcf9b29f2f2cada4bef4cba7e910b2865e671ffa7ff2c8cb1b1f28ab3fb65a1e
7
- data.tar.gz: 0d3e77e6cd44a095f5d7d45d7130ea2fd685bda224e1d31d1739eb60580216a90ab6be253ca8ae4cbad9ec70f8e57a9e9fdcbdbf50ca6d2c8045982c146fc014
6
+ metadata.gz: 1dc516300e9686ad0b9418f653ecdc4a78853f8f7a93334beb8d834fffdb741649b369e001c5b2f13f763f270239654d75d28c50ddadf6a9d0f3ace1aec80544
7
+ data.tar.gz: 13d73e7b3017f22ddbf4394ae263f5d9adfd50eb95f6060b4b8e7ee0aad40096fc47456e2440b6754f11342d46dd573feb155c093a28886896d8ac9dcadcfb58
data/bin/victor CHANGED
@@ -3,7 +3,7 @@ require 'victor/cli'
3
3
  require 'pretty_trace/enable-trim'
4
4
 
5
5
  include Colsole
6
- PrettyTrace.filter [/gem/, /lib/, /bin\/victor/]
6
+ PrettyTrace.filter [/gem/, /lib/, %r{bin/victor}]
7
7
  PrettyTrace.debug_tip
8
8
 
9
9
  router = Victor::CLI::CommandLine.router
@@ -1,12 +1,13 @@
1
1
  require 'mister_bin'
2
- requires 'commands/base', 'commands'
2
+ requires 'commands/base'
3
+ requires 'commands'
3
4
 
4
5
  module Victor
5
6
  module CLI
6
7
  class CommandLine
7
8
  def self.router
8
9
  router = MisterBin::Runner.new version: VERSION,
9
- header: "Victor SVG Utilities"
10
+ header: 'Victor SVG Utilities'
10
11
 
11
12
  router.route 'init', to: Commands::Init
12
13
  router.route 'convert', to: Commands::Convert
@@ -15,6 +16,5 @@ module Victor
15
16
  router
16
17
  end
17
18
  end
18
-
19
19
  end
20
- end
20
+ end
@@ -9,4 +9,4 @@ module Victor
9
9
  end
10
10
  end
11
11
  end
12
- end
12
+ end
@@ -2,30 +2,32 @@ module Victor
2
2
  module CLI
3
3
  module Commands
4
4
  class Convert < Base
5
- summary "Convert SVG to Ruby code"
5
+ summary 'Convert SVG to Ruby code'
6
6
 
7
- usage "victor convert SVG_FILE [RUBY_FILE --template NAME]"
8
- usage "victor convert (-h|--help)"
7
+ usage 'victor convert SVG_FILE [RUBY_FILE --template NAME]'
8
+ usage 'victor convert (-h|--help)'
9
9
 
10
- option "-t, --template NAME", "Name of the Ruby template to use. Can be:\n" +
11
- " standalone a full standalone Ruby script\n" +
12
- " dsl a Victor DSL script\n" +
13
- " cli a Victor CLI compatible DSL script (default)"
10
+ option '-t, --template NAME', <<~USAGE
11
+ Name of the Ruby template to use. Can be:
12
+ standalone a full standalone Ruby script
13
+ dsl a Victor DSL script
14
+ cli a Victor CLI compatible DSL script (default)
15
+ USAGE
14
16
 
15
- param "SVG_FILE", "Input SVG file"
16
- param "RUBY_FILE", "Output Ruby file. Leave empty to write to stdout"
17
+ param 'SVG_FILE', 'Input SVG file'
18
+ param 'RUBY_FILE', 'Output Ruby file. Leave empty to write to stdout'
17
19
 
18
- example "victor convert example.svg example.rb"
20
+ example 'victor convert example.svg example.rb'
19
21
 
20
22
  def run
21
- svg_file = args["SVG_FILE"]
23
+ svg_file = args['SVG_FILE']
22
24
  template = args['--template']
23
25
  svg_node = SVGNode.load_file svg_file, layout: template
24
26
 
25
27
  validate_template template if template
26
28
 
27
29
  code = svg_node.render
28
- ruby_file = args["RUBY_FILE"]
30
+ ruby_file = args['RUBY_FILE']
29
31
 
30
32
  if ruby_file
31
33
  File.write ruby_file, code
@@ -37,9 +39,9 @@ module Victor
37
39
 
38
40
  def validate_template(template)
39
41
  allowed = %w[cli dsl standalone]
40
- unless allowed.include? template
41
- raise "Template not found #{template}\nAvailable templates: #{allowed.join ', '}"
42
- end
42
+ return if allowed.include? template
43
+
44
+ raise "Template not found #{template}\nAvailable templates: #{allowed.join ', '}"
43
45
  end
44
46
  end
45
47
  end
@@ -2,20 +2,22 @@ module Victor
2
2
  module CLI
3
3
  module Commands
4
4
  class Init < Base
5
- summary "Create a sample Victor Ruby script"
5
+ summary 'Create a sample Victor Ruby script'
6
6
 
7
- usage "victor init RUBY_FILE [--template TEMPLATE]"
8
- usage "victor init (-h|--help)"
7
+ usage 'victor init RUBY_FILE [--template TEMPLATE]'
8
+ usage 'victor init (-h|--help)'
9
9
 
10
- option "-t, --template NAME", "Name of the Ruby template to use. Can be:\n" +
11
- " standalone a full standalone Ruby script\n" +
12
- " dsl a Victor DSL script\n" +
13
- " cli a Victor CLI compatible DSL script (default)"
10
+ option '-t, --template NAME', <<~USAGE
11
+ Name of the Ruby template to use. Can be:
12
+ standalone a full standalone Ruby script
13
+ dsl a Victor DSL script
14
+ cli a Victor CLI compatible DSL script (default)
15
+ USAGE
14
16
 
15
- param "RUBY_FILE", "Output Ruby file"
17
+ param 'RUBY_FILE', 'Output Ruby file'
16
18
 
17
- example "victor init ghost.rb"
18
- example "victor init ghost.rb --template standalone"
19
+ example 'victor init ghost.rb'
20
+ example 'victor init ghost.rb --template standalone'
19
21
 
20
22
  def run
21
23
  raise "File already exists #{filename}" if File.exist? filename
@@ -26,21 +28,21 @@ module Victor
26
28
 
27
29
  File.write filename, content
28
30
  say "Saved #{filename}"
29
-
31
+
30
32
  if template == 'cli'
31
- say %Q[Run !txtblu!victor render "#{filename}"!txtrst! to render]
33
+ say %[Run !txtblu!victor render "#{filename}"!txtrst! to render]
32
34
  else
33
- say %Q[Run !txtblu!ruby "#{filename}"!txtrst! to render]
35
+ say %[Run !txtblu!ruby "#{filename}"!txtrst! to render]
34
36
  end
35
37
  end
36
38
 
37
39
  private
38
40
 
39
41
  def filename
40
- @filename ||= if args["RUBY_FILE"].end_with? '.rb'
41
- args["RUBY_FILE"]
42
+ @filename ||= if args['RUBY_FILE'].end_with? '.rb'
43
+ args['RUBY_FILE']
42
44
  else
43
- args['RUBY_FILE'] + ".rb"
45
+ "#{args['RUBY_FILE']}.rb"
44
46
  end
45
47
  end
46
48
 
@@ -59,11 +61,11 @@ module Victor
59
61
  end
60
62
 
61
63
  def templates_path
62
- @templates_path ||= File.expand_path "../templates/init", __dir__
64
+ @templates_path ||= File.expand_path '../templates/init', __dir__
63
65
  end
64
66
 
65
67
  def available_templates
66
- ['cli', 'dsl', 'standalone']
68
+ %w[cli dsl standalone]
67
69
  end
68
70
  end
69
71
  end
@@ -4,22 +4,24 @@ module Victor
4
4
  module CLI
5
5
  module Commands
6
6
  class Render < Base
7
- summary "Render Ruby code to SVG"
7
+ summary 'Render Ruby code to SVG'
8
8
 
9
- usage "victor render RUBY_FILE [SVG_FILE] [options]"
10
- usage "victor render (-h|--help)"
9
+ usage 'victor render RUBY_FILE [SVG_FILE] [options]'
10
+ usage 'victor render (-h|--help)'
11
11
 
12
- option '-t, --template TEMPLATE', "Set SVG template\n"+
13
- "Can be: default, html, minimal, or a file path"
12
+ option '-t, --template TEMPLATE', <<~USAGE
13
+ Set SVG template
14
+ Can be: default, html, minimal, or a file path
15
+ USAGE
14
16
 
15
17
  option '-w, --watch', 'Watch the source file and regenerate on change'
16
18
 
17
- param "RUBY_FILE", "Input Ruby file"
18
- param "SVG_FILE", "Output SVG file. Leave empty to write to stdout"
19
+ param 'RUBY_FILE', 'Input Ruby file'
20
+ param 'SVG_FILE', 'Output SVG file. Leave empty to write to stdout'
19
21
 
20
- example "victor render input.rb output.svg"
21
- example "victor render input.rb output.svg --watch"
22
- example "victor render input.rb --template minimal"
22
+ example 'victor render input.rb output.svg'
23
+ example 'victor render input.rb output.svg --watch'
24
+ example 'victor render input.rb --template minimal'
23
25
 
24
26
  def run
25
27
  if args['--watch']
@@ -49,7 +51,7 @@ module Victor
49
51
  def watch
50
52
  say "Watching #{ruby_file} for changes"
51
53
  file_watcher.watch do |changes|
52
- changes.each do |path, event|
54
+ changes.each do |_path, event|
53
55
  yield unless event == :deleted
54
56
  end
55
57
  end
@@ -58,7 +60,7 @@ module Victor
58
60
  def watch_and_generate
59
61
  watch do
60
62
  generate
61
- rescue Exception => e
63
+ rescue => e
62
64
  say! "!undred!#{e.class}!txtrst!\n#{e.message}"
63
65
  end
64
66
  end
@@ -68,11 +70,11 @@ module Victor
68
70
  end
69
71
 
70
72
  def ruby_file
71
- args["RUBY_FILE"]
73
+ args['RUBY_FILE']
72
74
  end
73
75
 
74
76
  def svg_file
75
- args["SVG_FILE"]
77
+ args['SVG_FILE']
76
78
  end
77
79
 
78
80
  def template
@@ -1,4 +1,4 @@
1
- require "css_parser"
1
+ require 'css_parser'
2
2
 
3
3
  module Victor
4
4
  module CLI
@@ -19,9 +19,6 @@ module Victor
19
19
  def parser
20
20
  @parser ||= CssParser::Parser.new
21
21
  end
22
-
23
22
  end
24
23
  end
25
24
  end
26
-
27
-
@@ -7,28 +7,27 @@ module Victor
7
7
  map do |key, value|
8
8
  key = key.to_key if key.is_a? String
9
9
 
10
- if key == "style"
10
+ if key == 'style'
11
11
  value = "{ #{value.style_to_hash.render} }"
12
12
  elsif value.is_a? String
13
13
  value = value.to_value
14
14
  end
15
15
 
16
16
  "#{key}: #{value}"
17
- end.join ", "
17
+ end.join ', '
18
18
  end
19
-
20
19
  end
21
20
 
22
21
  refine String do
23
22
  def to_key
24
- gsub('-', '_').to_sym.inspect[1..-1]
23
+ tr('-', '_').to_sym.inspect[1..]
25
24
  end
26
25
 
27
26
  def to_value
28
- if to_f.to_s == self or to_i.to_s == self
27
+ if (to_f.to_s == self) || (to_i.to_s == self)
29
28
  self
30
29
  else
31
- %Q["#{self}"]
30
+ %["#{self}"]
32
31
  end
33
32
  end
34
33
 
@@ -37,10 +36,9 @@ module Victor
37
36
  def style_to_hash
38
37
  parser = CssParser::Parser.new
39
38
  parser.load_string! "victor { #{self} }"
40
- parser.to_h["all"]["victor"]
39
+ parser.to_h['all']['victor']
41
40
  end
42
-
43
41
  end
44
42
  end
45
43
  end
46
- end
44
+ end
@@ -32,7 +32,6 @@ module Victor
32
32
  def built_in_templates
33
33
  %w[default minimal html]
34
34
  end
35
-
36
35
  end
37
36
  end
38
37
  end
@@ -29,7 +29,7 @@ module Victor
29
29
  # Returns formatted Ruby code
30
30
  def render
31
31
  Rufo::Formatter.format ruby_code
32
- rescue Rufo::SyntaxError => e
32
+ rescue Rufo::SyntaxError
33
33
  raise ruby_code
34
34
  end
35
35
 
@@ -87,7 +87,7 @@ module Victor
87
87
  # Returns the path to the appropriate ERB template, based on type
88
88
  def erb_template_file
89
89
  file = type == :root ? "root_#{layout}" : type
90
- path = File.expand_path "templates/nodes/#{file}.erb", __dir__
90
+ File.expand_path "templates/nodes/#{file}.erb", __dir__
91
91
  end
92
92
 
93
93
  # Returns the internal element type
@@ -114,13 +114,13 @@ module Victor
114
114
 
115
115
  # Returns a hash of attributes
116
116
  def attributes!
117
- node.attribute_nodes.map do |attr|
117
+ node.attribute_nodes.to_h do |attr|
118
118
  name = attr.name
119
119
  value = attr.value
120
120
  key = attr.respond_to?(:prefix) ? "#{attr.prefix}:#{name}" : name
121
-
121
+
122
122
  [key, value]
123
- end.to_h
123
+ end
124
124
  end
125
125
 
126
126
  def content!
@@ -135,7 +135,6 @@ module Victor
135
135
  # :nocov:
136
136
  end
137
137
  end
138
-
139
138
  end
140
139
  end
141
140
  end
@@ -1,7 +1,7 @@
1
1
  # Render this by running:
2
2
  # victor render "%{filename}"
3
3
 
4
- setup viewBox: "0 0 100 100"
4
+ setup viewBox: '0 0 100 100'
5
5
 
6
6
  build do
7
7
  circle cx: 50, cy: 50, r: 40, fill: 'yellow'
@@ -11,5 +11,5 @@ build do
11
11
  circle cx: x, cy: 40, r: 8, fill: 'white'
12
12
  end
13
13
 
14
- path d: "M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z", fill: 'white'
14
+ path d: 'M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z', fill: 'white'
15
15
  end
@@ -2,7 +2,7 @@
2
2
  # ruby "%{filename}"
3
3
  require 'victor/script'
4
4
 
5
- setup viewBox: "0 0 100 100"
5
+ setup viewBox: '0 0 100 100'
6
6
 
7
7
  build do
8
8
  circle cx: 50, cy: 50, r: 40, fill: 'yellow'
@@ -12,8 +12,8 @@ build do
12
12
  circle cx: x, cy: 40, r: 8, fill: 'white'
13
13
  end
14
14
 
15
- path d: "M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z", fill: 'white'
15
+ path d: 'M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z', fill: 'white'
16
16
  end
17
17
 
18
18
  puts render
19
- save "%{basename}"
19
+ save '%{basename}'
@@ -2,7 +2,7 @@
2
2
  # ruby "%{filename}"
3
3
  require 'victor'
4
4
 
5
- svg = Victor::SVG.new viewBox: "0 0 100 100"
5
+ svg = Victor::SVG.new viewBox: '0 0 100 100'
6
6
 
7
7
  svg.build do
8
8
  circle cx: 50, cy: 50, r: 40, fill: 'yellow'
@@ -12,8 +12,8 @@ svg.build do
12
12
  circle cx: x, cy: 40, r: 8, fill: 'white'
13
13
  end
14
14
 
15
- path d: "M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z", fill: 'white'
15
+ path d: 'M11 100 l13 -15 l13 15 l13 -15 l13 15 l13 -15 l13 15 Z', fill: 'white'
16
16
  end
17
17
 
18
18
  puts svg.render
19
- svg.save "%{basename}"
19
+ svg.save '%{basename}'
@@ -1,5 +1,5 @@
1
1
  module Victor
2
2
  module CLI
3
- VERSION = "0.3.4"
3
+ VERSION = '0.3.6'
4
4
  end
5
- end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: victor-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -9,120 +9,126 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-10-23 00:00:00.000000000 Z
12
+ date: 2023-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: filewatcher
15
+ name: colsole
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.0'
20
+ version: '0.8'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.1
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
- version: '2.0'
30
+ version: '0.8'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
28
34
  - !ruby/object:Gem::Dependency
29
- name: nokogiri
35
+ name: css_parser
30
36
  requirement: !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - "~>"
33
39
  - !ruby/object:Gem::Version
34
- version: '1.10'
40
+ version: '1.7'
35
41
  type: :runtime
36
42
  prerelease: false
37
43
  version_requirements: !ruby/object:Gem::Requirement
38
44
  requirements:
39
45
  - - "~>"
40
46
  - !ruby/object:Gem::Version
41
- version: '1.10'
47
+ version: '1.7'
42
48
  - !ruby/object:Gem::Dependency
43
- name: pretty_trace
49
+ name: filewatcher
44
50
  requirement: !ruby/object:Gem::Requirement
45
51
  requirements:
46
52
  - - "~>"
47
53
  - !ruby/object:Gem::Version
48
- version: 0.2.5
54
+ version: '2.0'
49
55
  type: :runtime
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
52
58
  requirements:
53
59
  - - "~>"
54
60
  - !ruby/object:Gem::Version
55
- version: 0.2.5
61
+ version: '2.0'
56
62
  - !ruby/object:Gem::Dependency
57
- name: requires
63
+ name: mister_bin
58
64
  requirement: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: '0.2'
68
+ version: '0.7'
63
69
  type: :runtime
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: '0.2'
75
+ version: '0.7'
70
76
  - !ruby/object:Gem::Dependency
71
- name: rufo
77
+ name: nokogiri
72
78
  requirement: !ruby/object:Gem::Requirement
73
79
  requirements:
74
80
  - - "~>"
75
81
  - !ruby/object:Gem::Version
76
- version: '0.12'
82
+ version: '1.10'
77
83
  type: :runtime
78
84
  prerelease: false
79
85
  version_requirements: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - "~>"
82
88
  - !ruby/object:Gem::Version
83
- version: '0.12'
89
+ version: '1.10'
84
90
  - !ruby/object:Gem::Dependency
85
- name: colsole
91
+ name: pretty_trace
86
92
  requirement: !ruby/object:Gem::Requirement
87
93
  requirements:
88
94
  - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '0.7'
96
+ version: '0.2'
91
97
  type: :runtime
92
98
  prerelease: false
93
99
  version_requirements: !ruby/object:Gem::Requirement
94
100
  requirements:
95
101
  - - "~>"
96
102
  - !ruby/object:Gem::Version
97
- version: '0.7'
103
+ version: '0.2'
98
104
  - !ruby/object:Gem::Dependency
99
- name: css_parser
105
+ name: requires
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
108
  - - "~>"
103
109
  - !ruby/object:Gem::Version
104
- version: '1.7'
110
+ version: '1.0'
105
111
  type: :runtime
106
112
  prerelease: false
107
113
  version_requirements: !ruby/object:Gem::Requirement
108
114
  requirements:
109
115
  - - "~>"
110
116
  - !ruby/object:Gem::Version
111
- version: '1.7'
117
+ version: '1.0'
112
118
  - !ruby/object:Gem::Dependency
113
- name: mister_bin
119
+ name: rufo
114
120
  requirement: !ruby/object:Gem::Requirement
115
121
  requirements:
116
122
  - - "~>"
117
123
  - !ruby/object:Gem::Version
118
- version: '0.7'
124
+ version: '0.12'
119
125
  type: :runtime
120
126
  prerelease: false
121
127
  version_requirements: !ruby/object:Gem::Requirement
122
128
  requirements:
123
129
  - - "~>"
124
130
  - !ruby/object:Gem::Version
125
- version: '0.7'
131
+ version: '0.12'
126
132
  - !ruby/object:Gem::Dependency
127
133
  name: victor
128
134
  requirement: !ruby/object:Gem::Requirement
@@ -169,7 +175,8 @@ files:
169
175
  homepage: https://github.com/dannyben/victor-cli
170
176
  licenses:
171
177
  - MIT
172
- metadata: {}
178
+ metadata:
179
+ rubygems_mfa_required: 'true'
173
180
  post_install_message:
174
181
  rdoc_options: []
175
182
  require_paths:
@@ -185,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
192
  - !ruby/object:Gem::Version
186
193
  version: '0'
187
194
  requirements: []
188
- rubygems_version: 3.3.14
195
+ rubygems_version: 3.4.3
189
196
  signing_key:
190
197
  specification_version: 4
191
198
  summary: CLI for Victor, the SVG Library