mail_merge 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mail_merge.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ = mail_merge
2
+
3
+ Mail Merge Gem
4
+
5
+ Parses a string and replaces specified merge fields with the evaluated result:
6
+
7
+ [Usage]
8
+ * MailMerge.merge(content, options = {}, merge_fields = [], delimeter = "::")
9
+
10
+ [Examples]
11
+ * merged_content = MailMerge.merge(content, {:site => @site, :user => @user}, ['::site.name::', '::user.full_name::']) # Basic example
12
+ * merged_content = MailMerge.merge(content, {:site => @site, :user => @user}) # This will evaluate any merge fields that start with 'site' or 'user'
13
+ * merged_content = MailMerge.merge(content, {:site => @site, :user => @user}, ['~~site.name~~', '~~user.full_name~~'], "~~") # Using your own delimeter
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,28 @@
1
+ module MailMerge
2
+ # Performs a mail merge based on the options hash that is passed in
3
+ # Example: MailMerge.merge(content, {:site => @site, :user => @user}, ['::site.name::', '::user.full_name::'])
4
+ # will search text_block.content and find all instances of ::user.[method]::
5
+ # and ::site.[method]:: and send the [method] to the associated object
6
+ # Chaining works as well (ex. ::site.organization.name:: yields 'TST Media')
7
+ def self.merge(content, options = {}, merge_fields = [], delimeter = "::")
8
+ merged = content
9
+ options.keys.each do |key|
10
+ obj = options[key]
11
+ merged = merged.gsub(/#{delimeter}#{key.to_s}\.[\w|\.]*#{delimeter}/) do |s|
12
+ if merge_fields.empty? or merge_fields.include?(s)
13
+ begin
14
+ res = s[/\..*\w/][/\w.*/].split('.').collect{|m| obj = obj.send(m)}.last
15
+ obj = options[key]
16
+ res
17
+ rescue
18
+ s
19
+ end
20
+ else
21
+ s
22
+ end
23
+ end
24
+ end
25
+ merged
26
+ end
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module MailMerge
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mail_merge/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mail_merge"
7
+ s.version = MailMerge::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ian Ehlert"]
10
+ s.email = ["ehlertij@gmail.com"]
11
+ s.homepage = "https://github.com/ehlertij/mail_merge"
12
+ s.summary = %q{Mail Merge Gem}
13
+ s.description = %q{A simple gem that will perform a mail merge on a string based on merge fields provided.}
14
+
15
+ s.rubyforge_project = "mail_merge"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail_merge
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 4
10
+ version: 0.0.4
11
+ platform: ruby
12
+ authors:
13
+ - Ian Ehlert
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-12 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A simple gem that will perform a mail merge on a string based on merge fields provided.
23
+ email:
24
+ - ehlertij@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/mail_merge.rb
37
+ - lib/mail_merge/version.rb
38
+ - mail_merge.gemspec
39
+ has_rdoc: true
40
+ homepage: https://github.com/ehlertij/mail_merge
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: mail_merge
69
+ rubygems_version: 1.6.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Mail Merge Gem
73
+ test_files: []
74
+