sequel-reporter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequel-reporter.gemspec
4
+ gemspec
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
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ system 'rspec --color --format=documentation test'
5
+ end
@@ -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
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sequel-reporter'
4
+
5
+ # Uncomment the appropriate database gem or add your own for
6
+ # your database
7
+
8
+ #gem 'pg'
9
+ #gem 'mysql2'
10
+ #gem 'sqlite3-ruby'
data/data/Rakefile.tt ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require './application'
3
+ require 'sequel/extensions/migration'
4
+
5
+ namespace :db do
6
+ task :migrate => :environment do
7
+ app = <%= @name.capitalize %>::Application.new
8
+ Sequel::Migrator.apply(app.db, 'migrate')
9
+ end
10
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ require './application'
2
+
3
+ run <%= @name.capitalize %>::Application
data/data/lib/.gitkeep ADDED
File without changes
File without changes
File without changes