prawn_report 1.9.21 → 1.9.22

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.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/ac_filter_defs_controller.rb +16 -17
  3. data/app/controllers/custom_generate_report_controller.rb +18 -18
  4. data/app/controllers/generate_report_controller.rb +24 -24
  5. data/app/controllers/report_templates_controller.rb +40 -48
  6. data/app/models/ac_filter.rb +15 -15
  7. data/app/models/ac_filter_def.rb +38 -40
  8. data/app/models/ac_filter_option.rb +5 -5
  9. data/app/models/report_template.rb +22 -27
  10. data/lib/ac_filters_utils.rb +187 -189
  11. data/lib/active_record_helpers.rb +218 -219
  12. data/lib/bands/band.rb +23 -23
  13. data/lib/bands/footer_band.rb +7 -7
  14. data/lib/bands/header_band.rb +9 -9
  15. data/lib/bands/summary_band.rb +7 -7
  16. data/lib/custom_report_controller.rb +48 -60
  17. data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +0 -1
  18. data/lib/prawn_report.rb +21 -21
  19. data/lib/prawn_report/version.rb +3 -0
  20. data/lib/prawn_report_seeds.rb +45 -59
  21. data/lib/report.rb +189 -195
  22. data/lib/report_helpers.rb +82 -83
  23. data/lib/report_info.rb +27 -27
  24. data/repo/bands/footers/footer_001.rb +20 -20
  25. data/repo/bands/headers/header_001.rb +61 -61
  26. data/repo/bands/headers/header_002.rb +31 -31
  27. data/repo/reports/column_group.rb +4 -3
  28. data/repo/reports/listing.rb +1 -59
  29. data/repo/reports/simple_listing.rb +130 -149
  30. metadata +58 -90
  31. data/app/serializers/ac_filter_def_serializer.rb +0 -10
  32. data/app/serializers/ac_filter_option_serializer.rb +0 -7
  33. data/app/serializers/ac_filter_serializer.rb +0 -9
  34. data/app/serializers/report_template_basic_serializer.rb +0 -4
  35. data/app/serializers/report_template_serializer.rb +0 -9
  36. 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.to_s.gsub('\\', '\\\\\\').gsub('"', '\"')
104
- end
105
- else
106
- r += '"' + s.to_s.gsub('\\', '\\\\\\').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.symbolize_keys!
133
- if params[:include_all_belongs_to] == true
134
- rec.class.reflect_on_all_associations(:belongs_to).collect do |a|
135
- r += render_indent(first_line)
136
- r += a.name.to_s + ":\n"
137
- indent
138
- r += serialize_record(rec.send(a.name), false,
139
- {:include_all_belongs_to => params[:include_all_belongs_to]}) if rec.send(a.name)
140
- unindent
141
- end
142
- else
143
- params[:included_belongs_to] ||= {}
144
- params[:included_belongs_to].each_pair do |k,v|
145
- v.symbolize_keys!
146
- serialization_params = v
147
- type = v[:type].to_sym || :fields
148
- master_rec = rec.send(k)
149
- if type == :fields
150
- v[:fields].each do |f|
151
- r += render_indent(first_line)
152
- val = master_rec ? master_rec.send(f) : nil
153
- r += serialize_key_value(k.to_s + '_' + f.to_s, val)
154
- first_line = false
155
- end
156
- elsif type == :record
157
- r += render_indent(first_line)
158
- r += k.to_s + ":\n"
159
- indent
160
- r += serialize_record(master_rec, false, v[:params]) if master_rec #as_not_array
161
- unindent
162
- end
163
- end
164
- end
165
- r
166
- end
167
-
168
- def serialize_has_manys(rec, first_line, params)
169
- r = ''
170
- params[:included_has_many] ||= {}
171
- params[:included_has_many].each_pair do |k,v|
172
- r += render_indent(first_line)
173
- r += k.to_s + ":"
174
- r += serialize_has_many(rec.send(k), v)
175
- first_line = false
176
- end
177
- r
178
- end
179
-
180
- def serialize_methods(rec, first_line, params)
181
- r = ''
182
- params[:included_methods] ||= {}
183
- params[:included_methods].each do |v|
184
- r += render_indent(first_line)
185
- val = rec.send(v)
186
- r += serialize_key_value(v, val)
187
- first_line = false
188
- end
189
- r
190
- end
191
-
192
- def serialize_has_many(hm, params)
193
- original_indent = @indent_level
194
- r = ''
195
- if hm.count == 0
196
- r += " []\n"
197
- else
198
- r += "\n"
199
- hm.each do |det|
200
- reset_indent(original_indent)
201
- indent
202
- r += serialize_record(det, true, params || {}) #asarray
203
- end
204
- end
205
- r
206
- end
207
-
208
- end
209
-
210
- module PrawnReportActiveRecord
211
-
212
- def pr_serialize(params = {})
213
- a = ActiveRecordYAMLSerializer.new(self, params)
214
- a.serialize
215
- a
216
- end
217
-
218
- end
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