Publishing and prettifying Gists through google apps script

The other day, I showed how to prettify Google Apps Script snippets and scriptDB contents, include them in web sites, blogs and google sites, and encode them in jSon and jSonP using the GAS content service and html service. This provides a simple way to share your code.

However, you often want to mix that in with stuff that is not Google Apps Script related, for example javascript, html code or some other language. In a post a while ago I showed how to embed gist snippets in the same way. However these snippets have been processed using the gist prettifier so don’t have a common look and feel when mixed with the GAS/Caja prettifier.

I figured that I could probably take Gist samples via Google Apps Script and pass them through the same prettifier. Here is the container that does that. What we are looking at here is a little bit of html code embedded in this blog as follows.

<iframe height="400"
src=”http://xliberation.com/p/gaspubcontainer.html?
source=gist&library=4117688&module=gaspubcontainer.html” width=”100%”>

to give this embeded gist.

http://xliberation.com/p/gaspubcontainer.html?source=gist&library=4117688&module=gaspubcontainer.html


What is happening here?
Using exactly the same technique as with publishing the Apps Script, I’m using a Google Apps Script template to output the gist code, which has been read by GAS. Here’s the entire library code (inserted with the code below)

<iframe height="400"
src=”http://xliberation.com/p/gaspubcontainer.html?source=script&library=mcpher&module=gasPub” width=”100%”>

http://xliberation.com/p/gaspubcontainer.html?source=script&library=mcpher&module=gasPub

Parameters
For a full description of the parameters, see the Excel Liberation site.

In the case of the above we use source=gist or source=script to indicate where the source data is coming from, library=mcpher or library=4117688 to identify either the GAS library or the gist ID, and module=gasPub or module=gaspubcontainer.html to identify the module name or the gist fileName. If this is blank for source=gist, then all code in all filenames in that Gist will be shown.

To Use
http://xliberation.com/p/gaspubcontainer.html is typically used for embedding in preference to calling the GAS module directly. This gets round cross domain problems associated with the GAS content service. If you are only embedding Gists, then you can use all this with no changes. Just use the gaspubcontainer.html as described, with your parameters. If you are planning to publish your own GAS code or scriptDB contents, you will need need to copy the GAS code and attach your own libraries as described on the Excel Liberation site.

Author: bm082975

Leave a Reply

Your email address will not be published. Required fields are marked *