Skip to content

Instantly share code, notes, and snippets.

@Swiip
Created December 23, 2014 13:39
Show Gist options
  • Save Swiip/49d500b424ffeb3ceff7 to your computer and use it in GitHub Desktop.
Save Swiip/49d500b424ffeb3ceff7 to your computer and use it in GitHub Desktop.
Prototype of Mardown template engine
/* jshint evil:true */
var fs = require('fs');
var _ = require('lodash');
var marked = require('marked');
var renderer = new marked.Renderer();
var model = fs.readFileSync('model.md').toString();
var Entities = require('html-entities').AllHtmlEntities;
var entities = new Entities();
var result = '';
var test = null;
//console.log('model', model;
var data = {
props: {
cssPreprocessor: {
extension: 'css'
},
jsPreprocessor: {
extension: 'js'
}
}
};
renderer.paragraph = function(text) {
if(/^if/.test(text)) {
var source = 'with(data) { ' + entities.decode(text.substring(2)) + '; }';
test = eval(source);
} else if(/^else/.test(text)) {
test = !test;
} else {
test = null;
}
};
renderer.code = function(code, lang, callback) {
if(test === null || test) {
result = result + code + '\n';
}
};
marked(model, {
renderer: renderer
}, function(content) {
console.log('result', _.template(result, data));
});
'use strict';

var gulp = require('gulp');

gulp.task('watch', ['wiredep', 'injector:css', 'injector:js'] ,function () {
  gulp.watch('src/{app,components}/**/*.<%= props.cssPreprocessor.extension %>', ['injector:css']);

if props.jsPreprocessor.extension === 'js'

  gulp.watch('src/{app,components}/**/*.js', ['injector:js']);

else

  gulp.watch('src/{app,components}/**/*.{js,<%= props.jsPreprocessor.extension %>}', ['injector:js']);

endif

  gulp.watch('src/assets/images/**/*', ['images']);
  gulp.watch('bower.json', ['wiredep']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment