Permalink
Browse files

Merging in proxyPrefix, renaming to parameterize and adding docs/exam…

…ples
  • Loading branch information...
1 parent a12b966 commit 12cb040869cc6a504ebafb2f1e52340bc0528416 @jsoma committed Mar 29, 2013
Showing with 37 additions and 7 deletions.
  1. +9 −1 README.md
  2. +25 −0 examples/proxy/parameterize.html
  3. +3 −6 src/tabletop.js
View
@@ -112,6 +112,8 @@ You pass in either `key` as the actual spreadsheet key, or just the full publish
`debug` returns on debug mode, which gives you plenty of messaging about what's going on under the hood.
+`parameterize` changes the src of all injected scripts. Instead of `src`, `src` is URI encoded and appended to `parameterize`, e.g. set it to `http://example.herokuapp.com/?url=`. Mostly for [gs-proxy](https://github.com/MinnPost/gs-proxy).
+
`callbackContext` sets the `this` for your callback. It's the tabletop object by default.
### Tabletop itself
@@ -197,7 +199,7 @@ See the `postProcess` call? That's called on every row after Tabletop.Model gets
A sample lives in `/examples/timeline_setter/`
-## Caching Google Spreadsheets
+## Caching/Proxying Google Spreadsheets
Yeah, Google Spreadsheets can sometimes be slow or sometimes be overwhelmed or *maybe* one day Google will just up and disappear on us. So Tabletop.js now supports fetching your data from elsewhere, using options like `endpoint` and `proxy`.
@@ -207,6 +209,10 @@ Yeah, Google Spreadsheets can sometimes be slow or sometimes be overwhelmed or *
If you don't mind running around with Heroku and AWS, [Flatware](https://github.com/jsoma/flatware) is an app I built that uploads the spreadsheet JSON response to S3.
+### Using gs-proxy
+
+[gs-proxy](https://github.com/MinnPost/gs-proxy) is another option that also uses Heroku. You'll set `parameterize` to something like `http://example.herokuapp.com/?url=` and off you go!
+
### Using other caching
You can point `proxy` at anything you'd like as long as it has `KEY` and `KEY-SHEET_ID` files sitting in a directory. Feel free to host it on your own server! You can use `/caching/local.rb` if you want a pretty easy solution for generating the flat files.
@@ -240,3 +246,5 @@ A [Facebook-esque timeline](http://builtbybalance.com/github-timeline/) from [Ba
[Jonathan Soma](http://twitter.com/dangerscarf), who would rather be cooking than coding. Inspired by the relentless demands of [John Keefe(https://twitter.com/jkeefe) of WNYC.
Thanks to [Scott Seaward](https://github.com/plainview) for implementing multi-instance Tabletop.
+
+[Alan Palazzolo](https://github.com/zzolo) hooked the world up with [gs-proxy](https://github.com/MinnPost/gs-proxy) and added support for it into Tabletop via `parameterize`
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <h1>This isn't meant to work</h1>
+ <p>But that doesn't meant you can learn! It's meant to use something like <a href="https://github.com/MinnPost/gs-proxy">gs-proxy</a>.</p>
+ <p>I don't have an instance of gs-proxy running for this, just take a peek at the injected JavaScript.</p>
+ <!-- Don't need jQuery for Tabletop, but using it for this example -->
+ <script type="text/javascript" src="../common/jquery.js"></script>
+ <script type="text/javascript" src="../../src/tabletop.js"></script>
+ <script type="text/javascript">
+ var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdE5OcDE1SENpT1g2R2JEX2tnZ3ZIWHc&output=html';
+
+ $(document).ready( function() {
+ Tabletop.init( { key: public_spreadsheet_url,
+ callback: function() {
+ console.log("Completed'");
+ },
+ parameterize: 'https://www.example.com/?url=',
+ debug: true } )
+ })
+
+ document.write("The published spreadsheet is located at <a target='_new' href='" + public_spreadsheet_url + "'>" + public_spreadsheet_url + "</a>");
+ </script>
+ </body>
+</html>
View
@@ -54,9 +54,7 @@
this.singleton = true;
}
- // The proxyPrefix allows for a proxy of type
- // http://example.com/proxy?url=http://originalrequest.com
- this.proxyPrefix = options.proxyPrefix || false;
+ this.parameterize = options.parameterize || false;
if(this.singleton) {
if(typeof(Tabletop.singleton) !== 'undefined') {
@@ -154,9 +152,8 @@
script.src = this.endpoint + url;
}
- // Handle a proxy prefix
- if (this.proxyPrefix) {
- script.src = this.proxyPrefix + encodeURIComponent(script.src);
+ if (this.parameterize) {
+ script.src = this.parameterize + encodeURIComponent(script.src);
}
document.getElementsByTagName('script')[0].parentNode.appendChild(script);

0 comments on commit 12cb040

Please sign in to comment.