Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

action mailer support (merge_mailer feature)

  • Loading branch information...
commit 76091f308d5c52dca3911ecdc83cc0603ab3da92 1 parent b500eb0
Roman rkononov authored
Showing with 27 additions and 3 deletions.
  1. +12 −1 lib/simple_worker/base.rb
  2. +15 −2 lib/simple_worker/service.rb
13 lib/simple_worker/base.rb
View
@@ -12,12 +12,14 @@ class << self
@merged = []
@merged_workers = []
@merged_gems = []
+ @merged_mailers = []
@unmerged = []
def reset!
@merged = []
@merged_workers = []
@merged_gems = []
+ @merged_mailers = []
@unmerged = []
end
@@ -76,6 +78,14 @@ def merge_gem(gem_name, version=nil)
require gem_info[:require] || gem_name
end
+ #merge action_mailer mailers
+ def merge_mailer(mailer, params={})
+ check_for_file mailer
+ basename = File.basename(mailer, File.extname(mailer))
+ path_to_templates = params[:path_to_templates]||File.join(Rails.root, "app/views/#{basename}")
+ @merged_mailers<<{:name=>basename, :path_to_templates=>path_to_templates, :filename => mailer}.merge!(params)
+ end
+
# merges the specified files.
# todo: don't allow multiple files per merge, just one like require
def merge(*files)
@@ -276,6 +286,7 @@ def upload_if_needed
merged = self.class.instance_variable_get(:@merged)
unmerged = self.class.instance_variable_get(:@unmerged)
merged_gems = self.class.instance_variable_get(:@merged_gems)
+ merged_mailers = self.class.instance_variable_get(:@merged_mailers)
# puts 'merged1=' + merged.inspect
subclass = self.class
@@ -294,7 +305,7 @@ def upload_if_needed
# puts 'merged with superclass=' + merged.inspect
end
merged += SimpleWorker.config.models if SimpleWorker.config.models
- SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems)
+ SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers)
self.class.instance_variable_set(:@uploaded, true)
else
SimpleWorker.logger.debug 'Already uploaded for ' + self.class.name
17 lib/simple_worker/service.rb
View
@@ -59,7 +59,7 @@ def upload(filename, class_name, options={})
end
- zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems])
+ zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:merged_mailers])
# sys.classes[subclass].__file__
# puts '__FILE__=' + Base.subclass.__file__.to_s
@@ -98,7 +98,7 @@ def get_gem_path(gem_info)
end
end
- def build_merged_file(filename, merge, unmerge, merged_gems)
+ def build_merged_file(filename, merge, unmerge, merged_gems,merged_mailers)
# unless (merge && merge.size > 0) || (merged_gems && merged_gems.size > 0)
# return filename
# end
@@ -117,6 +117,10 @@ def build_merged_file(filename, merge, unmerge, merged_gems)
f.write "require '#{r}'\n"
end
end
+ if merged_mailers
+ f.write "require 'action_mailer'\n"
+ f.write "ActionMailer::Base.prepend_view_path('templates')\n"
+ end
f.write File.open(filename, 'r') { |mo| mo.read }
end
merge << tmp_file
@@ -152,6 +156,15 @@ def build_merged_file(filename, merge, unmerge, merged_gems)
# puts "merging #{m} into #{filename}"
f.add(File.basename(m), m)
end
+ merged_mailers.each do |mailer|
+ puts "Collecting mailer #{mailer[:name]}"
+ f.add(File.basename(mailer[:filename]), mailer[:filename])
+ path = mailer[:path_to_templates]
+ Dir["#{path}/**/**"].each do |file|
+ zdest = "templates/#{mailer[:name]}/#{file.sub(path+'/', '')}"
+ f.add(zdest, file)
+ end
+ end
end
fname2
end
Please sign in to comment.
Something went wrong with that request. Please try again.