nguyen 0.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: acfaf8065a261f6cc2b2f5b95887a48d450686b6529a315664982c13ecc0c8d0
4
+ data.tar.gz: 99729f86c46f23fc9846f1af8c727da593066dc9df39c4283eceba5b6bd2bb68
5
+ SHA512:
6
+ metadata.gz: 5d65ce412084256c66f6061c32301f4d48772aafd28b438049877191bb93d72592cc13b9727c46d445be4d7cb8d41fb1db2163ba22c1d03d3739fd0a64907d8f
7
+ data.tar.gz: b8ebe36c4cbff4e667b38dad208c305035bfc18623b68bace90ff8753f0a6aa7fb203fcec0332a959b155166c9a646d3cee455bb9601cf26b2abeee9d85f7d07
@@ -0,0 +1,49 @@
1
+ ## Filing an issue
2
+
3
+ When filing an issue, please provide these details:
4
+
5
+ * A comprehensive list of steps to reproduce the issue.
6
+ * The version of Nguyen.
7
+ * Any relevant stack traces ("Full trace" preferred)
8
+
9
+ In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
10
+
11
+ Any issue that is open for 14 days without actionable information or activity will be marked as "stalled" and then closed. Stalled issues can be re-opened if the information requested is provided.
12
+
13
+ ## Pull requests
14
+
15
+ We gladly accept pull requests to fix bugs and, in some circumstances, add new features to Spree.
16
+
17
+ Here's a quick guide:
18
+
19
+ 1. Fork the repo.
20
+
21
+ 2. Run the tests. We only take pull requests with passing tests, and it's great
22
+ to know that you have a clean slate:
23
+
24
+ bundle install
25
+ bundle exec rake test
26
+
27
+ 3. Add a test for your change. Only refactoring and documentation changes
28
+ require no new tests. If you are adding functionality or fixing a bug, we need
29
+ a test!
30
+
31
+ 4. Make the test pass.
32
+
33
+ 5. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
34
+
35
+ At this point you're waiting on us. We like to at least comment on, if not
36
+ accept, pull requests within three business days (and, typically, one business
37
+ day). We may suggest some changes or improvements or alternatives.
38
+
39
+ Syntax:
40
+
41
+ * Two spaces, no tabs.
42
+ * No trailing whitespace. Blank lines should not have any space.
43
+ * Prefer &&/|| over and/or.
44
+ * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or my_method my_arg.
45
+ * `a = b` and not `a=b`.
46
+ * `a_method { |block| ... }` and not `a_method { | block | ... }`
47
+ * Follow the conventions you see used in the source already.
48
+
49
+ And in case we didn't emphasize it enough: we love tests!
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2012 Trung Lê
3
+ Copyright (c) 2014 Trung Lê
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -0,0 +1,76 @@
1
+ # Nguyên the PDF Field Merger
2
+
3
+ A very lightweight library that fill PDF forms using XFDF/FDF with pdftk
4
+
5
+ You could download pdftk at http://www.accesspdf.com/pdftk/
6
+
7
+ Nguyên is a fork of Jens Krämer's pdf-forms with addition of filling forms with XFDF feature.
8
+
9
+ [![Build Status](https://secure.travis-ci.org/ruby-journal/nguyen.png)](http://travis-ci.org/ruby-journal/nguyen)
10
+ [![Code Climate](https://codeclimate.com/github/ruby-journal/nguyen/badges/gpa.svg)](https://codeclimate.com/github/ruby-journal/nguyen)
11
+
12
+ ## EXAMPLE:
13
+
14
+ ### FDF creation
15
+
16
+ ```ruby
17
+ fdf = Nguyen::Fdf.new(key: 'value', other_key: 'other value')
18
+ # use to_fdf if you just want the FDF data, without writing it to a file
19
+ puts fdf.to_fdf
20
+ # write fdf file
21
+ fdf.save_to('path/to/file.fdf')
22
+ ```
23
+
24
+ ### XFDF creation
25
+
26
+ ```ruby
27
+ xfdf = Nguyen::Xfdf.new(key: 'value', other_key: 'other value')
28
+ # use to_xfdf if you just want the XFDF data, without writing it to a file
29
+ puts xfdf.to_xfdf
30
+ # write xfdf file
31
+ xfdf.save_to('path/to/file.xfdf')
32
+ ```
33
+
34
+ ### Query form fields and fill out PDF forms with pdftk
35
+
36
+ ```ruby
37
+ # adjust the pdftk path to suit your pdftk installation
38
+ pdftk = Nguyen::PdftkWrapper.new('/usr/local/bin/pdftk')
39
+
40
+ # find out the field names that are present in form.pdf
41
+ pdftk.get_field_names('path/to/form.pdf')
42
+
43
+ # take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
44
+
45
+ # with fdf
46
+ fdf = Nguyen::Fdf.new(foo: 'bar')
47
+ pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', fdf)
48
+
49
+ # with xfdf
50
+ xfdf = Nguyen::Xfdf.new(foo: 'bar')
51
+ pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', xfdf)
52
+
53
+ # will work with xfdf or fdf xml string directly as well
54
+ xfdf_string = <<XML
55
+ <?xml version="1.0" encoding="UTF-8"?>
56
+ <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"><fields><field name="foo"><value>bar</value></field></fields></xfdf>
57
+ XML
58
+ # or xfdf_string = Nguyen::Xfdf.new(foo: 'bar').to_xfdf
59
+ pdftk.fill_form('/path/to/form', 'myform.pdf', xfdf_string)
60
+ ```
61
+
62
+ ## INSTALL:
63
+
64
+ gem install nguyen
65
+
66
+ ## Source Code:
67
+
68
+ git clone http://github.com/ruby-journal/nguyen.git
69
+
70
+ ## Contribution:
71
+
72
+ I greatly welcome contributions, please feel free to fork and submit pull request.
73
+
74
+ ## LICENSE
75
+
76
+ see [LICENSE](LICENSE)
@@ -1,11 +1,4 @@
1
- require 'nguyen/fdf'
2
- require 'nguyen/xfdf'
3
- require 'nguyen/pdf'
4
- require 'nguyen/pdftk_wrapper'
5
-
6
- module Nguyen
7
- # shorthand for Nguyen::PdftkWrapper.new(...)
8
- def self.new(*args)
9
- PdftkWrapper.new(*args)
10
- end
11
- end
1
+ require_relative 'nguyen/fdf'
2
+ require_relative 'nguyen/xfdf'
3
+ require_relative 'nguyen/pdf'
4
+ require_relative 'nguyen/pdftk_wrapper'
@@ -11,9 +11,9 @@ module Nguyen
11
11
  def initialize(data = {}, options = {})
12
12
  @data = data
13
13
  @options = {
14
- :file => nil,
15
- :ufile => nil,
16
- :id => nil
14
+ file: nil,
15
+ ufile: nil,
16
+ id: nil
17
17
  }.merge(options)
18
18
  end
19
19
 
@@ -37,7 +37,7 @@ module Nguyen
37
37
 
38
38
  # write fdf content to path
39
39
  def save_to(path)
40
- (File.open(path, 'w') << to_fdf).close
40
+ File.write(path, to_fdf)
41
41
  end
42
42
 
43
43
  protected
@@ -86,4 +86,4 @@ EOFOOTER
86
86
  end
87
87
 
88
88
  end
89
- end
89
+ end
@@ -14,11 +14,11 @@ module Nguyen
14
14
  @options = options
15
15
  end
16
16
 
17
- # pdftk.fill_form '/path/to/form.pdf', '/path/to/destination.pdf', xfdf_or_fdf_object
18
- def fill_form(template, destination, form_data_format)
17
+ # pdftk.fill_form '/path/to/form.pdf', '/path/to/destination.pdf', xfdf_or_fdf_object or xfdf_or_fdf_string
18
+ def fill_form(template, destination, form_data)
19
19
  tmp = Tempfile.new('pdf_forms-fdf')
20
20
  tmp.close
21
- form_data_format.save_to tmp.path
21
+ form_data.respond_to?(:save_to) ? form_data.save_to(tmp.path) : File.write(tmp.path, form_data)
22
22
  command = pdftk_command %Q("#{template}"), 'fill_form', %Q("#{tmp.path}"), 'output', destination, add_options(tmp.path)
23
23
  output = %x{#{command}}
24
24
  unless File.readable?(destination) && File.size(destination) > 0
@@ -29,7 +29,7 @@ module Nguyen
29
29
  end
30
30
 
31
31
  # pdftk.read '/path/to/form.pdf'
32
- # returns an instance of PdfForms::Pdf representing the given template
32
+ # returns an instance of Nguyen::Pdf representing the given template
33
33
  def read(path)
34
34
  Pdf.new path, self
35
35
  end
@@ -44,7 +44,7 @@ module Nguyen
44
44
 
45
45
  def cat(*files,output)
46
46
  files = files[0] if files[0].class == Array
47
- input = files.map{|f| %Q("#{f}")}
47
+ input = files.map{|f| %Q(#{f})}
48
48
  call_pdftk(*input,'output',output)
49
49
  end
50
50
 
@@ -0,0 +1,3 @@
1
+ module Nguyen
2
+ VERSION = '1.0.3'
3
+ end
@@ -8,20 +8,20 @@ module Nguyen
8
8
  def initialize(fields = {}, options = {})
9
9
  @fields = fields
10
10
  @options = {
11
- :file => nil,
12
- :id => nil
11
+ file: nil,
12
+ id: nil
13
13
  }.merge(options)
14
14
  end
15
15
 
16
16
  # generate XFDF content
17
17
  def to_xfdf
18
- builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
18
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
19
19
  xml.xfdf('xmlns' => 'http://ns.adobe.com/xfdf/', 'xml:space' => 'preserve') {
20
- xml.f(:href => options[:file]) if options[:file]
21
- xml.ids(:original => options[:id], :modified => options[:id]) if options[:id]
20
+ xml.f(href: options[:file]) if options[:file]
21
+ xml.ids(original: options[:id], modified: options[:id]) if options[:id]
22
22
  xml.fields {
23
23
  @fields.each do |field, value|
24
- xml.field(:name => field) {
24
+ xml.field(name: field) {
25
25
  if value.is_a? Array
26
26
  value.each { |item| xml.value(item.to_s) }
27
27
  else
@@ -32,13 +32,13 @@ module Nguyen
32
32
  }
33
33
  }
34
34
  end
35
- builder.to_xml
35
+ builder.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
36
36
  end
37
37
 
38
38
  # write fdf content to path
39
39
  def save_to(path)
40
- (File.open(path, 'w') << to_xfdf).close
40
+ File.write(path, to_xfdf)
41
41
  end
42
42
 
43
43
  end
44
- end
44
+ end
metadata CHANGED
@@ -1,69 +1,81 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nguyen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 1.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Trung Lê
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 1.5.5
19
+ version: '1.10'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 1.5.5
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
30
41
  description: Forms for Nguyên is Ruby library that could merge PDF fields by XFDF/FDF
31
42
  via pdftk.
32
- email: joneslee85@gmail.com
43
+ email: trung.le@ruby-journal.com
33
44
  executables: []
34
45
  extensions: []
35
46
  extra_rdoc_files: []
36
47
  files:
48
+ - CONTRIBUTING.md
49
+ - LICENSE
50
+ - README.md
51
+ - lib/nguyen.rb
37
52
  - lib/nguyen/fdf.rb
38
53
  - lib/nguyen/pdf.rb
39
54
  - lib/nguyen/pdftk_wrapper.rb
55
+ - lib/nguyen/version.rb
40
56
  - lib/nguyen/xfdf.rb
41
- - lib/nguyen.rb
42
- - LICENSE
43
- - README.rdoc
44
- homepage: http://github.com/joneslee85/nguyen
45
- licenses: []
57
+ homepage: http://github.com/ruby-journal/nguyen
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
46
61
  post_install_message:
47
62
  rdoc_options: []
48
63
  require_paths:
49
64
  - lib
50
65
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
66
  requirements:
53
- - - ! '>='
67
+ - - ">="
54
68
  - !ruby/object:Gem::Version
55
- version: 1.8.7
69
+ version: 2.5.0
56
70
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
71
  requirements:
59
- - - ! '>='
72
+ - - ">="
60
73
  - !ruby/object:Gem::Version
61
- version: 1.3.6
74
+ version: '0'
62
75
  requirements:
63
76
  - pdtk 1.44.1 or newer
64
- rubyforge_project:
65
- rubygems_version: 1.8.24
77
+ rubygems_version: 3.0.3
66
78
  signing_key:
67
- specification_version: 3
79
+ specification_version: 4
68
80
  summary: Fill out PDF forms by XFDF/FDF via pdftk.
69
81
  test_files: []
@@ -1,60 +0,0 @@
1
- = Nguyên the PDF Field Merger
2
-
3
- A very lightweight library that fill PDF forms using XFDF/FDF with pdftk
4
-
5
- You could download pdftk at http://www.accesspdf.com/pdftk/
6
-
7
- Nguyên is a fork of Jens Krämer's pdf-forms with addition of filling forms with XFDF feature.
8
-
9
- == EXAMPLE:
10
-
11
- === FDF creation
12
-
13
- fdf = Nguyen::Fdf.new(:key => 'value', :other_key => 'other value')
14
- # use to_fdf if you just want the FDF data, without writing it to a file
15
- puts fdf.to_fdf
16
- # write fdf file
17
- fdf.save_to('path/to/file.fdf')
18
-
19
-
20
- === XFDF creation
21
-
22
- xfdf = Nguyen::Xfdf.new(:key => 'value', :other_key => 'other value')
23
- # use to_xfdf if you just want the XFDF data, without writing it to a file
24
- puts xfdf.to_xfdf
25
- # write xfdf file
26
- xfdf.save_to('path/to/file.xfdf')
27
-
28
- === Query form fields and fill out PDF forms with pdftk
29
-
30
- # adjust the pdftk path to suit your pdftk installation
31
- pdftk = Nguyen.new('/usr/local/bin/pdftk')
32
-
33
- # find out the field names that are present in form.pdf
34
- pdftk.get_field_names('path/to/form.pdf')
35
-
36
- # take form.pdf, set the 'foo' field to 'bar' and save the document to myform.pdf
37
-
38
- # with fdf
39
- fdf = Nguyen::Fdf(:foo => 'bar')
40
- pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', fdf)
41
-
42
- # with xfdf
43
- xfdf = Nguyen::Xfdf(:foo => 'bar')
44
- pdftk.fill_form('/path/to/form.pdf', 'myform.pdf', xfdf)
45
-
46
- == INSTALL:
47
-
48
- $ gem install nguyen
49
-
50
- == Source Code:
51
-
52
- $ git clone http://github.com/joneslee85/nguyen.git
53
-
54
- == Contribution:
55
-
56
- I greatly welcome contributions, please feel free to fork and submit pull request.
57
-
58
- == LICENSE
59
-
60
- see LICENSE