jreport 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ae098da68e76d1ec098964073b15d82e97d7033
4
- data.tar.gz: caeeffb61ff055814868db6112c3be1dd320d70e
3
+ metadata.gz: db1cd2a36206b50c30fb79c039b47e816a13cc65
4
+ data.tar.gz: a257095bc4af0811eadf2af61a022100012cf91c
5
5
  SHA512:
6
- metadata.gz: 18723152e117c79d845695f1f7fd23933a60c9dd09b51e76bfeb24e5df409da48292e82f172ea24153e79be52690982be2f02c9d9a9406bc9f5ff945752761b1
7
- data.tar.gz: 4e9c00d7692fe50081915da9c005aeaf6c8a7ebb7849257bd6c1f459d801e1bca06f1fc41389c6eacdfb9b8492450a74d24c4b70c30e6025fe9970a1dce4548f
6
+ metadata.gz: 142474ce6e052aaeb96d77330399c23f379c0b945d7d6e0dc4e8c88a39a4e36ae1778e272ba018ee47baa55def0b8df76ff27b02732eb117544fb3fc65217d52
7
+ data.tar.gz: 6c75afc8ff78294a70900f7c8079d617876a1b413c27c4d34fd2271e3df94ed9ea50d2b741a5e8b0a023597f4d3c1ab42f54e6b4e73c62c4580c525021f704a9
data/README.md CHANGED
@@ -65,26 +65,28 @@ Besides, if you use active-record to store the data you get, you can even return
65
65
 
66
66
  Below the controllers folder, jreport create weather_controller.rb, with the last two arguments of 'jreport generate scaffold' command, WeatherController has two methods: daily_report and weekly_report. In this method, you can filter the data as you like(with data and data= method).
67
67
 
68
- But it's important to specify email configurations(from,to,subject). You can use options to cover this.
68
+ But it's important to specify email configurations(from,to,subject). You can use the mail argument to cover this.
69
69
 
70
70
  And you can save final html string to 'save_to'.
71
71
 
72
72
  class WeatherController
73
73
  # The method looks like xxx_report would be used to generate report
74
- def daily_report
75
- # TODO: add code here
76
- self.data=self.data.first
77
- self.options['from']='from@example.com'
78
- self.options['to']='to@example.com'
79
- self.options['subject']='example daily report'
74
+ def daily_report(mail)
75
+ # TODO: add code here
76
+ self.data=self.data.first
77
+ mail.from='from@example.com'
78
+ mail.to='to@example.com'
79
+ mail.subject='example daily report'
80
+ mail.content_type="text/html;charset=UTF-8"
80
81
  end
81
- def weekly_report
82
- # TODO: add code here
83
- self.options['from']='from@example.com'
84
- self.options['to']='to@example.com'
85
- self.options['subject']='example weekly report'
82
+ def weekly_report(mail)
83
+ # TODO: add code here
84
+ mail.from='from@example.com'
85
+ mail.to='to@example.com;to1@example.com'
86
+ mail.subject='example weekly report'
87
+ mail.content_type="text/html;charset=UTF-8"
86
88
 
87
- self.save_to='/home/jreport/example_w.html'
89
+ self.save_to='/home/jreport/example_w.html'
88
90
  end
89
91
  end
90
92
 
@@ -23,23 +23,21 @@ module Jreport
23
23
  begin
24
24
  ctrl=ctrl_klas.new
25
25
  class << ctrl
26
- attr_accessor :data,:options,:save_to
26
+ attr_accessor :data,:save_to
27
27
  end
28
- ctrl.data,ctrl.options=fetch_data,{}
29
- ctrl.send m
28
+ ctrl.data=fetch_data
29
+ # initialize a mail object
30
+ mail=Mail.new
31
+ ctrl.send m,mail
30
32
  dir="#{@root}/views/#{@_report}"
31
33
  html=render_html(dir,m.to_s,:data=>ctrl.data)
32
- if ctrl.save_to
33
- File.open(ctrl.save_to,'w'){|fi| fi.write(html) }
34
- end
35
- ops=ctrl.options.merge!('body'=>html,'content-type'=>"text/html;charset=UTF-8")
36
- puts "Sending #{m}..."
37
- if ctrl.respond_to? :send_mail
38
- ctrl.send :send_mail,ops
39
- else
40
- puts "Send with default mail client"
41
- send_mail ops
42
- end
34
+ File.open(ctrl.save_to,'w'){|fi| fi.write(html) } if ctrl.save_to
35
+ # send out report
36
+ mail.body=html
37
+ if mail.to
38
+ mail.deliver!
39
+ puts "Mail sent!"
40
+ end
43
41
  rescue=>e
44
42
  puts e
45
43
  puts e.backtrace
@@ -59,27 +57,5 @@ module Jreport
59
57
  html
60
58
  end
61
59
 
62
- def send_mail(options)
63
- begin
64
- m=Mail.new do
65
- from options['from']
66
- to options['to']
67
- subject options['subject']
68
- html_part do
69
- body options['body']
70
- content_type options['content-type']
71
- end
72
- if options['files']
73
- options.split(';').each{|f| add_file f }
74
- end
75
- end
76
- m.deliver!
77
- puts 'Report sent!'
78
- rescue=>e
79
- puts "Send mail faild!"
80
- puts e.backtrace
81
- end
82
- end
83
-
84
60
  end
85
61
  end
@@ -1,3 +1,3 @@
1
1
  module Jreport
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,3 @@
1
+ Mail.defaults do
2
+ delivery_method :sendmail
3
+ end
@@ -2,7 +2,7 @@
2
2
  class <%= controller.split('_').map{|x| x.capitalize }.join %>Controller
3
3
  # The method looks like xxx_report would be used to generate report
4
4
  <% methods.each do |m| %>
5
- def <%=m%>_report
5
+ def <%=m%>_report(mail)
6
6
  # TODO: add code here
7
7
  end
8
8
  <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jreport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - qjpcpu
@@ -144,6 +144,7 @@ files:
144
144
  - skel/boot.rb
145
145
  - skel/collectors/template.eruby
146
146
  - skel/config/.gitkeep
147
+ - skel/config/mail_config.rb
147
148
  - skel/controllers/template.eruby
148
149
  - skel/db/connection.rb
149
150
  - skel/db/database.yml