Skip to content

Instantly share code, notes, and snippets.

@DavidBruant
Last active February 9, 2016 22:42
Show Gist options
  • Save DavidBruant/6262612 to your computer and use it in GitHub Desktop.
Save DavidBruant/6262612 to your computer and use it in GitHub Desktop.
Turn "HTML" files into JS and CSS TextOutputs
function unescape(content){
return content.replace('&lt;', '<')
.replace('&gt;', '>');
}
function getJavaScriptTextOutput(filename){
var content = HtmlService.createHtmlOutputFromFile(filename).getContent();
content = unescape(content);
return ContentService.createTextOutput( content ).setMimeType(ContentService.MimeType.JAVASCRIPT);
}
function getCSSTextOutput(filename){
var content = HtmlService.createHtmlOutputFromFile(filename).getContent();
content = unescape(content);
var textOutput =ContentService.createTextOutput( content );
return ContentService.createTextOutput( content ).setMimeType(ContentService.MimeType.CSS);
}
function doGet(req) {
"use strict";
var parameters = req.parameter;
// <script src="?script=file.js"></script>
if(parameters.script){
return getJavaScriptTextOutput(parameters.script);
}
// <link rel="stylesheet" href="?style=file.css">
if(parameters.style){
return getCSSTextOutput(parameters.style)
}
// not an asset. Do what you would normally.
}
@brainysmurf
Copy link

Doesn't seem that it works given that ContentService.MimeType.CSS is undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment