prawn_commander 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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/prawn_commander.rb +60 -0
- data/spec/matcher/command_matcher.rb +27 -0
- data/spec/prawn_commander_spec.rb +29 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- metadata +107 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= Prawn Commander
|
2
|
+
|
3
|
+
Command center for prawn commands that enable logging commands before or without executing them.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# require 'rubygems'
|
2
|
+
# require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "prawn_commander"
|
8
|
+
gem.summary = %Q{Command center for prawn commands that enable logging}
|
9
|
+
gem.description = %Q{Command center for prawn commands that enable logging commands before or without executing them}
|
10
|
+
gem.email = "kmandrup@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/kristianmandrup/prawn_commander"
|
12
|
+
gem.authors = ["Kristian Mandrup"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta13"
|
14
|
+
gem.add_dependency "prawn", ">= 0.8.4"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
# require 'spec/rake/spectask'
|
23
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
# spec.libs << 'lib' << 'spec'
|
25
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
# spec.libs << 'lib' << 'spec'
|
30
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
# spec.rcov = true
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# task :spec => :check_dependencies
|
35
|
+
#
|
36
|
+
# task :default => :spec
|
37
|
+
#
|
38
|
+
# require 'rake/rdoctask'
|
39
|
+
# Rake::RDocTask.new do |rdoc|
|
40
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
#
|
42
|
+
# rdoc.rdoc_dir = 'rdoc'
|
43
|
+
# rdoc.title = "prawn_commander #{version}"
|
44
|
+
# rdoc.rdoc_files.include('README*')
|
45
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Howrah
|
2
|
+
module Prawn
|
3
|
+
class Commander
|
4
|
+
attr_accessor :prawn_document, :prawn_commands, :options
|
5
|
+
|
6
|
+
def initialize(prawn_document, options = {:dry_run => true})
|
7
|
+
@prawn_document = prawn_document
|
8
|
+
@prawn_commands = []
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw_prawn_commands
|
13
|
+
raw_commands = []
|
14
|
+
prawn_commands.each do |command|
|
15
|
+
args = command[:args].size == 1 ? command[:args][0] : command[:args]
|
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}"
|
24
|
+
end
|
25
|
+
raw_commands
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_raw_prawn_commands
|
29
|
+
puts raw_prawn_commands.join("\n")
|
30
|
+
end
|
31
|
+
|
32
|
+
def prawn_command(method, *args, &block)
|
33
|
+
raise "#{method} is not a valid prawn command on a prawn document" if !valid_prawn_command?(method)
|
34
|
+
add_command(method, args.dup, block != nil)
|
35
|
+
|
36
|
+
# make clone of command to ensure the original is not in any way modified internally by prawn
|
37
|
+
cmd = Marshal.load( Marshal.dump(prawn_commands.last) )
|
38
|
+
prawn_document.send cmd[:method], *cmd[:args] if !options[:dry_run]
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def valid_prawn_command?(method)
|
44
|
+
prawn_document.respond_to? method
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_command(method, args, has_block)
|
48
|
+
cmd = command(method, args, has_block)
|
49
|
+
prawn_commands << cmd.dup
|
50
|
+
end
|
51
|
+
|
52
|
+
def command(method, args, has_block)
|
53
|
+
cmd = {:method => method}
|
54
|
+
cmd.merge! :block => has_block if has_block
|
55
|
+
cmd.merge! :args => args if !args.flatten.empty?
|
56
|
+
cmd
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Matchers
|
2
|
+
class PrawnCommand
|
3
|
+
def initialize(method, args)
|
4
|
+
@expected = {:method => method, :args => args}
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(actual)
|
8
|
+
@actual = actual
|
9
|
+
@actual == @expected
|
10
|
+
end
|
11
|
+
|
12
|
+
def failure_message
|
13
|
+
"expected command #{@expected.inspect} but got command '#{@actual.inspect}'"
|
14
|
+
end
|
15
|
+
|
16
|
+
def negative_failure_message
|
17
|
+
"expected command '#{@expected..inspect}' but found command '#{@actual.inspect}'"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def be_command(method, args)
|
22
|
+
args = [args] if !args.kind_of? Array
|
23
|
+
args = [args] if method == :formatted_text_box && !args[0].kind_of?(Array)
|
24
|
+
PrawnCommand.new(method, args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2
|
+
|
3
|
+
describe Howrah::Prawn::Commander do
|
4
|
+
let (:doc) { Prawn::Document.new(:page_size => "A4") }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@commander = Howrah::Prawn::Commander.new doc
|
8
|
+
end
|
9
|
+
|
10
|
+
context "clean commander" do
|
11
|
+
it "should have a prawn document" do
|
12
|
+
@commander.prawn_document.should == doc
|
13
|
+
end
|
14
|
+
|
15
|
+
context "issue 'move_down' prawn command" do
|
16
|
+
it "should add 'move_down' to command stack" do
|
17
|
+
@commander.prawn_command(:move_down, 10)
|
18
|
+
@commander.prawn_commands.first.should be_command(:move_down, 10)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "issue 'go_down' prawn command" do
|
23
|
+
it "should raise error and NOT add command to prawn command stack" do
|
24
|
+
lambda { @commander.prawn_command(:go_down, 10) }.should raise_error
|
25
|
+
@commander.prawn_commands.first.should_not be_command(:go_down, 10)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prawn_commander
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-25 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta13
|
33
|
+
version: 2.0.0.beta13
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: prawn
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 8
|
47
|
+
- 4
|
48
|
+
version: 0.8.4
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Command center for prawn commands that enable logging commands before or without executing them
|
52
|
+
email: kmandrup@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
61
|
+
- .document
|
62
|
+
- .gitignore
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- lib/prawn_commander.rb
|
68
|
+
- spec/matcher/command_matcher.rb
|
69
|
+
- spec/prawn_commander_spec.rb
|
70
|
+
- spec/spec.opts
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/kristianmandrup/prawn_commander
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --charset=UTF-8
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Command center for prawn commands that enable logging
|
104
|
+
test_files:
|
105
|
+
- spec/matcher/command_matcher.rb
|
106
|
+
- spec/prawn_commander_spec.rb
|
107
|
+
- spec/spec_helper.rb
|