pdf_ravager 0.0.2-java → 0.0.3-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,6 +21,7 @@ info = pdf do
21
21
  fill 'male', :if => data[:gender] == 'm'
22
22
  fill 'female', :if => data[:gender] == 'f'
23
23
  end
24
+ check 'related' if data[:relation]
24
25
  checkbox_group 'relation' do
25
26
  check 'parent', :if => ['Mom', 'Dad'].include?(data[:relation])
26
27
  check 'sibling', :if => ['Brother', 'Sister'].include?(data[:relation])
@@ -17,6 +17,13 @@ module PDFRavager
17
17
  @fields << {:name => name, :value => value, :type => :text}
18
18
  end
19
19
 
20
+ def check(name, opts={})
21
+ return if opts.has_key?(:when) && !opts[:when]
22
+ return if opts.has_key?(:if) && !opts[:if]
23
+ return if opts.has_key?(:unless) && opts[:unless]
24
+ @fields << {:name => name, :value => true, :type => :checkbox}
25
+ end
26
+
20
27
  def radio_group(gname, &blk)
21
28
  fields = []
22
29
  # TODO: replace w/ singleton method?
@@ -25,7 +32,7 @@ module PDFRavager
25
32
  return if opts.has_key?(:when) && !opts[:when]
26
33
  return if opts.has_key?(:if) && !opts[:if]
27
34
  return if opts.has_key?(:unless) && opts[:unless]
28
- fields << {:name => "#{gname}.#{name}", :value => true, :type => :radio}
35
+ fields << {:name => gname, :value => name, :type => :radio}
29
36
  end
30
37
  blk.call
31
38
  send(:undef_method, :fill)
@@ -35,27 +42,29 @@ module PDFRavager
35
42
  end
36
43
 
37
44
  def checkbox_group(gname, &blk)
38
- fields = []
39
45
  # TODO: replace w/ singleton method?
40
46
  PDF.instance_eval do
47
+ alias_method :__check_original__, :check
41
48
  send(:define_method, :check) do |name, opts={}|
42
- return if opts.has_key?(:when) && !opts[:when]
43
- return if opts.has_key?(:if) && !opts[:if]
44
- return if opts.has_key?(:unless) && opts[:unless]
45
- fields << {:name => "#{gname}.#{name}", :value => true, :type => :checkbox}
49
+ __check_original__("#{gname}.#{name}", opts)
46
50
  end
47
51
  blk.call
48
- send(:undef_method, :check)
52
+ # restore check method back to normal
53
+ alias_method :check, :__check_original__
54
+ send(:undef_method, :__check_original__)
49
55
  end
50
-
51
- @fields += fields
52
56
  end
53
57
 
54
58
  if RUBY_PLATFORM =~ /java/
55
59
  def ravage(file, opts={})
56
60
  PDFRavager::Ravager.open(opts.merge(:in_file => file)) do |pdf|
57
61
  @fields.each do |f|
58
- pdf.set_field_value(f[:name], f[:value])
62
+ value = if f[:type] == :checkbox
63
+ !!f[:value] ? '1' : '0' # Checkbox default string values
64
+ else
65
+ f[:value]
66
+ end
67
+ pdf.set_field_value(f[:name], value)
59
68
  end
60
69
  end
61
70
  end
@@ -32,10 +32,6 @@ module PDFRavager
32
32
  end
33
33
 
34
34
  def set_field_value(name, value)
35
- # Convert boolean values to default checkbox string value
36
- if value.instance_of?(TrueClass) || value.instance_of?(FalseClass)
37
- value = !!value ? '1' : '0'
38
- end
39
35
  # First use AcroForms method
40
36
  begin
41
37
  @afields.setField(XfaForm::Xml2Som::getShortName(SOM.escape(name)), value)
@@ -1,3 +1,3 @@
1
1
  module PDFRavager
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/pdf_ravager.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{DSL to aid filling out AcroForms PDF and XFA documents}
14
14
 
15
15
  s.add_dependency "json"
16
+ s.add_dependency "nokogiri"
16
17
  s.add_development_dependency "bundler", ">= 1.0.0"
17
18
 
18
19
  s.files = `git ls-files`.split("\n")
data/spec/pdf_spec.rb CHANGED
@@ -11,6 +11,7 @@ class TestPDF < MiniTest::Unit::TestCase
11
11
  text 'text_if_false', 'foo', :if => false
12
12
  text 'text_unless_true', 'foo', :unless => true
13
13
  text 'text_unless_false', 'foo', :unless => false
14
+ check 'checkbox'
14
15
  radio_group 'radio_group_always_filled' do
15
16
  fill 'foo'
16
17
  end
@@ -78,32 +79,36 @@ class TestPDF < MiniTest::Unit::TestCase
78
79
  assert_includes @pdf.fields, {:name => 'text_unless_false', :value => 'foo', :type => :text}
79
80
  end
80
81
 
82
+ def test_that_checkbox_is_set
83
+ assert_includes @pdf.fields, {:name => 'checkbox', :value => true, :type => :checkbox}
84
+ end
85
+
81
86
  def test_that_radio_group_always_filled_is_filled
82
- assert_includes @pdf.fields, {:name => 'radio_group_always_filled.foo', :value => true, :type => :radio}
87
+ assert_includes @pdf.fields, {:name => 'radio_group_always_filled', :value => 'foo', :type => :radio}
83
88
  end
84
89
 
85
90
  def test_that_radio_group_when_true_is_set
86
- assert_includes @pdf.fields, {:name => 'radio_group_when.true', :value => true, :type => :radio}
91
+ assert_includes @pdf.fields, {:name => 'radio_group_when', :value => 'true', :type => :radio}
87
92
  end
88
93
 
89
94
  def test_that_radio_group_when_false_is_not_set
90
- refute_includes @pdf.fields, {:name => 'radio_group_when.false', :value => true, :type => :radio}
95
+ refute_includes @pdf.fields, {:name => 'radio_group_when', :value => 'false', :type => :radio}
91
96
  end
92
97
 
93
98
  def test_that_radio_group_if_true_is_set
94
- assert_includes @pdf.fields, {:name => 'radio_group_if.true', :value => true, :type => :radio}
99
+ assert_includes @pdf.fields, {:name => 'radio_group_if', :value => 'true', :type => :radio}
95
100
  end
96
101
 
97
102
  def test_that_radio_group_if_false_is_not_set
98
- refute_includes @pdf.fields, {:name => 'radio_group_if.false', :value => true, :type => :radio}
103
+ refute_includes @pdf.fields, {:name => 'radio_group_if', :value => 'false', :type => :radio}
99
104
  end
100
105
 
101
106
  def test_that_radio_group_unless_true_is_not_set
102
- refute_includes @pdf.fields, {:name => 'radio_group_unless.true', :value => true, :type => :radio}
107
+ refute_includes @pdf.fields, {:name => 'radio_group_unless', :value => 'true', :type => :radio}
103
108
  end
104
109
 
105
110
  def test_that_radio_group_unless_false_is_set
106
- assert_includes @pdf.fields, {:name => 'radio_group_unless.false', :value => true, :type => :radio}
111
+ assert_includes @pdf.fields, {:name => 'radio_group_unless', :value => 'false', :type => :radio}
107
112
  end
108
113
 
109
114
  def test_that_checkbox_group_always_checked_is_checked
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pdf_ravager
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: java
7
7
  authors:
8
8
  - Abe Voelker
@@ -27,6 +27,22 @@ dependencies:
27
27
  none: false
28
28
  prerelease: false
29
29
  type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: bundler
32
48
  version_requirements: !ruby/object:Gem::Requirement