jreport 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
 - data/README.md +15 -13
 - data/lib/jreport/assembler.rb +12 -36
 - data/lib/jreport/version.rb +1 -1
 - data/skel/config/mail_config.rb +3 -0
 - data/skel/controllers/template.eruby +1 -1
 - metadata +2 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: db1cd2a36206b50c30fb79c039b47e816a13cc65
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a257095bc4af0811eadf2af61a022100012cf91c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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  
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 89 
     | 
    
         
            +
                		self.save_to='/home/jreport/example_w.html'
         
     | 
| 
       88 
90 
     | 
    
         
             
            		end
         
     | 
| 
       89 
91 
     | 
    
         
             
            	end
         
     | 
| 
       90 
92 
     | 
    
         | 
    
        data/lib/jreport/assembler.rb
    CHANGED
    
    | 
         @@ -23,23 +23,21 @@ module Jreport 
     | 
|
| 
       23 
23 
     | 
    
         
             
                    begin
         
     | 
| 
       24 
24 
     | 
    
         
             
                      ctrl=ctrl_klas.new
         
     | 
| 
       25 
25 
     | 
    
         
             
                      class << ctrl
         
     | 
| 
       26 
     | 
    
         
            -
                        attr_accessor :data,: 
     | 
| 
      
 26 
     | 
    
         
            +
                        attr_accessor :data,:save_to
         
     | 
| 
       27 
27 
     | 
    
         
             
                      end
         
     | 
| 
       28 
     | 
    
         
            -
                      ctrl.data 
     | 
| 
       29 
     | 
    
         
            -
                       
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                       
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
    
        data/lib/jreport/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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
         
     |