34 lines
15 KiB
JSON
34 lines
15 KiB
JSON
{
|
|
"name": "tabletop",
|
|
"version": "1.3.1",
|
|
"description": "**Tabletop.js** takes a Google Spreadsheet and makes it easily accessible through JavaScript. With zero dependencies!",
|
|
"main": "src/tabletop.js",
|
|
"directories": {
|
|
"example": "examples"
|
|
},
|
|
"scripts": {
|
|
"test": "node examples/nodejs/test.js"
|
|
},
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/jsoma/tabletop.git"
|
|
},
|
|
"author": "",
|
|
"license": "BSD",
|
|
"readmeFilename": "README.md",
|
|
"gitHead": "fdb1c3ee3bc0f7f3be6ab223a56f9f050fe32496",
|
|
"dependencies": {
|
|
"request": "~2.16.6"
|
|
},
|
|
"engines": {
|
|
"node": ">=0.10.0"
|
|
},
|
|
"readme": "# **Tabletop.js** (gives spreadsheets legs)\n\n**Tabletop.js** takes a Google Spreadsheet and makes it easily accessible through JavaScript. With zero dependencies!\n\nTabletop.js easily integrates Google Spreadsheets with Backbone.js, Handlebars, and anything else that is hip and cool. It will also help you make new friends and play jazz piano.\n\n### Like how easy?\n\n function init() {\n Tabletop.init( { key: '0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE',\n callback: function(data, tabletop) { console.log(data) },\n simpleSheet: true } )\n }\n\nWill give you\n\n [ { name: \"Carrot\", category: \"Vegetable\", healthiness: \"Adequate\" }, \n { name: \"Pork Shoulder\", category: \"Meat\", healthiness: \"Questionable\" }, \n { name: \"Bubblegum\", category: \"Candy\", healthiness: \"Super High\"} ]\n\nYes, that easy.\n\n## Notes\n\n## Getting Started\n\nYou might have seen some instructions on [http://builtbybalance.com/Tabletop/](http://builtbybalance.com/Tabletop/), but please ignore them, because they're *super super out of date*. Probably don't *break* anything, but they sure ain't current (not my domain, can't take them down). These docs here are the most up-to-date, so treat them as the gospel truth!\n\n### 1) Getting your data out there\n\n_The first step is to get your data out into a form Tabletop can digest_\n\nTake a Google Spreadsheet. Give it some column headers, give it some content.\n\n Name Category Healthiness\n Carrot Vegetable Adequate\n Pork Shoulder Meat Questionable\n Bubblegum Candy Super High\n \nIn Google Docs, then go up to the `File` menu and pick `Publish to the web`. Fiddle with whatever you want, then click `Start publishing`. A URL will appear, something like `https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html`\n\nCopy that! In theory you're interested in the part between `key=` and `&` but you can use the whole thing if you want.\n\n### 2) Setting up Tabletop\n\n_Now you're going to feed your spreadsheet into Tabletop_\n\nInclude Tabletop in your HTML, then try the following, substituting your URL for `public_spreadsheet_url`\n\n <script type=\"text/javascript\">\n window.onload = function() { init() };\n \n var public_spreadsheet_url = 'https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdDNZUzRlYldnWTZCLXdrMXlYQzVxSFE&output=html';\n\n function init() {\n Tabletop.init( { key: public_spreadsheet_url,\n callback: showInfo,\n simpleSheet: true } )\n }\n\n function showInfo(data, tabletop) {\n alert(\"Successfully processed!\")\n console.log(data);\n }\n </script>\n\nOpen up your console and check out the data that you got. All of those rows were turned right into objects! **See how easy that was?** \n\nPlease don't hold`window.onload` against me, you're free to use `$(document).ready` and all of that jQuery jazz.\n\n### 3) Honestly, that's it.\n\nCheck out the reference and the examples, but basically you're set. The only thing to think about right _now_ is if you want to deal with multiple sheets you can get rid of `simpleSheet: true` (more on that later).\n\nYou might also be interested in the publishing/republishing/publish-as-it-changes aspects of Google Spreadsheets, but you'll need to google that for any specifics.\n\n# Reference\n\n## The Moving Parts\n\n### Tabletop initialization\n\nThe simplest Tabletop initialization works like this\n\n var tabletop = Tabletop.init( { key: public_spreadsheet_url, callback: showInfo } )\n \nWith a function living somewhere else called `showInfo`.\n\nYou pass in either `key` as the actual spreadsheet key, or just the full published-spreadsheet URL. It calls showInfo when done, passing an array of models. Options in general are\n\n`key` is the key of the published spreadsheet or the URL of the published spreadsheet.\n\n`callback` is the callback for when the data has been successfully pulled. It will be passed an object containing the models found in the spreadsheet (worksheets => models), and the tabletop instance. Each of these models contains the rows on that worksheet (see Tabletop.Model). If simpleSheet is turned on it simply receives an array of rows of the first worksheet.\n\n`simpleSheet` can be true or false (default false). It assumes you have one table and you don't care what it's called, so it sends the callback an array of rows instead of a list of models. Peek at the examples for more info.\n\n`parseNumbers` can be true or false (default false). If true, Tabletop will automatically parse any numbers for you so they don't run around as strings.\n\n`postProcess` is a function that processes each row after it has been created. Use this to rename columns, compute attributes, etc. See the TimelineSetter example below.\n\n`wanted` is an array of sheets you'd like to pull. If you have 20 sheets in a public spreadsheet you might as well only pull what you need to access. See the example in simple/multiple.html. Defaults to all.\n\n`endpoint` is the protocol and domain you'd like to query for your spreadsheet. Defaults to `https://spreadsheets.google.com`.\n\n`singleton` assigned the instantiated Tabletop object to Tabletop.singleton, implemented to simplify caching and proxying of requests. Defaults to `false`.\n\n`simple_url`, if true, changes all requests to `KEY` and `KEY-SHEET_ID`. Defaults to `false`.\n\n`proxy` allows you to easily use spreadsheets not located on Google Spreadsheet servers. Setting `proxy: \"http://www.proxy.com\"` is equivalent to setting `{ simple_url: true, singleton: true, endpoint: \"http://www.proxy.com\" }`. [Flatware](https://github.com/jsoma/flatware) might provide better documentation.\n\n`wait` prevents tabletop from pulling the Google spreadsheet until you're ready. Used in the backbone.js example.\n\n`query` sends a [structured query](https://developers.google.com/google-apps/spreadsheets/#sending_a_structured_query_for_rows) along with the spreadsheet request, so you can ask for rows with `age > 55` and the like. Right now it's passed with *every request*, though, so if you're using multiple tables you'll end up in Problem City. It should work great with `simpleSheet` situations, though.\n\n`debug` returns on debug mode, which gives you plenty of messaging about what's going on under the hood.\n\n`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).\n\n`callbackContext` sets the `this` for your callback. It's the tabletop object by default.\n\n### Tabletop itself\n\nOnce you've initialized a `tabletop` object you can access its good parts.\n\n`.sheets()` are the `Tabletop.Model`s that were populated, one per worksheet. You access a sheet by its name. \n\n`.sheets(name)` is how you access a specific sheet. Say I have a worksheet called **Cats I Know**, I'll access it via `tabletop.sheets(\"Cats I Know\")`\n\n`.model_names` are the names of the models [read: sheets] that Tabletop knows about\n\n`.data()` returns the rows of the first model if you're in simpleSheet mode. It's the same as `.sheets()` otherwise. This is just a little sugar.\n\n`.fetch()` manually initializes a pulling of the data\n\n`.addWanted(name)` adds a sheet to the list that are updated with `.fetch`\n\n### Tabletop.Model\n\nTabletop.Model is pretty boring, let's be honest.\n\n`.name` is the name of the worksheet it came from (the tab at the bottom of the spreadsheet)\n\n`.column_names` gives you the names of the columns in that table\n\n`.all()` returns an array of the rows of the table, in the style of `[ { name: \"Tom\", age: 5}, { name: \"Liz\", age: 12 } ]`\n\n`.toArray()` returns the rows of the table with numbered indices instead of named ones [ [ \"Tom\", 5] , [ \"Liz\", 12 ] ]\n\n## What the hell do I do with this?\n\nImagine it's a read-only, JavaScript CMS that you can edit through Google Docs. It's like _Christmas_ up in here.\n\n### Working with Tabletop and Handlebars\n\nSuper easy. Just feed the models to Handlebars and you're all set to build the templates.\n\n### Working with Tabletop and Backbone.js\n\nI've put together a Backbone.tabletopSync driver for Backbone collections and models. It's read-only, but you can't really complain if you're powering your Backbone app through Google Spreadsheets.\n\nSource is, of course, in `/src`, and you can check it out in action in `/examples/backbone/`\n\n### Working with Tabletop and TimelineSetter\n\nTabletop was originally built to work with ProPublica's <a href=\"http://propublica.github.com/timeline-setter/\">TimelineSetter</a>, a JS+Ruby library that creates timelines. You need some specifically-formatted JSON which is created by a Ruby script from a CSV, which means your workflow is usually spreadsheet -> CSV -> Ruby -> JSON -> JS.\n\nWith Tabletop, though, you get to hook right into a Google Spreadsheet for all of your info! You just need to massage your data a _little_ bit, thanks to Google's API messing with column names and you needing a timestamp.\n\nYou can see this in the examples directory, but here are the important parts.\n\n <script type=\"text/javascript\">\n var public_spreadsheet_url = \"https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=0AmYzu_s7QHsmdHk2akhfdG5iTk96OUt6UjJJX1dYMFE&single=true&gid=0&output=html\"\n\n $(document).ready( function() {\n /* \n Need to post-process elements because Google Spreadsheets abbreviates \n 'display_date' column as 'displaydate' and you need to parse the date\n into the 'timestamp' field for TimelineSetter\n simpleSheet: true sends array of rows to callback, so you don't need to\n do the whole Tabletop.sheets('Sheet1').all() thing.\n */\n Tabletop.init( { key: public_spreadsheet_url,\n callback: drawTimeline,\n simpleSheet: true,\n postProcess: function(element) {\n element[\"display_date\"] = element[\"displaydate\"];\n element[\"timestamp\"] = Date.parse( element[\"date\"] );\n } \n })\n })\n \n function drawTimeline(data, tabletop) {\n var currentTimeline = TimelineSetter.Timeline.boot(\n data,\n {\"container\":\"#timeline\",\"interval\":\"\"}\n );\n }\n </script>\n\nSee the `postProcess` call? That's called on every row after Tabletop.Model gets done working on it. It allows you to rename columns or edit data points without having to messily do it outside of Tabletop. I'm sure it has uses outside of TimelineSetter, too.\n\nA sample lives in `/examples/timeline_setter/`\n\n## Caching/Proxying Google Spreadsheets\n\nYeah, 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`.\n\n`proxy` is the fun one, in that it rewrites your requests to be simpler-looking and plays nicely with the app & example I put together.\n\n### Using Flatware\n\nIf 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.\n\n### Using gs-proxy\n\n[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!\n\n### Using other caching\n\nYou 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.\n\n# Notes\n\n## Strange behavior\n\n**Empty tables are trouble.** We can't get column names from them (c'mon, Google!), so don't be too confused when a table with 0 rows is coming back with an empty `.column_names` or your code starts throwing weird errors when processing the results.\n\n**Empty rows are trouble.** If you have a row that's completely empty, Google doesn't return any rows after the empty row. As a result, you need to make sure every line in your spreadsheet has data in it.\n\n## If you are having trouble\n\nTurn on debugging by passing `debug: true` when you initialize Tabletop. Check out the console, I try to keep my error messages chatty and informative. Or just email me at [jonathan.soma@gmail.com](mailto:jonathan.soma@gmail.com), I'm happy to help!\n\n## Tabletop.js in the wild\n\n**The more examples the better, right?** Feel free to fork or contact me if you have a good example of something you've done.\n\nA [contextual video player](http://www.aljazeera.com/indepth/interactive/2012/04/20124107156511888.html) with [popcorn.js](http://popcornjs.org) by [@maboa](https://twitter.com/maboa) \n\nThe [WNYC mayoral tracker](http://project.wnyc.org/elections/mayor-tracker/) uses Tabletop along with [Backbone.js](http://backbonejs.org)\n\nA [Facebook-esque timeline](http://builtbybalance.com/github-timeline/) from [Balance Media](http://builtbybalance.com) (with a [git repo](https://github.com/balancemedia/Timeline))\n\n[Mapsheet](https://github.com/jsoma/mapsheet) creates super easy, customizable maps.\n\n## Other Options\n\nIf you aren't really feeling Tabletop, you should give [Dataset](http://misoproject.com/dataset/) a shot. It's \"a JavaScript client-side data transformation and management library,\" which means it does a hell of a lot more than our dear Tabletop.\n\n## Credits\n\n[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.\n\nThanks to [Scott Seaward](https://github.com/plainview) for implementing multi-instance Tabletop.\n\n[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`\n\n[Max Ogden](https://github.com/maxogden) was kind enough to lend Tabletop nodejs support as part of an [Open News](http://www.mozillaopennews.org) [code sprint](http://www.mozillaopennews.org/codesprints.html)",
|
|
"_id": "tabletop@1.3.1",
|
|
"dist": {
|
|
"shasum": "dd3b4b394a92799a74a12686883ef6119fe1ec81"
|
|
},
|
|
"_from": "tabletop@1.3.1",
|
|
"_resolved": "https://registry.npmjs.org/tabletop/-/tabletop-1.3.1.tgz"
|
|
}
|