prawn_commander 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/prawn_commander.rb +59 -51
- data/prawn_commander.gemspec +60 -0
- data/spec/prawn_commander_spec.rb +4 -3
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/prawn_commander.rb
CHANGED
@@ -1,60 +1,68 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Prawn
|
2
|
+
class Commander
|
3
|
+
attr_accessor :prawn_document, :prawn_commands, :options
|
4
|
+
|
5
|
+
def initialize(prawn_doc = nil, options = {:dry_run => true})
|
6
|
+
@prawn_document = prawn_doc
|
7
|
+
@prawn_commands = []
|
8
|
+
@options = options
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# arg_str = args
|
17
|
-
arg_str = case args
|
18
|
-
when Array
|
19
|
-
args.map{|a| a.inspect}.join(',')
|
20
|
-
else
|
21
|
-
args
|
22
|
-
end
|
23
|
-
raw_commands << "#{command[:method]} #{arg_str}"
|
11
|
+
def raw_prawn_commands
|
12
|
+
raw_commands = []
|
13
|
+
prawn_commands.each do |command|
|
14
|
+
args = command[:args].size == 1 ? command[:args][0] : command[:args]
|
15
|
+
# arg_str = args
|
16
|
+
arg_str = case args
|
17
|
+
when Array
|
18
|
+
args.map{|a| a.inspect}.join(',')
|
19
|
+
else
|
20
|
+
args
|
24
21
|
end
|
25
|
-
raw_commands
|
22
|
+
raw_commands << "#{command[:method]} #{arg_str}"
|
26
23
|
end
|
24
|
+
raw_commands
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
def print_raw_prawn_commands
|
28
|
+
puts raw_prawn_commands.join("\n")
|
29
|
+
end
|
30
|
+
|
31
|
+
def prawn_command(method, *args, &block)
|
32
|
+
raise "#{method} is not a valid prawn command on a prawn document" if !valid_prawn_command?(method)
|
33
|
+
add_command(method, args.dup, block != nil)
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
# make clone of command to ensure the original is not in any way modified internally by prawn
|
36
|
+
cmd = Marshal.load( Marshal.dump(prawn_commands.last) )
|
37
|
+
document_execute cmd if prawn_document
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
40
|
+
protected
|
41
|
+
|
42
|
+
def test_doc
|
43
|
+
@test_doc ||= Prawn::Document.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def document_execute cmd
|
47
|
+
puts prawn_document
|
48
|
+
prawn_document.send cmd[:method], *cmd[:args] if !options[:dry_run]
|
49
|
+
end
|
50
|
+
|
51
|
+
def valid_prawn_command?(method)
|
52
|
+
test_doc.respond_to? method
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_command(method, args, has_block)
|
56
|
+
cmd = command(method, args, has_block)
|
57
|
+
prawn_commands << cmd.dup
|
58
|
+
end
|
59
|
+
|
60
|
+
def command(method, args, has_block)
|
61
|
+
cmd = {:method => method}
|
62
|
+
cmd.merge! :block => has_block if has_block
|
63
|
+
cmd.merge! :args => args if !args.flatten.empty?
|
64
|
+
cmd
|
58
65
|
end
|
59
66
|
end
|
60
67
|
end
|
68
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{prawn_commander}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-06-25}
|
13
|
+
s.description = %q{Command center for prawn commands that enable logging commands before or without executing them}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/prawn_commander.rb",
|
27
|
+
"prawn_commander.gemspec",
|
28
|
+
"spec/matcher/command_matcher.rb",
|
29
|
+
"spec/prawn_commander_spec.rb",
|
30
|
+
"spec/spec.opts",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/kristianmandrup/prawn_commander}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
|
+
s.summary = %q{Command center for prawn commands that enable logging}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/matcher/command_matcher.rb",
|
40
|
+
"spec/prawn_commander_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta13"])
|
50
|
+
s.add_runtime_dependency(%q<prawn>, [">= 0.8.4"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta13"])
|
53
|
+
s.add_dependency(%q<prawn>, [">= 0.8.4"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta13"])
|
57
|
+
s.add_dependency(%q<prawn>, [">= 0.8.4"])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -1,15 +1,16 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Prawn::Commander do
|
4
4
|
let (:doc) { Prawn::Document.new(:page_size => "A4") }
|
5
5
|
|
6
6
|
before(:each) do
|
7
|
-
@commander =
|
7
|
+
@commander = Prawn::Commander.new
|
8
8
|
end
|
9
9
|
|
10
10
|
context "clean commander" do
|
11
11
|
it "should have a prawn document" do
|
12
|
-
|
12
|
+
doc_commander = Prawn::Commander.new doc
|
13
|
+
doc_commander.prawn_document.should == doc
|
13
14
|
end
|
14
15
|
|
15
16
|
context "issue 'move_down' prawn command" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- Rakefile
|
66
66
|
- VERSION
|
67
67
|
- lib/prawn_commander.rb
|
68
|
+
- prawn_commander.gemspec
|
68
69
|
- spec/matcher/command_matcher.rb
|
69
70
|
- spec/prawn_commander_spec.rb
|
70
71
|
- spec/spec.opts
|