In a number of articles and blog posts I’ve been looking at using Google Apps Script to publish data, to store it a scriptDB and to behave as a proxy for both access and processing. Pulling it all together, here is a way to publish data in multiple formats from scriptdb, to publish custom data, and even to publish the code of your own scripts. In these examples for now, all data and scripts are public. I haven’t implemented oAuth as part of the tool yet.
To implement your own version of this, see Step by Step Gas Publisher
How it fits together
Here’s a quick explanation of what you will need.
- The publisher is a single script that can access all your public/enabled projects and retrieve source code, scriptDB contents or any kind of data (for example proxy processing, or spreadsheet data that you write a simple custom template handler for.
- The templates (google Apps Html service templates) are used to format and enumerate the data. 2 templates are provided – one for html and another for js. You can write your own or modify these as required.
- html format is expressed using the apps script HTML service. In other words a standalone web page is generated with the contents of the selected input.
- js, json, and jsonp are expressed using the apps script content service. In other words, some further processing and formatting is expected to happen on the expressed data.
- js format takes the encoded html code created by its template and assigns that to a variable. The generated script is inserted in a container web page, and that variable is simple assigned to a document element to provide formatted content. This mostly useful for inserting into Iframes for embedding in gadgets or web pages. This avoid cross domain x-frame problems that arise using iFrames with the apps script content service.
|module||Name of the module or siloid in scriptDB to fetch. Can also be a gist filename stored in a Gist, or the url of a web page.|
|template||The name of the html service template to use. Needed for js & html. Ignored for the others. If not specified then the default template for the type is used|
|library||The name of the attached library that hosts the module. If not specified will look in the same project as the publisher. If your are using a Gist as your source this can also be a gistID.|
|source||the data source. Can be script|scriptdb|custom|gist|web. The data is rendered according to the template selected and the output type. You need to write your own handler for custom. Click on the options to see what you get as an html output for each one. script is the default.|
|callback||the callback for jsonp. If you select jsonp type, but don’t specify a callback, you get plain json.|
What’s happening here
Embedding in google sites and other places.