no_notifier_needed 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm_install_on_use_flag=1
2
+ rvm_gemset_create_on_use_flag=1
3
+ rvm 1.9.3-p125@no_notifier
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'haml'
6
+ gem 'rails', '>= 3.2.11'
7
+
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", ">= 1.2.3"
15
+ gem "jeweler", "~> 1.8.4"
16
+ gem "simplecov", ">= 0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.11)
5
+ actionpack (= 3.2.11)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.11)
8
+ activemodel (= 3.2.11)
9
+ activesupport (= 3.2.11)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.11)
18
+ activesupport (= 3.2.11)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.11)
21
+ activemodel (= 3.2.11)
22
+ activesupport (= 3.2.11)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.11)
26
+ activemodel (= 3.2.11)
27
+ activesupport (= 3.2.11)
28
+ activesupport (3.2.11)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ bourne (1.1.2)
33
+ mocha (= 0.10.5)
34
+ builder (3.0.4)
35
+ erubis (2.7.0)
36
+ git (1.2.5)
37
+ haml (3.1.7)
38
+ hike (1.2.1)
39
+ i18n (0.6.1)
40
+ jeweler (1.8.4)
41
+ bundler (~> 1.0)
42
+ git (>= 1.2.5)
43
+ rake
44
+ rdoc
45
+ journey (1.0.4)
46
+ json (1.7.6)
47
+ mail (2.4.4)
48
+ i18n (>= 0.4.0)
49
+ mime-types (~> 1.16)
50
+ treetop (~> 1.4.8)
51
+ metaclass (0.0.1)
52
+ mime-types (1.19)
53
+ mocha (0.10.5)
54
+ metaclass (~> 0.0.1)
55
+ multi_json (1.5.0)
56
+ polyglot (0.3.3)
57
+ rack (1.4.3)
58
+ rack-cache (1.2)
59
+ rack (>= 0.4)
60
+ rack-ssl (1.3.2)
61
+ rack
62
+ rack-test (0.6.2)
63
+ rack (>= 1.0)
64
+ rails (3.2.11)
65
+ actionmailer (= 3.2.11)
66
+ actionpack (= 3.2.11)
67
+ activerecord (= 3.2.11)
68
+ activeresource (= 3.2.11)
69
+ activesupport (= 3.2.11)
70
+ bundler (~> 1.0)
71
+ railties (= 3.2.11)
72
+ railties (3.2.11)
73
+ actionpack (= 3.2.11)
74
+ activesupport (= 3.2.11)
75
+ rack-ssl (~> 1.3.2)
76
+ rake (>= 0.8.7)
77
+ rdoc (~> 3.4)
78
+ thor (>= 0.14.6, < 2.0)
79
+ rake (10.0.3)
80
+ rdoc (3.12)
81
+ json (~> 1.4)
82
+ shoulda (3.3.2)
83
+ shoulda-context (~> 1.0.1)
84
+ shoulda-matchers (~> 1.4.1)
85
+ shoulda-context (1.0.2)
86
+ shoulda-matchers (1.4.2)
87
+ activesupport (>= 3.0.0)
88
+ bourne (~> 1.1.2)
89
+ simplecov (0.7.1)
90
+ multi_json (~> 1.0)
91
+ simplecov-html (~> 0.7.1)
92
+ simplecov-html (0.7.1)
93
+ sprockets (2.2.2)
94
+ hike (~> 1.2)
95
+ multi_json (~> 1.0)
96
+ rack (~> 1.0)
97
+ tilt (~> 1.1, != 1.3.0)
98
+ thor (0.16.0)
99
+ tilt (1.3.3)
100
+ treetop (1.4.12)
101
+ polyglot
102
+ polyglot (>= 0.3.1)
103
+ tzinfo (0.3.35)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ bundler (>= 1.2.3)
110
+ haml
111
+ jeweler (~> 1.8.4)
112
+ rails (>= 3.2.11)
113
+ rdoc (~> 3.12)
114
+ shoulda
115
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Robert R. Meyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ no_notifier_needed
2
+ ==================
3
+
4
+ Cleaning up Notifier file to allow for Email Templates in HAML and ERB with Resque and God
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = no_notifier_needed
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to no_notifier_needed
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Robert R. Meyer. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "no_notifier_needed"
18
+ gem.homepage = "http://github.com/Blue-Dog-Archolit/no_notifier_needed"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Gem used to reduce the size of Notifier and provide Templates}
21
+ gem.description = %Q{A work in progress}
22
+ gem.email = "Blue.Dog.Archolite@gmail.com"
23
+ gem.authors = ["Robert R. Meyer"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "no_notifier_needed #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,14 @@
1
+ require 'no_notifier_needed/send'
2
+ require 'no_notifier_needed/translate'
3
+ require 'no_notifier_needed/render'
4
+
5
+
6
+ module NoNotifierNeeded
7
+ include NoNotifierNeeded::Send
8
+ include NoNotifierNeeded::Translate
9
+ include NoNotifierNeeded::Render
10
+
11
+ end
12
+
13
+ require 'no_notifier_needed/railtie.rb' if defined?(Rails)
14
+ ::ActionMailer::Base.extend NoNotifierNeeded
@@ -0,0 +1,13 @@
1
+ module NoNotifierNeeded
2
+ class Railtie < Rails::Railtie
3
+ initializer "Include code in controller" do
4
+ ActiveSupport.on_load(:action_controller) do
5
+
6
+ #::ActionMailer::Base.send(:include, ActionView::Helpers::)
7
+ ::ActionMailer::Base.send(:include, Rails.application.routes.url_helpers) # brings ActionDispatch::Routing::UrlFor
8
+ ::ActionMailer::Base.send(:include, ActionView::Helpers::UrlHelper)
9
+ ::ActionMailer::Base.send(:include, ActionView::Helpers::TextHelper)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module NoNotifierNeeded
2
+ module Render
3
+ def render_template_body_type(template)
4
+ result = template.template_type == 'haml' ? render_haml(template.body) : render_erb(template.body)
5
+ result.strip!
6
+ end
7
+
8
+ def render_template_subject_type(template)
9
+ result = template.template_type == 'haml' ? render_haml(template.subject) : render_erb(template.subject)
10
+ result.strip!
11
+ end
12
+
13
+ def render_haml(template_string)
14
+ Haml::Engine.new(template_string).render(self)
15
+ end
16
+
17
+ def render_erb(template_string)
18
+ ERB.new(template_string).result(binding)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module NoNotifierNeeded
2
+ module Send
3
+ def send_now(which_email, *args)
4
+ email_hash = translate_to_hash(which_email, args)
5
+ Resque.enqueue(EmailProcessor, email_hash)
6
+ end
7
+
8
+ def send_in(time_from_now, which_email, *args)
9
+ email_hash = translate_to_hash(which_email, args)
10
+ Resque.enqueue_at(time_from_now, EmailProcessor, email_hash)
11
+ end
12
+
13
+ def send_at(what_time, which_email, *args)
14
+ email_hash = translate_to_hash(which_email, args)
15
+ time_from_now = what_time.is_a?(Time) ? what_time : Chronic.parse(what_time)
16
+ Resque.enqueue_at(time_from_now, EmailProcessor, email_hash)
17
+ end
18
+
19
+ def mcp(email_name, args)
20
+ @template = EmailTemplate.find_by_name(email_name)
21
+ raise "Email Template name not found" if @template.nil?
22
+
23
+ args_to_instance_vars(args)
24
+
25
+
26
+ mail_is = ActionMailer::Base.mail(get_send_hash) do|format|
27
+ format.html { render :inline => render_template_body_type(@template) }
28
+ end
29
+
30
+ return mail_is
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,73 @@
1
+ module NoNotifierNeeded
2
+ module Translate
3
+ def url_for(destination)
4
+ unless destination.is_a?(Hash) || destination.match(/_path/i)
5
+ raise ArgumentError.new(" must pass something that ends with a _path. #{destination} sent.")
6
+ end
7
+ to_send = "Rails.application.routes.url_helpers.#{destination}"
8
+ instance_eval to_send
9
+ end
10
+
11
+ def email_link_to(title, link)
12
+ return title if link.blank?
13
+ if link.match(/http:\/\/[\w*\.]*\//i)
14
+ root_link = link
15
+ else
16
+ link_broken = link.split('//dabble.co').last
17
+ link_broken = link_broken.split('/').reject{|e| e.blank?}.join('/')
18
+ root_link = "http://dabble.co/" + link_broken
19
+ end
20
+ "<a href='#{root_link}'>#{title}</a>"
21
+ end
22
+
23
+ def get_send_hash
24
+ mailers = ActiveSupport::DescendantsTracker.descendants(ActionMailer::Base)
25
+ send_hash = {}
26
+ send_hash.merge!(mailers.first.default)
27
+
28
+ send_hash[:subject] = render_template_subject_type(@template)
29
+ send_hash[:to] = @to.nil? ? @user.email : @to
30
+ send_hash[:from] = @from unless @from.nil?
31
+ send_hash[:reply_to] = @reply_to unless @reply_to.nil?
32
+ send_hash
33
+ end
34
+
35
+ def args_to_instance_vars(args)
36
+ #take each key, if a model, make it an @#{model} = model.find(value)
37
+ known_models = ActiveRecord::Base.send( :subclasses )
38
+
39
+ #else make it a @#{name}=#{value}
40
+ args.each do |k,v|
41
+ if Object.const_defined?(k.classify) && known_models.include?(k.classify.constantize)
42
+ self.instance_eval("@#{k}= #{k.classify}.find(#{v})")
43
+ else
44
+ if v.is_a?(String)
45
+ self.instance_eval("@#{k} = \"#{v}\"")
46
+ else
47
+ self.instance_eval("@#{k}=#{v}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def translate_to_hash(which_email, args)
54
+ known_models = ActiveRecord::Base.send( :subclasses )
55
+
56
+ th = {}
57
+ th[:which_email] = which_email
58
+
59
+ args = args.flatten if args.respond_to?(:flatten)
60
+ args.each do |a|
61
+ next if a.blank?
62
+ if known_models.include?(a.class)
63
+ th[a.class.name.downcase.to_sym] = a.id
64
+ elsif a.is_a?(Hash)
65
+ a.each{|k,v| th[k.to_sym] = CGI.escapeHTML(v) }
66
+ else
67
+ raise ArgumentError.new("Unknown values passed to email procesor '#{a}' with #{args.inspect}")
68
+ end
69
+ end
70
+ th
71
+ end
72
+ end
73
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'no_notifier_needed'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestNoNotifierNeeded < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: no_notifier_needed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert R. Meyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: haml
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.2.11
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.11
46
+ - !ruby/object:Gem::Dependency
47
+ name: shoulda
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.2.3
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.3
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.4
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A work in progress
127
+ email: Blue.Dog.Archolite@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files:
131
+ - LICENSE.txt
132
+ - README.md
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rvmrc
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - README.rdoc
142
+ - Rakefile
143
+ - VERSION
144
+ - lib/no_notifier_needed.rb
145
+ - lib/no_notifier_needed/railtie.rb
146
+ - lib/no_notifier_needed/render.rb
147
+ - lib/no_notifier_needed/send.rb
148
+ - lib/no_notifier_needed/translate.rb
149
+ - test/helper.rb
150
+ - test/test_no_notifier_needed.rb
151
+ homepage: http://github.com/Blue-Dog-Archolit/no_notifier_needed
152
+ licenses:
153
+ - MIT
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: 2611355939096765334
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.24
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: A Gem used to reduce the size of Notifier and provide Templates
179
+ test_files: []