Last active
December 30, 2015 13:39
-
-
Save darkoverlordofdata/7837076 to your computer and use it in GitHub Desktop.
Liquid.js wrapper for use in Node.js
This file contains hidden or 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
# | |
# Liquid.js wrapper | |
# | |
# Copy your Liquid.js distro file to the same folder | |
# | |
# | |
fs = require('fs') | |
path = require('path') | |
LIQUID_JS = './liquid.js' # path to the Liquid.js distribution | |
# relative to the current folder | |
# | |
# Initialize Liquid | |
# | |
# Satisfies dependancies, loads liquid.js | |
# | |
# @paran [String] source file system root | |
# @param [String] lang iso 639-1 language code | |
# @returns [Object] the Liquid.js module reference | |
# | |
# | |
module.exports = ($source, $lang='en') -> | |
# | |
# Fabricate a document object for strftime | |
# | |
Object.defineProperties @, | |
document: | |
get: -> | |
getElementsByTagName: ($name) -> | |
if $name is 'html' then [lang: $lang] else [] | |
# | |
# Now we can safely load Liquid.js | |
# | |
eval String(fs.readFileSync(path.resolve(__dirname, LIQUID_JS))) | |
# | |
# Load template files from file system | |
# | |
Liquid.readTemplateFile = ($file) -> | |
$path = path.resolve($source, $file) | |
String(fs.readFileSync($path)) | |
Liquid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment