the_merger 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ #source 'https://rubygems.org'
2
+ source 'http://rubygems.railscamp.org'
3
+ gem 'rake'
4
+ # Specify your gem's dependencies in the_merger.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Pope
2
+
3
+ MIT License
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,65 @@
1
+ # TheMerger
2
+
3
+ A mail merge gem which allows you to do the following;
4
+ - link to a table eg: clients.
5
+ - dynamically collects fields from the linked table and displays them in a helper drop down box
6
+ - creates a letters table to store you custom letters to be mail merged
7
+ - does the mail merging part which is to regex a body of text and replace with fields
8
+ - manages bulk emails
9
+ - manages scheduled emails (optional)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'the_merger'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install the_merger
24
+
25
+ ## Configure
26
+
27
+ When using TheMerger in a controller you have to add the following line to the top
28
+
29
+ include TheMerger
30
+
31
+ Create a yaml file in your config directory called 'the_merger.yml' with something like this
32
+
33
+ ---
34
+ merge_model: "Client"
35
+
36
+
37
+ To use the javascript included in this gem put the following in your application.js
38
+
39
+ //= require the_merger/application
40
+
41
+ ## Usage
42
+
43
+ Currently it's just one method and this is how you pass it information
44
+
45
+ body = "Dear [firstname] [lastname], Please update your listing, from Mick"
46
+ TheMerger.merge_fields(body, "firstname", "lastname")
47
+
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
56
+
57
+ ## TODO
58
+
59
+ - DONE - Get all users from the users table
60
+ - DONE - Mail merge and output to the screen
61
+ - DONE - Make the table a variable
62
+ - DONE - Create a method to get all fields from the selected table.
63
+ - DONE - Create a helper method to have a dropdown of fields
64
+ - DONE - Turn this into an engine so that I can include asset pipeline javascript.
65
+ - Get the Email all button to work
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,71 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 2010 C. F., Wong (<a href="http://cloudgen.w0ng.hk">Cloudgen Examplet Store</a>)
4
+ * Licensed under the MIT License:
5
+ * http://www.opensource.org/licenses/mit-license.php
6
+ *
7
+ */
8
+ (function($,len,createRange,duplicate){
9
+ $.fn.caret=function(options,opt2){
10
+ var start,end,t=this[0],browser='';//,browser=$.browser.msie;
11
+ if(typeof options==="object" && typeof options.start==="number" && typeof options.end==="number") {
12
+ start=options.start;
13
+ end=options.end;
14
+ } else if(typeof options==="number" && typeof opt2==="number"){
15
+ start=options;
16
+ end=opt2;
17
+ } else if(typeof options==="string"){
18
+ if((start=t.value.indexOf(options))>-1) end=start+options[len];
19
+ else start=null;
20
+ } else if(Object.prototype.toString.call(options)==="[object RegExp]"){
21
+ var re=options.exec(t.value);
22
+ if(re != null) {
23
+ start=re.index;
24
+ end=start+re[0][len];
25
+ }
26
+ }
27
+ if(typeof start!="undefined"){
28
+ if(browser){
29
+ var selRange = this[0].createTextRange();
30
+ selRange.collapse(true);
31
+ selRange.moveStart('character', start);
32
+ selRange.moveEnd('character', end-start);
33
+ selRange.select();
34
+ } else {
35
+ this[0].selectionStart=start;
36
+ this[0].selectionEnd=end;
37
+ }
38
+ this[0].focus();
39
+ return this
40
+ } else {
41
+ // Modification as suggested by Андрей Юткин
42
+ if(browser){
43
+ var selection=document.selection;
44
+ if (this[0].tagName.toLowerCase() != "textarea") {
45
+ var val = this.val(),
46
+ range = selection[createRange]()[duplicate]();
47
+ range.moveEnd("character", val[len]);
48
+ var s = (range.text == "" ? val[len]:val.lastIndexOf(range.text));
49
+ range = selection[createRange]()[duplicate]();
50
+ range.moveStart("character", -val[len]);
51
+ var e = range.text[len];
52
+ } else {
53
+ var range = selection[createRange](),
54
+ stored_range = range[duplicate]();
55
+ stored_range.moveToElementText(this[0]);
56
+ stored_range.setEndPoint('EndToEnd', range);
57
+ var s = stored_range.text[len] - range.text[len],
58
+ e = s + range.text[len]
59
+ }
60
+ // End of Modification
61
+ } else {
62
+ var s=t.selectionStart,
63
+ e=t.selectionEnd;
64
+ }
65
+ var te=t.value.substring(s,e);
66
+ return {start:s,end:e,text:te,replace:function(st){
67
+ return t.value.substring(0,s)+st+t.value.substring(e,t.value[len])
68
+ }}
69
+ }
70
+ }
71
+ })(jQuery,"length","createRange","duplicate");
@@ -0,0 +1,9 @@
1
+ #= require jquery.caret.1.02
2
+ #= require the_merger/insert_field
3
+
4
+ the_merger = new TheMerger
5
+
6
+ $ ->
7
+ $('.insert_field').click ->
8
+ the_merger.insert_field($(".mail_merge_body"), $("#field").val())
9
+ false
@@ -0,0 +1,9 @@
1
+ class window.TheMerger
2
+
3
+ insert_field: (body,field) ->
4
+ start=body.caret().start; # Get the start of the caret
5
+ first_half=body.val().slice(0, start); # Get all text up to caret
6
+ last_half=body.val().slice(start, body.len); # Get all text from caret to end
7
+ text = first_half + "[" + field + "]" + last_half # Glue it all together with field
8
+ body.val(text) # Put the result back into the text_area
9
+ false
@@ -0,0 +1,9 @@
1
+ class TheMerger::Mailer < ActionMailer::Base
2
+
3
+ def batch_mail(from,subject,body,person)
4
+ mail(from: from,
5
+ to: person.email,
6
+ subject: subject,
7
+ body: body)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ class TheMerger::Engine < Rails::Engine
2
+ engine_name :the_merger
3
+ end
@@ -0,0 +1,3 @@
1
+ module TheMerger
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ module TheMerger
2
+ module ViewHelpers
3
+ class FieldSelector
4
+ def select_field
5
+ "<b>Select field box</b>"
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/the_merger.rb ADDED
@@ -0,0 +1,54 @@
1
+ require "the_merger/version"
2
+
3
+ module TheMerger
4
+ #
5
+ # Default settings for TheMerger
6
+ #
7
+ # - merge_model: User
8
+ #
9
+
10
+ def merge_fields(subject,original_body)
11
+ parse_config
12
+
13
+ @merge_model.constantize.all.each do |user|
14
+ body = original_body.dup
15
+
16
+ model_fields.each do |field|
17
+ newbody = body.gsub!("[#{field}]", user.send(field))
18
+ body = newbody unless newbody.nil?
19
+ end
20
+
21
+ # Send the emails
22
+ mailer = TheMerger::Mailer.batch_mail("from@example.com", subject, body, user)
23
+ mailer.deliver
24
+
25
+ end
26
+ end
27
+
28
+ def field_selection
29
+ body = select_tag :field, options_for_select(model_fields)
30
+ body += button_tag "Insert", class: "insert_field"
31
+ content_tag(:div, body, class: "merge_field")
32
+ end
33
+
34
+ def model_fields
35
+ parse_config
36
+ @merge_model.constantize.attribute_names.reject{|x| %w[created_at updated_at id].include?(x)}
37
+ end
38
+
39
+ private
40
+
41
+ def parse_config
42
+ path = "#{Rails.root}/config/the_merger.yml"
43
+
44
+ if File.exists?(path)
45
+ conf=YAML::load(IO.read(path))
46
+ @merge_model = conf["merge_model"]
47
+ else
48
+ @merge_model = "User"
49
+ end
50
+ end
51
+ end
52
+
53
+ require "the_merger/engine"
54
+ ActionView::Base.send :include, TheMerger
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_merger/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "the_merger"
8
+ gem.version = TheMerger::VERSION
9
+ gem.authors = ["Michael Pope"]
10
+ gem.email = ["map7777@gmail.com"]
11
+ gem.description = %q{Mail merge a table of fields into a standard letter}
12
+ gem.summary = %q{Mail Merge}
13
+ gem.homepage = ""
14
+
15
+ # gem.add_development_dependency "mail"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_merger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Pope
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Mail merge a table of fields into a standard letter
15
+ email:
16
+ - map7777@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - app/assets/javascript/jquery.caret.1.02.js
27
+ - app/assets/javascript/the_merger/application.js.coffee
28
+ - app/assets/javascript/the_merger/insert_field.js.coffee
29
+ - app/mailer/the_merger/mailer.rb
30
+ - lib/the_merger.rb
31
+ - lib/the_merger/engine.rb
32
+ - lib/the_merger/version.rb
33
+ - lib/the_merger/view_helpers/field_selector.rb
34
+ - the_merger.gemspec
35
+ homepage: ''
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ segments:
48
+ - 0
49
+ hash: -3883735968301740834
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ segments:
57
+ - 0
58
+ hash: -3883735968301740834
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 1.8.23
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Mail Merge
65
+ test_files: []