pdf_ravager 0.0.5-java → 0.0.6-java

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,7 +17,7 @@ data = {:name => 'Bob', :gender => 'm', :relation => 'Uncle' }
17
17
 
18
18
  info = pdf do
19
19
  text 'name', data[:name]
20
- rich_text 'name_stylized', "<b>#{data[:name]}</b>" # warning: text is not HTML-escaped!
20
+ text 'name_stylized', "<b>#{data[:name]}</b>", :rich => true
21
21
  radio_group 'sex' do
22
22
  fill 'male' if data[:gender] == 'm'
23
23
  fill 'female' if data[:gender] == 'f'
@@ -45,14 +45,18 @@ To query and modify a form's field names, use a tool such as Adobe
45
45
  LiveCycle.
46
46
 
47
47
  ### Rich Text
48
- The `rich_text` type is specific to XFA forms. To understand how it
49
- should be used, see the "Rich Text Reference" section of
50
- [Adobe's XFA standard][1]. Rich Text is defined there as a subset of
48
+ Rich text is specific to XFA forms. To understand how it should be used,
49
+ see the "Rich Text Reference" section of [Adobe's XFA standard][1].
50
+ Rich Text is defined there as a subset of
51
51
  XHTML and CSS which uses some custom restrictions and extensions by
52
52
  Adobe. The minimum XHTML and CSS elements that a standards-compliant
53
53
  XFA processor (e.g. Adobe Reader) must support are also listed there
54
54
  and can be used as a guide.
55
55
 
56
+ **Note**: Rich text values are not HTML-escaped or sanitized in any
57
+ way. It is suggested that you call `CGI.escape_html` on user-supplied
58
+ input.
59
+
56
60
  ### Checkbox Groups
57
61
  Because there is no such thing as a "checkbox group," the
58
62
  `checkbox_group` syntax is simply syntactic sugar for calling
@@ -11,11 +11,11 @@ module PDFRavager
11
11
  end
12
12
 
13
13
  def text(name, value, opts={})
14
- @fields << {:name => name, :value => value, :type => :text}
15
- end
16
-
17
- def rich_text(name, value, opts={})
18
- @fields << {:name => name, :value => value, :type => :rich_text}
14
+ if opts.empty?
15
+ @fields << {:name => name, :value => value, :type => :text}
16
+ else
17
+ @fields << {:name => name, :value => value, :type => :text, :options => opts}
18
+ end
19
19
  end
20
20
 
21
21
  def check(name, opts={})
@@ -59,7 +59,7 @@ module PDFRavager
59
59
  else
60
60
  f[:value]
61
61
  end
62
- pdf.set_field_value(f[:name], value, f[:type])
62
+ pdf.set_field_value(f[:name], value, f[:type], f[:options])
63
63
  end
64
64
  end
65
65
  end
@@ -82,9 +82,13 @@ module PDFRavager
82
82
 
83
83
  def self.json_create(obj)
84
84
  fields = obj["data"]["fields"].map do |f|
85
- # symbolize the keys
85
+ # symbolize the root keys
86
86
  f = f.inject({}){|h,(k,v)| h[k.to_sym] = v; h}
87
87
  f[:type] = f[:type].to_sym if f[:type]
88
+ # symbolize the :options keys
89
+ if f[:options]
90
+ f[:options] = f[:options].inject({}){|h,(k,v)| h[k.to_sym] = v; h}
91
+ end
88
92
  f
89
93
  end
90
94
  o = new(obj["data"]["name"], :fields => fields)
@@ -31,8 +31,8 @@ module PDFRavager
31
31
  out
32
32
  end
33
33
 
34
- def set_field_value(name, value, type=nil)
35
- return set_rich_text_field(name, value) if type == :rich_text
34
+ def set_field_value(name, value, type=nil, options={})
35
+ return set_rich_text_field(name, value) if type == :text && options[:rich] == true
36
36
  begin
37
37
  # First try AcroForms method of setting value
38
38
  @afields.setField(XfaForm::Xml2Som::getShortName(SOM.escape(name)), value)
@@ -1,3 +1,3 @@
1
1
  module PDFRavager
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/spec/pdf_spec.rb CHANGED
@@ -4,9 +4,9 @@ require 'pdf_ravager/pdf'
4
4
  class TestPDF < MiniTest::Unit::TestCase
5
5
  def setup
6
6
  @pdf = pdf 'foo.pdf' do
7
- text 'text', 'foo'
8
- rich_text 'rich_text', '<b>foo</b>'
9
- check 'checkbox'
7
+ text 'text', 'foo'
8
+ text 'rich_text', '<b>foo</b>', :rich => true
9
+ check 'checkbox'
10
10
  checkbox_group 'checkbox_group' do
11
11
  check 'foo'
12
12
  end
@@ -27,7 +27,7 @@ class TestPDF < MiniTest::Unit::TestCase
27
27
  end
28
28
 
29
29
  def test_that_rich_text_is_set
30
- assert_includes @pdf.fields, {:name => 'rich_text', :value => '<b>foo</b>', :type => :rich_text}
30
+ assert_includes @pdf.fields, {:name => 'rich_text', :value => '<b>foo</b>', :type => :text, :options => {:rich => true}}
31
31
  end
32
32
 
33
33
  def test_that_checkbox_is_set
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.5
5
+ version: 0.0.6
6
6
  platform: java
7
7
  authors:
8
8
  - Abe Voelker