Skip to content

Commit 5e0400d

Browse files
committed
Using Google Spreadsheets as a CMS for Meteor
Just a little story
1 parent 21328cc commit 5e0400d

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

BONUS-STORY.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Using Google Spreadsheets as a CMS for Meteor
2+
3+
Have you ever seen this workflow?
4+
5+
Someone shares a spreadsheet with a team, and several people add their contributions to it. The spreadsheet becomes the place that it's easy to manage, but eventually that data is meant to be used to manage data elsewhere, and later somebody inputs, copies, or imports the spreadsheet to some other format for presentation on the web.
6+
7+
At several of the e-commerce companies where I've worked, using a spreadsheet was just part of the typical workflow. For example, buyers would maintain a list of vendors, and products in a spreadsheet. Often this was because they didn't have all the data yet to make the products available - somebody had to decide the best marketing description, a manager needed to make sure the profit margins were correct for pricing,etc. After all that internal process was completed, we'd import that product spreadsheet into our e-commerce software's database when we'd want to make the product available online. In a couple extreme cases, we actually would send the spreadsheet off to a offshore firm who specializes in manual data entry into platforms like Magento. After the data was inputed into the shop, we'd have to recheck it once more for accuracy before publishing! Phew!
8+
9+
10+
At [Ongo Works](http://ongo.works) we maintain a Google Docs Spreadsheet that is a list of features and related information like "status" and "Github Issue" for the [Reaction Commerce](http://reactioncommerce.com/) project. I started looking for a simple CMS for our project features list for [Reaction Commerce](http://reactioncommerce.com/vision), when I thought - why not just use the spreadsheet itself as our CMS for our site? Turns out with [Meteor](http://meteor.com) and the [Google Spreadsheet API](https://developers.google.com/google-apps/spreadsheets/?csw=1) this is pretty simple to do.
11+
12+
Here's how I did it:
13+
14+
First you need to publish your spreadsheet, and get the "spreadsheet key". In your spreadsheet goto `File -> Publish to Web`, start publishing and grab the spreadsheet key from the spreadsheet url.
15+
16+
![image](spreadsheet-publish.png)
17+
18+
You can preview the json output of your spreadsheet after publishing with:
19+
20+
`https://spreadsheets.google.com/feeds/list/<spreadsheet key>/od6/public/values?alt=json`
21+
22+
I fetched this with `Meteor.http.get` and created a template helper, and looped through the results to format into an object that my template uses.
23+
24+
*client/view.html*
25+
26+
Template.view.helpers
27+
spreadsheetData: () ->
28+
# fetches from a google docs spreadhsheet, with "Feature, Description, Status" cells
29+
Meteor.http.get "https://spreadsheets.google.com/feeds/list/<spreadsheet key>/od6/public/values?alt=json", (error,result) ->
30+
31+
# loop and do some formatting
32+
items = [];
33+
for item,index in result.data.feed.entry
34+
items[index].status = item.gsx$status.$t.toLowercase()
35+
...
36+
return items
37+
38+
In this case each cell value is accessed with `item.gsx$<column header>.$t`
39+
40+
This works pretty well, but there's usually a second or so delay before the result are rendered. To take care of this, I decided to fetch with a server side method `Meteor.call('spreadsheet/fetch',"<spreadsheet key>")` and insert the results into a collection `GASpreadsheet` and publish this to the client.
41+
42+
Now, instead of calling the directly using `Meteor.http.get` in the client view, you can do:
43+
44+
# fetches from a google docs spreadsheet, with cell data
45+
Meteor.call "spreadsheet/fetch","<spreadsheet key>"
46+
47+
spreadsheetData = GASpreadsheet.findOne({spreadsheet:'<spreadsheet name or index>'})
48+
49+
#loop and do some formatting
50+
if spreadsheetData
51+
for index,row of spreadsheetData.cells
52+
if ( row[1] ) then feature = row[1].value
53+
54+
This will first render the collection (cached copy), but will also update with the latest from the spreadsheet whenever a user views this page.
55+
56+
57+
I've created a package that you can use at [ongoworks/meteor-google-spreadsheet](https://github.com/ongoworks/meteor-google-spreadsheets)
58+
59+
In this package, the spreadsheet is fetched using the NPM package [node-google-spreadsheets](https://github.com/samcday/node-google-spreadsheets), wrapped, and inserted into the collection `GASpreadsheet`.
60+
61+
I'm going to continue to add functionality to the package, two way syncing, editing the spreadsheet data in Meteor,etc as time permits.
62+
63+
So, now I have a CMS with team administration and revision control. I could easily add a field "visible", and filter the results by properties before displaying in the template view.
64+
65+
66+
Easy and fun. Hope you enjoy it.
67+

spreadsheet-publish.png

237 KB
Loading

0 commit comments

Comments
 (0)