skeptick 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,15 @@
1
+ require 'skeptick/sugar/geometry'
2
+
3
+ module Skeptick
4
+ module ResizedImage
5
+ def resized_image(path, options = {})
6
+ image("#{path}[#{geometry(options)}]")
7
+ end
8
+ end
9
+
10
+ include ResizedImage
11
+
12
+ class DslContext
13
+ include ResizedImage
14
+ end
15
+ end
@@ -0,0 +1,42 @@
1
+ require 'skeptick/sugar/compose'
2
+ require 'skeptick/sugar/format'
3
+ require 'skeptick/sugar/draw'
4
+
5
+ module Skeptick
6
+ module RoundedCornersImage
7
+ def rounded_corners_image(*args, &blk)
8
+ opts = args.last.is_a?(Hash) ? args.pop : {}
9
+ radius = opts[:radius] || 15
10
+ size = opts[:size]
11
+ width = opts[:width]
12
+ height = opts[:height]
13
+
14
+ if size
15
+ width, height = size.split('x').map(&:to_i)
16
+ end
17
+
18
+ border = if width && height
19
+ "roundrectangle 1,1 #{width},#{height} #{radius},#{radius}"
20
+ else
21
+ Convert.new(self, *args, to: 'info:') do
22
+ format "roundrectangle 1,1 %[fx:w], %[fx:h] #{radius},#{radius}"
23
+ end.run.strip
24
+ end
25
+
26
+ compose(:dstin, *args) do
27
+ convert(&blk) if block_given?
28
+
29
+ convert do
30
+ set '+clone'
31
+ set :draw, border
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ class DslContext
38
+ include RoundedCornersImage
39
+ end
40
+
41
+ include RoundedCornersImage
42
+ end
@@ -0,0 +1,12 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def swap(*args)
4
+ if args.size != 0 && args.size != 2
5
+ raise ArgumentError,
6
+ "wrong number of arguments (#{args.size} for 0, 2)"
7
+ end
8
+
9
+ args.empty? ? set('+swap') : set(:swap, args.join(','))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def text(string, options = {})
4
+ if options[:left] && options[:top]
5
+ opts = "#{options[:left]},#{options[:top]} "
6
+ end
7
+
8
+ set :draw, "text #{opts}'#{string}'"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ require 'skeptick/sugar/compose'
2
+
3
+ module Skeptick
4
+ module TornPaperImage
5
+ def torn_paper_image(*args, &blk)
6
+ opts = args.last.is_a?(Hash) ? args.pop : {}
7
+ spread = opts[:spread] || 1
8
+ blur = opts[:blur] || '0x.7'
9
+ threshold = opts[:threshold] || 50
10
+
11
+ compose(:copy_opacity, *args) do
12
+ convert(&blk) if block_given?
13
+ convert do
14
+ set '+clone'
15
+ set '-virtual-pixel', 'transparent'
16
+ set :spread, spread
17
+ set :channel, 'A'
18
+ set :blur, blur
19
+ set :threshold, "#{threshold}%"
20
+ end
21
+
22
+ set :blur, blur
23
+ end
24
+ end
25
+ end
26
+
27
+ class DslContext
28
+ include TornPaperImage
29
+ end
30
+
31
+ include TornPaperImage
32
+ end
@@ -0,0 +1,8 @@
1
+ module Skeptick
2
+ class DslContext
3
+ def write(path)
4
+ append(:write, path)
5
+ end
6
+ end
7
+ end
8
+
@@ -1,3 +1,3 @@
1
1
  module Skeptick
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
data/logo.rb CHANGED
@@ -1,4 +1,6 @@
1
- require_relative 'lib/skeptick'
1
+ $: << 'lib'
2
+ require 'skeptick'
3
+ puts "Skeptick #{Skeptick::VERSION}"
2
4
 
3
5
  include Skeptick
4
6
 
@@ -7,18 +9,17 @@ image_size = '400x120'
7
9
  paper = rounded_corners_image(size: image_size, radius: 25) do
8
10
  set :size, image_size
9
11
  image 'tile:granite:'
10
- apply '-brightness-contrast', '38x-33'
11
- apply :blur, '0x0.5'
12
+ set '-brightness-contrast', '38x-25'
13
+ set :blur, '0x0.5'
12
14
  end
13
15
 
14
16
  left, top = 8, 80
15
17
  text = image do
16
18
  canvas :none, size: '395x110'
17
- font 'Handwriting - Dakota Regular'
19
+ font 'Handwriting - Dakota'
18
20
  set :pointsize, 90
19
21
  set :fill, 'gradient:#37e-#007'
20
- write 'Skeptick', left: left, top: top
21
- apply :blur, '0x0.7'
22
+ text 'Skeptick', left: left, top: top
22
23
  end
23
24
 
24
25
  bezier = \
@@ -32,14 +33,14 @@ curve = image do
32
33
  draw "fill none bezier #{bezier}"
33
34
  end
34
35
 
35
- result_path = "#{File.dirname(__FILE__)}/logo2.png"
36
+ result_path = "#{File.dirname(__FILE__)}/logo.png"
36
37
 
37
- torn = torn_paper_image(
38
+ final = torn_paper_image \
38
39
  paper * (text + curve),
39
40
  spread: 50,
40
41
  blur: '3x10'
41
- )
42
42
 
43
- logo = convert(torn, to: result_path)
44
- logo.build
43
+ logo_script = convert(final, to: result_path)
44
+ puts logo_script.to_s
45
+ logo_script.run
45
46
  # system "osascript refresh_preview.scpt"
@@ -1,2 +1,2 @@
1
1
  tell application "Preview" to activate
2
- tell application "Sublime Text 2" to activate
2
+ tell application "Sublime Text" to activate
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'posix-spawn', '~> 0.3.6'
21
21
  gem.add_development_dependency 'rake', '>= 0.9.2'
22
+ gem.add_development_dependency 'pry'
22
23
  end
@@ -7,10 +7,34 @@ require_relative 'test_helper'
7
7
  class ConvertTest < Skeptick::TestCase
8
8
  include Skeptick
9
9
 
10
- def test_dsl_method_available
10
+ def test_dsl_method_convert_available
11
11
  assert_respond_to self, :convert
12
12
  end
13
13
 
14
+ def test_dsl_method_image_available
15
+ assert_respond_to self, :image
16
+ end
17
+
18
+ def test_set_adds_setting_to_convert_segment
19
+ cmd = convert do
20
+ image 'bar'
21
+ set '-foo'
22
+ end
23
+
24
+ assert_equal 'convert bar -foo miff:-', cmd.to_s
25
+ end
26
+
27
+ def test_append_appends_to_convert_segment
28
+ cmd = convert do
29
+ image do
30
+ append '-foo'
31
+ image 'bar'
32
+ end
33
+ end
34
+
35
+ assert_equal 'convert bar -foo miff:-', cmd.to_s
36
+ end
37
+
14
38
  def test_lvars_from_external_context_are_accessible
15
39
  foo = '-test'
16
40
  cmd = convert { set foo }
@@ -78,30 +102,30 @@ class ConvertTest < Skeptick::TestCase
78
102
  end
79
103
 
80
104
  def test_convert_with_ops
81
- cmd = convert { with '-foo' }
105
+ cmd = convert { set :foo }
82
106
  assert_equal 'convert -foo miff:-', cmd.to_s
83
107
  end
84
108
 
85
109
  def test_convert_with_concatenated_ops
86
- cmd = convert { with '-foo', 'bar' }
110
+ cmd = convert { set '-foo', 'bar' }
87
111
  assert_equal 'convert -foo bar miff:-', cmd.to_s
88
112
  end
89
113
 
90
114
  def test_convert_with_multiple_ops
91
- cmd = convert { with '-foo'; with '+bar' }
115
+ cmd = convert { set '-foo'; set '+bar' }
92
116
  assert_equal 'convert -foo +bar miff:-', cmd.to_s
93
117
  end
94
118
 
95
119
  def test_convert_with_multiple_concatenated_ops
96
- cmd = convert { with '-foo', 'bar'; with '+baz', 'qux' }
120
+ cmd = convert { set '-foo', 'bar'; set '+baz', 'qux' }
97
121
  assert_equal 'convert -foo bar +baz qux miff:-', cmd.to_s
98
122
  end
99
123
 
100
124
  def test_convert_with_ops_inputs_and_output
101
125
  cmd = convert('foo', 'bar', to: 'baz') do
102
126
  image 'qux'
103
- with '+quux'
104
- with '-corge', 'grault'
127
+ set '+quux'
128
+ set :corge, 'grault'
105
129
  end
106
130
 
107
131
  assert_equal 'convert foo bar qux +quux -corge grault baz', cmd.to_s
@@ -109,69 +133,140 @@ class ConvertTest < Skeptick::TestCase
109
133
 
110
134
  def test_nested_convert
111
135
  cmd = convert(to: 'baz') do
112
- convert('foo') { with 'bar' }
136
+ convert('foo') { set '-bar' }
113
137
  end
114
138
 
115
- assert_equal 'convert ( foo bar ) baz', cmd.to_s
139
+ assert_equal 'convert foo -bar baz', cmd.to_s
116
140
  end
117
141
 
118
142
  def test_nested_convert_ignores_output
119
143
  cmd = convert(to: 'baz') do
120
- convert('foo', to: 'nowhere') { with 'bar' }
144
+ convert('foo', to: 'nowhere') { set :bar }
121
145
  end
122
146
 
123
- assert_equal 'convert ( foo bar ) baz', cmd.to_s
147
+ assert_equal 'convert foo -bar baz', cmd.to_s
124
148
  end
125
149
 
126
150
  def test_multi_image_nested_convert
127
151
  cmd = convert('foo', to: 'bar') do
128
152
  convert('qux') do
129
- with '+asdf'
130
- with '+fdsa'
153
+ set '+asdf'
154
+ set '+fdsa'
131
155
  end
132
156
 
133
157
  image 'bleh'
134
- with '-resize'
158
+ set '-resize'
135
159
  end
136
160
 
137
161
  assert_equal 'convert foo ( qux +asdf +fdsa ) bleh -resize bar', cmd.to_s
138
162
  end
139
163
 
140
164
  def test_convert_composition
141
- complex_image = convert('qux') do
142
- with '+asdf'
143
- with '+fdsa'
165
+ complex_image = convert('image1') do
166
+ set '+image1-x'
167
+ set '+image1-y'
144
168
  end
145
169
 
146
- cmd = convert('foo', to: 'bar') do
170
+ cmd = convert('image2', to: 'bar') do
147
171
  image complex_image
148
- image 'bleh'
149
- with '-resize'
172
+ image 'image3'
173
+ set '-setting-for-all-images'
150
174
  end
151
175
 
152
- assert_equal 'convert foo ( qux +asdf +fdsa ) bleh -resize bar', cmd.to_s
176
+ assert_equal 'convert image2 ( image1 +image1-x +image1-y ) image3 '\
177
+ '-setting-for-all-images bar', cmd.to_s
153
178
  end
154
179
 
155
180
  def test_convert_double_nesting_with_composition
156
- complex_image = convert('foo', to: 'nowhere') do
157
- convert('bar', to: 'nowhere') do
158
- convert('baz') do
159
- image 'image1'
160
- with '-option', 'qux'
181
+ complex_image = convert('image1', to: 'nowhere') do
182
+ convert('image2', to: 'nowhere') do
183
+ convert('image3') do
184
+ image 'image4'
185
+ set :option, 'qux'
161
186
  end
162
187
 
163
- image 'image2'
164
- with '+option'
188
+ image 'image5'
189
+ set '+option'
165
190
  end
166
191
  end
167
192
 
168
- cmd = convert('image3') do
193
+ cmd = convert('image6') do
169
194
  image complex_image
170
- image 'image4'
171
- with '-option', 'quux'
195
+ image 'image7'
196
+ set '-option', 'quux'
197
+ end
198
+
199
+ assert_equal 'convert image6 ( image1 ( image2 ( image3 image4 -option '\
200
+ 'qux ) image5 +option ) ) image7 -option quux miff:-', cmd.to_s
201
+ end
202
+
203
+ def test_convert_reusing_variable
204
+ cmd = 'foo'
205
+ cmd = convert('bar') { set(:arg); image(cmd) }
206
+ assert_equal 'convert bar -arg foo miff:-', cmd.to_s
207
+ end
208
+
209
+ def test_inject_image_into_convert
210
+ sample = image do
211
+ set :size, '400x400'
212
+ image 'tile:granite:'
213
+ set '-brightness-contrast', '38x-33'
214
+ set :blur, '0x0.5'
215
+ end
216
+
217
+ cmd = convert do
218
+ set '-foo'
219
+ image sample
220
+ set '-bar'
221
+ end
222
+
223
+ assert_equal 'convert -foo ( -size 400x400 tile:granite: ' +
224
+ '-brightness-contrast 38x-33 -blur 0x0.5 ) -bar miff:-', cmd.to_s
225
+ end
226
+
227
+ def test_inject_image_into_convert_as_argument
228
+ sample = image do
229
+ set :size, '400x400'
230
+ image 'tile:granite:'
231
+ append '-brightness-contrast', '38x-33'
232
+ append :blur, '0x0.5'
233
+ end
234
+
235
+ cmd = convert(sample)
236
+ assert_equal 'convert -size 400x400 tile:granite: -brightness-contrast ' +
237
+ '38x-33 -blur 0x0.5 miff:-', cmd.to_s
238
+ end
239
+
240
+ def test_declare_image_inside_convert
241
+ cmd = convert do
242
+ set '-foo'
243
+ image do
244
+ set :size, '400x400'
245
+ image 'tile:granite:'
246
+ append '-brightness-contrast', '38x-33'
247
+ append :blur, '0x0.5'
248
+ end
249
+ set '-bar'
250
+ end
251
+
252
+ assert_equal 'convert -foo ( -size 400x400 tile:granite: ' +
253
+ '-brightness-contrast 38x-33 -blur 0x0.5 ) -bar miff:-', cmd.to_s
254
+ end
255
+
256
+ def test_convert_as_image_object
257
+ sample = convert('foo', to: 'bar') do
258
+ set :baz
259
+ end
260
+
261
+ cmd = convert do
262
+ image do
263
+ set :setting
264
+ append :operation
265
+ image sample
266
+ end
172
267
  end
173
268
 
174
- assert_equal 'convert image3 ( foo ( bar ( baz image1 -option qux ) ' +
175
- 'image2 +option ) ) image4 -option quux miff:-', cmd.to_s
269
+ assert_equal 'convert -setting ( foo -baz ) -operation miff:-',
270
+ cmd.to_s
176
271
  end
177
272
  end
@@ -0,0 +1,16 @@
1
+ require_relative '../test_helper'
2
+ require 'skeptick/sugar/canvas'
3
+
4
+ class CanvasTest < Skeptick::TestCase
5
+ include Skeptick
6
+
7
+ def test_canvas_in_convert_with_size
8
+ cmd = convert { canvas :none, size: '100x200' }
9
+ assert_equal 'convert -size 100x200 canvas:none miff:-', cmd.to_s
10
+ end
11
+
12
+ def test_canvas_in_convert_without_size
13
+ cmd = convert { canvas :none }
14
+ assert_equal 'convert canvas:none miff:-', cmd.to_s
15
+ end
16
+ end