Class: FreshVectorSalad::Fresh
- Inherits:
-
Object
- Object
- FreshVectorSalad::Fresh
- Defined in:
- lib/fresh_vector_salad.rb
Instance Method Summary collapse
- #auto ⇒ Object
- #auto_compile ⇒ Object
- #auto_render ⇒ Object
-
#initialize(options, callbacks) ⇒ Fresh
constructor
A new instance of Fresh.
- #start_inkscape ⇒ Object
Constructor Details
#initialize(options, callbacks) ⇒ Fresh
Returns a new instance of Fresh.
7 8 9 10 |
# File 'lib/fresh_vector_salad.rb', line 7 def initialize(, callbacks) @o = @callbacks = callbacks end |
Instance Method Details
#auto ⇒ Object
12 13 14 15 |
# File 'lib/fresh_vector_salad.rb', line 12 def auto auto_compile auto_render end |
#auto_compile ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fresh_vector_salad.rb', line 17 def auto_compile puts "Compiling..." start = Time.now begin File.write "#{@o.naked_file}.svg", VectorSalad::ExportWithMagic.new(@o).export puts "Compiled in #{Time.now - start} seconds." auto_render rescue Exception => e puts e.inspect e.backtrace.each { |l| puts l } @callbacks.error end end |
#auto_render ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fresh_vector_salad.rb', line 33 def auto_render puts "Rendering..." start = Time.now if @ink_i.nil? puts "Starting Inkscape" @ink_o, @ink_i, _x = start_inkscape end begin @ink_o.expect(">") do |result| result.each { |r| puts r } @ink_i.puts("\"#{@o.naked_file}.svg\" --export-background=white --export-dpi=#{@o.dpi} --export-png=\"#{@o.naked_file}.png\"") end @ink_o.expect("Bitmap saved") do |result| result.each { |r| puts r } end @callbacks.success puts "Rendered in #{Time.now - start} seconds." rescue Exception => e puts e.inspect e.backtrace.each { |l| puts l } @callbacks.error end end |
#start_inkscape ⇒ Object
58 59 60 61 |
# File 'lib/fresh_vector_salad.rb', line 58 def start_inkscape ink = "inkscape -z --shell" PTY.spawn(ink) end |