skeptick 0.1.1 → 0.2.0

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +14 -0
  3. data/README.md +63 -289
  4. data/lib/skeptick/command.rb +8 -19
  5. data/lib/skeptick/convert.rb +65 -82
  6. data/lib/skeptick/core.rb +1 -7
  7. data/lib/skeptick/dsl_context.rb +32 -0
  8. data/lib/skeptick/sugar.rb +13 -7
  9. data/lib/skeptick/sugar/canvas.rb +8 -0
  10. data/lib/skeptick/sugar/clone.rb +9 -0
  11. data/lib/skeptick/sugar/compose.rb +50 -0
  12. data/lib/skeptick/sugar/delete.rb +9 -0
  13. data/lib/skeptick/sugar/draw.rb +7 -0
  14. data/lib/skeptick/sugar/font.rb +7 -0
  15. data/lib/skeptick/sugar/format.rb +7 -0
  16. data/lib/skeptick/sugar/geometry.rb +25 -31
  17. data/lib/skeptick/sugar/resized_image.rb +15 -0
  18. data/lib/skeptick/sugar/rounded_corners_image.rb +42 -0
  19. data/lib/skeptick/sugar/swap.rb +12 -0
  20. data/lib/skeptick/sugar/text.rb +11 -0
  21. data/lib/skeptick/sugar/torn_paper_image.rb +32 -0
  22. data/lib/skeptick/sugar/write.rb +8 -0
  23. data/lib/skeptick/version.rb +1 -1
  24. data/logo.rb +12 -11
  25. data/refresh_preview.scpt +1 -1
  26. data/skeptick.gemspec +1 -0
  27. data/test/convert_test.rb +128 -33
  28. data/test/sugar/canvas_test.rb +16 -0
  29. data/test/sugar/clone_test.rb +41 -0
  30. data/test/sugar/{composition_test.rb → compose_test.rb} +35 -87
  31. data/test/sugar/delete_test.rb +41 -0
  32. data/test/sugar/draw_test.rb +11 -0
  33. data/test/sugar/font_test.rb +11 -0
  34. data/test/sugar/format_test.rb +12 -0
  35. data/test/sugar/{resizing_test.rb → resized_image_test.rb} +5 -5
  36. data/test/sugar/rounded_corners_image_test.rb +53 -0
  37. data/test/sugar/swap_test.rb +28 -0
  38. data/test/sugar/text_test.rb +22 -0
  39. data/test/sugar/torn_paper_image_test.rb +53 -0
  40. data/test/sugar/write_test.rb +14 -0
  41. metadata +57 -34
  42. data/lib/skeptick/chain.rb +0 -55
  43. data/lib/skeptick/chain/dsl_context.rb +0 -21
  44. data/lib/skeptick/convert/dsl_context.rb +0 -27
  45. data/lib/skeptick/helper.rb +0 -26
  46. data/lib/skeptick/image.rb +0 -69
  47. data/lib/skeptick/image/dsl_context.rb +0 -29
  48. data/lib/skeptick/sugar/composition.rb +0 -55
  49. data/lib/skeptick/sugar/debugging.rb +0 -12
  50. data/lib/skeptick/sugar/drawing.rb +0 -32
  51. data/lib/skeptick/sugar/edges.rb +0 -70
  52. data/lib/skeptick/sugar/formatting.rb +0 -12
  53. data/lib/skeptick/sugar/resizing.rb +0 -16
  54. data/lib/skeptick/sugar/sequence_manipulation.rb +0 -43
  55. data/test/chain_test.rb +0 -94
  56. data/test/image_test.rb +0 -145
  57. data/test/sugar/debugging_test.rb +0 -24
  58. data/test/sugar/drawing_test.rb +0 -86
  59. data/test/sugar/edges_test.rb +0 -99
  60. data/test/sugar/formatting_test.rb +0 -19
  61. data/test/sugar/sequence_manipulation_test.rb +0 -98
@@ -4,26 +4,15 @@ require 'skeptick/error'
4
4
 
5
5
  module Skeptick
6
6
  class Command
7
- module Executable
8
- def command
9
- Command.new(self)
10
- end
11
-
12
- def execute
13
- command.run
14
- end
15
- alias_method :build, :execute
16
- alias_method :run, :execute
17
- end
7
+ attr_reader :shellwords
18
8
 
19
- def initialize(command_obj)
20
- @command_obj = command_obj
9
+ def initialize(shellwords)
10
+ @shellwords = shellwords
21
11
  end
22
12
 
23
- def command
24
- @command_obj.to_s.shellsplit.shelljoin
13
+ def to_s
14
+ shellwords.join(' ')
25
15
  end
26
- alias_method :to_s, :command
27
16
 
28
17
  def run(spawn_options = {})
29
18
  opts = {}
@@ -32,14 +21,14 @@ module Skeptick
32
21
  opts.merge(spawn_options)
33
22
 
34
23
  if Skeptick.debug_mode?
35
- Skeptick.log("Skeptick Command: #{command}")
24
+ Skeptick.log("Skeptick Command: #{to_s}")
36
25
  end
37
26
 
38
- im_process = POSIX::Spawn::Child.new(command, opts)
27
+ im_process = POSIX::Spawn::Child.new(*shellwords, opts)
39
28
 
40
29
  if !im_process.success?
41
30
  raise ImageMagickError,
42
- "ImageMagick error\nCommand: #{command}\nSTDERR:\n#{im_process.err}"
31
+ "ImageMagick error\nCommand: #{to_s}\nSTDERR:\n#{im_process.err}"
43
32
  end
44
33
 
45
34
  im_process.status
@@ -1,109 +1,92 @@
1
- require 'skeptick/helper'
2
- require 'skeptick/image'
3
- require 'skeptick/chain'
4
- require 'skeptick/convert/dsl_context'
1
+ require 'skeptick/dsl_context'
5
2
  require 'skeptick/command'
6
3
 
7
4
  module Skeptick
8
5
  class Convert
9
- include Command::Executable
6
+ attr_reader :context, :prepends, :subjects, :appends
10
7
 
11
- attr_accessor :prepends, :appends
8
+ BINARY_PATH = 'convert'.freeze
9
+ DEFAULT_OUTPUT = 'miff:-'.freeze
12
10
 
13
11
  def initialize(context, *args, &blk)
14
12
  @context = context
15
- @options = Helper.extract_options!(args)
16
- @args = args.map {|a| Image.new(@context, a)}
17
- @block = blk
18
- @to = parse_pipe(@options[:to])
19
- @inner = false
20
-
21
- @beginning = nil
22
- @ending = nil
23
- @prepends = []
24
- @appends = []
25
-
26
- reset
27
- end
28
-
29
- def prepend(*args)
30
- @prepends << Helper.process_args(*args)
31
- end
32
-
33
- def append(*args)
34
- @appends << Helper.process_args(*args)
35
- end
13
+ opts = args.last.is_a?(Hash) ? args.pop : {}
14
+
15
+ @objects = [
16
+ @beginning = BINARY_PATH.dup,
17
+ @prepends = setup_prepends,
18
+ @subjects = setup_subjects,
19
+ @appends = setup_appends,
20
+ @ending = opts.fetch(:to) { DEFAULT_OUTPUT.dup }
21
+ ]
22
+
23
+ args.each do |arg|
24
+ subjects << if arg.is_a?(Convert)
25
+ arg
26
+ else
27
+ Convert.new(@context).tap{ |c| c.subjects << arg }
28
+ end
29
+ end
36
30
 
37
- def set(*args)
38
- @objects << Helper.process_args(*args)
31
+ DslContext.new(self).instance_eval(&blk) if block_given?
39
32
  end
40
- alias_method :apply, :set
41
- alias_method :with, :set
42
33
 
34
+ def run; command.run end
35
+ def to_s; shellwords.join(' ') end
36
+ def inspect; "#{self.class}(\"#{to_s}\")" end
37
+ def shellwords; tokens.map { |obj| token_to_str(obj) } end
38
+ def command; Command.new(shellwords) end
43
39
 
44
- def convert(*args, &blk)
45
- Convert.new(@context, *args, &blk).tap do |c_obj|
46
- @objects << Image.new(@context, c_obj)
47
- end
48
- end
40
+ protected
49
41
 
50
- def image(obj = nil, &blk)
51
- @objects << Image.new(@context, obj, &blk)
52
- end
42
+ def nest!
43
+ add_parenth = (@subjects.size > 1) ||
44
+ (@subjects.size < 2 && (!appends.empty? || !prepends.empty?))
53
45
 
54
- def destination=(to)
55
- if inner?
56
- raise 'cannot assign output to parentheses-wrapped image conversion'
46
+ if add_parenth
47
+ @beginning.replace('(')
48
+ @ending.replace(')')
57
49
  else
58
- @to = to
50
+ @beginning.clear
51
+ @ending.clear
59
52
  end
60
53
  end
61
54
 
62
- def piping?
63
- !inner? && parts.last == Chain::PIPE
64
- end
65
-
66
- def become_inner
67
- @inner = true
68
- self
69
- end
70
-
71
- def parts
72
- reset
73
- @objects = []
74
- DslContext.new(self).instance_eval(&@block) if @block
75
- wrap
76
- [@beginning, *@prepends, *@args, *@objects, *@appends, @ending].compact
77
- end
78
-
79
- def to_s
80
- parts.join(' ')
81
- end
82
-
83
- def inspect
84
- "Skeptick::Convert(#{to_s})"
85
- end
86
-
87
- def process_method_missing(*args, &blk)
88
- @context.send(*args, &blk)
55
+ def tokens
56
+ @objects.flatten.reject{ |obj| empty_string?(obj) }.map { |obj|
57
+ if obj.is_a?(Convert)
58
+ obj.nest!
59
+ obj.tokens
60
+ else
61
+ obj
62
+ end
63
+ }.flatten.tap do |array|
64
+ if array[1] == '(' && array[-2] == ')'
65
+ array.delete_at(1)
66
+ array.delete_at(-2)
67
+ end
68
+ end
89
69
  end
90
70
 
91
71
  private
92
- def reset
93
- @objects = []
94
- end
95
72
 
96
- def inner?
97
- @inner
98
- end
73
+ def setup_prepends; [] end
74
+ def setup_subjects; [] end
75
+ def setup_appends; [] end
99
76
 
100
- def wrap
101
- @beginning = inner? ? '(' : 'convert'
102
- @ending = inner? ? ')' : @to || Chain::PIPE
103
- end
77
+ def empty_string?(obj)
78
+ obj.is_a?(String) && obj.empty?
79
+ end
104
80
 
105
- def parse_pipe(obj)
106
- obj == :pipe ? Chain::PIPE : obj
81
+ def token_to_str(obj)
82
+ case obj
83
+ when Symbol
84
+ "-#{obj}"
85
+ when Range
86
+ "#{obj.min}-#{obj.max}"
87
+ else
88
+ obj.to_s
107
89
  end
90
+ end
108
91
  end
109
92
  end
@@ -1,7 +1,5 @@
1
1
  require 'skeptick/version'
2
2
  require 'skeptick/convert'
3
- require 'skeptick/image'
4
- require 'skeptick/chain'
5
3
  require 'skeptick/railtie' if defined?(Rails)
6
4
 
7
5
  module Skeptick
@@ -34,10 +32,6 @@ module Skeptick
34
32
  end
35
33
 
36
34
  def image(*args, &blk)
37
- Skeptick::Image.new(self, *args, &blk)
38
- end
39
-
40
- def chain(*args, &blk)
41
- Skeptick::Chain.new(self, *args, &blk)
35
+ Skeptick::Convert.new(self, *args, &blk)
42
36
  end
43
37
  end
@@ -0,0 +1,32 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def initialize(convert)
4
+ @convert = convert
5
+ end
6
+
7
+ def prepend(*args)
8
+ @convert.prepends.push(*args)
9
+ end
10
+
11
+ def set(*args)
12
+ @convert.subjects.push(*args)
13
+ end
14
+
15
+ def append(*args)
16
+ @convert.appends.push(*args)
17
+ end
18
+
19
+ def convert(*args, &blk)
20
+ @convert.subjects << Convert.new(self, *args, &blk)
21
+ end
22
+ alias_method :image, :convert
23
+
24
+ def method_missing(*args, &blk)
25
+ @convert.context.send(*args, &blk)
26
+ end
27
+
28
+ def respond_to_missing?(meth, include_all)
29
+ @convert.context.respond_to?(meth, include_all)
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,14 @@
1
- require 'skeptick/sugar/composition'
2
- require 'skeptick/sugar/debugging'
3
- require 'skeptick/sugar/drawing'
1
+ require 'skeptick/sugar/compose'
2
+ require 'skeptick/sugar/write'
3
+ require 'skeptick/sugar/draw'
4
+ require 'skeptick/sugar/canvas'
5
+ require 'skeptick/sugar/font'
6
+ require 'skeptick/sugar/text'
4
7
  require 'skeptick/sugar/geometry'
5
- require 'skeptick/sugar/resizing'
6
- require 'skeptick/sugar/sequence_manipulation'
7
- require 'skeptick/sugar/formatting'
8
- require 'skeptick/sugar/edges'
8
+ require 'skeptick/sugar/clone'
9
+ require 'skeptick/sugar/delete'
10
+ require 'skeptick/sugar/swap'
11
+ require 'skeptick/sugar/format'
12
+ require 'skeptick/sugar/resized_image'
13
+ require 'skeptick/sugar/rounded_corners_image'
14
+ require 'skeptick/sugar/torn_paper_image'
@@ -0,0 +1,8 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def canvas(string, options = {})
4
+ set(:size, options[:size]) if options[:size]
5
+ set "canvas:#{string}"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def clone(*args)
4
+ obj = (args.size < 2 ? args.first : args)
5
+ obj = obj.join(',') if obj.is_a?(Array)
6
+ obj ? set(:clone, obj) : set('+clone')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ module Skeptick
2
+ class Compose < Convert
3
+ def initialize(context, *args, &blk)
4
+ @blending = args.shift.to_s
5
+ super
6
+ end
7
+
8
+ def setup_appends
9
+ [:compose, @blending, :composite]
10
+ end
11
+ end
12
+
13
+ class Convert
14
+ def +(other)
15
+ Compose.new(@context, :over, self, other)
16
+ end
17
+
18
+ def -(other)
19
+ Compose.new(@context, :dstout, self, other)
20
+ end
21
+
22
+ def *(other)
23
+ Compose.new(@context, :multiply, self, other)
24
+ end
25
+
26
+ def /(other)
27
+ Compose.new(@context, :divide, self, other)
28
+ end
29
+
30
+ def &(other)
31
+ Compose.new(@context, :dstin, self, other).tap do |c|
32
+ c.subjects << :alpha << 'Set'
33
+ end
34
+ end
35
+
36
+ def |(other)
37
+ Compose.new(@context, :dstover, self, other)
38
+ end
39
+ end
40
+
41
+ class DslContext
42
+ def compose(blending, *args, &blk)
43
+ @convert.subjects << Compose.new(self, blending, *args, &blk)
44
+ end
45
+ end
46
+
47
+ def compose(blending, *args, &blk)
48
+ Compose.new(self, blending, *args, &blk)
49
+ end
50
+ end
@@ -0,0 +1,9 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def delete(*args)
4
+ obj = (args.size < 2 ? args.first : args)
5
+ obj = obj.join(',') if obj.is_a?(Array)
6
+ obj ? set(:delete, obj) : set('+delete')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def draw(*args)
4
+ set :draw, args.join(' ')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def font(name)
4
+ set '-font', name.split(/\s/).map(&:capitalize).join('-')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def format(*args)
4
+ set '-format', args.join(' ')
5
+ end
6
+ end
7
+ end
@@ -1,38 +1,32 @@
1
1
  module Skeptick
2
- module Sugar
3
- module Geometry
4
- def geometry(options = {})
5
- result = ''
2
+ def geometry(options = {})
3
+ result = ''
6
4
 
7
- result << if options[:size]
8
- options[:size]
9
- else
10
- if options[:width] && options[:height]
11
- "#{options[:width]}x#{options[:height]}"
12
- elsif options[:width]
13
- "#{options[:width]}x"
14
- elsif options[:height]
15
- "x#{options[:height]}"
16
- else
17
- ''
18
- end
19
- end
5
+ result << if options[:size]
6
+ options[:size]
7
+ else
8
+ if options[:width] && options[:height]
9
+ "#{options[:width]}x#{options[:height]}"
10
+ elsif options[:width]
11
+ "#{options[:width]}x"
12
+ elsif options[:height]
13
+ "x#{options[:height]}"
14
+ else
15
+ ''
16
+ end
17
+ end
20
18
 
21
- if options[:left] || options[:top]
22
- left = '%+d' % (options[:left] || 0)
23
- top = '%+d' % (options[:top] || 0)
24
- result << "#{left}#{top}"
25
- end
19
+ if options[:left] || options[:top]
20
+ left = '%+d' % (options[:left] || 0)
21
+ top = '%+d' % (options[:top] || 0)
22
+ result << "#{left}#{top}"
23
+ end
26
24
 
27
- result << '%' if options[:percentage]
28
- result << '!' if options[:exact]
29
- result << '<' if options[:expand_only]
30
- result << '>' if options[:shrink_only]
25
+ result << '%' if options[:percentage]
26
+ result << '!' if options[:exact]
27
+ result << '<' if options[:expand_only]
28
+ result << '>' if options[:shrink_only]
31
29
 
32
- result
33
- end
34
- end
30
+ result
35
31
  end
36
-
37
- include Sugar::Geometry
38
32
  end