Last active
February 9, 2016 22:42
-
-
Save DavidBruant/6262612 to your computer and use it in GitHub Desktop.
Turn "HTML" files into JS and CSS TextOutputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function unescape(content){ | |
return content.replace('<', '<') | |
.replace('>', '>'); | |
} | |
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't seem that it works given that
ContentService.MimeType.CSS
is undefined.