sequel-reporter 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +5 -0
- data/bin/sequel-reporter +13 -0
- data/data/Gemfile +10 -0
- data/data/Rakefile.tt +10 -0
- data/data/application.rb.tt +17 -0
- data/data/config.ru +3 -0
- data/data/lib/.gitkeep +0 -0
- data/data/migrate/.gitkeep +0 -0
- data/data/public/.gitkeep +0 -0
- data/data/public/css/bootstrap.css +6307 -0
- data/data/public/css/bootstrap.min.css +873 -0
- data/data/public/img/glyphicons-halflings-white.png +0 -0
- data/data/public/img/glyphicons-halflings.png +0 -0
- data/data/public/js/bootstrap.js +2279 -0
- data/data/public/js/bootstrap.min.js +7 -0
- data/data/public/js/jquery-1.9.1.js +9597 -0
- data/data/views/error.erb +5 -0
- data/data/views/layout.erb +60 -0
- data/data/views/reports/dashboard.erb +5 -0
- data/data/views/table.erb +31 -0
- data/lib/sequel-reporter/application.rb +51 -0
- data/lib/sequel-reporter/cli.rb +28 -0
- data/lib/sequel-reporter/helpers.rb +52 -0
- data/lib/sequel-reporter/report.rb +171 -0
- data/lib/sequel-reporter/version.rb +5 -0
- data/lib/sequel-reporter.rb +11 -0
- data/sequel-reporter.gemspec +25 -0
- data/test/report_spec.rb +63 -0
- data/test/spec_helper.rb +16 -0
- metadata +161 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Pete Keen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Sequel::Reporter
|
2
|
+
|
3
|
+
`Sequel::Reporter` is a small opinionated framework for writing web-based reports using the [Sequel](http://sequel.rubyforge.org) database toolkit. It provides a simple structure and helpers for easily writing reports.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install sequel-reporter
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Generate a new reporting project using the sequel-reporter binary:
|
12
|
+
|
13
|
+
$ sequel-reporter new foo
|
14
|
+
$ cd foo
|
15
|
+
$ bundle install
|
16
|
+
$ bundle exec rackup
|
17
|
+
|
18
|
+
Then navigate your browser to http://localhost:9292
|
19
|
+
|
20
|
+
## Writing Reports
|
21
|
+
|
22
|
+
Reports are `erb` files located in `views/reports`. Here's a very simple example report:
|
23
|
+
|
24
|
+
<% @query = query do %>
|
25
|
+
select "pete" as name, 28 as age
|
26
|
+
<% end %>
|
27
|
+
<%= table @query %>
|
28
|
+
|
29
|
+
### Helpers
|
30
|
+
|
31
|
+
The `query` helper takes a block of SQL and returns a `Sequel::Reporter::Report` instance. It can take a few options:
|
32
|
+
|
33
|
+
* `:pivot` is the name of a column to pivot the report on.
|
34
|
+
* `:pivot_sort_order` says how to order the resulting pivoted columns. Can be `asc` or `desc`. Defaults to `asc`.
|
35
|
+
|
36
|
+
Sequel Reporter uses [Twitter Bootstrap](http://twitter.github.com/bootstrap) for formatting, so you can use whatever you want to format your reports from there.
|
37
|
+
|
38
|
+
The `table` helper takes a query produced by the `query` helper and some options and builds an HTML table. Also, it can take a `:links` option which will linkify values in the table. Here's an example:
|
39
|
+
|
40
|
+
:links => {"Account" => "/reports/register?account=:1"}
|
41
|
+
|
42
|
+
This says that every value in the `Account` column will be surrounded with an `<a>` tag pointing at `/reports/register?account=:1`, where `:1` will be replaced by the value in column 1 of that particular row. You can also use `:title` in a link template. It will get replaced with the title of the column that is currently getting linked. In this case, `:title` would get replaced with `Account`.
|
43
|
+
|
44
|
+
### Reports as Classes
|
45
|
+
|
46
|
+
Sometimes writing a report in a `erb` file isn't the most convenient thing. If you want, you can write the query portion of a report as a class and put it in the `lib` directory. All `.rb` files in `lib` and subdirectories will be loaded at application start up. The idiom to use is to construct a class with a class-level `run` method which takes a `db`, which is then passed to `from_query`. Here's an example:
|
47
|
+
|
48
|
+
class SomeComplicatedReport < Sequel::Reporter::Report
|
49
|
+
def self.run(db)
|
50
|
+
from_query(db, """
|
51
|
+
select "something complicated" as foo
|
52
|
+
""")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Then in your `erb` report you'd use it like this:
|
57
|
+
|
58
|
+
<%= table SomeComplicatedReport.run(@db) %>
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/sequel-reporter
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require "sequel-reporter"
|
7
|
+
rescue LoadError => e
|
8
|
+
path = File.expand_path '../../lib', __FILE__
|
9
|
+
$:.unshift(path) if File.directory?(path) && !$:.include?(path)
|
10
|
+
require 'sequel-reporter'
|
11
|
+
end
|
12
|
+
|
13
|
+
Sequel::Reporter::CLI.start
|
data/data/Gemfile
ADDED
data/data/Rakefile.tt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sequel-reporter'
|
3
|
+
|
4
|
+
module <%= @name.capitalize %>
|
5
|
+
class Application < Sequel::Reporter::Application
|
6
|
+
# Set this to the URL for your database. Remember to
|
7
|
+
# uncomment the correct gem in the Gemfile for your
|
8
|
+
# sequel adapter.
|
9
|
+
set :database_url, 'sqlite:///'
|
10
|
+
|
11
|
+
# Set this to the report that should be used for your index
|
12
|
+
set :index_report, :dashboard
|
13
|
+
|
14
|
+
# Set this to the base directory for the app
|
15
|
+
set :root, File.expand_path("..", __FILE__)
|
16
|
+
end
|
17
|
+
end
|
data/data/config.ru
ADDED
data/data/lib/.gitkeep
ADDED
File without changes
|
File without changes
|
File without changes
|