table_setter 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,2 +1,2 @@
1
-
1
+ * Replace table-sorter with something simpler -- and more rock solid.
2
2
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 2
2
+ :minor: 2
3
3
  :build:
4
+ :patch: 3
4
5
  :major: 0
5
- :minor: 2
@@ -225,6 +225,8 @@ script/generate table-setter</pre>
225
225
  <h2><a id="credits" href="#toc">Credits</a></h2>
226
226
  <p><a href="http://github.com/thejefflarson">Jeff Larson</a> (Maintainer), <a href="http://github.com/brianboyer/">Brian Boyer</a>, <a href="http://github.com/kleinmatic">Scott Klein</a>, <a href="http://github.com/markpercival">Mark Percival</a>, <a href="http://github.com/seebq">Charles Brian Quinn</a>, <a href="http://github.com/bouvard">Christopher Groskopf</a>, and <a href="http://github.com/ryanmark">Ryan Mark</a>.</p>
227
227
  <h2><a id="changes" href="#toc">Change Log</a></h2>
228
+ <strong>0.2.3</strong>
229
+ <p>JavaScript fix for table-sorter.</p>
228
230
  <strong>0.2.2</strong>
229
231
  <p>Fixing long standing bug with empty prefixes in the <strong>build</strong> command.</p>
230
232
  <strong>0.2.1</strong>
@@ -232,7 +234,7 @@ script/generate table-setter</pre>
232
234
  <strong>0.2.0</strong>
233
235
  <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>
234
236
  <strong>0.1.11</strong>
235
- <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>
237
+ <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>
236
238
  <strong>0.1.10</strong>
237
239
  <p>New formatters via <a href="http://github.com/ryanmark">Ryan Mark</a>.
238
240
  <strong>0.1.9</strong>
data/index.html CHANGED
@@ -222,6 +222,8 @@ script/generate table-setter</pre>
222
222
  <h2><a id="credits" href="#toc">Credits</a></h2>
223
223
  <p><a href="http://github.com/thejefflarson">Jeff Larson</a> (Maintainer), <a href="http://github.com/brianboyer/">Brian Boyer</a>, <a href="http://github.com/kleinmatic">Scott Klein</a>, <a href="http://github.com/markpercival">Mark Percival</a>, <a href="http://github.com/seebq">Charles Brian Quinn</a>, <a href="http://github.com/bouvard">Christopher Groskopf</a>, and <a href="http://github.com/ryanmark">Ryan Mark</a>.</p>
224
224
  <h2><a id="changes" href="#toc">Change Log</a></h2>
225
+ <strong>0.2.3</strong>
226
+ <p>JavaScript fix for table-sorter.</p>
225
227
  <strong>0.2.2</strong>
226
228
  <p>Fixing long standing bug with empty prefixes in the <strong>build</strong> command.</p>
227
229
  <strong>0.2.1</strong>
@@ -229,7 +231,7 @@ script/generate table-setter</pre>
229
231
  <strong>0.2.0</strong>
230
232
  <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>
231
233
  <strong>0.1.11</strong>
232
- <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>
234
+ <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>
233
235
  <strong>0.1.10</strong>
234
236
  <p>New formatters via <a href="http://github.com/ryanmark">Ryan Mark</a>.
235
237
  <strong>0.1.9</strong>
data/lib/table_setter.rb CHANGED
@@ -15,19 +15,19 @@ module TableSetter
15
15
  autoload :App, 'table_setter/app'
16
16
  autoload :Command, 'table_setter/command'
17
17
  autoload :Table, 'table_setter/table'
18
-
18
+
19
19
  ROOT = File.expand_path(File.dirname(__FILE__) + "/..") unless defined? ROOT
20
-
20
+
21
21
  class << self
22
22
  attr_reader :config_path
23
-
23
+
24
24
  def configure(path)
25
25
  @config_path = File.expand_path(path)
26
26
  end
27
-
27
+
28
28
  def table_path
29
29
  @config_path + "/tables/"
30
30
  end
31
-
31
+
32
32
  end
33
33
  end
@@ -8,7 +8,7 @@ module TableSetter
8
8
  # The +Table+ class handles processing the yaml processing and csv loading,
9
9
  # through table fu
10
10
  attr_reader :data, :table_opts, :facets, :prev_page, :next_page, :page
11
-
11
+
12
12
  # A new Table should accept a slug, mapped to a yaml in the tables directory,
13
13
  # optionally you can defer loading of the table until you're ready to render it.
14
14
  def initialize(slug, opts={:defer => false})
@@ -20,7 +20,7 @@ module TableSetter
20
20
  self.load
21
21
  end
22
22
  end
23
-
23
+
24
24
  # The load method handles the actual request either to the file system or remote url.
25
25
  # It performs the requested data manipulations form the yml file after the data has been loaded.
26
26
  # We're keeping this explicit to control against unnecessary http requests.
@@ -33,7 +33,7 @@ module TableSetter
33
33
  end
34
34
  @data.delete_rows! @table_opts[:dead_rows] if @table_opts[:dead_rows]
35
35
  end
36
-
36
+
37
37
  # The csv_data for the table fu instance is loaded either from the remote source or from a local
38
38
  # file, depending on the keys present in the yaml file.
39
39
  def csv_data
@@ -42,71 +42,71 @@ module TableSetter
42
42
  when file then File.open(uri).read
43
43
  end
44
44
  end
45
-
45
+
46
46
  # Returns a usable uri based on what sort of input we have.
47
47
  def uri
48
- case
48
+ case
49
49
  when google_key then "http://spreadsheets.google.com/pub?key=#{google_key}&output=csv"
50
50
  when url then url
51
51
  when file then File.expand_path("#{TableSetter.table_path}#{file}")
52
52
  end
53
53
  end
54
-
54
+
55
55
  # The real +updated_at+ of a Table instance is the newer modification time of the csv file or
56
56
  # the yaml file. Updates to either resource should break the cache.
57
57
  def updated_at
58
58
  csv_time = google_key.nil? ? modification_time(uri) : google_modification_time
59
59
  (csv_time > yaml_time ? csv_time : yaml_time).to_s
60
60
  end
61
-
61
+
62
62
  def faceted?
63
63
  !@facets.nil?
64
64
  end
65
-
65
+
66
66
  # A table isn't sortable by tablesorter if it's either faceted or multi-page paginated.
67
67
  def sortable?
68
68
  !faceted? && !hard_paginate?
69
69
  end
70
-
70
+
71
71
  # hard_paginate instructs the app to render batches of a table.
72
72
  def hard_paginate?
73
73
  @table_opts[:hard_paginate] == true
74
74
  end
75
-
76
- # The number of rows per page. Defaults to 20
75
+
76
+ # The number of rows per page. Defaults to 20
77
77
  def per_page
78
78
  @table_opts[:per_page] || 20
79
79
  end
80
-
80
+
81
81
  # paginate uses TableFu's only! method to batch the table. It also computes the page attributes
82
82
  # which are nil and meaningless otherwise.
83
83
  def paginate!(curr_page)
84
84
  return if !hard_paginate?
85
85
  @page = curr_page.to_i
86
86
  raise ArgumentError if @page < 1 || @page > total_pages
87
- adj_page = @page - 1 > 0 ? @page - 1 : 0
87
+ adj_page = @page - 1 > 0 ? @page - 1 : 0
88
88
  @prev_page = adj_page > 0 ? adj_page : nil
89
89
  @next_page = page < total_pages ? (@page + 1) : nil
90
90
  @data.only!(adj_page * per_page..(@page * per_page - 1))
91
91
  end
92
-
93
-
92
+
93
+
94
94
  # The total pages we'll have. We need to calculate it before paginate, so that we still have the
95
95
  # full @data.rows.length
96
96
  def total_pages
97
97
  @total_pages ||= (@data.rows.length / per_page.to_f).ceil
98
98
  end
99
-
99
+
100
100
  # A convienence method to return the sort array for table setter.
101
101
  def sort_array
102
102
  @data.sorted_by.inject([]) do |memo, (key, value)|
103
103
  memo << [@data.columns.index(key), value == 'descending' ? 1 : 0]
104
104
  end
105
105
  end
106
-
106
+
107
107
  # We magically need access to the top level keys like google_key, or uri for the other methods.
108
108
  # It's a bit dangerous because everything returns nil otherwise. At some point we should eval
109
- # and create methods at boot time.
109
+ # and create methods at boot time.
110
110
  def method_missing(method)
111
111
  if @table_opts[method]
112
112
  @table_opts[method]
@@ -117,11 +117,10 @@ module TableSetter
117
117
 
118
118
  # Returns the google modification time of the spreadsheet. The public urls don't set the
119
119
  # last-modified header on anything, so we have to do a little dance to find out when exactly
120
- # the spreadsheet was last modified. The od[0-9] part of the feed url changes at whim, so we'll
121
- # need to keep an eye on it. Another propblem is that curb doesn't feel like parsing headers, so
120
+ # the spreadsheet was last modified. The od[0-9] part of the feed url changes at whim, so we'll
121
+ # need to keep an eye on it. Another problem is that curb doesn't feel like parsing headers, so
122
122
  # since a head request from google is pretty lightweight we can get away with using Net:HTTP.
123
- # If for whatever reason the google modification time is busted we'll return the epoch,
124
- # and rely on the yaml modified time.
123
+ # If for whatever reason the google modification time is busted we'll the yaml modified time.
125
124
  def google_modification_time
126
125
  local_url = URI.parse "http://spreadsheets.google.com/feeds/list/#{google_key}/od6/public/basic"
127
126
  web_modification_time local_url
@@ -136,7 +135,7 @@ module TableSetter
136
135
  end
137
136
  resp['Last-Modified'].nil? ? Time.at(0) : Time.parse(resp['Last-Modified'])
138
137
  end
139
-
138
+
140
139
  # Dispatches to web_modification_time if we're dealing with a url, otherwise just stats the
141
140
  # local file.
142
141
  def modification_time(path)
@@ -170,11 +169,11 @@ module TableSetter
170
169
  public
171
170
 
172
171
  class << self
173
-
172
+
174
173
  # Returns all the tables in the table directory. Each table is deferred so accessing the @data
175
174
  # attribute will throw and error.
176
175
  def all
177
- tables=[]
176
+ tables=[]
178
177
  Dir.glob("#{TableSetter.table_path}/*.yml").each do |file|
179
178
  table = new(File.basename(file, ".yml"), :defer => true)
180
179
  tables << table if table.live
@@ -191,7 +190,7 @@ module TableSetter
191
190
  obj_time = File.new(File.expand_path obj).mtime
192
191
  if memo_time > obj_time
193
192
  memo
194
- else
193
+ else
195
194
  obj
196
195
  end
197
196
  end
@@ -226,7 +225,7 @@ class TableFu::Formatting
226
225
  def markdown(cell)
227
226
  RDiscount.new(cell).to_html
228
227
  end
229
-
228
+
230
229
  # format as a link, if the href is empty don't make the link active
231
230
  def link(linkname, href)
232
231
  title = linkname.to_s.gsub(/(["])/, "'")
@@ -236,17 +235,17 @@ class TableFu::Formatting
236
235
  "<a title=\"#{title}\">#{linkname}</a>"
237
236
  end
238
237
  end
239
-
238
+
240
239
  # make it strong
241
240
  def strong(cell)
242
241
  "<strong>#{cell}</strong>"
243
242
  end
244
-
243
+
245
244
  # make it small
246
245
  def small(cell)
247
246
  "<small>#{cell}</small>"
248
247
  end
249
-
248
+
250
249
  # join multiple columns, with optional delimiter
251
250
  def join(*args)
252
251
  args.join(" ")
data/table_setter.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{table_setter}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeff Larson"]
12
- s.date = %q{2010-11-09}
12
+ s.date = %q{2010-11-12}
13
13
  s.description = %q{A sinatra based app for rendering CSVs hosted on google docs or locally in custom HTML}
14
14
  s.email = %q{thejefflarson@gmail.com}
15
15
  s.executables = ["table-setter", "table-setter"]
@@ -35,10 +35,12 @@ $(document).ready(function(){
35
35
  type: "numeric"
36
36
  });
37
37
 
38
- // Overriding format float to actually test a bit better.
38
+ // Overriding format float to actually test a bit better. If it is a number
39
+ // already we'll return the number's value, if not we'll call the old parse
40
+ // float from table sorter.
39
41
  var oldFloat = $.tablesorter.formatFloat;
40
42
  $.tablesorter.formatFloat = $.tablesorter.formatInt = function(obj){
41
- return (obj === +obj) || (toString.call(obj) === '[object Number]') ? 0 : oldFloat(obj);
43
+ return (obj === +obj) || (Object.prototype.toString.call(obj) === '[object Number]') ? obj : oldFloat(obj);
42
44
  };
43
45
 
44
46
  //initialize the table
@@ -3,7 +3,7 @@ table:
3
3
  file: example_formatted.csv
4
4
  deck:
5
5
  <p>The success of the federal stimulus program may hinge on the speed with which the government is able to distribute the billions authorized by Congress. Unlike some other estimates of the cost of the stimulus, which are based on spending projections, we took our numbers from the actual budget authority issued by Congress — $792 billion and change. We'll be tracking the progress of stimulus payments made by federal agencies weekly.</p>
6
-
6
+
7
7
  footer:
8
8
  <p>This chart and other stories are part of Eye on the Stimulus, our blog dedicated to tracking the stimulus from bill to building.</p>
9
9
  column_options:
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_setter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Larson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-09 00:00:00 -05:00
18
+ date: 2010-11-12 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency