compendium 1.0.5 → 1.0.6

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWQyNzhiZThjMTNmZGNiNTg1NzY1YzlhMGUwOGM1ZDllOGU1YzhkYQ==
4
+ YWEzYjAwNDlhYjlhZGQ1ODY0NTBmNThhY2ZjOTU4ZTMzMWMzM2Y0OA==
5
5
  data.tar.gz: !binary |-
6
- NWIyNjQ5YzBjMWI4YTZjMWNjOTEzMmExM2U3OTE5NTI5NTUyYzI0ZQ==
6
+ YWZlOGE4NmE3NjQ5ZDM1ODZmMzlhOTJiZjhmYWZjYTU0NTNiN2FiMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWMxY2NjZDlhYmNjMzliNTJjMjE3N2Y3N2EyMmNmNjQ5Nzc3ZWYwZWIwYjli
10
- NjBlYTNlMTRlNzRmZDg3NjdjNTUxNmM5NTZhODhhNGFmZjk0ZTg4MTkwMzBi
11
- NjMyZDgyZWM5NjUxOWRmYTg4N2UzMjFlNWM0ZGExOTRiZTRiZjE=
9
+ NjQyMDM2NTE0OGYxMzZhZGUxNzQ5MDkzNGJlMDJmMzcxZjgyNTFjNzAzNDkw
10
+ ZmVkNWVlNTcxYzkwZTFhOGE1ODdjYmE2NzdlMjNmOGM2Y2I3MjAwZTNlYWI1
11
+ NzAwNmVlZTY2OTYwMzI5MDcwMTcxYzg3MmY5Y2Q3ZjI2NTRhNzM=
12
12
  data.tar.gz: !binary |-
13
- ZWI0OGNlYTkzNmQ2MDQ5ZGE4ZmM0NWY5NmRlZDU0NjNhNzgwNzFkMDI3MjA4
14
- OTFkOGZhYzY0ZWZiYWNkMjY0ZDVjMjlmMzJkM2EwYTEzN2NkYTAxNzM5NzA0
15
- MDA1Njk3ZDQ5NjAxNWRmNTdkZWE2NWM4NDVhMGE2YzE3ZmNhZDc=
13
+ YmYzYmRjZDkyN2Q5ZWU2ZDlhODBiMmJkMjgxNzY3NWE0ZmM4YTFjZDE4NGNj
14
+ MDY2NTk2YzkwYjIyMmZiMTA1MGYxOWRmOTI2N2NmZjE0MDVlNmYyYTdiNzZh
15
+ NTIyMjQ3NzNmZDRiYTE3YjI4NTg2NmM5NzJiNWFkODkxM2I1MWI=
data/README.md CHANGED
@@ -8,42 +8,46 @@ Compendium is a reporting framework for Rails which makes it easy to create and
8
8
 
9
9
  A Compendium report is a subclass of `Compendium::Report`. Reports can be defined using the simple DSL:
10
10
 
11
- class MyReport < Compendium::Report
12
- # Options define which parameters your report will accept when being set up.
13
- # An option is defined with a name, a type, and some settings (ie. default value, choices for radio buttons and
14
- # dropdowns, etc.)
15
- option :starting_on, :date, default: -> { Date.today - 1.month }
16
- option :ending_on, :date, default: -> { Date.today }
17
- option :currency, :radio, choices: [:USD, :CAD, :GBP]
18
-
19
- # By default, queries are converted to SQL and executed instead of returning AR models
20
- # The query definition block gets the report's current parameters
21
- # totals: true means that the last row returned should be interpretted as a row of totals
22
- query :deliveries, totals: true do |params|
23
- Items.where(delivered: true, purchased_at: (params[:starting_on]..params[:ending_on]))
24
- end
25
-
26
- # Define a query which collects data by using AR directly
27
- query :on_hand_inventory, collect: :active_record do |params|
28
- Items.where(in_stock: true)
29
- end
30
-
31
- # Define a query that works on another query's result set
32
- # Note: chart and data are aliases for query
33
- chart :deliveries_over_time, through: :deliveries do |results|
34
- results.group_by(&:purchased_at)
35
- end
36
-
37
- # Queries can also be used to drive metrics
38
- metric :shipping_time, -> results { results.last['shipping_time'] }, through: :deliveries
39
- end
11
+ ```ruby
12
+ class MyReport < Compendium::Report
13
+ # Options define which parameters your report will accept when being set up.
14
+ # An option is defined with a name, a type, and some settings (ie. default value, choices for radio buttons and
15
+ # dropdowns, etc.)
16
+ option :starting_on, :date, default: -> { Date.today - 1.month }
17
+ option :ending_on, :date, default: -> { Date.today }
18
+ option :currency, :radio, choices: [:USD, :CAD, :GBP]
19
+
20
+ # By default, queries are converted to SQL and executed instead of returning AR models
21
+ # The query definition block gets the report's current parameters
22
+ # totals: true means that the last row returned should be interpretted as a row of totals
23
+ query :deliveries, totals: true do |params|
24
+ Items.where(delivered: true, purchased_at: (params[:starting_on]..params[:ending_on]))
25
+ end
26
+
27
+ # Define a query which collects data by using AR directly
28
+ query :on_hand_inventory, collect: :active_record do |params|
29
+ Items.where(in_stock: true)
30
+ end
31
+
32
+ # Define a query that works on another query's result set
33
+ # Note: chart and data are aliases for query
34
+ chart :deliveries_over_time, through: :deliveries do |results|
35
+ results.group_by(&:purchased_at)
36
+ end
37
+
38
+ # Queries can also be used to drive metrics
39
+ metric :shipping_time, -> results { results.last['shipping_time'] }, through: :deliveries
40
+ end
41
+ ```
40
42
 
41
43
  Reports can then also be simply instantiated (which is done automatically if using the supplied
42
44
  `Compendium::ReportsController`):
43
45
 
44
- report = MyReport.new(starting_on: '2013-06-01')
45
- report.run(self) # The parameter is the context to run the report in; usually this should be
46
- # a controller context so that methods like current_user can be used
46
+ ```ruby
47
+ report = MyReport.new(starting_on: '2013-06-01')
48
+ report.run(self) # The parameter is the context to run the report in; usually this should be
49
+ # a controller context so that methods like current_user can be used
50
+ ```
47
51
 
48
52
  Compendium also comes with a variety of different presenters, for rendering the setup page, and displaying charts
49
53
  (`report.render_chart`), tables (`report.render_table`) and metrics for your report. Charting is delegated through a
@@ -60,7 +64,9 @@ method (*NOTE:* you have to pass `local_assigns` into it if you want locals to b
60
64
  Routes are not automatically added to your application. In order to do so, you can use the `mount_compendium` helper
61
65
  within your `config/routes.rb` file
62
66
 
63
- mount_compendium at: '/report', controller: 'reports' # controller defaults to compendium/reports
67
+ ```ruby
68
+ mount_compendium at: '/report', controller: 'reports' # controller defaults to compendium/reports
69
+ ```
64
70
 
65
71
  ### Interaction with other gems
66
72
  * If [accessible_tooltip](https://github.com/dvandersluis/accessible_tooltip) is present, option notes will be rendered
@@ -2,10 +2,19 @@ module Compendium::Presenters
2
2
  class Metric < Base
3
3
  presents :metric
4
4
 
5
- delegate :name, :query, :ran?, to: :metric
5
+ delegate :name, :query, :description, :ran?, to: :metric
6
+
7
+ def initialize(template, object, options = {})
8
+ super(template, object)
9
+ @options = options
10
+ end
6
11
 
7
12
  def label
8
- t("#{query}.#{name}")
13
+ @options[:label] || t("#{query}.#{name}")
14
+ end
15
+
16
+ def description
17
+ @options[:description]
9
18
  end
10
19
 
11
20
  def result(number_format = '%0.1f', display_nil_as = :na)
@@ -15,5 +24,9 @@ module Compendium::Presenters
15
24
  t(display_nil_as)
16
25
  end
17
26
  end
27
+
28
+ def render
29
+ @template.render 'compendium/reports/metric', metric: self
30
+ end
18
31
  end
19
32
  end
@@ -0,0 +1,5 @@
1
+ .metric{ id: metric.label.parameterize }
2
+ .metric-label
3
+ = metric.label
4
+ .metric-data= metric.result
5
+ .metric-label-small= metric.description
@@ -20,6 +20,10 @@ module Compendium
20
20
  end
21
21
  alias_method :has_ran?, :ran?
22
22
 
23
+ def render(template, *options, &block)
24
+ Compendium::Presenters::Metric.new(template, self, *options, &block).render
25
+ end
26
+
23
27
  private
24
28
 
25
29
  def condition_failed?(ctx)
@@ -1,3 +1,3 @@
1
1
  module Compendium
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compendium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  type: :runtime
@@ -119,6 +119,7 @@ files:
119
119
  - app/classes/compendium/presenters/table.rb
120
120
  - app/controllers/compendium/reports_controller.rb
121
121
  - app/helpers/compendium/reports_helper.rb
122
+ - app/views/compendium/reports/_metric.haml
122
123
  - app/views/compendium/reports/run.haml
123
124
  - app/views/compendium/reports/setup.haml
124
125
  - compendium.gemspec