fresh_vector_salad 0.0.1 → 0.2.0

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
  SHA1:
3
- metadata.gz: 54d64a59bf8a6e9ab5fa08ee375b6367c63645e2
4
- data.tar.gz: d36a489c7dfd1024f6352b8d22b5ce3ba464a915
3
+ metadata.gz: a64538d275583c623fb846e733d581b1bca67317
4
+ data.tar.gz: 0cb5c1d8aceb0dd7d7bd28eea2486e5ece847720
5
5
  SHA512:
6
- metadata.gz: 30506dee6d666a24ae5ca0df4eb56f7d5705046a0e45dc0214cdd612a5097526c51775e8cb038f671a90ee493c5cee1997c9830d3fd1942e7fb1cb3fd3168638
7
- data.tar.gz: b0194a2d9d309eb2b4d6eca1dc6202fd72b466f55c6b712bc09518ed0c039e83581892bc90b24e0b2f078e7a06f59c955ad8d82dcd012dd87519f6026e61e40d
6
+ metadata.gz: 951fa9c765fcd691c52b4aa4e2cad6577200ffb27cd41c2d3e66b73721213425ede928fc2ea6917921d66613a15bb903dac535183ed3a757f1df1482be256954
7
+ data.tar.gz: 422873b59b00e9d828dfd4693e54bce8b0b37e5547b38461f869638b37ab2ea8a4e4865bd8859f1a2be939e88335081f1bb8dcf627a53e810833eaf16d942f10
@@ -1,109 +1,67 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'fresh_vector_salad'
4
- require 'optparse'
5
- require 'ostruct'
6
- require 'tk'
7
- require 'tkextlib/tkimg'
8
- require 'open3'
9
- require 'expect'
10
- require 'pty'
3
+ require "vector_salad/optparse"
4
+ require "fresh_vector_salad"
5
+ require "optparse"
6
+ require "ostruct"
7
+ require "tk"
8
+ require "tkextlib/tkimg"
9
+ require "open3"
10
+ require "expect"
11
+ require "pty"
11
12
  #require 'listen'
12
13
 
13
14
  module FreshVectorSalad
14
- class FreshOptparse
15
- #
16
- # Return a structure describing the options.
17
- #
18
- def self.parse(args)
19
- # The options specified on the command line will be collected in *options*.
20
- # We set default values here.
21
- options = OpenStruct.new
22
- options.verbose = false
23
- options.dpi = 90
24
-
25
- opt_parser = OptionParser.new do |opts|
26
- opts.banner = "Usage: vrs [options]"
27
-
28
- opts.separator ""
29
- opts.separator "Specific options:"
30
-
31
- opts.on('-p', "--path PATH",
32
- "PATH to the files.") do |path|
33
- #strip trailing slash
34
- path = path =~ /\/\z/ ? path[0..-2] : path
35
- options.path = path
36
- end
37
-
38
- opts.on('-d', "--dpi [DPI]",
39
- "Export DPI (default 90). Use to shrink or expand the preview.") do |dpi|
40
- options.dpi = dpi
41
- end
42
-
43
- opts.on("--crop CROP",
44
- "Set width and height manually, format WIDTHxHEIGHT, e.g: 400x600.") do |crop|
45
- options.width, options.height = crop.split('x').map(&:to_i)
46
- end
47
-
48
- opts.on('-f', "--filename FILENAME",
49
- "FILENAME (without extension) to compile from and render to.") do |file|
50
- options.file = file
51
- end
52
-
53
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
54
- options.verbose = v
55
- end
56
-
57
- opts.separator ""
58
- opts.separator "Common options:"
59
-
60
- # No argument, shows at tail. This will print an options summary.
61
- # Try it and see!
62
- opts.on_tail("-h", "--help", "Show this message") do
63
- puts opts
64
- exit
65
- end
66
-
67
- # Another typical switch to print the version.
68
- opts.on_tail("--version", "Show version") do
69
- puts FreshVectorSalad::VERSION
70
- exit
71
- end
72
- end
73
-
74
- opt_parser.parse!(args)
75
- options
76
- end
77
- end
78
-
79
-
80
15
  class Callbacks
81
16
  def initialize(options, image, label)
82
17
  @options, @image, @label = options, image, label
83
18
  end
84
19
 
85
20
  def success
86
- @image.file = "#{@options.path}/#{@options.file}.png"
21
+ @image.file = "#{@options.naked_file}.png"
87
22
  @label.height = @image.height + 10
88
23
  @label.width = @image.width + 10
89
- @label.background = 'white'
24
+ @label.background = "white"
90
25
  @label.pack
91
26
  end
92
27
 
93
28
  def error
94
- @label.background = 'red'
29
+ @label.background = "red"
30
+ end
31
+ end
32
+ end
33
+
34
+ module VectorSalad
35
+ class Optparse
36
+ defaults[:verbose] = false
37
+ defaults[:dpi] = 90
38
+
39
+ self.tool_name = "fresh_vector_salad"
40
+
41
+ optparse.on_head("-d", "--dpi DPI", "Export DPI (default 90). Use to shrink or expand the preview.") do |dpi|
42
+ options.dpi = dpi
43
+ end
44
+
45
+ optparse.on_head("-v", "--[no-]verbose", "Run verbosely") do |v|
46
+ options.verbose = v
47
+ end
48
+
49
+ optparse.on_tail("--version", "Show version") do
50
+ puts FreshVectorSalad::VERSION
51
+ exit
95
52
  end
96
53
  end
97
54
  end
98
55
 
99
- options = FreshVectorSalad::FreshOptparse.parse(ARGV)
100
- options.filepath = "#{options.path}/#{options.file}"
56
+ ARGV << "-h" if ARGV.empty?
57
+ options = VectorSalad::Optparse.parse(ARGV)
58
+ options.naked_file = options.file[0...-3]
101
59
 
102
60
  TkRoot.new do
103
61
  title "Fresh Vector Salad"
104
62
  end
105
63
 
106
- image = TkPhotoImage.new()
64
+ image = TkPhotoImage.new
107
65
 
108
66
  label = TkLabel.new
109
67
  label.image = image
@@ -117,9 +75,9 @@ fvs.auto_compile
117
75
  #fvs.auto_compile if modified.any?{ |m| m =~ /\.rb$/ }
118
76
  #end.start
119
77
  Thread.new do
120
- last = File.stat("#{options.filepath}.rb").mtime
121
- while true
122
- now = File.stat("#{options.filepath}.rb").mtime
78
+ last = File.stat(options.file).mtime
79
+ loop do
80
+ now = File.stat(options.file).mtime
123
81
  if now > last
124
82
  fvs.auto_compile
125
83
  last = now
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'fresh_vector_salad/version'
4
+ require "fresh_vector_salad/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fresh_vector_salad"
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["simon@sfcgeorge.co.uk"]
11
11
  spec.summary = %q{Fresh View Vector Salad Images}
12
12
  spec.description = %q{Live reloads images generated by Vector Salad}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/sfcgeorge/fresh_vector_salad"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- #spec.add_dependency "listen", "~> 2.8"
22
- spec.add_dependency "vector_salad", "~> 0.0"
21
+ spec.add_dependency "vector_salad", "~> 0.2"
23
22
 
24
23
  spec.add_development_dependency "bundler", "~> 1.7"
25
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,3 @@
1
1
  module FreshVectorSalad
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "fresh_vector_salad/version"
2
- require 'vector_salad/export_with_magic'
3
- require 'ostruct'
2
+ require "vector_salad/export_with_magic"
3
+ require "ostruct"
4
4
 
5
5
  module FreshVectorSalad
6
6
  class Fresh
@@ -15,72 +15,48 @@ module FreshVectorSalad
15
15
  end
16
16
 
17
17
  def auto_compile
18
- puts 'Compiling...'
18
+ puts "Compiling..."
19
19
  start = Time.now
20
20
 
21
- #_, _, stderr = start_vector_salad
22
- #if e = stderr.gets
23
- #puts e
24
- #@callbacks.error
25
- #else
26
- #puts "Compiled in #{Time.now - start} seconds."
27
- #auto_render
28
- #end
29
-
30
21
  begin
31
- options = OpenStruct.new
32
- options.file = "#{@o.path}/#{@o.file}.rb"
33
- options.width = @o.width
34
- options.height = @o.height
35
- o = VectorSalad::ExportWithMagic.new(options).export
36
- File.open("#{@o.path}/#{@o.file}.svg", 'w') do |file|
37
- file.sync = true
38
- file.write(o)
39
- file.fsync
40
- end
41
- File.write("#{@o.path}/#{@o.file}.svg", o)
22
+ File.write "#{@o.naked_file}.svg",
23
+ VectorSalad::ExportWithMagic.new(@o).export
42
24
  puts "Compiled in #{Time.now - start} seconds."
43
25
  auto_render
44
26
  rescue Exception => e
45
27
  puts e.inspect
46
- e.backtrace.each{ |l| puts l }
28
+ e.backtrace.each { |l| puts l }
47
29
  @callbacks.error
48
30
  end
49
31
  end
50
32
 
51
- def start_vector_salad
52
- vs = "vector_salad -f \"#{@o.path}/#{@o.file}.rb\" > \"#{@o.path}/#{@o.file}.svg\""
53
- return Open3.popen3(vs)
54
- end
55
-
56
33
  def auto_render
57
- puts 'Rendering...'
34
+ puts "Rendering..."
58
35
  start = Time.now
59
36
  if @ink_i.nil?
60
- puts 'Starting Inkscape'
61
- @ink_o, @ink_i, _ = start_inkscape
37
+ puts "Starting Inkscape"
38
+ @ink_o, @ink_i, _x = start_inkscape
62
39
  end
63
40
 
64
41
  begin
65
42
  @ink_o.expect(">") do |result|
66
- result.each{ |r| puts r }
67
- @ink_i.puts("\"#{@o.path}/#{@o.file}.svg\" --export-background=white --export-dpi=#{@o.dpi} --export-png=\"#{@o.path}/#{@o.file}.png\"")
43
+ result.each { |r| puts r }
44
+ @ink_i.puts("\"#{@o.naked_file}.svg\" --export-background=white --export-dpi=#{@o.dpi} --export-png=\"#{@o.naked_file}.png\"")
68
45
  end
69
46
  @ink_o.expect("Bitmap saved") do |result|
70
- result.each{ |r| puts r }
47
+ result.each { |r| puts r }
71
48
  end
72
49
  @callbacks.success
73
50
  puts "Rendered in #{Time.now - start} seconds."
74
51
  rescue Exception => e
75
52
  puts e.inspect
76
- e.backtrace.each{ |l| puts l }
53
+ e.backtrace.each { |l| puts l }
77
54
  @callbacks.error
78
55
  end
79
56
  end
80
57
 
81
58
  def start_inkscape
82
59
  ink = "inkscape -z --shell"
83
- #Open3.popen3(ink)
84
60
  PTY.spawn(ink)
85
61
  end
86
62
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fresh_vector_salad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon George
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-19 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vector_salad
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.0'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ files:
69
69
  - fresh_vector_salad.gemspec
70
70
  - lib/fresh_vector_salad.rb
71
71
  - lib/fresh_vector_salad/version.rb
72
- homepage: ''
72
+ homepage: https://github.com/sfcgeorge/fresh_vector_salad
73
73
  licenses:
74
74
  - MIT
75
75
  metadata: {}