capcode-render-mail 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 glejeune
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.
@@ -0,0 +1,3 @@
1
+ = capcode-render-mail
2
+
3
+ Capcode plugin to send mail
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-render-mail"
8
+ gem.summary = %Q{Capcode plugin to send mail}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+
14
+ gem.add_dependency('mail')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-render-mail}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-06}
13
+ s.description = %q{Capcode plugin to send mail}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-render-mail.gemspec",
24
+ "examples/mail/mail_html.rhtml",
25
+ "examples/mail/mail_text.rhtml",
26
+ "examples/mail/ok.rhtml",
27
+ "examples/mail/rubyfr.png",
28
+ "examples/render-email.rb",
29
+ "lib/capcode/render/email.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-render-mail}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Capcode plugin to send mail}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<mail>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<mail>, [">= 0"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<mail>, [">= 0"])
48
+ end
49
+ end
50
+
@@ -0,0 +1 @@
1
+ This mail was send at <b><%= @time %></b>
@@ -0,0 +1 @@
1
+ This mail was send at <%= @time %>
@@ -0,0 +1 @@
1
+ Mail <b>send !!!</b>
Binary file
@@ -0,0 +1,68 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ require 'capcode/render/markaby'
4
+ require 'capcode/render/erb'
5
+ require 'capcode/render/static'
6
+ require 'graphviz'
7
+ $:.unshift( "../lib" )
8
+ require 'capcode/render/email'
9
+
10
+ module Capcode
11
+ set :email, { :server => '127.0.0.1', :port => 25 }
12
+ set :erb, "mail"
13
+ set :static, "mail"
14
+
15
+ class Index < Route '/'
16
+ def get
17
+ render :markaby => :index, :layout => :glop
18
+ end
19
+ end
20
+
21
+ class SendMail < Route '/send'
22
+ def get
23
+ @time = Time.now
24
+ render :email => {
25
+ :from => 'you@yourdomain.com',
26
+ :to => 'friend@hisdomain.com',
27
+ :subject => "Mail renderer example...",
28
+
29
+ :body => {
30
+ :text => { :erb => :mail_text },
31
+ :html => { :erb => :mail_html, :content_type => 'text/html; charset=UTF-8' }
32
+ },
33
+ :file => [
34
+ { :data => :image, :filename => "hello.png", :mime_type => "image/png" },
35
+ "rubyfr.png"
36
+ ],
37
+ :ok => { :erb => :ok },
38
+ :error => { :redirect => Index }
39
+ }
40
+ end
41
+ end
42
+ end
43
+
44
+ module Capcode::Views
45
+ def glop
46
+ html do
47
+ body do
48
+ yield
49
+ end
50
+ end
51
+ end
52
+
53
+ def index
54
+ h1 "Send me an email"
55
+ a "Send mail", :href => URL(Capcode::SendMail)
56
+ end
57
+
58
+ def image
59
+ GraphViz::new( "G" ) { |g|
60
+ g.hello << g.world
61
+ g.bonjour - g.monde
62
+ g.hola > g.mundo
63
+ g.holla >> g.welt
64
+ }.output( :png => String )
65
+ end
66
+ end
67
+
68
+ Capcode.run( )
@@ -0,0 +1,73 @@
1
+ begin
2
+ require 'mail'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "mail could not be loaded (is it installed?): #{e.message}"
5
+ end
6
+
7
+ module Capcode
8
+ module Helpers
9
+ def render_email( f, _ ) #:nodoc:
10
+ if @smtp.nil?
11
+ @smtp = { :server => "127.0.0.1", :port => 25 }.merge(Capcode.options[:email] || {})
12
+ end
13
+
14
+ # Set SMTP info
15
+ conf = Mail::Configuration.instance.defaults
16
+ conf.smtp @smtp[:server], @smtp[:port]
17
+
18
+ # Create mail
19
+ mail = Mail.new()
20
+
21
+ # Mail Header
22
+ mail.from = f[:from]
23
+ mail.subject = f[:subject] if f.has_key?(:subject)
24
+ [:to, :cc, :bcc].each do |t|
25
+ next unless f.has_key?(t) and not f[t].nil?
26
+ if f[t].class == Array
27
+ mail[t] = f[t]
28
+ else
29
+ mail[t] = f[t].to_s.split( ',' ).map { |x| x.strip }
30
+ end
31
+ end
32
+ mail.message_id = f[:message_id] if f.has_key?(:message_id)
33
+
34
+ # Mail Body
35
+ if f[:body].class == String
36
+ mail.body = f[:body]
37
+ elsif f[:body].class == Hash
38
+ if f[:body].has_key?(:html)
39
+ mail.html_part = Mail::Part.new
40
+ mail.html_part.content_type = f[:body][:html].delete(:content_type) { |_| 'text/html' }
41
+ mail.html_part.body = render( f[:body][:html] )
42
+ end
43
+ if f[:body].has_key?(:text)
44
+ mail.text_part = Mail::Part.new
45
+ mail.text_part.body = render( f[:body][:text] )
46
+ end
47
+ end
48
+
49
+ # Mail Attachment
50
+ if f.has_key?(:file)
51
+ f[:file] = [f[:file]] unless f[:file].class == Array
52
+ f[:file].each do |file|
53
+ data = {}
54
+ if file.class == Hash
55
+ data[:filename] = file.delete(:filename) if file.has_key?(:filename)
56
+ data[:mime_type] = file.delete(:mime_type) if file.has_key?(:mime_type)
57
+ data[:data] = self.send(file[:data])
58
+ else
59
+ data = { :data => render( :static => file, :exact_path => false ), :filename => File.basename(file) }
60
+ end
61
+ mail.add_file(data)
62
+ end
63
+ end
64
+
65
+ begin
66
+ mail.deliver!
67
+ render f[:ok]
68
+ rescue
69
+ render f[:error]
70
+ end
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-render-mail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mail
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capcode plugin to send mail
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - capcode-render-mail.gemspec
39
+ - examples/mail/mail_html.rhtml
40
+ - examples/mail/mail_text.rhtml
41
+ - examples/mail/ok.rhtml
42
+ - examples/mail/rubyfr.png
43
+ - examples/render-email.rb
44
+ - lib/capcode/render/email.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-render-mail
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Capcode plugin to send mail
73
+ test_files: []
74
+