table_setter 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/Rakefile +10 -52
- data/documentation/index.html.erb +5 -6
- data/lib/table_setter.rb +2 -3
- data/lib/table_setter/table.rb +0 -1
- data/lib/table_setter/version.rb +3 -0
- data/table_setter.gemspec +26 -161
- data/test/table-setter-app_test.rb +22 -0
- data/{spec/table-setter-command_spec.rb → test/table-setter-command_test.rb} +15 -16
- data/test/table-setter_test.rb +172 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +2 -7
- metadata +144 -183
- data/VERSION.yml +0 -5
- data/index.html +0 -305
- data/spec/spec.opts +0 -1
- data/spec/table-setter-app_spec.rb +0 -24
- data/spec/table-setter_spec.rb +0 -173
data/VERSION.yml
DELETED
data/index.html
DELETED
@@ -1,305 +0,0 @@
|
|
1
|
-
|
2
|
-
<!DOCTYPE html>
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
6
|
-
<title>TableSetter</title>
|
7
|
-
<link rel="stylesheet" type="text/css" href="documentation/css/styles.css" />
|
8
|
-
<link rel="stylesheet" type="text/css" href="documentation/css/dawn.css" />
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
<a href="http://www.propublica.org" class="propublica"> </a>
|
12
|
-
<h1>TableSetter <small>– Version: 0.2.11</small></h1>
|
13
|
-
<p><a href="https://github.com/propublica/table-setter">TableSetter</a> is a Ruby app that provides an easy way to present CSVs hosted locally or remotely (e.g. on google, etc) in custom HTML. TableSetter in the wild: <a href="http://projects.propublica.org/tables/failed-banks">a list of all stimulus projects from last year</a>, <a href="http://projects.propublica.org/tables/stimulus-spending-progress">the stimulus spending progress</a>, or <a href="http://projects.propublica.org/tables/failed-banks">a list of failed banks due to the last recession</a>.</p>
|
14
|
-
<p>Each table is filterable and sortable on multiple columns. Also each column can be formatted in one of many different styles. In production mode, <strong>TableSetter</strong> provides valid expires headers and can be coupled with an upstream cache like <a href="http://rtomayko.github.com/rack-cache/">Rack::Cache</a> or varnish for speedy presentation.</p>
|
15
|
-
<h2><a id="toc">Table of Contents</a></h2>
|
16
|
-
<ul>
|
17
|
-
<li><a href="#installation">Installation</a></li>
|
18
|
-
<li><a href="#tablesetter">The table-setter command</a></li>
|
19
|
-
<li><a href="#thedirectory">The Configuration Directory</a></li>
|
20
|
-
<li><a href="#thefile">A TableSetter File</a></li>
|
21
|
-
<li><a href="#deployment">Deployment</a></li>
|
22
|
-
<li><a href="#rails">Rails</a></li>
|
23
|
-
<li><a href="#links">Links</a></li>
|
24
|
-
<li><a href="#credits">Credits</a></li>
|
25
|
-
<li><a href="#changes">Change Log</a></li>
|
26
|
-
<li><a href="#license">License</a></li>
|
27
|
-
</ul>
|
28
|
-
<h2><a id="installation" href="#toc">Installation</a></h2>
|
29
|
-
<p>Install <strong>TableSetter</strong> through rubygems:</p>
|
30
|
-
<pre class="dawn">
|
31
|
-
gem install table_setter</pre>
|
32
|
-
<p>or from the source files:</p>
|
33
|
-
<pre class="dawn">
|
34
|
-
git clone git://github.com/propublica/table-setter.git
|
35
|
-
cd table-setter
|
36
|
-
rake install</pre>
|
37
|
-
<p>After you've installed the gem you'll have a new executable: <strong>table-setter</strong>. You can view the subcommands available by typing <strong>table-setter --help</strong>. To set things up you'll need to run it with the <strong>install</strong> command to install the configuration files and ERB templates into a directory. </p>
|
38
|
-
<pre>
|
39
|
-
table-setter install path/to/directory</pre>
|
40
|
-
<p>
|
41
|
-
To start the development server run:
|
42
|
-
</p>
|
43
|
-
<pre>
|
44
|
-
table-setter start path/to/directory</pre>
|
45
|
-
<p>Go to development url, <a href="http://localhost:3000/">http://localhost:3000/</a> and you'll see a list of the example tables. You can peruse the examples <a href="http://propublica.github.com/table-setter/documentation/tables/">here</a>.</p>
|
46
|
-
<h2><a id="tablesetter" href="#toc">The table-setter command</a></h2>
|
47
|
-
<p>
|
48
|
-
The <strong>table-setter</strong> command responds to three subcommands:
|
49
|
-
<ul>
|
50
|
-
<li><strong>install <DIRECTORY></strong> installs the tablesetter files into the current directory or one you specify.</li>
|
51
|
-
<li><strong>start <DIRECTORY></strong> starts the development server so you can preview your tables before deploying.</li>
|
52
|
-
<li><strong>build <DIRECTORY> -p <PATH></strong> builds a static version of the tables, <strong><PATH></strong> is the relative path where you want to place the tables on your webserver.
|
53
|
-
See <a href="#deployment">Deployment</a></li>
|
54
|
-
</ul>
|
55
|
-
</p>
|
56
|
-
<h2><a id="thedirectory" href="#toc">The Configuration Directory</a></h2>
|
57
|
-
<p>
|
58
|
-
The configuration folder contains the javascripts, stylesheets, view templates (written in <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/">ERB</a>), rackup file, and most importantly the configuration files for each table.
|
59
|
-
</p>
|
60
|
-
<p>You'll put table definition files in the <strong>table</strong> directory, your javascript in <strong>public/javascripts</strong> and css in <strong>public/stylesheets</strong>. You can make most HTML customizations in <strong>views/layout.erb</strong>.
|
61
|
-
<p class="file">
|
62
|
-
The <strong>config.ru</strong> file is a rackup file that instructs the webserver to start the <strong>TableSetter</strong> application and serve the assets contained in the configuration folder. In most cases you'll want to use apache and passenger (see <a href="#deployment">Deployment</a> for details).
|
63
|
-
</p>
|
64
|
-
<p class="dir">
|
65
|
-
In <strong>public</strong> you'll find the static assets required for the look and feel and functionality of the table:
|
66
|
-
</p>
|
67
|
-
<ul>
|
68
|
-
<li class="dir"> The <strong>images</strong> directory contains the small images <img src="template/public/images/th_arrow_asc.gif" style="display:inline"> and <img src="template/public/images/th_arrow_desc.gif" style="display:inline"> which show the user the sorting direction of a given column.</li>
|
69
|
-
<li class="dir"> The <strong>javascripts</strong> directory contains scripts that power the dynamic functionality of a table. Each file depends on <a href="http://jquery.com/">jQuery</a>:
|
70
|
-
<ul>
|
71
|
-
<li class="file"><strong>application.js</strong> dispatches to the other javascript files to render the table at load time. It also defines the column highlighting function.</li>
|
72
|
-
<li class="file"><strong>jquery.tablesorter.js</strong> the jQuery <a href="http://tablesorter.com/docs/">tablesorter plugin</a> that handles the dynamic sorting by column.</li>
|
73
|
-
<li class="file"><strong>jquery.tablesorter.pager.js</strong> the <a href="http://tablesorter.com/docs/example-pager.html">tablesorter pager plugin</a> to tablesorter that provides the paging functionality.</li>
|
74
|
-
<li class="file"><strong>jquery.tablesorter.multipagefilter.js</strong> a custom plugin that allows for searching across multiple pages</li>
|
75
|
-
</ul>
|
76
|
-
</li>
|
77
|
-
<li class="dir">The <strong>stylesheets</strong> directory contains <strong>application.css</strong>, the <strong>TableSetter</strong> stylesheet. Each style is prefaced with <strong>#tablefu</strong> so you should be able to include your organization's css on the page without affecting the tables.</li>
|
78
|
-
</ul>
|
79
|
-
<p class="dir">The <strong>tables</strong> directory contains yml configuration files for each of the tables you want to deploy. By default it contains:</p>
|
80
|
-
<ul>
|
81
|
-
<li class="file"><strong>example.yml</strong> contains most of the simple options in a <strong>TableSetter</strong> file.</li>
|
82
|
-
<li class="file"><strong>example_local.yml</strong> and <strong>example_local.csv</strong> shows how to build a table from a local file. It also is hard_paginated (see <a href="#thefile">A Table Setter File</a>).</li>
|
83
|
-
<li class="file"><strong>example_faceted.yml</strong> is an example of faceting.</li>
|
84
|
-
<li class="file"><strong>example_formatted.yml</strong> and <strong>example_formatted.csv</strong> shows how to apply formatting to a column and a group of columns.</li>
|
85
|
-
</ul>
|
86
|
-
<p class="dir">The <strong>views</strong> directory contains the <a href="http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/">ERB</a> templates needed to render the table pages and index page.</p>
|
87
|
-
<ul>
|
88
|
-
<li class="file">
|
89
|
-
<strong>404.erb</strong> and <strong>500.erb</strong> render when a table is not found or a server error occurs, respectively.
|
90
|
-
</li>
|
91
|
-
<li class="file"><strong>layout.erb</strong> contains the basic frame of the page. You should place most of your customizations here. If you'd like to add custom html, place it above or below the <strong><%= yield %></strong> tag.</li>
|
92
|
-
<li class="file"><strong>index.erb</strong> renders the table list for the root path of the app.</li>
|
93
|
-
<li class="file"><strong>table.erb</strong> renders an individual table. You shouldn't have to tweak this much, if at all.</li>
|
94
|
-
</ul>
|
95
|
-
<h2><a id="thefile" href="#toc">A TableSetter File</a></h2>
|
96
|
-
<p>Each TableSetter file is written in <a href="http://www.yaml.org/">YAML</a> and outlines the the display options for a particular table. The filename dictates the path where it will appear (e.g. a config file named example.yml will appear at <strong>http://host/example</strong>). Initially TableSetter installs a few examples to get you started (see <a href="#thedirectory">above</a>).</p>
|
97
|
-
<p>Each table setter file must begin with a <strong>table:</strong> declaration, and it's important to note that whitespace matters. For example consider this csv:</p>
|
98
|
-
<pre>
|
99
|
-
Bank,Spent,Funds,Link
|
100
|
-
McDuck Bank,100000,10000000,http://diveintomoney.com
|
101
|
-
Potter Savings and Loans,1100,1000000,http://angelsandwingsmrstewart.com
|
102
|
-
</pre>
|
103
|
-
<p>these are the example options in a <strong>TableSetter</strong> config file:
|
104
|
-
<pre>
|
105
|
-
table:
|
106
|
-
title: The title of the table
|
107
|
-
|
108
|
-
# google_key:, file:, or url: define how a table is loaded.
|
109
|
-
# only one is necessary
|
110
|
-
file: loads a local CSV file from the /tables directory.
|
111
|
-
url: will load a CSV file from an external server, and
|
112
|
-
google_key: is a google key url from an external google doc (see note).
|
113
|
-
|
114
|
-
deck: A HTML string describing the table, appears above the table itself.
|
115
|
-
|
116
|
-
footer: A HTML string for notes/caveats etc. Appears below the table.
|
117
|
-
|
118
|
-
column_options: # Defines a hash of options that are passed onto TableFu
|
119
|
-
|
120
|
-
columns: # A list of columns to include, for example:
|
121
|
-
- Bank # would only include the bank column in the table
|
122
|
-
|
123
|
-
style: # A list of style declarations by column, for example:
|
124
|
-
Bank: 'text-align:left;' # would left-align the text in the "Bank" column.
|
125
|
-
|
126
|
-
sorted_by: # Defines the sort order and column to sort by of the table.
|
127
|
-
Bank: ascending # would sort by the Bank column in ascending order
|
128
|
-
|
129
|
-
total: # Declares which columns should have a totals row.
|
130
|
-
['Funds', 'Spent']
|
131
|
-
|
132
|
-
formatting: # Defines which of the TableFu formatters to apply to a column.
|
133
|
-
(%) Spent: bar # applies the bar formatter to the '(%) Spent' column.
|
134
|
-
Link: # Creates a meta column form two other columns
|
135
|
-
method: link # describes the formatter to use
|
136
|
-
arguments: ['Bank', 'URL'] # Combines Bank and URL as arguments
|
137
|
-
|
138
|
-
faceting: # Describes the faceting, or grouping, to apply to a table
|
139
|
-
facet_by: Bank # groups the records by bank name
|
140
|
-
|
141
|
-
hard_paginate: true # Dictates that the table should be spread across multiple pages
|
142
|
-
# can't be used with faceting, and disables the user filtering
|
143
|
-
|
144
|
-
per_page: 250 # Instructs TableSetter to only page by 250 rows.
|
145
|
-
|
146
|
-
live: true # publishes the table in the index page. Note that even if live is
|
147
|
-
# set to false the table is still accessible directly.
|
148
|
-
|
149
|
-
</pre>
|
150
|
-
|
151
|
-
<h3>NB: A Note About google_key</h3>
|
152
|
-
<p>At ProPublica, we mainly use TableSetter to format public google spreadsheets. You can find the <strong>google_key</strong> by publishing a spreadsheet as a webpage:</p>
|
153
|
-
<img src="documentation/images/publish.png">
|
154
|
-
<p>and in the dialog box, the google key is here:</p>
|
155
|
-
<img src="documentation/images/key.png">
|
156
|
-
<h2><a id="deployment" href="#toc">Deployment</a></h2>
|
157
|
-
|
158
|
-
<h3>Passenger</h3>
|
159
|
-
<em>(Cribbed from the excellent <a href="http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application">passenger documentation</a>.)</em>
|
160
|
-
<p>If you're familiar with deploying a Rails application under passenger, not much changes when deploying a rack basked application. <strong>TableSetter</strong> includes a <strong>config.ru</strong> file that should be sufficient under most situations. You'll need to create a <strong>tmp</strong> directory inside the <strong>TableSetter</strong> directory on the server. The following virtual host configuration will deploy <strong>TableSetter</strong> directory:
|
161
|
-
</p>
|
162
|
-
<pre>
|
163
|
-
<VirtualHost *:80>
|
164
|
-
ServerName www.yourdomain.com
|
165
|
-
DocumentRoot /path/to/table-setter/public
|
166
|
-
</VirtualHost></pre>
|
167
|
-
<p>If you want to deploy <strong>TableSetter</strong> under a sub URI you should symlink the public folder to a directory in the document root:</p>
|
168
|
-
<pre>
|
169
|
-
ln -s /path/to/table-setter/public /docroot/tables</pre>
|
170
|
-
<p>
|
171
|
-
and change you're apache config to reflect the sub URI:
|
172
|
-
</p>
|
173
|
-
<pre>
|
174
|
-
<VirtualHost *:80>
|
175
|
-
ServerName www.yourdomain.com
|
176
|
-
DocumentRoot /docroot/tables
|
177
|
-
RackBaseURI /tables
|
178
|
-
</VirtualHost></pre>
|
179
|
-
<h3>Caching</h3>
|
180
|
-
<p>You probably don't want to parse a remote CSV file on every request in production, so the <strong>config.ru</strong> file contains directives to enable <strong>Rack:Cache</strong> a simple reverse proxy cache. If your web server is not behind an upstream cache you'll want to enable it by uncommenting the required lines.<p>
|
181
|
-
<p>You'll also want to enable the <strong>TableSetter:App</strong> expire time by uncommenting this line:</p>
|
182
|
-
<pre>
|
183
|
-
TableSetter::App.cache_timeout = 60 * 15 # 15 minutes</pre>
|
184
|
-
<p>That line dictates the max age of a request and you'll want to tweak it depending on how frequently changed your tables will be and how many users you expect. If you want to define any <a href="https://github.com/propublica/table-fu">TableFu</a> formatters you should do so in <strong>config.ru</strong>.</p>
|
185
|
-
|
186
|
-
<h3>Static</h3>
|
187
|
-
<p>You can also use to pre-build <strong>table-setter</strong> your tables as html and upload the built files to your web server. You can build them using the <strong>table-setter</strong> command:</p>
|
188
|
-
<pre>
|
189
|
-
table-setter build path/to/table-setter/directory -p path</pre>
|
190
|
-
<p>The build tables will be placed in the <strong>out</strong> directory inside the configuration directory.</p>
|
191
|
-
<p>The <strong>-p</strong> flag dictates where on the server relative to root you'll install the files. If I want my tables to appear under the <strong>tables/</strong> directory on my site, I'd run:</p>
|
192
|
-
<pre>
|
193
|
-
table-setter build path/to/table-setter/directory -p tables</pre>
|
194
|
-
<p>And upload the files in the <strong>out/tables</strong> directory.</p>
|
195
|
-
<h2><a id="rails" href="#toc">Rails</a></h2>
|
196
|
-
<p>In order to use table-setter as a Rails, you'll need to install the <a href="http://github.com/propublica/table-setter-generator">table-setter-generator </a> gem. Once you've done that you'll be able to run:</p>
|
197
|
-
<pre>
|
198
|
-
script/generate table-setter</pre>
|
199
|
-
<p>In your existing Rails app path and it will install the <strong>TableSetter</strong> routes, controller, views, and <strong>Table</strong> model.</p>
|
200
|
-
<h2><a id="links" href="#toc">Links</a></h2>
|
201
|
-
<ul>
|
202
|
-
<li><a href="http://github.com/propublica/table-fu">TableFu</a><br>
|
203
|
-
A gem that provides the conceptual backend to <strong>TableSetter</strong>.</li>
|
204
|
-
<li><a href="http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application">Passenger Documentation</a><br>
|
205
|
-
The Passenger Documention section on how to deploy a rack app under passenger.</li>
|
206
|
-
<li><a href="http://docs.heroku.com/rack">Heroku Documentation</a><br>
|
207
|
-
How to deploy a rack app in heroku.</li>
|
208
|
-
<li><a href="http://github.com/propublica/table-fu/issues">Issues</a><br>
|
209
|
-
The github issue tracker. Post bug reports and feature requests here.</li>
|
210
|
-
<li><a href="http://www.yaml.org/">YAML</a><br>
|
211
|
-
The YAML homepage. <strong>TableSetter</strong> config files are YAML files.
|
212
|
-
</li>
|
213
|
-
<li><a href="doc/index.html">API Docs</a></li>
|
214
|
-
<li><a href="http://www.pbs.org/newshour/interactive/static/tables/health-states/">In the Wild: PBS NewsHour</a><br>
|
215
|
-
A state by state breakdown of legislative challenges to health care reform.
|
216
|
-
</li>
|
217
|
-
<li>
|
218
|
-
<a href="http://media.apps.chicagotribune.com/tables/speed.html">In the Wild: Chicago Tribune</a><br>
|
219
|
-
A table showing leniency rates of Chicago area judges in speeding cases.
|
220
|
-
</li>
|
221
|
-
<li>
|
222
|
-
<a href="https://github.com/newsapps/tostones">In the Wild: Tostones, easy TableSetter testing and deployment</a><br>
|
223
|
-
A set of fabric deploy scripts for deploying TableSetter to s3.
|
224
|
-
</li>
|
225
|
-
</ul>
|
226
|
-
<h2><a id="credits" href="#toc">Credits</a></h2>
|
227
|
-
<p><a href="http://github.com/thejefflarson">Jeff Larson</a> (Maintainer),
|
228
|
-
<a href="http://github.com/brianboyer/">Brian Boyer</a>,
|
229
|
-
<a href="http://github.com/kleinmatic">Scott Klein</a>,
|
230
|
-
<a href="http://github.com/markpercival">Mark Percival</a>,
|
231
|
-
<a href="http://github.com/seebq">Charles Brian Quinn</a>,
|
232
|
-
<a href="http://github.com/bouvard">Christopher Groskopf</a>,
|
233
|
-
<a href="http://github.com/ryanmark">Ryan Mark</a>,
|
234
|
-
<a href="http://github.com/palewire">Ben Welsh</a>, and
|
235
|
-
<a href="http://github.com/jpmckinney">James McKinney</a>.</p>
|
236
|
-
<h2><a id="changes" href="#toc">Change Log</a></h2>
|
237
|
-
<strong>0.2.10</strong>
|
238
|
-
<p>Switch to https for google key.</p>
|
239
|
-
<strong>0.2.9</strong>
|
240
|
-
<p>Updated <strong>config.ru</strong> to fix the same bug in <strong>0.2.8</strong>, you'll want to regenerate your template.</p>
|
241
|
-
<strong>0.2.8</strong>
|
242
|
-
<p>Fixed a scope bug for 1.9.1 when <strong>Rack::File</strong> is around.</p>
|
243
|
-
<strong>0.2.7</strong>
|
244
|
-
<p>404 and 500 pages have no layout now, please update your templates accordingly.</p>
|
245
|
-
<strong>0.2.6</strong>
|
246
|
-
<p>Fixed a bug in <strong>table-setter start</strong> thanks to <a href="http://github.com/jfkeefe">John Keefe</a>
|
247
|
-
merged in some more changes from <a href="http://github.com/jpmckinney">James McKinney</a>
|
248
|
-
and added a <strong>lib/formatters.rb</strong> in the <strong>template</strong>, which is the standard
|
249
|
-
place to stash your custom formatters. Also, the <strong>build</strong> command
|
250
|
-
now errors loudly and exits if there's an error.</p>
|
251
|
-
<strong>0.2.5</strong>
|
252
|
-
<p>Loads of bullet-proofing from <a href="http://github.com/jpmckinney">James McKinney</a> and js fixes from <a href="http://github.com/palewire">Ben Welsh</a>, you'll want to re-run <strong>table-setter install</strong> to grab the changes, as with previous releases.</p>
|
253
|
-
<strong>0.2.4</strong>
|
254
|
-
<p>Fixes encodings issues and the FasterCSV name change for ruby 1.9.</p>
|
255
|
-
<strong>0.2.3</strong>
|
256
|
-
<p>JavaScript fix for table-sorter.</p>
|
257
|
-
<strong>0.2.2</strong>
|
258
|
-
<p>Fixing long standing bug with empty prefixes in the <strong>build</strong> command.</p>
|
259
|
-
<strong>0.2.1</strong>
|
260
|
-
<p>Table Urls have an optional trailing slash. Fixes a bug in <strong>0.2.0</strong></p>
|
261
|
-
<strong>0.2.0</strong>
|
262
|
-
<p>It's recommended not to use this version. <del><b>Backwards incompatible change:</b> Table urls no longer end in a trailing slash. Please modify the <strong>url_for</strong> calls in your templates to reflect the change.</del></p>
|
263
|
-
<strong>0.1.11</strong>
|
264
|
-
<p>JavaScript Fixes. <b>Note:</b> You'll need to delete the javascript's folder in the config directory and run <strong>table-setter install</strong> to grab the changes.</p>
|
265
|
-
<strong>0.1.10</strong>
|
266
|
-
<p>New formatters via <a href="http://github.com/ryanmark">Ryan Mark</a>.
|
267
|
-
<strong>0.1.9</strong>
|
268
|
-
<p>No Op.</p>
|
269
|
-
<strong>0.1.8</strong>
|
270
|
-
<p>Bunch of fixes from <a href="http://github.com/ryanmark">Ryan Mark</a>, and beta markdown functionality. Once Markdown is tested we'll release 0.2.0</p>
|
271
|
-
<strong>0.1.7</strong>
|
272
|
-
<p>Bugfix to the build command to place assets in the right place</p>
|
273
|
-
<strong>0.1.6</strong>
|
274
|
-
<p>Fix in <strong>build_assets</strong> in command.rb, via <a href="http://github.com/propublica/table-setter/commit/2dd207d57eda4d78520b8a5fa99e6e085952206a">Christopher Groskopf</a></p>
|
275
|
-
<strong>0.1.5</strong>
|
276
|
-
<p>Bugfixes.</p>
|
277
|
-
<strong>0.1.4</strong>
|
278
|
-
<p>Javascript fixes and thin added as a dependency.</p>
|
279
|
-
<strong>0.1.3</strong>
|
280
|
-
<p>Initial release.</p>
|
281
|
-
<h2><a id="license" href="#toc">License</a></h2>
|
282
|
-
<pre>Copyright (c) 2010 ProPublica
|
283
|
-
|
284
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
285
|
-
a copy of this software and associated documentation files (the
|
286
|
-
"Software"), to deal in the Software without restriction, including
|
287
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
288
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
289
|
-
permit persons to whom the Software is furnished to do so, subject to
|
290
|
-
the following conditions:
|
291
|
-
|
292
|
-
The above copyright notice and this permission notice shall be
|
293
|
-
included in all copies or substantial portions of the Software.
|
294
|
-
|
295
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
296
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
297
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
298
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
299
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
300
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
301
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
302
|
-
</pre>
|
303
|
-
|
304
|
-
</body>
|
305
|
-
</html>
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe TableSetter::App, "in the application" do
|
5
|
-
include Rack::Test::Methods
|
6
|
-
|
7
|
-
def app
|
8
|
-
TableSetter::App
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
|
-
it "should render the homepage" do
|
13
|
-
get '/'
|
14
|
-
last_response.body.include?("All Tables").should be_true
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
it "should render a table" do
|
19
|
-
get '/example_local/'
|
20
|
-
last_response.ok?.should be_true
|
21
|
-
last_response.body.include?("Browse All Approved Stimulus Highway Projects").should be_true
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/spec/table-setter_spec.rb
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
|
4
|
-
describe TableSetter::Table do
|
5
|
-
it 'should return the latest yaml modification time' do
|
6
|
-
`touch #{TableSetter::Table.table_path('example')}`
|
7
|
-
TableSetter::Table.fresh_yaml_time.should eql(
|
8
|
-
File.new(TableSetter::Table.table_path('example')).mtime)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TableSetter::Table do
|
13
|
-
before :all do
|
14
|
-
@table = TableSetter::Table.new("example_local")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should load from a google key, and defer loading when asked" do
|
18
|
-
table = TableSetter::Table.new("example", :defer => true)
|
19
|
-
table.data.should be_nil
|
20
|
-
table.load
|
21
|
-
table.data.should_not be_nil
|
22
|
-
table.data.headers.should_not be_nil
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should be able to find out if a given table exists' do
|
26
|
-
TableSetter::Table.exists?("non_existent_table").should be_false
|
27
|
-
TableSetter::Table.exists?("example").should be_true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should have a slug" do
|
31
|
-
@table.slug.should eql "example_local"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should have a deck" do
|
35
|
-
@table.deck.should_not be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should have 250 items per page" do
|
39
|
-
@table.per_page.should eql 250
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should be sortable" do
|
43
|
-
@table.sortable?.should be_false
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should have a footer" do
|
47
|
-
@table.footer.should_not be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have a title" do
|
51
|
-
@table.title.should_not be_nil
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should have 5805 rows" do
|
55
|
-
@table.data.rows.length.should eql 5805
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be stylish" do
|
59
|
-
@table.data.rows[1].column_for('State').style.should eql 'text-align:left;'
|
60
|
-
@table.data.rows[1].column_for('Project Description').style.should eql 'text-align:right;'
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should have stylish headers" do
|
64
|
-
@table.data.headers[0].style.should eql 'text-align:left;'
|
65
|
-
@table.data.headers[4].style.length.should eql 0
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should be formatted" do
|
69
|
-
@table.data.rows[1].column_for('ARRA Funds Obligated').to_s.should eql '$154,446'
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
|
75
|
-
describe TableSetter::Table, "with hard pagination" do
|
76
|
-
before :each do
|
77
|
-
@data = TableSetter::Table.new("example_local")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should not be sortable" do
|
81
|
-
@data.sortable?.should eql false
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should be paginated" do
|
85
|
-
@data.hard_paginate?.should eql true
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should paginate based on a page" do
|
89
|
-
@data.paginate! 3
|
90
|
-
@data.page.should eql 3
|
91
|
-
@data.prev_page.should eql 2
|
92
|
-
@data.next_page.should eql 4
|
93
|
-
@data.data.rows.length.should eql @data.per_page
|
94
|
-
@data.data.rows[0].column_for('State').to_s.should eql 'CALIFORNIA'
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should not paginate when given a bad value' do
|
98
|
-
lambda {@data.paginate!(-1)}.should raise_error(ArgumentError)
|
99
|
-
lambda {@data.paginate!(10000000)}.should raise_error(ArgumentError)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'should handle first page' do
|
103
|
-
@data.paginate! 1
|
104
|
-
@data.page.should eql 1
|
105
|
-
@data.prev_page.should eql nil
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'should handle last page' do
|
109
|
-
@data.paginate! @data.total_pages
|
110
|
-
@data.page.should eql @data.total_pages
|
111
|
-
@data.next_page.should eql nil
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
describe TableSetter::Table, "with faceting and macros" do
|
117
|
-
before :all do
|
118
|
-
@data = TableSetter::Table.new("example_faceted")
|
119
|
-
@tables = @data.facets
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'should load a faceted_table' do
|
123
|
-
data = TableSetter::Table.new("example_faceted", :defer=> true)
|
124
|
-
data.facets.should be_nil
|
125
|
-
data.load
|
126
|
-
tables = data.facets
|
127
|
-
tables.length.should eql 56
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should be faceted" do
|
131
|
-
@data.faceted?.should be_true
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should not be sortable" do
|
135
|
-
@data.sortable?.should be_false
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
it "should have 3 tables" do
|
140
|
-
@tables.length.should eql 56
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should have $212,774,529 for Alabama" do
|
144
|
-
@tables[0].total_for('Total Appropriation').to_s.should eql '$212,774,529'
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should have $416,075,044 for North Carolina with dead row" do
|
148
|
-
@tables[35].total_for('Total Appropriation').to_s.should eql '$423,318,645'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe TableSetter::Table, "group fetchers" do
|
153
|
-
it "should return live tables" do
|
154
|
-
TableSetter::Table.all.length.should eql 1
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe TableSetter::Table, "with urls and google bars" do
|
159
|
-
before :each do
|
160
|
-
@table = TableSetter::Table.new("example_formatted")
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should have a link row" do
|
164
|
-
@table.data.rows[1].column_for('Agency Webpage').to_s.should eql "<a href=\"http://www.hhs.gov/recovery/\" title=\"Health and Human Services\">Health and Human Services</a>"
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'should show a bar' do
|
168
|
-
@table.data.rows[1].column_for('Spent (%)').to_s.should eql "<div class=\"bar\" style=\"width:42.0%\">42.0%</div>"
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
|