prince_merge 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/bin/prince_merge +5 -0
- data/lib/prince_merge.rb +38 -0
- data/prince_merge.gemspec +22 -0
- data/templates/standard_envelope.haml +50 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Hugh Evans
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Prince Merge
|
2
|
+
============
|
3
|
+
|
4
|
+
Generate multiple addressed PDFs with the excellent [PrinceXML](http://princexml.com).
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
ruby prince_merge.rb addresses.csv mailrun.pdf
|
10
|
+
|
11
|
+
The first argument is a CSV containing the recipients. The CSV file needs a headers row and the bundled ``standard_envelope.haml`` template requires the following:
|
12
|
+
|
13
|
+
name
|
14
|
+
address_one
|
15
|
+
address_two
|
16
|
+
address_three
|
17
|
+
city
|
18
|
+
state
|
19
|
+
postal_code
|
20
|
+
country
|
21
|
+
|
22
|
+
The second argument is the file for output. There is also an optional third argument for specifying a different [HAML](http://haml-lang.com) template:
|
23
|
+
|
24
|
+
ruby prince_merge.rb addresses.csv mailrun.pdf letter.haml
|
25
|
+
|
26
|
+
TODO
|
27
|
+
----
|
28
|
+
|
29
|
+
* Make and publish a gem with an executable +prince_merge+
|
30
|
+
* Add some inline usage
|
31
|
+
* Error handling
|
32
|
+
|
33
|
+
Contributors
|
34
|
+
------------
|
35
|
+
|
36
|
+
* [Hugh Evans](http://github.com/hughevans)
|
37
|
+
* [Tim Riley](http://github.com/timriley)
|
38
|
+
* [Jared Fraser](http://github.com/modsognir)
|
39
|
+
|
40
|
+
Copyright
|
41
|
+
---------
|
42
|
+
|
43
|
+
Copyright © 2010 Hugh Evans. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/prince_merge
ADDED
data/lib/prince_merge.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
require 'haml'
|
5
|
+
require 'prince-ruby'
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
class PrinceMerge
|
9
|
+
attr_accessor :input, :output, :template
|
10
|
+
|
11
|
+
def initialize(input, output, template = nil)
|
12
|
+
@input = input
|
13
|
+
@output = output
|
14
|
+
@template = File.expand_path(File.dirname(__FILE__) + "/../templates/#{template || 'standard_envelope.haml'}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def template
|
18
|
+
File.read(@template)
|
19
|
+
end
|
20
|
+
|
21
|
+
def html
|
22
|
+
Haml::Engine.new(template).render(Object.new, :recipients => Recipient.load_from_csv(input))
|
23
|
+
end
|
24
|
+
|
25
|
+
def render
|
26
|
+
Prince.new.html_to_file(html, output)
|
27
|
+
end
|
28
|
+
|
29
|
+
class Recipient < OpenStruct
|
30
|
+
def self.load_from_csv(file)
|
31
|
+
recipients = []
|
32
|
+
CSV.foreach(file, :headers => true) do |row|
|
33
|
+
recipients << new(row.to_hash.delete_if {|k,v| k == nil})
|
34
|
+
end
|
35
|
+
recipients
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "prince_merge"
|
7
|
+
gem.version = "0.0.1"
|
8
|
+
gem.authors = ["Hugh Evans", "Jared Fraser"]
|
9
|
+
gem.email = ["hugh@artpop.com.au", "dev@jsf.io"]
|
10
|
+
gem.description = %q{A mail merge for developers.}
|
11
|
+
gem.summary = %q{A mail merge for developers.}
|
12
|
+
gem.homepage = ""
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency('haml', '>= 3.0.0')
|
20
|
+
gem.add_dependency('sass', '>= 3.0.0')
|
21
|
+
gem.add_dependency('prince-ruby', '>= 0.0.0')
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%style
|
5
|
+
:sass
|
6
|
+
@page
|
7
|
+
margin: 2cm
|
8
|
+
size: 22cm 11cm
|
9
|
+
body
|
10
|
+
background: #FFF
|
11
|
+
color: #000000
|
12
|
+
font-family: arial, "sans-serif"
|
13
|
+
font-size: 1em
|
14
|
+
.envelope
|
15
|
+
page-break-after: always
|
16
|
+
margin: 4cm 5cm
|
17
|
+
.name
|
18
|
+
margin-bottom: 0.3cm
|
19
|
+
.city_state_and_postal_code
|
20
|
+
margin-top: 0.1cm
|
21
|
+
.country
|
22
|
+
margin-top: 0.3cm
|
23
|
+
.postal_code
|
24
|
+
padding-left: 0.5cm
|
25
|
+
%body
|
26
|
+
- recipients.each do |recipient|
|
27
|
+
.envelope
|
28
|
+
.name
|
29
|
+
= recipient.name
|
30
|
+
|
31
|
+
.address_one
|
32
|
+
= recipient.address_one
|
33
|
+
|
34
|
+
- if recipient.address_two
|
35
|
+
.address_two
|
36
|
+
=recipient.address_two
|
37
|
+
|
38
|
+
- if recipient.address_three
|
39
|
+
.address_three
|
40
|
+
=recipient.address_three
|
41
|
+
|
42
|
+
.city_state_and_postal_code
|
43
|
+
== #{recipient.city},
|
44
|
+
= recipient.state
|
45
|
+
|
46
|
+
%span.postal_code
|
47
|
+
= recipient.postal_code
|
48
|
+
|
49
|
+
.country
|
50
|
+
= recipient.country.upcase
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prince_merge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hugh Evans
|
9
|
+
- Jared Fraser
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: haml
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: sass
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 3.0.0
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: prince-ruby
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.0.0
|
63
|
+
description: A mail merge for developers.
|
64
|
+
email:
|
65
|
+
- hugh@artpop.com.au
|
66
|
+
- dev@jsf.io
|
67
|
+
executables:
|
68
|
+
- prince_merge
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- Gemfile
|
74
|
+
- LICENSE
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- bin/prince_merge
|
78
|
+
- lib/prince_merge.rb
|
79
|
+
- prince_merge.gemspec
|
80
|
+
- templates/standard_envelope.haml
|
81
|
+
homepage: ''
|
82
|
+
licenses: []
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.23
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: A mail merge for developers.
|
105
|
+
test_files: []
|