skeptick 0.1.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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +584 -0
- data/Rakefile +10 -0
- data/foo.rb +1 -0
- data/lib/skeptick.rb +2 -0
- data/lib/skeptick/chain.rb +55 -0
- data/lib/skeptick/chain/dsl_context.rb +21 -0
- data/lib/skeptick/command.rb +46 -0
- data/lib/skeptick/convert.rb +109 -0
- data/lib/skeptick/convert/dsl_context.rb +27 -0
- data/lib/skeptick/core.rb +46 -0
- data/lib/skeptick/error.rb +4 -0
- data/lib/skeptick/helper.rb +26 -0
- data/lib/skeptick/image.rb +69 -0
- data/lib/skeptick/image/dsl_context.rb +29 -0
- data/lib/skeptick/railtie.rb +8 -0
- data/lib/skeptick/sugar.rb +8 -0
- data/lib/skeptick/sugar/composition.rb +55 -0
- data/lib/skeptick/sugar/debugging.rb +12 -0
- data/lib/skeptick/sugar/drawing.rb +32 -0
- data/lib/skeptick/sugar/edges.rb +70 -0
- data/lib/skeptick/sugar/formatting.rb +12 -0
- data/lib/skeptick/sugar/geometry.rb +38 -0
- data/lib/skeptick/sugar/resizing.rb +16 -0
- data/lib/skeptick/sugar/sequence_manipulation.rb +43 -0
- data/lib/skeptick/version.rb +3 -0
- data/logo.png +0 -0
- data/logo.rb +45 -0
- data/refresh_preview.scpt +2 -0
- data/skeptick.gemspec +21 -0
- data/test/chain_test.rb +94 -0
- data/test/convert_test.rb +177 -0
- data/test/image_test.rb +145 -0
- data/test/sugar/composition_test.rb +273 -0
- data/test/sugar/debugging_test.rb +24 -0
- data/test/sugar/drawing_test.rb +86 -0
- data/test/sugar/edges_test.rb +99 -0
- data/test/sugar/formatting_test.rb +19 -0
- data/test/sugar/geometry_test.rb +92 -0
- data/test/sugar/resizing_test.rb +25 -0
- data/test/sugar/sequence_manipulation_test.rb +98 -0
- data/test/test_helper.rb +11 -0
- metadata +117 -0
data/Rakefile
ADDED
data/foo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/autorun'; class FooTest < MiniTest::Unit::TestCase; def test_foo; assert_equal('0x0', '0x1') end end
|
data/lib/skeptick.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'skeptick/helper'
|
2
|
+
require 'skeptick/convert'
|
3
|
+
require 'skeptick/chain/dsl_context'
|
4
|
+
require 'skeptick/command'
|
5
|
+
|
6
|
+
module Skeptick
|
7
|
+
class Chain
|
8
|
+
include Command::Executable
|
9
|
+
|
10
|
+
PIPE = 'miff:-'
|
11
|
+
|
12
|
+
def initialize(context, *args, &blk)
|
13
|
+
options = Helper.extract_options!(args)
|
14
|
+
@to = options[:to]
|
15
|
+
@context = context
|
16
|
+
@block = blk
|
17
|
+
reset
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert(*args, &blk)
|
21
|
+
@executables << Convert.new(@context, *args, &blk)
|
22
|
+
end
|
23
|
+
|
24
|
+
def piping?
|
25
|
+
@executables.last && @executables.last.piping?
|
26
|
+
end
|
27
|
+
|
28
|
+
def process_method_missing(*args, &blk)
|
29
|
+
@context.send(*args, &blk)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
process_dsl
|
34
|
+
@executables.map(&:command).join(' | ')
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
"Skeptick::Chain(#{to_s})"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def reset
|
43
|
+
@executables = []
|
44
|
+
end
|
45
|
+
|
46
|
+
def process_dsl
|
47
|
+
reset
|
48
|
+
DslContext.new(self).instance_eval(&@block)
|
49
|
+
|
50
|
+
if @executables.size > 0 && @to && piping?
|
51
|
+
@executables.last.destination = @to
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Skeptick
|
2
|
+
class Chain
|
3
|
+
class DslContext
|
4
|
+
def initialize(chain)
|
5
|
+
@chain = chain
|
6
|
+
end
|
7
|
+
|
8
|
+
def convert(*args, &blk)
|
9
|
+
@chain.convert(*args, &blk)
|
10
|
+
end
|
11
|
+
|
12
|
+
def pipe_or(path)
|
13
|
+
@chain.piping? ? :pipe : path
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(*args, &blk)
|
17
|
+
@chain.process_method_missing(*args, &blk)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'posix/spawn'
|
3
|
+
require 'skeptick/error'
|
4
|
+
|
5
|
+
module Skeptick
|
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
|
18
|
+
|
19
|
+
def initialize(command_obj)
|
20
|
+
@command_obj = command_obj
|
21
|
+
end
|
22
|
+
|
23
|
+
def command
|
24
|
+
@command_obj.to_s.shellsplit.shelljoin
|
25
|
+
end
|
26
|
+
alias_method :to_s, :command
|
27
|
+
|
28
|
+
def run
|
29
|
+
opts = {}
|
30
|
+
opts[:chdir] = Skeptick.cd_path.to_s if Skeptick.cd_path
|
31
|
+
|
32
|
+
if Skeptick.debug_mode?
|
33
|
+
Skeptick.log("Skeptick Command: #{command}")
|
34
|
+
end
|
35
|
+
|
36
|
+
im_process = POSIX::Spawn::Child.new(command, opts)
|
37
|
+
|
38
|
+
if !im_process.success?
|
39
|
+
raise ImageMagickError,
|
40
|
+
"ImageMagick error\nCommand: #{command}\nSTDERR:\n#{im_process.err}"
|
41
|
+
end
|
42
|
+
|
43
|
+
im_process.status
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'skeptick/helper'
|
2
|
+
require 'skeptick/image'
|
3
|
+
require 'skeptick/chain'
|
4
|
+
require 'skeptick/convert/dsl_context'
|
5
|
+
require 'skeptick/command'
|
6
|
+
|
7
|
+
module Skeptick
|
8
|
+
class Convert
|
9
|
+
include Command::Executable
|
10
|
+
|
11
|
+
attr_accessor :prepends, :appends
|
12
|
+
|
13
|
+
def initialize(context, *args, &blk)
|
14
|
+
@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
|
36
|
+
|
37
|
+
def set(*args)
|
38
|
+
@objects << Helper.process_args(*args)
|
39
|
+
end
|
40
|
+
alias_method :apply, :set
|
41
|
+
alias_method :with, :set
|
42
|
+
|
43
|
+
|
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
|
49
|
+
|
50
|
+
def image(obj = nil, &blk)
|
51
|
+
@objects << Image.new(@context, obj, &blk)
|
52
|
+
end
|
53
|
+
|
54
|
+
def destination=(to)
|
55
|
+
if inner?
|
56
|
+
raise 'cannot assign output to parentheses-wrapped image conversion'
|
57
|
+
else
|
58
|
+
@to = to
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
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)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def reset
|
93
|
+
@objects = []
|
94
|
+
end
|
95
|
+
|
96
|
+
def inner?
|
97
|
+
@inner
|
98
|
+
end
|
99
|
+
|
100
|
+
def wrap
|
101
|
+
@beginning = inner? ? '(' : 'convert'
|
102
|
+
@ending = inner? ? ')' : @to || Chain::PIPE
|
103
|
+
end
|
104
|
+
|
105
|
+
def parse_pipe(obj)
|
106
|
+
obj == :pipe ? Chain::PIPE : obj
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Skeptick
|
2
|
+
class Convert
|
3
|
+
class DslContext
|
4
|
+
def initialize(convert)
|
5
|
+
@convert = convert
|
6
|
+
end
|
7
|
+
|
8
|
+
def set(*args)
|
9
|
+
@convert.set(*args)
|
10
|
+
end
|
11
|
+
alias_method :apply, :set
|
12
|
+
alias_method :with, :set
|
13
|
+
|
14
|
+
def convert(*args, &blk)
|
15
|
+
@convert.convert(*args, &blk)
|
16
|
+
end
|
17
|
+
|
18
|
+
def image(obj = nil, &blk)
|
19
|
+
@convert.image(obj, &blk)
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(*args, &blk)
|
23
|
+
@convert.process_method_missing(*args, &blk)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'skeptick/version'
|
2
|
+
require 'skeptick/convert'
|
3
|
+
require 'skeptick/image'
|
4
|
+
require 'skeptick/chain'
|
5
|
+
require 'skeptick/railtie' if defined?(Rails)
|
6
|
+
|
7
|
+
module Skeptick
|
8
|
+
class << self
|
9
|
+
attr_writer :debug_mode,
|
10
|
+
:logger,
|
11
|
+
:logger_method,
|
12
|
+
:cd_path
|
13
|
+
|
14
|
+
def log(message)
|
15
|
+
@logger ||= ::STDOUT
|
16
|
+
|
17
|
+
@logger_method ||=
|
18
|
+
if @logger.respond_to?(:debug); :debug
|
19
|
+
elsif @logger.respond_to?(:puts); :puts
|
20
|
+
else :write
|
21
|
+
end
|
22
|
+
|
23
|
+
@logger.public_send(@logger_method, message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def debug_mode?
|
27
|
+
@debug_mode
|
28
|
+
end
|
29
|
+
|
30
|
+
def cd_path
|
31
|
+
@cd_path
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def convert(*args, &blk)
|
36
|
+
Skeptick::Convert.new(self, *args, &blk)
|
37
|
+
end
|
38
|
+
|
39
|
+
def image(*args, &blk)
|
40
|
+
Skeptick::Image.new(self, *args, &blk)
|
41
|
+
end
|
42
|
+
|
43
|
+
def chain(*args, &blk)
|
44
|
+
Skeptick::Chain.new(self, *args, &blk)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Skeptick
|
2
|
+
module Helper
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def extract_options!(array)
|
6
|
+
array.last.is_a?(Hash) ? array.pop : {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def object_to_index_range_list(obj)
|
10
|
+
case obj
|
11
|
+
when Integer, String
|
12
|
+
obj
|
13
|
+
when Range
|
14
|
+
"#{obj.min}-#{obj.max}"
|
15
|
+
when Array
|
16
|
+
obj.join(',')
|
17
|
+
else
|
18
|
+
raise "invalid sequence reference"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_args(*args)
|
23
|
+
args.map{ |arg| arg.is_a?(Symbol) ? "-#{arg.to_s}" : arg }.join(' ')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'skeptick/helper'
|
2
|
+
require 'skeptick/convert'
|
3
|
+
require 'skeptick/chain'
|
4
|
+
require 'skeptick/image/dsl_context'
|
5
|
+
|
6
|
+
module Skeptick
|
7
|
+
class Image
|
8
|
+
attr_accessor :prepends, :appends
|
9
|
+
|
10
|
+
def initialize(context, obj = nil, &blk)
|
11
|
+
@context = context
|
12
|
+
@obj = obj || blk
|
13
|
+
reset
|
14
|
+
end
|
15
|
+
|
16
|
+
def set(*args)
|
17
|
+
@prepends << Helper.process_args(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def apply(*args)
|
21
|
+
@appends << Helper.process_args(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def image(obj, &blk)
|
25
|
+
@image = Image.new(@context, obj, &blk)
|
26
|
+
end
|
27
|
+
|
28
|
+
def convert(*args, &blk)
|
29
|
+
@image = Convert.new(@context, *args, &blk).become_inner
|
30
|
+
end
|
31
|
+
|
32
|
+
def process_method_missing(*args, &blk)
|
33
|
+
@context.send(*args, &blk)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
parts.join(' ')
|
38
|
+
end
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
"Skeptick::Image(#{to_s})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def parts
|
45
|
+
case @obj
|
46
|
+
when :pipe then [ Chain::PIPE ]
|
47
|
+
when Convert then @obj.become_inner.parts
|
48
|
+
when Image then @obj.parts
|
49
|
+
when Array then @obj
|
50
|
+
when Proc then build_parts
|
51
|
+
else [ @obj ]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def build_parts
|
58
|
+
reset
|
59
|
+
DslContext.new(self).instance_eval(&@obj)
|
60
|
+
[*@prepends, @image, *@appends].compact
|
61
|
+
end
|
62
|
+
|
63
|
+
def reset
|
64
|
+
@image = nil
|
65
|
+
@prepends = []
|
66
|
+
@appends = []
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Skeptick
|
2
|
+
class Image
|
3
|
+
class DslContext
|
4
|
+
def initialize(image)
|
5
|
+
@image = image
|
6
|
+
end
|
7
|
+
|
8
|
+
def set(*args)
|
9
|
+
@image.set(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply(*args)
|
13
|
+
@image.apply(*args)
|
14
|
+
end
|
15
|
+
|
16
|
+
def image(obj)
|
17
|
+
@image.image(obj)
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert(*args, &blk)
|
21
|
+
@image.convert(*args, &blk)
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(*args, &blk)
|
25
|
+
@image.process_method_missing(*args, &blk)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|