lean-ruport 0.3.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of lean-ruport might be problematic. Click here for more details.

Files changed (50) hide show
  1. data/ACKNOWLEDGEMENTS +33 -0
  2. data/AUTHORS +19 -0
  3. data/CHANGELOG +206 -0
  4. data/COPYING +340 -0
  5. data/LICENSE +7 -0
  6. data/README +209 -0
  7. data/Rakefile +54 -0
  8. data/TODO +27 -0
  9. data/lib/ruport.rb +58 -0
  10. data/lib/ruport/config.rb +114 -0
  11. data/lib/ruport/data_row.rb +144 -0
  12. data/lib/ruport/data_set.rb +221 -0
  13. data/lib/ruport/format.rb +116 -0
  14. data/lib/ruport/format/builder.rb +89 -0
  15. data/lib/ruport/format/document.rb +77 -0
  16. data/lib/ruport/format/open_node.rb +36 -0
  17. data/lib/ruport/parser.rb +202 -0
  18. data/lib/ruport/query.rb +208 -0
  19. data/lib/ruport/query/sql_split.rb +33 -0
  20. data/lib/ruport/report.rb +116 -0
  21. data/lib/ruport/report/mailer.rb +48 -0
  22. data/test/samples/addressbook.csv +6 -0
  23. data/test/samples/car_ads.txt +505 -0
  24. data/test/samples/data.csv +3 -0
  25. data/test/samples/document.xml +22 -0
  26. data/test/samples/five_lines.txt +5 -0
  27. data/test/samples/five_paragraphs.txt +9 -0
  28. data/test/samples/ross_report.txt +58530 -0
  29. data/test/samples/ruport_test.sql +8 -0
  30. data/test/samples/stonecodeblog.sql +279 -0
  31. data/test/samples/test.sql +2 -0
  32. data/test/samples/test.yaml +3 -0
  33. data/test/tc_builder.rb +116 -0
  34. data/test/tc_config.rb +41 -0
  35. data/test/tc_data_row.rb +36 -0
  36. data/test/tc_data_set.rb +141 -0
  37. data/test/tc_database.rb +25 -0
  38. data/test/tc_document.rb +42 -0
  39. data/test/tc_element.rb +18 -0
  40. data/test/tc_page.rb +42 -0
  41. data/test/tc_query.rb +55 -0
  42. data/test/tc_reading.rb +60 -0
  43. data/test/tc_report.rb +31 -0
  44. data/test/tc_section.rb +45 -0
  45. data/test/tc_sql_split.rb +18 -0
  46. data/test/tc_state.rb +142 -0
  47. data/test/ts_all.rb +9 -0
  48. data/test/ts_format.rb +5 -0
  49. data/test/ts_parser.rb +10 -0
  50. metadata +102 -0
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ = License Terms
2
+
3
+ Distributed under the user's choice of the GPL[http://www.gnu.org/copyleft/gpl.html] (see COPYING for details) or the
4
+ {Ruby software license}[http://www.ruby-lang.org/en/LICENSE.txt] by Gregory Brown.
5
+
6
+ Please email Greg[mailto:gregory.t.brown_AT_gmail.com] with any questions.
7
+
data/README ADDED
@@ -0,0 +1,209 @@
1
+ # ------------------------------------------------------------------------
2
+ # The <em>true story</em> behind Ruby Reports...
3
+ #
4
+ # ------ __________________ -------
5
+ # / \ o ( I miss pacman... ) / \
6
+ # o | O O | o o o ------------------ o o | O O |
7
+ # o | | ___________________________ o | |
8
+ # o \/\/\/\/\/ ( At least we're l33t now.. )o \/\/\/\/
9
+ # o ---------------------------
10
+ # o _________________________________________________
11
+ # o (vintage video game bad guys... ah... true l33tn355)
12
+ # --------------------------------------------------
13
+ #
14
+ # Not impressed? Fine, here's ya damn DOCS!
15
+ # -------------------------------------------------------------------------
16
+ #
17
+ # Contents:
18
+ #
19
+ # - What Ruport Is.
20
+ # - Installation
21
+ # - Caveats.
22
+ # - Resources
23
+ # - Background and Summary
24
+ #
25
+ # - What Ruport Is.
26
+ #
27
+ # Ruby Reports is a software library that aims to make the task of reporting
28
+ # less tedious and painful. It provides tools for data acquisition, database
29
+ # interaction, formatting, and parsing/munging. Designed to be extensible,
30
+ # it is possible to use Ruport for quick specific tasks as well as to build
31
+ # robust reporting applications.
32
+ #
33
+ # - Installation
34
+ #
35
+ # Optional Dependencies:
36
+ #
37
+ # Ruport has a number of optional dependencies:
38
+ #
39
+ # Ruby/DBI and appropriate dbds: Makes Query useable
40
+ # (must be installed manually)
41
+ #
42
+ # FasterCSV: Silently enables fast CSV parsing
43
+ # (available via rubygems)
44
+ #
45
+ # RedCloth: Enables textile/markdown filtering
46
+ # (available via rubygems)
47
+ #
48
+ # PDF::Writer: Enables printable documents via render_pdf (Experimental)
49
+ # (available via rubygems)
50
+ #
51
+ # The recommended method of installing ruport is RubyGems. It has been
52
+ # split into two packages, one that installs all of the dependencies
53
+ # by default, and one which does not install them.
54
+ #
55
+ # None of the dependencies are mandatory, so you can still use Ruport
56
+ # without them, as long as you don't need their functionality.
57
+ #
58
+ # To install ruport via rubygems with all it's dependencies (except DBI):
59
+ #
60
+ # sudo gem install ruport
61
+ #
62
+ # To install ruport via rubygems with no dependencies:
63
+ #
64
+ # sudo gem install ruport-lean
65
+ #
66
+ # Note that by installing any of the dependencies, either via gems or manually,
67
+ # their functionality will automatically be enabled in ruport-lean.
68
+ #
69
+ # To install ruport manually:
70
+ #
71
+ # sudo ruby setup.rb
72
+ #
73
+ # To not install ruport at all:
74
+ #
75
+ # ruby -Ipath/to/ruport/lib my_script.rb
76
+ #
77
+ # Check to see if it installed properly:
78
+ #
79
+ # ruby -rubygems -e "require 'ruport'; puts Ruport::VERSION"
80
+ # (omit the -rubygems flag if installed manually)
81
+ #
82
+ # If you get an error, please consult the mailing list.
83
+ #
84
+ # - Caveats
85
+ #
86
+ # Ruport is alpha software. It's not completely tested and the API is
87
+ # changing rapidly from version to version. Test suites are becoming
88
+ # increasingly robust, but have not identified all possible edge cases. If
89
+ # Ruport goes wild on you, it's because it hasn't been tamed yet.
90
+ #
91
+ # The functionality is also not complete yet. There is a lot left to be added
92
+ # and there is a lot to think about. If you find yourself wondering why
93
+ # feature foo is in Ruport, chances are it just hasn't been written yet.
94
+ #
95
+ # Documentation so far is something that is a struggle to keep up with. As of
96
+ # this release, there is at least partial documentation for the API. This
97
+ # will continue to get better as time goes on.
98
+ #
99
+ # Platform independence is a priority, but I don't absolutely always have
100
+ # access to every OS / DBMS combination, so if something breaks on your
101
+ # system, please feel free to yell loud at the mailing list.
102
+ #
103
+ # That having been said, I do use ruport in my daily work. That means that it
104
+ # will probably have at least something you will find useful. Or so I hope.
105
+ #
106
+ # - Resources
107
+ #
108
+ # The best way to get help and make suggestions is the Ruport mailing list.
109
+ # This software is on the move, so the list is the most reliable way of getting
110
+ # up to date information.
111
+ #
112
+ # - You can sign up and/or view the archives here:
113
+ # http://lists.stonecode.org/listinfo.cgi/ruport-stonecode.org
114
+ #
115
+ # Please do not hesitate to use this list! I am happily accepting patches and
116
+ # documentation, as well as encouraging design discussions and also am quite
117
+ # curious about what people use or want to use ruport for.
118
+ #
119
+ # Ruby Reports (Ruport) is a report generation and formatting toolset.
120
+ #
121
+ # I will announce Ruport releases on RubyTalk, on the Ruport mailing list, on
122
+ # Freshmeat, RAA, and the new_haven.rb mailing list. If you would like to
123
+ # keep an eye out for releases, please monitor one of those places.
124
+ #
125
+ # - You may download Ruport's source from the project page:
126
+ # http://rubyforge.org/projects/ruport
127
+ #
128
+ # - The latest stable API documentation is available at:
129
+ # http://ruport.rubyforge.org/docs
130
+ #
131
+ # - If you'd like to get some news on Ruport, you can check out my blog.
132
+ # (http://stonecode.org/blog)
133
+ #
134
+ # There also will be some tutorials on stonecode.org
135
+ #
136
+ # From time to time I will release example packages on RubyForge. Keep an eye
137
+ # out for these on ruport's project page and please note that unless otherwise
138
+ # noted, these examples are meant ONLY for the versions which they correspond
139
+ # to. (i.e. ruport-example-0.2.9 will NOT work with Ruport 0.3.8)
140
+ #
141
+ # If you are interested in developing Ruport, please *never* study code in
142
+ # official releases. As this software is in it's early stages, it's essential
143
+ # to keep an eye on the subversion repository. If you let me know you are
144
+ # interested in working on something, I will let you know if I'm actively
145
+ # working on that section.
146
+ #
147
+ # - Grabbing the code from the svn trunk is simple:
148
+ #
149
+ # svn checkout svn://rubyforge.org//var/svn/ruport
150
+ #
151
+ # Those who would like to become regular contributors will be given write
152
+ # access. Also, anyone interested in the internal design and project
153
+ # management aspects of Ruport can request to be added to our basecamp
154
+ # account. This is primarily intended for people who are working on the
155
+ # project actively, though.
156
+ #
157
+ # - Background / Summary
158
+ #
159
+ # Ruport aims to help you fetch data from various sources, perform
160
+ # manipulations on them as needed, and then output them in a variety
161
+ # of formats easily. The powerful ERb templating engine is integrated
162
+ # to let you embed Ruport code into your formatted data. Also, Ruport
163
+ # provides a high level interface to databases, to make getting
164
+ # your data easy.
165
+ #
166
+ # The standard datastructure for Ruport is the DataSet. It is an enumerable
167
+ # ordered list which consists of DataRow objects that can be accessed
168
+ # by field names or ordinal position. DataRows can be arbitrarily tagged,
169
+ # allowing for easy retrieval of the same rows for many different purposes.
170
+ #
171
+ # The rest of the code is organized into three main models, Report, Query,
172
+ # and Format. Each is meant to be a high level interface to Ruport.
173
+ # The inner classes can be used where a decent level of customization
174
+ # is needed.
175
+ #
176
+ # Report is in some sense the 'controller' of your application, and provides
177
+ # methods to help you write a Reporting application
178
+ #
179
+ # Format provides support for building filters and specialized formatting
180
+ # systems. Format::Builder can be used to add additional formats which can be
181
+ # used by DataSet#as, and the Format class can add filters to Report#render
182
+ #
183
+ # Query currently provides a high level interface to DBI. Soon it will support
184
+ # a mixin wrapper called Fetchable which will enable you to wrap whatever data
185
+ # source you choose. If you would like to query a database or load a sql dump,
186
+ # this class can help you do that. It can generate DataSets on the fly, or feed
187
+ # you DBI:Rows, depending on what you need.
188
+ #
189
+ # There is also a Config class which allows you to set things such as data
190
+ # sources, mailer information, and logging. Ruport#complain provides a robust
191
+ # way to handle error logging and warnings.
192
+ #
193
+ # Finally, Ruport provides a powerful yet oh-so-scary parsing tool. It is
194
+ # essentially James Edward Gray II's Parse::Input library within the Ruport
195
+ # library. (And will soon be integrated nicely too)
196
+ #
197
+ # Read the source of ruport/parser.rb if you have some gnarly data you need to
198
+ # munge.
199
+ #
200
+ # Finally, Please consult the API documentation and/or source code for more
201
+ # information. (http://ruport.rubyforge.org/docs). Not all classes have been
202
+ # documented but the ones that have may be easier to understand when their docs
203
+ # have been read. Also, feel free to contribute documentation.
204
+ #
205
+ # If you have any questions or concerns, hop on the mailing list and fire away!
206
+ #
207
+ # Thanks for downloading my software and I hope you enjoy it!
208
+ # -Greg
209
+
@@ -0,0 +1,54 @@
1
+ require "rake/rdoctask"
2
+ require "rake/testtask"
3
+ require "rake/gempackagetask"
4
+
5
+ require "rubygems"
6
+
7
+ LEAN=true
8
+
9
+ task :default => [:test]
10
+
11
+ Rake::TestTask.new do |test|
12
+ test.libs << "test"
13
+ test.test_files = [ "test/ts_all.rb" ]
14
+ test.verbose = true
15
+ end
16
+
17
+ spec = Gem::Specification.new do |spec|
18
+ spec.name = LEAN ? "lean-ruport" : "ruport"
19
+ spec.version = "0.3.8"
20
+ spec.platform = Gem::Platform::RUBY
21
+ spec.summary = "A generalized Ruby report generation and templating engine."
22
+
23
+ spec.files = spec.files = FileList[
24
+ 'lib/**/*.rb', 'bin/*', '[A-Z]*','test/**/*'].to_a.delete_if { |item|
25
+ item.include?("CVS") } + ["Rakefile"]
26
+ spec.require_path = "lib"
27
+
28
+ spec.test_file = "test/ts_all.rb"
29
+
30
+ spec.has_rdoc = true
31
+ spec.extra_rdoc_files = %w{README LICENSE TODO AUTHORS CHANGELOG}
32
+ spec.rdoc_options << '--title' << 'Ruport Documentation' <<
33
+ '--main' << 'README' << '-q'
34
+ unless LEAN
35
+ spec.add_dependency('fastercsv', '>= 0.1.0')
36
+ spec.add_dependency('RedCloth', '>= 3.0.0')
37
+ spec.add_dependency('pdf-writer', '>= 1.1.3')
38
+ end
39
+ spec.author = "Gregory Brown"
40
+ spec.email = " gregory.t.brown@gmail.com"
41
+ spec.rubyforge_project = "ruport"
42
+ spec.homepage = "http://ruport.rubyforge.org"
43
+ spec.description = <<END_DESC
44
+ Ruport is a powerful report generation engine that allows users to generate
45
+ custom ERb templates and easily query various forms of SQL databases via DBI.
46
+ It provides helper methods and utilities to generate professional reports
47
+ quickly and cleanly.
48
+ END_DESC
49
+ end
50
+
51
+ Rake::GemPackageTask.new(spec) do |pkg|
52
+ pkg.need_zip = true
53
+ pkg.need_tar = true
54
+ end
data/TODO ADDED
@@ -0,0 +1,27 @@
1
+ TODO: (Wiped clean for a fresh start as of 2006.02.20)
2
+
3
+ For Ruport 0.4.0
4
+
5
+ - Integrate Ruport::Parser into Report#parse and Format#parser
6
+
7
+ - Document the inner classes of Format
8
+
9
+ - Get unit tests up to 100% coverage
10
+
11
+ - make the Fetchable module to abstract data acquisition
12
+
13
+ High Priority Goals:
14
+
15
+ - Implement some aspects of XST into DataSet
16
+
17
+ - Offer charting support in Format
18
+
19
+ Community Requests:
20
+
21
+ - Integration with Rails (ActiveRecord)
22
+
23
+ Other (Unordered) Goals:
24
+
25
+ - Make mailer more robust via MailFactory
26
+
27
+ - Support KirbyBase
@@ -0,0 +1,58 @@
1
+ require "rubygems"
2
+ # ruport.rb : Ruby Reports toplevel module
3
+ #
4
+ # Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
5
+ #
6
+ # Copyright (c) 2006, All Rights Reserved.
7
+ #
8
+ # This is free software. You may modify and redistribute this freely under
9
+ # your choice of the GNU General Public License or the Ruby License.
10
+ #
11
+ # See LICENSE and COPYING for details
12
+ #
13
+
14
+ module Ruport
15
+ VERSION = "Ruport Version 0.3.8 (Developmental)"
16
+
17
+ # Ruports logging and error interface.
18
+ # Can generate warnings or raise fatal errors
19
+ #
20
+ # Takes a message to display and a set of options.
21
+ # Will log to the file defined by Config::log_file
22
+ #
23
+ # Options:
24
+ # <tt>:status</tt>:: sets the severity level. defaults to <tt>:warn</tt>
25
+ # <tt>:output</tt>:: optional secondary output, defaults to <tt>$stderr</tt>
26
+ # <tt>:level</tt>:: set to <tt>:log_only</tt> to disable secondary output
27
+ # <tt>:exception</tt>:: exception to throw on fail. Defaults to RunTimeError
28
+ #
29
+ # The status <tt>:warn</tt> will invoke Logger#warn. A status of
30
+ # <tt>:fatal</tt> will invoke Logger#fatal and raise an exception
31
+ #
32
+ # By default, complain will also print warnings to $stderr
33
+ # You can redirect this to any I/O object via <tt>:output</tt>
34
+ #
35
+ # You can prevent messages from appearing on the secondary output by setting
36
+ # <tt>:level</tt> to <tt>:log_only</tt>
37
+ #
38
+ # If you want to recover these messages to secondary output for debugging, you
39
+ # can use Config::enable_paranoia
40
+ def Ruport.complain(message,options={})
41
+ options[:status] ||= :warn
42
+ options[:output] ||= $stderr
43
+ case(options[:status])
44
+ when :warn
45
+ Ruport::Config::logger.warn(message) if Ruport::Config::logger
46
+ when :fatal
47
+ Ruport::Config::logger.fatal(message) if Ruport::Config::logger
48
+ raise options[:exception] || RuntimeError, message
49
+ end
50
+ options[:output].puts "[!!] #{message}" unless
51
+ options[:level].eql?(:log_only) and not Ruport::Config.paranoid?
52
+ end
53
+
54
+ end
55
+
56
+ %w[ config report format query data_row data_set].each { |lib|
57
+ require "ruport/#{lib}"
58
+ }
@@ -0,0 +1,114 @@
1
+ # ruport/config.rb : Ruby Reports configuration system
2
+ #
3
+ # Author: Gregory T. Brown (gregory.t.brown at gmail dot com)
4
+ #
5
+ # Copyright (c) 2006, All Rights Reserved.
6
+ #
7
+ # This is free software. You may modify and redistribute this freely under
8
+ # your choice of the GNU General Public License or the Ruby License.
9
+ #
10
+ # See LICENSE and COPYING for details
11
+ #
12
+ require "singleton"
13
+ require "ostruct"
14
+ module Ruport
15
+ # This class serves as the configuration system for Ruport.
16
+ # It's functionality is implemented through Config::method_missing
17
+ #
18
+ # source :default and mailer :default will become the fallback values if one
19
+ # is not specified in Report::Mailer or Query, but you may define as many
20
+ # sources as you like and switch between them later.
21
+ #
22
+ # An example config file is shown below:
23
+ #
24
+ # # password is optional, dsn may omit hostname for localhost
25
+ # Ruport::Config.source :default,
26
+ # :dsn => "dbi:mysql:somedb:db.blixy.org", :user => "root", :password => "chunky_bacon"
27
+ #
28
+ # # :password, :port, and :auth_type are optional. :port defaults to 25 and
29
+ # # :auth_type defaults to :plain. For more information, see the source
30
+ # # of Report::Mailer#select_mailer
31
+ # Ruport::Config.mailer :default,
32
+ # :host => "mail.chunkybacon.org", :address => "chunky@bacon.net",
33
+ # :user => "cartoon", :password => "fox", :port => 25, :auth_type => :login
34
+ #
35
+ # # optional, if specifed, Ruport#complain will report to it
36
+ # Ruport::Config.log_file 'foo.log'
37
+ #
38
+ # # optional, if enabled, will force :log_only complaint calls to
39
+ # # print to secondary output ($sterr by default).
40
+ # # call Ruport::Config.disable_paranoia to disable
41
+ # Ruport::Config.enable_paranoia
42
+ #
43
+ # Alternatively, this configuration could be done by opening the class:
44
+ # class Ruport::Config
45
+ #
46
+ # source :default, :dsn => "dbi:mysql:some_db", :user => "root"
47
+ #
48
+ # mailer :default, :host => "mail.iheartwhy.com",
49
+ # :address => "sandal@ruby-harmonix.net", :user => "sandal",
50
+ # :password => "abc123"
51
+ #
52
+ # logfile 'foo.log'
53
+ #
54
+ # end
55
+ #
56
+ # Saving this config information into a file and then requiring it can allow
57
+ # you share configurations between Ruport applications.
58
+ #
59
+ class Config
60
+ include Singleton
61
+
62
+ def Config.method_missing(method_id,*args)
63
+ case(method_id)
64
+ when :source
65
+ return @@sources[args.first] if args.length == 1
66
+ @@sources[args.first] = OpenStruct.new(*args[1..-1])
67
+ unless @@sources[args.first].send(:dsn)
68
+ Ruport.complain("Bad or missing DSN for source #{args.first}!")
69
+ end
70
+ when :mailer
71
+ @@mailers[args.first] = OpenStruct.new(*args[1..-1])
72
+ when :log_file
73
+ @@logger = Logger.new(args.first)
74
+ when :default_source
75
+ @@sources[:default]
76
+ when :default_mailer
77
+ @@mailers[:default]
78
+ when :sources
79
+ @@sources
80
+ when :mailers
81
+ @@mailers
82
+ when :logger
83
+ @@logger
84
+ when :enable_paranoia
85
+ @@paranoid = true
86
+ when :disable_paranoia
87
+ @@paranoid = false
88
+ when :paranoid?
89
+ @@paranoid
90
+ else
91
+ super
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def Config.init!
98
+ @@sources = { :default =>
99
+ OpenStruct.new( :dsn => "ruport",
100
+ :user => "",
101
+ :password => ""
102
+ )
103
+ }
104
+ @@mailers = { :default => nil }
105
+ @@logger ||= nil
106
+ @@paranoid ||= false
107
+ end
108
+
109
+
110
+
111
+ init!
112
+
113
+ end
114
+ end