prawn_report 1.9.21 → 1.9.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/controllers/ac_filter_defs_controller.rb +16 -17
- data/app/controllers/custom_generate_report_controller.rb +18 -18
- data/app/controllers/generate_report_controller.rb +24 -24
- data/app/controllers/report_templates_controller.rb +40 -48
- data/app/models/ac_filter.rb +15 -15
- data/app/models/ac_filter_def.rb +38 -40
- data/app/models/ac_filter_option.rb +5 -5
- data/app/models/report_template.rb +22 -27
- data/lib/ac_filters_utils.rb +187 -189
- data/lib/active_record_helpers.rb +218 -219
- data/lib/bands/band.rb +23 -23
- data/lib/bands/footer_band.rb +7 -7
- data/lib/bands/header_band.rb +9 -9
- data/lib/bands/summary_band.rb +7 -7
- data/lib/custom_report_controller.rb +48 -60
- data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +0 -1
- data/lib/prawn_report.rb +21 -21
- data/lib/prawn_report/version.rb +3 -0
- data/lib/prawn_report_seeds.rb +45 -59
- data/lib/report.rb +189 -195
- data/lib/report_helpers.rb +82 -83
- data/lib/report_info.rb +27 -27
- data/repo/bands/footers/footer_001.rb +20 -20
- data/repo/bands/headers/header_001.rb +61 -61
- data/repo/bands/headers/header_002.rb +31 -31
- data/repo/reports/column_group.rb +4 -3
- data/repo/reports/listing.rb +1 -59
- data/repo/reports/simple_listing.rb +130 -149
- metadata +58 -90
- data/app/serializers/ac_filter_def_serializer.rb +0 -10
- data/app/serializers/ac_filter_option_serializer.rb +0 -7
- data/app/serializers/ac_filter_serializer.rb +0 -9
- data/app/serializers/report_template_basic_serializer.rb +0 -4
- data/app/serializers/report_template_serializer.rb +0 -9
- data/lib/generators/prawn_report/install/templates/20140529153300_add_description_to_report_template.rb +0 -6
@@ -1,219 +1,218 @@
|
|
1
|
-
#coding: utf-8
|
2
|
-
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
class ActiveRecordYAMLSerializer
|
6
|
-
|
7
|
-
def initialize(obj, params)
|
8
|
-
@obj = obj
|
9
|
-
@params = params.symbolize_keys!
|
10
|
-
@contents = ''
|
11
|
-
@indent_level = 0
|
12
|
-
end
|
13
|
-
|
14
|
-
def serialize
|
15
|
-
@contents = ''
|
16
|
-
@contents += serialize_root_values(@params)
|
17
|
-
|
18
|
-
if @obj.is_a? ActiveRecord::Base
|
19
|
-
@contents += serialize_record(@obj, false, @params) #asnotarray
|
20
|
-
elsif @obj.is_a? Array
|
21
|
-
@contents += "items:\n"
|
22
|
-
@obj.each do |item|
|
23
|
-
reset_indent
|
24
|
-
indent
|
25
|
-
@contents += serialize_record(item, true, @params) #asarray
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_yaml
|
33
|
-
YAML::load( @contents )
|
34
|
-
end
|
35
|
-
|
36
|
-
def save_as(file_name)
|
37
|
-
File.open(file_name, 'w') do |f|
|
38
|
-
f.write @contents
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def indent
|
45
|
-
@indent_level += 1
|
46
|
-
end
|
47
|
-
|
48
|
-
def unindent
|
49
|
-
@indent_level -= 1
|
50
|
-
end
|
51
|
-
|
52
|
-
def reset_indent(level = 0)
|
53
|
-
@indent_level = level
|
54
|
-
end
|
55
|
-
|
56
|
-
def serialize_root_values(params)
|
57
|
-
r = ''
|
58
|
-
params[:root_values] ||= {}
|
59
|
-
params[:root_values].each_pair { |k,v| r += serialize_key_value(k,v) }
|
60
|
-
r
|
61
|
-
end
|
62
|
-
|
63
|
-
def serialize_record(rec, as_array, params = {})
|
64
|
-
r = ''
|
65
|
-
first_line = true
|
66
|
-
to_serialize = (rec.is_a? ActiveRecord::Base) ? rec.attributes : rec
|
67
|
-
|
68
|
-
to_serialize.each_pair do |k, v|
|
69
|
-
r += render_indent_first_line(as_array) if first_line
|
70
|
-
r += ' ' * @indent_level unless first_line
|
71
|
-
r += serialize_key_value(k,v)
|
72
|
-
first_line = false
|
73
|
-
end
|
74
|
-
|
75
|
-
if rec.is_a? ActiveRecord::Base
|
76
|
-
r += serialize_belongs_tos(rec, first_line, params)
|
77
|
-
r += serialize_has_manys(rec, first_line, params)
|
78
|
-
r += serialize_methods(rec, first_line, params)
|
79
|
-
end
|
80
|
-
|
81
|
-
r
|
82
|
-
end
|
83
|
-
|
84
|
-
def serialize_key_value(k, v)
|
85
|
-
k.to_s + ': ' + serialize_value(v)
|
86
|
-
end
|
87
|
-
|
88
|
-
def serialize_value(v)
|
89
|
-
if v.is_a? String
|
90
|
-
serialize_string(v)
|
91
|
-
else
|
92
|
-
v.to_s + "\n"
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def serialize_string(s)
|
97
|
-
s.strip!
|
98
|
-
r = ''
|
99
|
-
if s.lines.count > 1
|
100
|
-
r += "|-\n"
|
101
|
-
s.lines.each do |l|
|
102
|
-
r += ' ' * (@indent_level + 1)
|
103
|
-
r += l
|
104
|
-
end
|
105
|
-
else
|
106
|
-
r += '"' + s.to_s.gsub('
|
107
|
-
end
|
108
|
-
r + "\n"
|
109
|
-
end
|
110
|
-
|
111
|
-
def render_indent_first_line(as_array)
|
112
|
-
r = ''
|
113
|
-
if @indent_level != 0
|
114
|
-
r = ' ' * (@indent_level - 1)
|
115
|
-
if (as_array)
|
116
|
-
r += '- '
|
117
|
-
else
|
118
|
-
r += ' '
|
119
|
-
end
|
120
|
-
end
|
121
|
-
r
|
122
|
-
end
|
123
|
-
|
124
|
-
def render_indent(first_line)
|
125
|
-
r = ''
|
126
|
-
#r += render_indent_first_line(@indent_level) if first_line
|
127
|
-
r += ' ' * @indent_level unless first_line
|
128
|
-
end
|
129
|
-
|
130
|
-
def serialize_belongs_tos(rec, first_line, params)
|
131
|
-
r = ''
|
132
|
-
params
|
133
|
-
|
134
|
-
|
135
|
-
r +=
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
params[:included_belongs_to]
|
144
|
-
|
145
|
-
v
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
r +=
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
params[:included_has_many]
|
171
|
-
|
172
|
-
r +=
|
173
|
-
r += k
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
params[:included_methods]
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
a
|
214
|
-
a
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class ActiveRecordYAMLSerializer
|
6
|
+
|
7
|
+
def initialize(obj, params)
|
8
|
+
@obj = obj
|
9
|
+
@params = params.symbolize_keys!
|
10
|
+
@contents = ''
|
11
|
+
@indent_level = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def serialize
|
15
|
+
@contents = ''
|
16
|
+
@contents += serialize_root_values(@params)
|
17
|
+
|
18
|
+
if @obj.is_a? ActiveRecord::Base
|
19
|
+
@contents += serialize_record(@obj, false, @params) #asnotarray
|
20
|
+
elsif @obj.is_a? Array
|
21
|
+
@contents += "items:\n"
|
22
|
+
@obj.each do |item|
|
23
|
+
reset_indent
|
24
|
+
indent
|
25
|
+
@contents += serialize_record(item, true, @params) #asarray
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_yaml
|
33
|
+
YAML::load( @contents )
|
34
|
+
end
|
35
|
+
|
36
|
+
def save_as(file_name)
|
37
|
+
File.open(file_name, 'w') do |f|
|
38
|
+
f.write @contents
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def indent
|
45
|
+
@indent_level += 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def unindent
|
49
|
+
@indent_level -= 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset_indent(level = 0)
|
53
|
+
@indent_level = level
|
54
|
+
end
|
55
|
+
|
56
|
+
def serialize_root_values(params)
|
57
|
+
r = ''
|
58
|
+
params[:root_values] ||= {}
|
59
|
+
params[:root_values].each_pair { |k,v| r += serialize_key_value(k,v) }
|
60
|
+
r
|
61
|
+
end
|
62
|
+
|
63
|
+
def serialize_record(rec, as_array, params = {})
|
64
|
+
r = ''
|
65
|
+
first_line = true
|
66
|
+
to_serialize = (rec.is_a? ActiveRecord::Base) ? rec.attributes : rec
|
67
|
+
|
68
|
+
to_serialize.each_pair do |k, v|
|
69
|
+
r += render_indent_first_line(as_array) if first_line
|
70
|
+
r += ' ' * @indent_level unless first_line
|
71
|
+
r += serialize_key_value(k,v)
|
72
|
+
first_line = false
|
73
|
+
end
|
74
|
+
|
75
|
+
if rec.is_a? ActiveRecord::Base
|
76
|
+
r += serialize_belongs_tos(rec, first_line, params)
|
77
|
+
r += serialize_has_manys(rec, first_line, params)
|
78
|
+
r += serialize_methods(rec, first_line, params)
|
79
|
+
end
|
80
|
+
|
81
|
+
r
|
82
|
+
end
|
83
|
+
|
84
|
+
def serialize_key_value(k, v)
|
85
|
+
k.to_s + ': ' + serialize_value(v)
|
86
|
+
end
|
87
|
+
|
88
|
+
def serialize_value(v)
|
89
|
+
if v.is_a? String
|
90
|
+
serialize_string(v)
|
91
|
+
else
|
92
|
+
v.to_s + "\n"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def serialize_string(s)
|
97
|
+
s.strip!
|
98
|
+
r = ''
|
99
|
+
if s.lines.count > 1
|
100
|
+
r += "|-\n"
|
101
|
+
s.lines.each do |l|
|
102
|
+
r += ' ' * (@indent_level + 1)
|
103
|
+
r += l
|
104
|
+
end
|
105
|
+
else
|
106
|
+
r += '"' + s.to_s.gsub('"', '\"') + '"'
|
107
|
+
end
|
108
|
+
r + "\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
def render_indent_first_line(as_array)
|
112
|
+
r = ''
|
113
|
+
if @indent_level != 0
|
114
|
+
r = ' ' * (@indent_level - 1)
|
115
|
+
if (as_array)
|
116
|
+
r += '- '
|
117
|
+
else
|
118
|
+
r += ' '
|
119
|
+
end
|
120
|
+
end
|
121
|
+
r
|
122
|
+
end
|
123
|
+
|
124
|
+
def render_indent(first_line)
|
125
|
+
r = ''
|
126
|
+
#r += render_indent_first_line(@indent_level) if first_line
|
127
|
+
r += ' ' * @indent_level unless first_line
|
128
|
+
end
|
129
|
+
|
130
|
+
def serialize_belongs_tos(rec, first_line, params)
|
131
|
+
r = ''
|
132
|
+
if params[:include_all_belongs_to] == true
|
133
|
+
rec.class.reflect_on_all_associations(:belongs_to).collect do |a|
|
134
|
+
r += render_indent(first_line)
|
135
|
+
r += a.name.to_s + ":\n"
|
136
|
+
indent
|
137
|
+
r += serialize_record(rec.send(a.name), false,
|
138
|
+
{:include_all_belongs_to => params[:include_all_belongs_to]}) if rec.send(a.name)
|
139
|
+
unindent
|
140
|
+
end
|
141
|
+
else
|
142
|
+
params[:included_belongs_to] ||= {}
|
143
|
+
params[:included_belongs_to].each_pair do |k,v|
|
144
|
+
v.symbolize_keys!
|
145
|
+
serialization_params = v
|
146
|
+
type = v[:type].to_sym || :fields
|
147
|
+
master_rec = rec.send(k)
|
148
|
+
if type == :fields
|
149
|
+
v[:fields].each do |f|
|
150
|
+
r += render_indent(first_line)
|
151
|
+
val = master_rec ? master_rec.send(f) : nil
|
152
|
+
r += serialize_key_value(k.to_s + '_' + f.to_s, val)
|
153
|
+
first_line = false
|
154
|
+
end
|
155
|
+
elsif type == :record
|
156
|
+
r += render_indent(first_line)
|
157
|
+
r += k.to_s + ":\n"
|
158
|
+
indent
|
159
|
+
r += serialize_record(master_rec, false, v[:params]) if master_rec #as_not_array
|
160
|
+
unindent
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
r
|
165
|
+
end
|
166
|
+
|
167
|
+
def serialize_has_manys(rec, first_line, params)
|
168
|
+
r = ''
|
169
|
+
params[:included_has_many] ||= {}
|
170
|
+
params[:included_has_many].each_pair do |k,v|
|
171
|
+
r += render_indent(first_line)
|
172
|
+
r += k.to_s + ":"
|
173
|
+
r += serialize_has_many(rec.send(k), v)
|
174
|
+
first_line = false
|
175
|
+
end
|
176
|
+
r
|
177
|
+
end
|
178
|
+
|
179
|
+
def serialize_methods(rec, first_line, params)
|
180
|
+
r = ''
|
181
|
+
params[:included_methods] ||= {}
|
182
|
+
params[:included_methods].each do |v|
|
183
|
+
r += render_indent(first_line)
|
184
|
+
val = rec.send(v)
|
185
|
+
r += serialize_key_value(v, val)
|
186
|
+
first_line = false
|
187
|
+
end
|
188
|
+
r
|
189
|
+
end
|
190
|
+
|
191
|
+
def serialize_has_many(hm, params)
|
192
|
+
original_indent = @indent_level
|
193
|
+
r = ''
|
194
|
+
if hm.count == 0
|
195
|
+
r += " []\n"
|
196
|
+
else
|
197
|
+
r += "\n"
|
198
|
+
hm.each do |det|
|
199
|
+
reset_indent(original_indent)
|
200
|
+
indent
|
201
|
+
r += serialize_record(det, true, params || {}) #asarray
|
202
|
+
end
|
203
|
+
end
|
204
|
+
r
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
module PrawnReportActiveRecord
|
210
|
+
|
211
|
+
def pr_serialize(params = {})
|
212
|
+
a = ActiveRecordYAMLSerializer.new(self, params)
|
213
|
+
a.serialize
|
214
|
+
a
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
data/lib/bands/band.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
module PrawnReport
|
2
|
-
|
3
|
-
class Band
|
4
|
-
|
5
|
-
attr_accessor :height, :report
|
6
|
-
|
7
|
-
def initialize(report, params = {})
|
8
|
-
@report = report
|
9
|
-
end
|
10
|
-
|
11
|
-
def draw
|
12
|
-
internal_draw
|
13
|
-
end
|
14
|
-
|
15
|
-
def internal_draw; end
|
16
|
-
|
17
|
-
def self.height
|
18
|
-
20
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
1
|
+
module PrawnReport
|
2
|
+
|
3
|
+
class Band
|
4
|
+
|
5
|
+
attr_accessor :height, :report
|
6
|
+
|
7
|
+
def initialize(report, params = {})
|
8
|
+
@report = report
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
internal_draw
|
13
|
+
end
|
14
|
+
|
15
|
+
def internal_draw; end
|
16
|
+
|
17
|
+
def self.height
|
18
|
+
20
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|