skeptick 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +584 -0
  5. data/Rakefile +10 -0
  6. data/foo.rb +1 -0
  7. data/lib/skeptick.rb +2 -0
  8. data/lib/skeptick/chain.rb +55 -0
  9. data/lib/skeptick/chain/dsl_context.rb +21 -0
  10. data/lib/skeptick/command.rb +46 -0
  11. data/lib/skeptick/convert.rb +109 -0
  12. data/lib/skeptick/convert/dsl_context.rb +27 -0
  13. data/lib/skeptick/core.rb +46 -0
  14. data/lib/skeptick/error.rb +4 -0
  15. data/lib/skeptick/helper.rb +26 -0
  16. data/lib/skeptick/image.rb +69 -0
  17. data/lib/skeptick/image/dsl_context.rb +29 -0
  18. data/lib/skeptick/railtie.rb +8 -0
  19. data/lib/skeptick/sugar.rb +8 -0
  20. data/lib/skeptick/sugar/composition.rb +55 -0
  21. data/lib/skeptick/sugar/debugging.rb +12 -0
  22. data/lib/skeptick/sugar/drawing.rb +32 -0
  23. data/lib/skeptick/sugar/edges.rb +70 -0
  24. data/lib/skeptick/sugar/formatting.rb +12 -0
  25. data/lib/skeptick/sugar/geometry.rb +38 -0
  26. data/lib/skeptick/sugar/resizing.rb +16 -0
  27. data/lib/skeptick/sugar/sequence_manipulation.rb +43 -0
  28. data/lib/skeptick/version.rb +3 -0
  29. data/logo.png +0 -0
  30. data/logo.rb +45 -0
  31. data/refresh_preview.scpt +2 -0
  32. data/skeptick.gemspec +21 -0
  33. data/test/chain_test.rb +94 -0
  34. data/test/convert_test.rb +177 -0
  35. data/test/image_test.rb +145 -0
  36. data/test/sugar/composition_test.rb +273 -0
  37. data/test/sugar/debugging_test.rb +24 -0
  38. data/test/sugar/drawing_test.rb +86 -0
  39. data/test/sugar/edges_test.rb +99 -0
  40. data/test/sugar/formatting_test.rb +19 -0
  41. data/test/sugar/geometry_test.rb +92 -0
  42. data/test/sugar/resizing_test.rb +25 -0
  43. data/test/sugar/sequence_manipulation_test.rb +98 -0
  44. data/test/test_helper.rb +11 -0
  45. metadata +117 -0
@@ -0,0 +1,24 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/debugging'
3
+
4
+ class DebuggingTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_save_in_image
8
+ img = image do
9
+ image 'foo'
10
+ save 'path'
11
+ end
12
+
13
+ cmd = convert(img)
14
+ assert_equal 'convert foo -write path miff:-', cmd.to_s
15
+ end
16
+
17
+ def test_save_in_convert
18
+ cmd = convert('foo') do
19
+ save 'path'
20
+ end
21
+
22
+ assert_equal 'convert foo -write path miff:-', cmd.to_s
23
+ end
24
+ end
@@ -0,0 +1,86 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/drawing'
3
+
4
+ class DrawingTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_canvas_in_image_with_size
8
+ img = image { canvas :none, size: '100x200' }
9
+ cmd = convert(img)
10
+
11
+ assert_equal 'convert -size 100x200 canvas:none miff:-', cmd.to_s
12
+ end
13
+
14
+ def test_canvas_in_image_without_size
15
+ img = image { canvas :none }
16
+ cmd = convert(img)
17
+ assert_equal 'convert canvas:none miff:-', cmd.to_s
18
+ end
19
+
20
+ def test_canvas_in_convert_with_size
21
+ cmd = convert { canvas :none, size: '100x200' }
22
+ assert_equal 'convert -size 100x200 canvas:none miff:-', cmd.to_s
23
+ end
24
+
25
+ def test_canvas_in_convert_without_size
26
+ cmd = convert { canvas :none }
27
+ assert_equal 'convert canvas:none miff:-', cmd.to_s
28
+ end
29
+
30
+ def test_draw_in_image
31
+ img = image { draw 'fill none bezier 1,2 3,4' }
32
+ cmd = convert(img)
33
+ assert_equal 'convert -draw fill\ none\ bezier\ 1,2\ 3,4 miff:-', cmd.to_s
34
+ end
35
+
36
+ def test_draw_in_convert
37
+ cmd = convert { draw 'fill none bezier 1,2 3,4' }
38
+ assert_equal 'convert -draw fill\ none\ bezier\ 1,2\ 3,4 miff:-', cmd.to_s
39
+ end
40
+
41
+ def test_write_in_image_without_left_top
42
+ img = image { write 'Foo bar baz.' }
43
+ cmd = convert(img)
44
+ assert_equal 'convert -draw text\ \\\'Foo\ bar\ baz.\\\' miff:-', cmd.to_s
45
+ end
46
+
47
+ def test_write_in_image_with_left_top
48
+ img = image { write 'Foo bar baz.', left: 7, top: 9 }
49
+ cmd = convert(img)
50
+ assert_equal 'convert -draw text\ 7,9\ \\\'Foo\ bar\ baz.\\\' miff:-',
51
+ cmd.to_s
52
+ end
53
+
54
+ def test_write_in_image_with_left_only
55
+ img = image { write 'Foo bar baz.', left: 7 }
56
+ cmd = convert(img)
57
+ assert_equal 'convert -draw text\ \\\'Foo\ bar\ baz.\\\' miff:-', cmd.to_s
58
+ end
59
+
60
+ def test_write_in_convert_without_left_top
61
+ cmd = convert { write 'Foo bar baz.' }
62
+ assert_equal 'convert -draw text\ \\\'Foo\ bar\ baz.\\\' miff:-', cmd.to_s
63
+ end
64
+
65
+ def test_write_in_convert_with_left_top
66
+ cmd = convert { write 'Foo bar baz.', left: 7, top: 9 }
67
+ assert_equal 'convert -draw text\ 7,9\ \\\'Foo\ bar\ baz.\\\' miff:-',
68
+ cmd.to_s
69
+ end
70
+
71
+ def test_write_in_convert_with_top_only
72
+ cmd = convert { write 'Foo bar baz.', top: 9 }
73
+ assert_equal 'convert -draw text\ \\\'Foo\ bar\ baz.\\\' miff:-', cmd.to_s
74
+ end
75
+
76
+ def test_font_in_image
77
+ img = image { font 'handwriting - dakota Regular' }
78
+ cmd = convert(img)
79
+ assert_equal 'convert -font Handwriting---Dakota-Regular miff:-', cmd.to_s
80
+ end
81
+
82
+ def test_font_in_convert
83
+ cmd = convert { font 'handwriting - dakota Regular' }
84
+ assert_equal 'convert -font Handwriting---Dakota-Regular miff:-', cmd.to_s
85
+ end
86
+ end
@@ -0,0 +1,99 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/edges'
3
+
4
+ class EdgesTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_rounded_corners_image_without_block_and_radius
8
+ img = rounded_corners_image('foo', size: '200x300')
9
+
10
+ assert_equal 'convert foo ( +clone -alpha transparent -background none ' +
11
+ '-draw roundrectangle\ 1,1\ 200,300\ 15,15 ) -alpha set -compose dstin ' +
12
+ '-composite miff:-', img.to_s
13
+ end
14
+
15
+ def test_rounded_corners_image_with_block_and_radius
16
+ img = rounded_corners_image(size: '200x300', radius: 20) do
17
+ image 'tile:granite:'
18
+ apply '-brightness-contrast', '38x-33'
19
+ end
20
+
21
+ assert_equal 'convert tile:granite: -brightness-contrast 38x-33 ( +clone ' +
22
+ '-alpha transparent -background none -draw roundrectangle\ 1,1\ ' +
23
+ '200,300\ 20,20 ) -alpha set -compose dstin -composite miff:-', img.to_s
24
+ end
25
+
26
+ def test_nested_rounded_corners_image
27
+ cmd = convert(to: 'bar') do
28
+ rounded_corners_image('foo', size: '200x300', radius: 5)
29
+ end
30
+
31
+ assert_equal 'convert ( foo ( +clone -alpha transparent -background none ' +
32
+ '-draw roundrectangle\\ 1,1\\ 200,300\\ 5,5 ) -alpha set -compose ' +
33
+ 'dstin -composite ) bar', cmd.to_s
34
+ end
35
+
36
+ def test_nested_rounded_corners_image_via_lvar_arg
37
+ img = rounded_corners_image('foo', size: '200x300', radius: 5)
38
+ cmd = convert(img, to: 'bar')
39
+
40
+ assert_equal 'convert ( foo ( +clone -alpha transparent -background none ' +
41
+ '-draw roundrectangle\\ 1,1\\ 200,300\\ 5,5 ) -alpha set -compose ' +
42
+ 'dstin -composite ) bar', cmd.to_s
43
+ end
44
+
45
+ def test_nested_rounded_corners_image_via_lvar_in_block
46
+ img = rounded_corners_image('foo', size: '200x300', radius: 5)
47
+ cmd = convert(to: 'bar') { image(img) }
48
+
49
+ assert_equal 'convert ( foo ( +clone -alpha transparent -background none ' +
50
+ '-draw roundrectangle\\ 1,1\\ 200,300\\ 5,5 ) -alpha set -compose ' +
51
+ 'dstin -composite ) bar', cmd.to_s
52
+ end
53
+
54
+ def test_torn_paper_image_without_block_spread_blur_threshold
55
+ img = torn_paper_image('foo')
56
+ assert_equal 'convert foo ( +clone -alpha extract -virtual-pixel black ' +
57
+ '-spread 1 -blur 0x.7 -threshold 50% ) -alpha off ' +
58
+ '-compose copy_opacity -composite miff:-', img.to_s
59
+ end
60
+
61
+ def test_torn_paper_image_with_block_spread_blur_threshold
62
+ img = torn_paper_image('foo', spread: 17, blur: '1x4', threshold: 70) do
63
+ image 'tile:granite:'
64
+ apply '-brightness-contrast', '38x-33'
65
+ end
66
+
67
+ assert_equal 'convert tile:granite: -brightness-contrast 38x-33 ( +clone ' +
68
+ '-alpha extract -virtual-pixel black -spread 17 -blur 1x4 -threshold ' +
69
+ '70% ) -alpha off -compose copy_opacity -composite miff:-', img.to_s
70
+ end
71
+
72
+ def test_nested_torn_paper_image
73
+ cmd = convert(to: 'bar') do
74
+ torn_paper_image('foo')
75
+ end
76
+
77
+ assert_equal 'convert ( foo ( +clone -alpha extract -virtual-pixel black ' +
78
+ '-spread 1 -blur 0x.7 -threshold 50% ) -alpha off -compose ' +
79
+ 'copy_opacity -composite ) bar', cmd.to_s
80
+ end
81
+
82
+ def test_nested_torn_paper_image_via_lvar_arg
83
+ img = torn_paper_image('foo')
84
+ cmd = convert(img, to: 'bar')
85
+
86
+ assert_equal 'convert ( foo ( +clone -alpha extract -virtual-pixel black ' +
87
+ '-spread 1 -blur 0x.7 -threshold 50% ) -alpha off -compose ' +
88
+ 'copy_opacity -composite ) bar', cmd.to_s
89
+ end
90
+
91
+ def test_nested_torn_paper_image_via_lvar_in_block
92
+ img = torn_paper_image('foo')
93
+ cmd = convert(to: 'bar') { image(img) }
94
+
95
+ assert_equal 'convert ( foo ( +clone -alpha extract -virtual-pixel black ' +
96
+ '-spread 1 -blur 0x.7 -threshold 50% ) -alpha off -compose ' +
97
+ 'copy_opacity -composite ) bar', cmd.to_s
98
+ end
99
+ end
@@ -0,0 +1,19 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/formatting'
3
+
4
+ class FormattingTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_format_in_image
8
+ img = image { format "roundrectangle 1,1 %[fx:w], %[fx:h] 5,5" }
9
+ cmd = convert(img)
10
+ assert_equal 'convert -format roundrectangle\ 1,1\ \%\[fx:w\],\ ' +
11
+ '\%\[fx:h\]\ 5,5 miff:-', cmd.to_s
12
+ end
13
+
14
+ def test_format_in_convert
15
+ cmd = convert { format "roundrectangle 1,1 %[fx:w], %[fx:h] 5,5" }
16
+ assert_equal 'convert -format roundrectangle\ 1,1\ \%\[fx:w\],\ ' +
17
+ '\%\[fx:h\]\ 5,5 miff:-', cmd.to_s
18
+ end
19
+ end
@@ -0,0 +1,92 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/geometry'
3
+
4
+ class GeometryTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_blank_geometry
8
+ assert_equal '', geometry
9
+ end
10
+
11
+ def test_geometry_with_size
12
+ assert_equal '100x200', geometry(size: '100x200')
13
+ end
14
+
15
+ def test_geometry_with_width
16
+ assert_equal '100x', geometry(width: 100)
17
+ end
18
+
19
+ def test_geometry_with_height
20
+ assert_equal 'x200', geometry(height: 200)
21
+ end
22
+
23
+ def test_geometry_with_width_and_height
24
+ assert_equal '100x200', geometry(width: 100, height: 200)
25
+ end
26
+
27
+ def test_geometry_with_left
28
+ assert_equal '+5+0', geometry(left: 5)
29
+ end
30
+
31
+ def test_geometry_with_top
32
+ assert_equal '+0+7', geometry(top: 7)
33
+ end
34
+
35
+ def test_geometry_with_left_top
36
+ assert_equal '+5+7', geometry(left: 5, top: 7)
37
+ end
38
+
39
+ def test_geometry_with_negative_left
40
+ assert_equal '-5+7', geometry(left: -5, top: 7)
41
+ end
42
+
43
+ def test_geometry_with_negative_left_top
44
+ assert_equal '-5-7', geometry(left: -5, top: -7)
45
+ end
46
+
47
+ def test_geometry_with_left_width_height
48
+ assert_equal '100x200+5+0', geometry(left: 5, width: 100, height: 200)
49
+ end
50
+
51
+ def test_geometry_with_top_width_height
52
+ assert_equal '100x200+0+7', geometry(top: 7, width: 100, height: 200)
53
+ end
54
+
55
+ def test_geometry_with_left_top_width_height
56
+ assert_equal '100x200+5-7',
57
+ geometry(left: 5, top: -7, width: 100, height: 200)
58
+ end
59
+
60
+ def test_geometry_with_percentage
61
+ assert_equal '100x200%',
62
+ geometry(width: 100, height: 200, percentage: true)
63
+ end
64
+
65
+ def test_geometry_with_exact
66
+ assert_equal '100x200!', geometry(width: 100, height: 200, exact: true)
67
+ end
68
+
69
+ def test_geometry_with_expand_only
70
+ assert_equal '100x200<',
71
+ geometry(width: 100, height: 200, expand_only: true)
72
+ end
73
+
74
+ def test_geometry_with_expand_only
75
+ assert_equal '100x200>',
76
+ geometry(width: 100, height: 200, shrink_only: true)
77
+ end
78
+
79
+ def test_everything_together
80
+ assert_equal '100x200-7+5%!<>',
81
+ geometry(
82
+ width: 100,
83
+ height: 200,
84
+ left: -7,
85
+ top: 5,
86
+ percentage: true,
87
+ exact: true,
88
+ expand_only: true,
89
+ shrink_only: true
90
+ )
91
+ end
92
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/resizing'
3
+
4
+ class ResizingTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_resize_image_with_geometry_options
8
+ img = resized_image('foo', width: 200, shrink_only: true)
9
+ cmd = convert(img)
10
+ assert_equal 'convert foo[200x>] miff:-', cmd.to_s
11
+ end
12
+
13
+ def test_resize_image_nested_via_lvar
14
+ img = resized_image('foo', width: 200, shrink_only: true)
15
+ cmd = convert { image(img) }
16
+ assert_equal 'convert foo[200x>] miff:-', cmd.to_s
17
+ end
18
+
19
+ def test_resize_image_nested_via_block
20
+ cmd = convert do
21
+ resized_image('foo', height: 100, shrink_only: true)
22
+ end
23
+ assert_equal 'convert foo[x100>] miff:-', cmd.to_s
24
+ end
25
+ end
@@ -0,0 +1,98 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/sequence_manipulation'
3
+
4
+ class SequenceManipulationTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_clone_without_args
8
+ cmd = convert { clone }
9
+ assert_equal 'convert +clone miff:-', cmd.to_s
10
+ end
11
+
12
+ def test_clone_with_one_arg
13
+ cmd = convert { clone(1) }
14
+ assert_equal 'convert -clone 1 miff:-', cmd.to_s
15
+ end
16
+
17
+ def test_clone_with_two_args
18
+ cmd = convert { clone(1,3) }
19
+ assert_equal 'convert -clone 1,3 miff:-', cmd.to_s
20
+ end
21
+
22
+ def test_clone_with_array
23
+ cmd = convert { clone([1,3]) }
24
+ assert_equal 'convert -clone 1,3 miff:-', cmd.to_s
25
+ end
26
+
27
+ def test_clone_with_inclusive_range
28
+ cmd = convert { clone(1..3) }
29
+ assert_equal 'convert -clone 1-3 miff:-', cmd.to_s
30
+ end
31
+
32
+ def test_clone_with_exclusive_range
33
+ cmd = convert { clone(1...3) }
34
+ assert_equal 'convert -clone 1-2 miff:-', cmd.to_s
35
+ end
36
+
37
+ def test_clone_in_nested_convert
38
+ cmd = convert { convert { clone } }
39
+ assert_equal 'convert ( +clone ) miff:-', cmd.to_s
40
+ end
41
+
42
+ def test_delete_without_args
43
+ cmd = convert { delete }
44
+ assert_equal 'convert +delete miff:-', cmd.to_s
45
+ end
46
+
47
+ def test_delete_with_one_arg
48
+ cmd = convert { delete(1) }
49
+ assert_equal 'convert -delete 1 miff:-', cmd.to_s
50
+ end
51
+
52
+ def test_delete_with_two_args
53
+ cmd = convert { delete(1,3) }
54
+ assert_equal 'convert -delete 1,3 miff:-', cmd.to_s
55
+ end
56
+
57
+ def test_delete_with_array
58
+ cmd = convert { delete([1,3]) }
59
+ assert_equal 'convert -delete 1,3 miff:-', cmd.to_s
60
+ end
61
+
62
+ def test_delete_with_inclusive_range
63
+ cmd = convert { delete(1..3) }
64
+ assert_equal 'convert -delete 1-3 miff:-', cmd.to_s
65
+ end
66
+
67
+ def test_delete_with_exclusive_range
68
+ cmd = convert { delete(1...3) }
69
+ assert_equal 'convert -delete 1-2 miff:-', cmd.to_s
70
+ end
71
+
72
+ def test_delete_in_nested_convert
73
+ cmd = convert { convert { delete } }
74
+ assert_equal 'convert ( +delete ) miff:-', cmd.to_s
75
+ end
76
+
77
+ def test_swap_without_args
78
+ cmd = convert { swap }
79
+ assert_equal 'convert +swap miff:-', cmd.to_s
80
+ end
81
+
82
+ def test_swap_with_one_arg_raises_error
83
+ assert_raises(ArgumentError) do
84
+ convert{ swap(1) }.to_s
85
+ end
86
+ end
87
+
88
+ def test_swap_with_two_args
89
+ cmd = convert { swap(1,2) }
90
+ assert_equal 'convert -swap 1,2 miff:-', cmd.to_s
91
+ end
92
+
93
+ def test_swap_with_three_args_raises_error
94
+ assert_raises(ArgumentError) do
95
+ convert{ swap(1,2,3) }.to_s
96
+ end
97
+ end
98
+ end