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="https://storage.googleapis.com/toasty/p/gaspubcontainer.html?source=gist&library=4117688&module=gaspubcontainer.html" width="100%"></iframe>
to give this embeded gist.


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="https://storage.googleapis.com/toasty/p/gaspubcontainer.html?source=script&amp;library=mcpher&amp;module=gasPub" width="100%"></iframe>

 




 

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
https://storage.googleapis.com/toasty/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.
About brucemcp 225 Articles
I am a Google Developer Expert and decided to investigate Google Apps Script in my spare time. The more I investigated the more content I created so this site is extremely rich. Now, in 2019, a lot of things have disappeared or don’t work anymore due to Google having retired some stuff. I am however leaving things as is and where I came across some deprecated stuff, I have indicated it. I decided to write a book about it and to also create videos to teach developers who want to learn Google Apps Script. If you find the material contained in this site useful, you can support me by buying my books and or videos.