Commits

Torgny Bjers committed ac82061

Initial import of plugin

Comments (0)

Files changed (6)

+node_modules
+(The MIT License)
+
+Copyright © 2013 Xorcode, LLC. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+# wintersmith-liquid
+
+[Liquid](https://github.com/Shopify/liquid/) plugin for [Wintersmith](https://github.com/jnordberg/wintersmith), uses [liquid-node](https://github.com/sirlantis/liquid-node/) to take advantage of asynchronous behavior. The **liquid-node** module uses Q internally and thus we can take advantage of this in our template plugin.
+
+## Installation
+
+Navigate to the folder you created with `wintersmith new` and run
+
+    $ npm install wintersmith-liquid --save
+
+Once you have installed the plugin you need to modify your `config.json` and add `wintersmith-liquid` to the list of plugins for your site.
+
+Templates with the `.html` extensions are parsed with Liquid.
+
+## Todo
+
+- Add support for adding plugins to the Liquid parser
+
+## License
+
+(The MIT License)
+
+Copyright © 2013 Xorcode, LLC. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+require('coffee-script');
+module.exports = require('./plugin');
+{
+  "name": "wintersmith-liquid",
+  "version": "0.0.1",
+  "description": "Wintersmith template plugin for Liquid templates",
+  "author": "Torgny Bjers <torgny@xorcode.com>",
+  "license": "MIT",
+  "keywords": [
+    "wintersmith",
+    "wintersmith-plugin",
+    "liquid"
+  ],
+  "dependencies": {
+    "liquid-node": "~0.1.0",
+    "coffee-script": "~1.6.3",
+    "async": "~0.2.9"
+  }
+}
+async = require('async')
+Liquid = require('liquid-node')
+fs = require('fs')
+
+module.exports = (wintersmith, callback) ->
+
+  class LiquidTemplate extends wintersmith.TemplatePlugin
+
+    constructor: (@fn) ->
+
+    render: (locals, callback) ->
+      promise = @fn.render locals
+      promise.catch(callback).done (output) -> 
+        callback null, new Buffer output
+
+  LiquidTemplate.fromFile = (filepath, callback) ->
+    async.waterfall [
+      (callback) ->
+        fs.readFile filepath.full, callback
+      (buffer, callback) ->
+        conf = wintersmith.config.liquid or {}
+        conf.filename = filepath.full
+        try
+          tpl = Liquid.Template.parse buffer.toString()
+          callback null, new LiquidTemplate tpl
+        catch error
+          callback error
+    ], callback
+
+  wintersmith.registerTemplatePlugin '**/*.html', LiquidTemplate
+  callback()