meta_reports 0.0.2 → 0.0.3

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: b0103cf12f7263900625b165f723814ae925631a
4
- data.tar.gz: 1fa51dacb00f12e33d97fd30bc12ab5a710d1247
3
+ metadata.gz: 183b24506be1116a9d39a68487dd42a62faff299
4
+ data.tar.gz: c39766e84b3a4c341a24523431cdc90623c8c2e3
5
5
  SHA512:
6
- metadata.gz: 79e20859f1c5bce940148a04d1efa0d8f24656c79bb7fdeb1bd1e03a2365be69aebd03e4946940a1fab08fd6bbd1f7d6caf9f6f694f4101da3754579e869ff22
7
- data.tar.gz: 6da7d629504e5271ddac5a4ada0f2d5b620aa20f137cb236542d8503d0815857220a437028478f74066607d86c7bb52ead806b08da7544b9b88c7335008a3379
6
+ metadata.gz: 322e5a34703a417265c797d50278ff25b10e2f7aba3082742f86feb3bc96f68ba2a911e230d0f0d69ee2635d1e495d5f9aac296853b650a8b740d28b9939168e
7
+ data.tar.gz: 1d4765a6fffbebb7e78eb960d0539ccbaa26ad1627723bd92495db778bd98c9991fce6331bf09932e48fa775abc5e8293cce962c6a2b7165cd3f6c630ca5e7f4
data/Guardfile CHANGED
@@ -7,6 +7,7 @@ guard 'rspec', :version => 2, zeus: false, parallel: false, all_on_start: false,
7
7
  watch(%r{^app/models/meta_reports/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
8
8
  watch(%r{^app/controllers/meta_reports/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
9
9
  watch('lib/generators/meta_reports/install_generator.rb') { "spec/generators/install_spec.rb" }
10
+ watch('lib/generators/meta_reports/install_templates_generator.rb') { "spec/generators/install_templates_spec.rb" }
10
11
  watch('spec/dummy/app/controllers/application_controller.rb') { "spec/controllers" }
11
12
  # dummy app
12
13
  watch(%r{^spec/dummy/app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
data/README.md CHANGED
@@ -22,7 +22,9 @@ MetaReports exports to HTML, PDF, and XLSX formats. [More are to come](#todo).
22
22
 
23
23
  ##Philosophy
24
24
 
25
- MetaReports is avowedly fat model. It is also ActiveRecord based. This could change if a better way makes sense.
25
+ MetaReports is avowedly fat model. It is also ActiveRecord based. This could change if a better way makes sense.
26
+
27
+ **NOTE:** There is a generator that [installs templates only](#install-templates-only). Then you can use the data structures and templates in whatever way you see fit, and write your own controllers / reports.
26
28
 
27
29
  - **Fat model:** All reports are class methods in the MetaReports::Report class. This allows one to generate reports in various contexts without creating an instance (e.g. a mailer.) The reports themselves are meant to be pure data without formatting, except for class names, and html cell content if that is needed.
28
30
  - **ActiveRecord:** Right now a database record is required in addition to the class method. So far this is for convenience in listing available reports and handling permissions. Someday, the code for a report might also be stored in a database, or an abstract description of a report with a web based query builder could be implemented.
@@ -41,9 +43,32 @@ gem 'meta_reports'
41
43
 
42
44
  Run the `bundle` command to install it.
43
45
 
44
- Now run the generator:
46
+ There are two ways to use MetaReports:
47
+
48
+ 1. Install the templates, partials, helpers, and models only. No ActiveRecord is used.
49
+ 2. Install and mount the engine. In addition to the above, you will have a controller,
50
+ additional templates for creating forms, and an ActiveRecord model.
51
+
52
+ ####Install templates only
53
+
54
+ After installing the gem, run the generator:
55
+
56
+ rails generate meta_reports:install_templates
57
+
58
+ This copies over the meta_reports migration, model, views, and controller:
59
+
60
+ - `app/models/meta_reports/base.rb`: The ActiveRecord base, should you need it
61
+ - `app/models/meta_reports/data.rb`: The MetaReports::Data metadata model. Contains report data.
62
+ - `app/models/meta_reports/table.rb`: The MetaReports::Table model for storing options and table data.
63
+ - `app/models/meta_reports/report.rb`: The MetaReports::Report model for storing colors.
64
+ - `app/helpers/meta_reports/reports_helper.rb`: MetaReports helper methods.
65
+ - `app/views/meta_reports/reports/templates/*`: All templates.
66
+
67
+ ####Install the engine
68
+
69
+ After installing the gem, run the generator:
45
70
 
46
- rails generate meta_reports:install
71
+ rails generate meta_reports:install_engine
47
72
 
48
73
  This copies over the meta_reports migration, model, views, and controller:
49
74
 
@@ -60,9 +85,13 @@ Add authentication/authorization to the reports controller if desired.
60
85
 
61
86
  ###Writing a report
62
87
 
63
- - Write the data method using a static method in the `app/models/meta_reports/report.rb` model. The method should accept the params hash as its single argument. It should return the data in the form of a MetaReports::Data object or a hash.
64
- - Create a new report record using the reports page. The name must match the data method name.
65
- - If not using the default templates, write your own templates.
88
+ - With templates installed:
89
+ - Use the models and helper methods to create report data.
90
+ - Render it using the default templates, or any template of your own.
91
+ - With the engine installed:
92
+ - Write the data method using a static method in the `app/models/meta_reports/report.rb` model. The method should accept the params hash as its single argument. It should return the data in the form of a MetaReports::Data object or a hash.
93
+ - Create a new report record using the reports page. The name must match the data method name.
94
+ - If not using the default templates, write your own templates.
66
95
 
67
96
  ###MetaData
68
97
 
@@ -139,6 +168,7 @@ For HTML, necessary styles will either be injected into the HTML output, or a ra
139
168
 
140
169
  ##Changelog
141
170
 
171
+ - **0.0.3:** (10/7/13) Template/model/helper generator
142
172
  - **0.0.2:** (9/29/13) Relax rails requirement, better testing
143
173
  - **0.0.1:** (9/29/13) Initial release
144
174
 
@@ -1,5 +1,24 @@
1
1
  module MetaReports
2
2
  module ReportsHelper
3
+ def meta_report_color(klass, row = 0)
4
+ color = MetaReports::Report::COLORS[klass.to_sym]
5
+ return nil unless color
6
+ if color.is_a? Array
7
+ # the trailing split first is to drop any !important directive
8
+ # color = color[row%color.length].to_s.split.first
9
+ # the trailing gsub is to drop any !important directive
10
+ color = color[row%color.length].to_s.gsub(/\s.*$/,'')
11
+ end
12
+ if color.gsub!(/^\$/, '') # we have a variable
13
+ color = COLORS[color.to_sym]
14
+ if color.is_a? Array
15
+ choice = color.gsub!(/Odd/,'') ? 1 : 0
16
+ color = color[choice]
17
+ end
18
+ end
19
+ color
20
+ end
21
+
3
22
  def convert_margins_to_xlsx(margins)
4
23
  margins = [*margins].compact.map {|val| val/72.0}
5
24
  page_margins = {}
@@ -37,7 +56,7 @@ module MetaReports
37
56
  row_classes = opts[:row_classes] || {}
38
57
  row_colors = {}
39
58
  row_classes.each do |i, klass|
40
- if color = MetaReports::Report.color(klass, i)
59
+ if color = meta_report_color(klass, i)
41
60
  row_colors[i] = color
42
61
  end
43
62
  end
@@ -53,9 +72,11 @@ module MetaReports
53
72
  if _class =~ /\bbold\b|\bstrong\b/
54
73
  set_style(styling, :bold, i, j)
55
74
  end
56
- unless data[i][j][:image]
57
- data[i][j][:content] = data[i][j][:content].to_s unless data[i][j][:content].is_a? String
75
+ unless data[i][j][:image] || data[i][j][:content].is_a?(String)
76
+ data[i][j][:content] = data[i][j][:content].to_s
58
77
  end
78
+ elsif !data[i][j].is_a?(String)
79
+ data[i][j] = data[i][j].to_s
59
80
  end
60
81
  end
61
82
  end
@@ -83,7 +104,8 @@ module MetaReports
83
104
  data
84
105
  end
85
106
 
86
- def report_link(report, title = report.title)
107
+ def meta_report_link(report, title = report.title)
108
+ return nil unless report
87
109
  if report.direct
88
110
  content_tag :span do
89
111
  links = []
@@ -109,7 +131,8 @@ module MetaReports
109
131
  end
110
132
  end
111
133
 
112
- def report_alt_links(report, params)
134
+ def meta_report_alt_links(report, params)
135
+ return nil unless report
113
136
  links = []
114
137
  if report.format? :pdf
115
138
  links << link_to(image_tag('meta_reports/print.png'), params.merge({:format => :pdf}), :target => '_blank')
@@ -14,25 +14,6 @@ class MetaReports::Base < ActiveRecord::Base
14
14
 
15
15
  FORMATS = %w[html pdf xlsx]
16
16
 
17
- def self.color(klass, row = 0)
18
- color = COLORS[klass.to_sym]
19
- return nil unless color
20
- if color.is_a? Array
21
- # the trailing split first is to drop any !important directive
22
- # color = color[row%color.length].to_s.split.first
23
- # the trailing gsub is to drop any !important directive
24
- color = color[row%color.length].to_s.gsub(/\s.*$/,'')
25
- end
26
- if color.gsub!(/^\$/, '') # we have a variable
27
- color = COLORS[color.to_sym]
28
- if color.is_a? Array
29
- choice = color.gsub!(/Odd/,'') ? 1 : 0
30
- color = color[choice]
31
- end
32
- end
33
- color
34
- end
35
-
36
17
  def self.format_mask(format)
37
18
  1 << (FORMATS.index(format.to_s) || -1)
38
19
  end
@@ -2,7 +2,7 @@ require 'rails/generators'
2
2
 
3
3
  module MetaReports
4
4
  module Generators
5
- class InstallGenerator < Rails::Generators::Base
5
+ class InstallEngineGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
8
  desc 'Copy meta_reports migration, models, controllers, and views.'
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module MetaReports
4
+ module Generators
5
+ class InstallTemplatesGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../../../..', __FILE__)
7
+
8
+ desc 'Copy meta_reports templates.'
9
+
10
+ def install_models
11
+ directory "app/models/meta_reports", "app/models/meta_reports"
12
+ copy_file "lib/generators/meta_reports/templates/models/report_non_activerecord.rb", "app/models/meta_reports/report.rb"
13
+ end
14
+
15
+ def install_helper
16
+ copy_file "app/helpers/meta_reports/reports_helper.rb", "app/helpers/meta_reports/reports_helper.rb"
17
+ end
18
+
19
+ def install_views
20
+ directory "lib/generators/meta_reports/templates/views/templates", "app/views/meta_reports/reports/templates"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ class MetaReports::Report
2
+
3
+ #
4
+ # Shared colors. The key is the class name, value is RGB in hex format
5
+ #
6
+
7
+ COLORS = {
8
+ even: 'efefef',
9
+ odd: 'ffffff',
10
+ }
11
+
12
+
13
+ #
14
+ # Reports
15
+ #
16
+
17
+ def self.example_report(params)
18
+ {title: 'Example Report', subtitle: 'this is a test report', tables: {'Table 1' => [['One','Two','Three'],[1,2,3]]}}
19
+ MetaReports::Data.new do |d|
20
+ d.title = 'Example Report'
21
+ d.subtitle = 'Of the Testing Kind'
22
+ d.description = 'This is a test report.'
23
+ d.tables["Table 1"] = MetaReports::Table.new do |t|
24
+ t << ['One', 'Two', 'Three']
25
+ t << [1, 2, 3]
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -23,7 +23,7 @@
23
23
  <td><%= report.direct %></td>
24
24
  <td><%= report.views %></td>
25
25
  <td><%= report.target %></td>
26
- <td><%= report_link(report, 'Show') %></td>
26
+ <td><%= meta_report_link(report, 'Show') %></td>
27
27
  <td><%= link_to 'Edit', edit_report_path(report) %></td>
28
28
  <td><%= link_to 'Destroy', report, method: :delete, data: { confirm: 'Are you sure?' } %></td>
29
29
  </tr>
@@ -8,7 +8,7 @@ report = @report if defined?(report).nil?
8
8
  %>
9
9
  <%= content_tag(:h3, title.html_safe) if title %>
10
10
  <div>
11
- <%= report_alt_links(report[:report], params) %>
11
+ <%= meta_report_alt_links(report[:report], params) %>
12
12
  <% if report[:description] %><br><p class='description'><%= report[:description] %></p><% end %>
13
13
  </div>
14
14
 
@@ -21,6 +21,6 @@ report = @report if defined?(report).nil?
21
21
  <% end %>
22
22
  <% end %>
23
23
 
24
- <% unless request.xhr? %>
24
+ <% unless request.xhr? || report[:report].nil? %>
25
25
  <%= link_to 'Reports', '/meta_reports' %>
26
26
  <% end -%>
@@ -1,3 +1,3 @@
1
1
  module MetaReports
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -23,7 +23,7 @@
23
23
  <td><%= report.direct %></td>
24
24
  <td><%= report.views %></td>
25
25
  <td><%= report.target %></td>
26
- <td><%= report_link(report, 'Show') %></td>
26
+ <td><%= meta_report_link(report, 'Show') %></td>
27
27
  <td><%= link_to 'Edit', edit_report_path(report) %></td>
28
28
  <td><%= link_to 'Destroy', report, method: :delete, data: { confirm: 'Are you sure?' } %></td>
29
29
  </tr>
@@ -8,7 +8,7 @@ report = @report if defined?(report).nil?
8
8
  %>
9
9
  <%= content_tag(:h3, title.html_safe) if title %>
10
10
  <div>
11
- <%= report_alt_links(report[:report], params) %>
11
+ <%= meta_report_alt_links(report[:report], params) %>
12
12
  <% if report[:description] %><br><p class='description'><%= report[:description] %></p><% end %>
13
13
  </div>
14
14
 
@@ -22832,3 +22832,87 @@ Completed 200 OK in 8ms (Views: 7.1ms | ActiveRecord: 0.3ms)
22832
22832
   (0.2ms) rollback transaction
22833
22833
   (0.1ms) begin transaction
22834
22834
   (0.2ms) rollback transaction
22835
+  (0.3ms) begin transaction
22836
+  (0.1ms) rollback transaction
22837
+  (0.1ms) begin transaction
22838
+  (0.2ms) rollback transaction
22839
+  (0.1ms) begin transaction
22840
+  (0.2ms) rollback transaction
22841
+  (0.3ms) begin transaction
22842
+  (0.1ms) rollback transaction
22843
+  (0.3ms) begin transaction
22844
+  (0.1ms) rollback transaction
22845
+  (0.3ms) begin transaction
22846
+  (0.1ms) rollback transaction
22847
+  (0.3ms) begin transaction
22848
+  (0.2ms) rollback transaction
22849
+  (0.1ms) begin transaction
22850
+  (0.1ms) rollback transaction
22851
+  (0.1ms) begin transaction
22852
+  (0.2ms) rollback transaction
22853
+  (0.3ms) begin transaction
22854
+  (0.1ms) rollback transaction
22855
+  (0.3ms) begin transaction
22856
+  (0.1ms) rollback transaction
22857
+  (0.3ms) begin transaction
22858
+  (0.1ms) rollback transaction
22859
+  (0.3ms) begin transaction
22860
+  (0.1ms) rollback transaction
22861
+  (0.3ms) begin transaction
22862
+  (0.1ms) rollback transaction
22863
+  (0.3ms) begin transaction
22864
+  (0.1ms) rollback transaction
22865
+  (0.3ms) begin transaction
22866
+  (0.1ms) rollback transaction
22867
+  (0.3ms) begin transaction
22868
+  (0.1ms) rollback transaction
22869
+  (0.3ms) begin transaction
22870
+  (0.1ms) rollback transaction
22871
+  (0.3ms) begin transaction
22872
+  (0.1ms) rollback transaction
22873
+  (0.3ms) begin transaction
22874
+  (0.1ms) rollback transaction
22875
+  (0.1ms) begin transaction
22876
+  (0.1ms) rollback transaction
22877
+  (0.1ms) begin transaction
22878
+  (0.1ms) rollback transaction
22879
+  (0.3ms) begin transaction
22880
+  (0.1ms) rollback transaction
22881
+  (0.1ms) begin transaction
22882
+  (0.1ms) rollback transaction
22883
+  (0.1ms) begin transaction
22884
+  (0.1ms) rollback transaction
22885
+  (0.3ms) begin transaction
22886
+  (0.1ms) rollback transaction
22887
+  (0.1ms) begin transaction
22888
+  (0.1ms) rollback transaction
22889
+  (0.1ms) begin transaction
22890
+  (0.1ms) rollback transaction
22891
+  (0.3ms) begin transaction
22892
+  (0.2ms) rollback transaction
22893
+  (0.1ms) begin transaction
22894
+  (0.1ms) rollback transaction
22895
+  (0.1ms) begin transaction
22896
+  (0.2ms) rollback transaction
22897
+  (0.3ms) begin transaction
22898
+  (0.1ms) rollback transaction
22899
+  (0.3ms) begin transaction
22900
+  (0.1ms) rollback transaction
22901
+  (0.3ms) begin transaction
22902
+  (0.1ms) rollback transaction
22903
+  (0.3ms) begin transaction
22904
+  (0.1ms) rollback transaction
22905
+  (0.3ms) begin transaction
22906
+  (0.1ms) rollback transaction
22907
+  (0.3ms) begin transaction
22908
+  (0.1ms) rollback transaction
22909
+  (0.3ms) begin transaction
22910
+  (0.1ms) rollback transaction
22911
+  (0.3ms) begin transaction
22912
+  (0.1ms) rollback transaction
22913
+  (0.3ms) begin transaction
22914
+  (0.1ms) rollback transaction
22915
+  (0.3ms) begin transaction
22916
+  (0.1ms) rollback transaction
22917
+  (0.3ms) begin transaction
22918
+  (0.1ms) rollback transaction
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'fileutils'
3
3
 
4
- describe 'meta_reports:install', disabled: false do
4
+ describe 'meta_reports:install_engine', disabled: false do
5
5
  before :all do
6
6
  Dir.chdir(Rails.root) do
7
7
  FileUtils.cp "config/routes_empty.rb", "config/routes.rb"
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe 'meta_reports:install_templates', disabled: false do
5
+ it "should generate views" do
6
+ subject.should generate("app/models/meta_reports")
7
+ subject.should generate("app/models/meta_reports/base.rb")
8
+ subject.should generate("app/models/meta_reports/data.rb")
9
+ subject.should generate("app/models/meta_reports/report.rb")
10
+ subject.should generate("app/models/meta_reports/table.rb")
11
+ subject.should generate("app/views/meta_reports/reports/templates")
12
+ subject.should generate("app/views/meta_reports/reports/templates/_default.html.erb")
13
+ subject.should generate("app/views/meta_reports/reports/templates/_default_footer.pdf.prawn")
14
+ subject.should generate("app/views/meta_reports/reports/templates/_default_table.html.erb")
15
+ subject.should generate("app/views/meta_reports/reports/templates/_default_table.pdf.prawn")
16
+ subject.should generate("app/views/meta_reports/reports/templates/default.html.erb")
17
+ subject.should generate("app/views/meta_reports/reports/templates/default.pdf.prawn")
18
+ subject.should generate("app/views/meta_reports/reports/templates/default.xlsx.axlsx")
19
+ subject.should generate("app/helpers/meta_reports/reports_helper.rb")
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meta_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Peden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2013-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -254,8 +254,10 @@ files:
254
254
  - app/models/meta_reports/table.rb
255
255
  - config/routes.rb
256
256
  - db/migrate/20130801071213_create_meta_reports_reports.rb
257
- - lib/generators/meta_reports/install_generator.rb
257
+ - lib/generators/meta_reports/install_engine_generator.rb
258
+ - lib/generators/meta_reports/install_templates_generator.rb
258
259
  - lib/generators/meta_reports/templates/models/report.rb
260
+ - lib/generators/meta_reports/templates/models/report_non_activerecord.rb
259
261
  - lib/generators/meta_reports/templates/views/_form.html.erb
260
262
  - lib/generators/meta_reports/templates/views/edit.html.erb
261
263
  - lib/generators/meta_reports/templates/views/forms/_form_example.html.erb
@@ -364,7 +366,8 @@ files:
364
366
  - spec/dummy/tmp/cache/assets/test/sprockets/e858c95fa595e319dac0065d49982967
365
367
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
366
368
  - spec/features/dummy_spec.rb
367
- - spec/generators/install_spec.rb
369
+ - spec/generators/install_engine_spec.rb
370
+ - spec/generators/install_templates_spec.rb
368
371
  - spec/models/data_spec.rb
369
372
  - spec/models/table_spec.rb
370
373
  - spec/spec_helper.rb
@@ -483,7 +486,8 @@ test_files:
483
486
  - spec/dummy/tmp/cache/assets/test/sprockets/e858c95fa595e319dac0065d49982967
484
487
  - spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655
485
488
  - spec/features/dummy_spec.rb
486
- - spec/generators/install_spec.rb
489
+ - spec/generators/install_engine_spec.rb
490
+ - spec/generators/install_templates_spec.rb
487
491
  - spec/models/data_spec.rb
488
492
  - spec/models/table_spec.rb
489
493
  - spec/spec_helper.rb