jreport 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +110 -2
- data/lib/jreport/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fd100b4fe07ebef2ac618b7d30ee9b7ef774001
|
4
|
+
data.tar.gz: 544b7008fdb377868d44dedb374c3994dd1a4ace
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72af3b3590020e478a4cde999a3e446efbbf4ad310c4c7a9b90659d5e2d90caadb990ee8cc6042bd3a48c2653aea4eafefd149c2b932f31d1498da8f1b04ce80
|
7
|
+
data.tar.gz: dcfb92b92147206d2ca0c2660900611e5f710c5d98988d48bb92825bf2793d5e3f34bca3db5c731c6d4eed92656d94da7070c945aa92d96036676a3886d9bf38
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Jreport
|
2
2
|
|
3
|
-
|
3
|
+
Jreport is used for the scenerio: collect and sort data, then make a report and send to someone. With jreport, you can focus on how to collect and sort data, and jreort would merge the data to the html template you design, then it will send the report to someoen you specfic. If you're a rails developer, you would get started quickly.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,115 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Create a jreport project
|
22
|
+
|
23
|
+
jreport new example
|
24
|
+
|
25
|
+
The project looks like:
|
26
|
+
|
27
|
+
example
|
28
|
+
├── Gemfile
|
29
|
+
├── boot.rb
|
30
|
+
├── collectors
|
31
|
+
├── config
|
32
|
+
├── controllers
|
33
|
+
├── db
|
34
|
+
│ ├── connection.rb
|
35
|
+
│ ├── database.yml
|
36
|
+
│ └── migrate
|
37
|
+
├── helpers
|
38
|
+
├── models
|
39
|
+
├── rakefile
|
40
|
+
└── views
|
41
|
+
|
42
|
+
### Create a jreport scaffold
|
43
|
+
|
44
|
+
jreport generate scaffold weather daily weekly
|
45
|
+
|
46
|
+
Command above means we will collect some weather data, then we would use this data to produce two report: a daily report and a weekly report.
|
47
|
+
|
48
|
+
#### Collector
|
49
|
+
|
50
|
+
Check the project folder, this command create weather_collector.rb in collectors folder, the WeatherCollector class contains a method fetch_data.
|
51
|
+
You'd better return the data with the method.
|
52
|
+
For example:
|
53
|
+
|
54
|
+
class WeatherCollector
|
55
|
+
def fetch_data
|
56
|
+
#TODO: add code here
|
57
|
+
[1,2,3,4]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
You can return any ruby object, only if you know what it is.
|
62
|
+
Besides, if you use active-record to store the data you get, you can even return nothing here.
|
63
|
+
|
64
|
+
#### Controller
|
65
|
+
|
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
|
+
|
68
|
+
But it's important to specify email configurations(from,to,subject). You can use options to cover this.
|
69
|
+
|
70
|
+
And you can save final html string to 'save_to'.
|
71
|
+
|
72
|
+
class WeatherController
|
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'
|
80
|
+
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'
|
86
|
+
|
87
|
+
self.save_to='/home/jreport/example_w.html'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#### View
|
92
|
+
|
93
|
+
In views folder, there is a folder weather contains 4 files. File daily_report.eruby and daily_report.css for the daily report, the other two are for weekly report.
|
94
|
+
|
95
|
+
You can complete a beautiful template accroding to erubis grammar, and the css code should be put into *.css file.
|
96
|
+
|
97
|
+
This is a simple weekly report template:
|
98
|
+
|
99
|
+
<h1>weekly</h1>
|
100
|
+
<%= data %>
|
101
|
+
|
102
|
+
Note: in the template you can use helper method that is defined in helpers folder. You can access the active record classes, too.
|
103
|
+
### Gnerate report
|
104
|
+
|
105
|
+
jreport make weather
|
106
|
+
|
107
|
+
Then jreport would send two email: daily report and weekly report.
|
108
|
+
|
109
|
+
### Use active record
|
110
|
+
|
111
|
+
Create active record is similar to rails:
|
112
|
+
|
113
|
+
jreport generate model man name:string
|
114
|
+
|
115
|
+
That create a migration file under db/migrate and a class file under models.
|
116
|
+
|
117
|
+
You can migrate db changes:
|
118
|
+
|
119
|
+
rake db:migrate
|
120
|
+
|
121
|
+
P.S. See all available rake command:
|
122
|
+
|
123
|
+
rake -T
|
124
|
+
|
125
|
+
|
126
|
+
### Others
|
127
|
+
|
128
|
+
* Email detail configurations, please check [mail](https://github.com/mikel/mail).
|
129
|
+
* View template details, please check [erubis](https://github.com/genki/erubis).
|
22
130
|
|
23
131
|
## Contributing
|
24
132
|
|
data/lib/jreport/version.rb
CHANGED