UNPKG

beast-roar

Version:

This is a Framework that can help to generate views for your applications

1,262 lines (1,032 loc) 38.5 kB
// Generated by CoffeeScript 1.7.1 (function() { var Asset, CallableFunction, ChildDirective, CommandLine, CustomDirective, Directive, DirectoryManager, EndForEach, EndIf, FileManager, ForEach, If, Log, MegaFile, NameDirective, NeedDirective, PHPRouteBuilder, ParentDirective, Placeholder, RenderDirective, RenderLine, RepeatDirective, RouteBuilder, SectionDirective, StopDirective, Variable, ViewBuilder, async, fs, mkdirp, os, path, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; fs = require("fs"); RouteBuilder = (function() { function RouteBuilder(jsonFile) { this.file = jsonFile; this.load(this.file); this.parseRoute(this.routes); } RouteBuilder.prototype.load = function(file) { var content; content = fs.readFileSync(file, { encoding: "utf8" }); this.routes = JSON.parse(content); return this.routes; }; RouteBuilder.prototype.parseRoute = function(settings) { var match, p, param, parameter, rawParam, result, route, _i, _j, _len, _len1, _ref, _results; parameter = new RegExp("{.*?}", "g"); _ref = settings.routes; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { route = _ref[_i]; param = []; while ((result = parameter.exec(route.url))) { rawParam = result[0].replace(/({|})/g, ""); rawParam = rawParam.split(" "); param.push(rawParam); } match = route.url; for (_j = 0, _len1 = param.length; _j < _len1; _j++) { p = param[_j]; if (p.length === 1) { p.push("[^/]+"); } match = match.replace(new RegExp("{ ?" + p[0] + ".*?}"), "(" + p[1] + ")"); } _results.push(route.match = match); } return _results; }; RouteBuilder.prototype["export"] = function(file) { this.routes; return fs.writeFile(file, JSON.stringify(this.routes, null, 2)); }; return RouteBuilder; })(); exports.RouteBuilder = RouteBuilder; PHPRouteBuilder = (function(_super) { __extends(PHPRouteBuilder, _super); function PHPRouteBuilder(file) { PHPRouteBuilder.__super__.constructor.call(this, file); } PHPRouteBuilder.prototype.object = function(object) { var str; str = JSON.stringify(object); return console.log(str); }; return PHPRouteBuilder; })(RouteBuilder); exports.PHPRouteBuilder = PHPRouteBuilder; Placeholder = (function() { function Placeholder(match, replacement, preview) { var _base, _base1; this.match = match; this.replacement = replacement; this.preview = preview; this["static"] = this.constructor; if ((_base = this["static"]).regex == null) { _base.regex = new RegExp(this.match); } if ((_base1 = this["static"]).regexR == null) { _base1.regexR = new RegExp(this.match, "g"); } } Placeholder.prototype.canHandle = function(text) { return this["static"].regex.exec(text) !== null; }; Placeholder.prototype.getReplacement = function(text) { return text.replace(this["static"].regexR, this.replacement, text); }; Placeholder.prototype.getPreviewReplacement = function(text) { return text.replace(this["static"].regexR, this.preview, text); }; return Placeholder; })(); exports.Placeholder = Placeholder; Asset = (function(_super) { __extends(Asset, _super); function Asset() { Asset.__super__.constructor.call(this, "{{ *?asset[*](.*?)[*] *?}}", "<?php echo assets(\"$1\") ?>", "../application/assets/$1"); } return Asset; })(Placeholder); exports.Asset = Asset; EndForEach = (function(_super) { __extends(EndForEach, _super); function EndForEach() { EndForEach.__super__.constructor.call(this, "@endforeach", "<?php endforeach; ?>", ""); } return EndForEach; })(Placeholder); exports.EndForEach = EndForEach; ForEach = (function(_super) { __extends(ForEach, _super); function ForEach() { ForEach.__super__.constructor.call(this, "@foreach\\((.*)\\)", "<?php foreach$1: ?>", ""); } return ForEach; })(Placeholder); exports.ForEach = ForEach; EndIf = (function(_super) { __extends(EndIf, _super); function EndIf() { EndIf.__super__.constructor.call(this, "@endif", "<?php endif; ?>", ""); } return EndIf; })(Placeholder); exports.EndIf = EndIf; If = (function(_super) { __extends(If, _super); function If() { If.__super__.constructor.call(this, "@if\\((.+)\\)", "<?php if($1): ?>", ""); } return If; })(Placeholder); exports.If = If; CallableFunction = (function(_super) { __extends(CallableFunction, _super); function CallableFunction() { CallableFunction.__super__.constructor.call(this, "{{exec\\*(.*)\\* ?([^}]*)}}", "<?php echo $1 ?>", "$2"); } return CallableFunction; })(Placeholder); exports.Variable = Variable; Variable = (function(_super) { __extends(Variable, _super); function Variable() { Variable.__super__.constructor.call(this, "{{ ?([^@ ]+) ?([^}]*?)}}", "<?php echo $$$1 ?>", "$2"); } return Variable; })(Placeholder); exports.Variable = Variable; Placeholder = (function() { function Placeholder(match, replacement, preview) { var _base, _base1; this.match = match; this.replacement = replacement; this.preview = preview; this["static"] = this.constructor; if ((_base = this["static"]).regex == null) { _base.regex = new RegExp(this.match); } if ((_base1 = this["static"]).regexR == null) { _base1.regexR = new RegExp(this.match, "g"); } } Placeholder.prototype.canHandle = function(text) { return this["static"].regex.exec(text) !== null; }; Placeholder.prototype.getReplacement = function(text) { return text.replace(this["static"].regexR, this.replacement, text); }; Placeholder.prototype.getPreviewReplacement = function(text) { return text.replace(this["static"].regexR, this.preview, text); }; return Placeholder; })(); exports.Placeholder = Placeholder; fs = require("fs"); MegaFile = require("mega-reader").MegaFile; async = require("async"); mkdirp = require("mkdirp"); path = require("path"); os = require("os"); RenderLine = (function() { function RenderLine(name, bin, stack) { this.name = name; this.bin = bin; this.stack = stack; process.output.debug("renderline " + this.name + " created"); this.line = []; } RenderLine.prototype.clear = function() { this.position = -1; this.tools = []; return this.readers = []; }; RenderLine.prototype.buildReaders = function() { var file, _i, _len, _ref, _results; _ref = this.line; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { file = _ref[_i]; _results.push(this.readers.push(new MegaFile([file.filename]))); } return _results; }; RenderLine.prototype.buildtools = function() { var tool, _i, _len, _ref, _results; _ref = [new Asset, new NeedDirective, new ParentDirective, new RepeatDirective, new SectionDirective, new NameDirective, new ChildDirective, new RenderDirective, new StopDirective, new CallableFunction, new Variable, new If, new EndIf, new ForEach, new EndForEach]; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; _results.push(this.tools.push(tool)); } return _results; }; RenderLine.prototype.shift = function() { return this.line.shift(); }; RenderLine.prototype.unshift = function(item) { return this.line.unshift(item); }; RenderLine.prototype.push = function(item) { return this.line.push(item); }; RenderLine.prototype.pop = function(item) { return this.line.pop(item); }; RenderLine.prototype.position = null; RenderLine.prototype.internalLine = function(text) { var tool, value, _i, _len, _ref; value = null; _ref = this.tools; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; if (tool.canHandle(text)) { value = tool; break; } } return value; }; RenderLine.prototype.makefile = function() { if (!fs.existsSync(this.bin)) { mkdirp.sync(this.bin); } return fs.openSync(this.previewFile(), "w"); }; RenderLine.prototype.previewFile = function() { return "" + this.bin + path.sep + this.name + ".html"; }; RenderLine.prototype.printFile = function(file, reader, repeat) { var directive, line, stop; if (repeat == null) { repeat = 1; } while (true) { process.output.debug("--------------------------------"); process.output.debug("" + repeat + "," + reader.files); stop = false; if (reader.hasNextLine()) { line = reader.getNextLine(); process.output.debug("" + line); directive = this.internalLine(line); if (!directive) { fs.writeSync(file, "" + line + os.EOL); } else if (directive instanceof ChildDirective) { this.printChild(file, directive.getDirective(line)); } else if (directive instanceof NeedDirective) { this.printNeed(file, directive.getDirective(line).value); } else if (directive instanceof StopDirective) { stop = true; } else if (directive instanceof Asset || directive instanceof Variable || directive instanceof CallableFunction || directive instanceof If || directive instanceof EndIf || directive instanceof ForEach || directive instanceof EndForEach) { fs.writeSync(file, "" + (directive.getPreviewReplacement(line)) + os.EOL + " "); } } if (reader.hasNextLine()) { if (!stop) { continue; } } if (repeat > 0) { reader.reset(); repeat--; } if (repeat <= 0) { break; } } return process.debug = false; }; RenderLine.prototype.printRenderFile = function(file) { var reader, repeat; this.position++; repeat = this.line[this.position].repeat; reader = this.readers[this.position]; this.printFile(file, reader, repeat); return this.position--; }; RenderLine.prototype.printChild = function(file, secDirective) { var cd, line, reader; this.position++; reader = this.readers[this.position]; reader.reset(); cd = new CustomDirective(secDirective.key.replace("#child", "section"), secDirective.value); process.output.debug("" + (JSON.stringify(secDirective))); while (true) { if (reader.hasNextLine()) { line = reader.getNextLine(); if (!cd.canHandle(line)) { continue; } } break; } this.position--; return this.printRenderFile(file); }; RenderLine.prototype.printNeed = function(file, need) { var f, reader, _i, _len, _ref; reader = null; _ref = this.stack; for (_i = 0, _len = _ref.length; _i < _len; _i++) { f = _ref[_i]; if (!(f.name === need)) { continue; } reader = f; break; } return this.printFile(file, new MegaFile([reader.filename]), reader.repeat); }; RenderLine.prototype.render = function() { var file; this.clear(); this.buildtools(); this.buildReaders(); file = this.makefile(); this.printRenderFile(file); return fs.closeSync(file); }; RenderLine.prototype.toString = function() { var l, obj, str, _i, _len, _ref; obj = []; _ref = this.line; for (_i = 0, _len = _ref.length; _i < _len; _i++) { l = _ref[_i]; obj.push(l.toString()); } str = obj.join(",\n"); return str; }; return RenderLine; })(); exports.RenderLine = RenderLine; path = require("path"); mkdirp = require("mkdirp"); MegaFile = require("mega-reader").MegaFile; ViewBuilder = (function() { function ViewBuilder(filename, name, bin, ext, stack) { this.filename = filename; this.name = name; this.bin = bin; this.ext = ext; this.stack = stack; this.mr = new MegaFile([this.filename]); this.mr.reset(); this.tools = []; this.buildtools(); this["export"](); } ViewBuilder.prototype["export"] = function() { var _results; if (!fs.existsSync(this.bin)) { mkdirp(this.bin); } fs.writeFileSync(this.file(), ""); this.print("<?php ini_set('error_reporting', 0);?>"); _results = []; while (true) { if (this.mr.hasNextLine()) { _results.push(this.print(this.mr.getNextLine())); } else { this.print("<?php\nif(isset($renderstack) && count($renderstack)>0){\n $last=&array_pop($renderstack);\n foreach($last->sections as $key=>$value){\n $last->parent=str_replace(\"#child \".$key, $value, $last->parent);\n }\n}\n echo $last->parent;\n unset($last)\n?>"); break; } } return _results; }; ViewBuilder.prototype.print = function(line) { var parentname, sectionName, t; t = this.canHandle(line); if (t) { if (t instanceof NeedDirective) { line = "<?php include('" + (t.getDirective(line).value) + "." + this.ext + "') ?>"; } if (t instanceof RenderDirective || t instanceof RepeatDirective || t instanceof NameDirective) { line = ""; return; } if (t instanceof ParentDirective) { parentname = t.getDirective(line).value; line = "<?php\n $renderstack[]= new stdClass();\n ob_start();\n include(\"" + parentname + "." + this.ext + "\");\n $last=&$renderstack[count($renderstack)-1];\n $last->parent=ob_get_clean();\n $last->sections=[];\n?>"; } if (t instanceof SectionDirective) { this.sectionName = t.getDirective(line).value; line = "<?php ob_start();?>"; } if (t instanceof StopDirective) { sectionName = this.sectionName; delete this.sectionName; line = "<?php\n $section_buffer=ob_get_clean();\n $last->sections['" + sectionName + "']=$section_buffer\n?>"; } if (t instanceof Variable || t instanceof CallableFunction || t instanceof If || t instanceof EndIf || t instanceof ForEach || t instanceof EndForEach || t instanceof Asset) { line = t.getReplacement(line); } } return fs.appendFileSync(this.file(), "" + line + os.EOL); }; ViewBuilder.prototype.canHandle = function(line) { var t, _i, _len, _ref; _ref = this.tools; for (_i = 0, _len = _ref.length; _i < _len; _i++) { t = _ref[_i]; if (t.canHandle(line)) { return t; } } return false; }; ViewBuilder.prototype.buildtools = function() { var tool, _i, _len, _ref, _results; _ref = [new Asset, new NeedDirective, new ParentDirective, new RepeatDirective, new SectionDirective, new NameDirective, new ChildDirective, new RenderDirective, new StopDirective, new CallableFunction, new Variable, new If, new EndIf]; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; _results.push(this.tools.push(tool)); } return _results; }; ViewBuilder.prototype.file = function() { var file; return file = path.resolve(this.bin, "" + this.name + "." + this.ext); }; return ViewBuilder; })(); fs = require("fs"); MegaFile = require("mega-reader").MegaFile; FileManager = (function() { function FileManager(filename, bin, stack) { this.filename = filename; this.bin = bin; this.stack = stack; this.mr = new MegaFile([this.filename]); this.mr.reset(); this.tools = []; this.needed = []; this.section = []; this.child = []; this.buildtools(); this.analyze(); } FileManager.prototype.repeat = null; FileManager.prototype.needed = null; FileManager.prototype.parent = null; FileManager.prototype.section = null; FileManager.prototype.name = null; FileManager.prototype.child = null; FileManager.prototype.renderline = null; FileManager.prototype.analyze = function() { var cd, file, named, nd, pd, rd, sd; file = fs.readFileSync(this.filename, { encoding: "utf8" }); if ((new RenderDirective).canHandle(file)) { this.render = true; } if ((rd = new RepeatDirective).canHandle(file)) { this.repeat = rd.getDirective(file).value; } if ((nd = new NeedDirective).canHandle(file)) { this.needed.push(nd.getDirective(file).value); } if ((pd = new ParentDirective).canHandle(file)) { this.parent = pd.getDirective(file).value; } if ((sd = new SectionDirective).canHandle(file)) { this.section.push(sd.getDirective(file).value); } if ((named = new NameDirective).canHandle(file)) { this.name = named.getDirective(file).value; } if ((cd = new ChildDirective).canHandle(file)) { return this.child.push(cd.getDirective(file).value); } }; FileManager.prototype.build = function(callback) { if (this.render) { this.buildRenderLine(); } return callback.call(); }; FileManager.prototype.buildRenderLine = function() { var item; process.output.debug("building renderline"); this.renderline = new RenderLine(this.name, this.bin, this.stack); item = this; while (true) { if (!item) { break; } this.renderline.unshift(item); item = item.getParent(); } return this.renderline.render(); }; FileManager.prototype["export"] = function() { return this.vb = new ViewBuilder(this.filename, this.name, this.bin, "php", this.stack); }; FileManager.prototype.toString = function() { var obj; obj = { name: this.name, parent: this.parent, needed: this.needed, sections: this.section, repeat: this.repeat, render: this.render, child: this.child }; return JSON.stringify(obj, void 0, 2); }; FileManager.prototype.buildtools = function() { var tool, _i, _len, _ref, _results; _ref = [new NeedDirective, new ParentDirective, new RepeatDirective, new SectionDirective]; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; _results.push(this.tools.push(tool)); } return _results; }; FileManager.prototype.getParent = function() { var fm, _i, _len, _ref; if (!this.parent) { return this.parent; } _ref = this.stack; for (_i = 0, _len = _ref.length; _i < _len; _i++) { fm = _ref[_i]; if (fm.name === this.parent) { return fm; } } }; return FileManager; })(); Directive = (function() { function Directive(symbol, input, parent) { var _base, _base1; this.symbol = symbol; this.input = input != null ? input : null; this.parent = parent != null ? parent : null; if (this.constructor === Directive) { throw new Error("Class Directive is an Abstract Class"); } this["static"] = this.constructor; if (this.input !== null) { if ((_base = this["static"]).regex == null) { _base.regex = new RegExp("#" + this.symbol + " " + this.input); } } else { if ((_base1 = this["static"]).regex == null) { _base1.regex = new RegExp("#" + this.symbol); } } } Directive.prototype.canHandle = function(text) { var result; if ((result = this["static"].regex.exec(text)) !== null) { return true; } else { return false; } }; Directive.prototype.getDirective = function(text) { var key, obj, result, string, stringSplit, value; result = this["static"].regex.exec(text); string = result[0]; stringSplit = string.split(" "); key = stringSplit.shift(); value = stringSplit.join(" "); obj = { key: key, value: value }; return obj; }; return Directive; })(); exports.Directive = Directive; CustomDirective = (function(_super) { __extends(CustomDirective, _super); function CustomDirective(symbol, input) { CustomDirective.__super__.constructor.call(this, symbol, input); if (this.input !== null) { this["static"] = this; this["static"].regex = new RegExp("#" + this.symbol + " " + this.input); } else { this["static"].regex = new RegExp("#" + this.symbol); } } return CustomDirective; })(Directive); exports.CustomDirective = CustomDirective; StopDirective = (function(_super) { __extends(StopDirective, _super); function StopDirective() { StopDirective.__super__.constructor.call(this, "stop"); } return StopDirective; })(Directive); exports.StopDirective = StopDirective; ChildDirective = (function(_super) { __extends(ChildDirective, _super); function ChildDirective() { ChildDirective.__super__.constructor.call(this, "child", "[^ \r\n]+"); } return ChildDirective; })(Directive); exports.ChildDirective = ChildDirective; NameDirective = (function(_super) { __extends(NameDirective, _super); function NameDirective() { NameDirective.__super__.constructor.call(this, "name", "[^ \r\n]+"); } return NameDirective; })(Directive); exports.NameDirective = NameDirective; RenderDirective = (function(_super) { __extends(RenderDirective, _super); function RenderDirective() { RenderDirective.__super__.constructor.call(this, "render"); } return RenderDirective; })(Directive); exports.RenderDirective = RenderDirective; SectionDirective = (function(_super) { __extends(SectionDirective, _super); function SectionDirective() { SectionDirective.__super__.constructor.call(this, "section", "[^ \r\n]+"); } return SectionDirective; })(Directive); exports.SectionDirective = SectionDirective; RepeatDirective = (function(_super) { __extends(RepeatDirective, _super); function RepeatDirective() { RepeatDirective.__super__.constructor.call(this, "repeat", "[0-9]+"); } return RepeatDirective; })(Directive); exports.RepeatDirective = RepeatDirective; ParentDirective = (function(_super) { __extends(ParentDirective, _super); function ParentDirective() { ParentDirective.__super__.constructor.call(this, "parent", "[^ \r\n]+"); } return ParentDirective; })(Directive); exports.ParentDirective = ParentDirective; NeedDirective = (function(_super) { __extends(NeedDirective, _super); function NeedDirective() { NeedDirective.__super__.constructor.call(this, "need", "[^ \r\n]+"); } return NeedDirective; })(Directive); exports.NeedDirective = NeedDirective; fs = require("fs"); MegaFile = require("mega-reader").MegaFile; async = require("async"); mkdirp = require("mkdirp"); path = require("path"); os = require("os"); RenderLine = (function() { function RenderLine(name, bin, stack) { this.name = name; this.bin = bin; this.stack = stack; process.output.debug("renderline " + this.name + " created"); this.line = []; } RenderLine.prototype.clear = function() { this.position = -1; this.tools = []; return this.readers = []; }; RenderLine.prototype.buildReaders = function() { var file, _i, _len, _ref, _results; _ref = this.line; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { file = _ref[_i]; _results.push(this.readers.push(new MegaFile([file.filename]))); } return _results; }; RenderLine.prototype.buildtools = function() { var tool, _i, _len, _ref, _results; _ref = [new Asset, new NeedDirective, new ParentDirective, new RepeatDirective, new SectionDirective, new NameDirective, new ChildDirective, new RenderDirective, new StopDirective, new CallableFunction, new Variable, new If, new EndIf, new ForEach, new EndForEach]; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; _results.push(this.tools.push(tool)); } return _results; }; RenderLine.prototype.shift = function() { return this.line.shift(); }; RenderLine.prototype.unshift = function(item) { return this.line.unshift(item); }; RenderLine.prototype.push = function(item) { return this.line.push(item); }; RenderLine.prototype.pop = function(item) { return this.line.pop(item); }; RenderLine.prototype.position = null; RenderLine.prototype.internalLine = function(text) { var tool, value, _i, _len, _ref; value = null; _ref = this.tools; for (_i = 0, _len = _ref.length; _i < _len; _i++) { tool = _ref[_i]; if (tool.canHandle(text)) { value = tool; break; } } return value; }; RenderLine.prototype.makefile = function() { if (!fs.existsSync(this.bin)) { mkdirp.sync(this.bin); } return fs.openSync(this.previewFile(), "w"); }; RenderLine.prototype.previewFile = function() { return "" + this.bin + path.sep + this.name + ".html"; }; RenderLine.prototype.printFile = function(file, reader, repeat) { var directive, line, stop; if (repeat == null) { repeat = 1; } while (true) { process.output.debug("--------------------------------"); process.output.debug("" + repeat + "," + reader.files); stop = false; if (reader.hasNextLine()) { line = reader.getNextLine(); process.output.debug("" + line); directive = this.internalLine(line); if (!directive) { fs.writeSync(file, "" + line + os.EOL); } else if (directive instanceof ChildDirective) { this.printChild(file, directive.getDirective(line)); } else if (directive instanceof NeedDirective) { this.printNeed(file, directive.getDirective(line).value); } else if (directive instanceof StopDirective) { stop = true; } else if (directive instanceof Asset || directive instanceof Variable || directive instanceof CallableFunction || directive instanceof If || directive instanceof EndIf || directive instanceof ForEach || directive instanceof EndForEach) { fs.writeSync(file, "" + (directive.getPreviewReplacement(line)) + os.EOL + " "); } } if (reader.hasNextLine()) { if (!stop) { continue; } } if (repeat > 0) { reader.reset(); repeat--; } if (repeat <= 0) { break; } } return process.debug = false; }; RenderLine.prototype.printRenderFile = function(file) { var reader, repeat; this.position++; repeat = this.line[this.position].repeat; reader = this.readers[this.position]; this.printFile(file, reader, repeat); return this.position--; }; RenderLine.prototype.printChild = function(file, secDirective) { var cd, line, reader; this.position++; reader = this.readers[this.position]; reader.reset(); cd = new CustomDirective(secDirective.key.replace("#child", "section"), secDirective.value); process.output.debug("" + (JSON.stringify(secDirective))); while (true) { if (reader.hasNextLine()) { line = reader.getNextLine(); if (!cd.canHandle(line)) { continue; } } break; } this.position--; return this.printRenderFile(file); }; RenderLine.prototype.printNeed = function(file, need) { var f, reader, _i, _len, _ref; reader = null; _ref = this.stack; for (_i = 0, _len = _ref.length; _i < _len; _i++) { f = _ref[_i]; if (!(f.name === need)) { continue; } reader = f; break; } return this.printFile(file, new MegaFile([reader.filename]), reader.repeat); }; RenderLine.prototype.render = function() { var file; this.clear(); this.buildtools(); this.buildReaders(); file = this.makefile(); this.printRenderFile(file); return fs.closeSync(file); }; RenderLine.prototype.toString = function() { var l, obj, str, _i, _len, _ref; obj = []; _ref = this.line; for (_i = 0, _len = _ref.length; _i < _len; _i++) { l = _ref[_i]; obj.push(l.toString()); } str = obj.join(",\n"); return str; }; return RenderLine; })(); exports.RenderLine = RenderLine; async = require("async"); DirectoryManager = (function() { function DirectoryManager(fileManager) { this.fileManager = fileManager; this.readDirFinished = __bind(this.readDirFinished, this); process.output.debug("entering DirectoryManager " + (Date.now())); this.files = []; this.dirRead = require('node-dir'); /* bindings */ this.add = this.add.bind(this); this.loadFiles = this.loadFiles.bind(this); this.buildIndex = this.buildIndex.bind(this); this.buildConcreteView = this.buildConcreteView.bind(this); } DirectoryManager.prototype.watchDirectory = function() {}; DirectoryManager.prototype.exclude = null; DirectoryManager.prototype.match = null; DirectoryManager.prototype.loadFiles = function(directory, bin, match, exclude, loadFileFinished) { this.bin = bin; this.match = match != null ? match : null; this.exclude = exclude != null ? exclude : null; this.loadFileFinished = loadFileFinished != null ? loadFileFinished : null; process.output.debug("getting ready to load the files"); return this.dirRead.files(directory, this.readDirFinished); }; DirectoryManager.prototype.readDirFinished = function(err, files) { var after, afterIterator; process.output.debug("we have finished reading the directory and now wish to process the files"); afterIterator = (function(_this) { return function(file, fileBuilt) { return file.build(fileBuilt); }; })(this); after = (function(_this) { return function() { return async.each(_this.files, afterIterator, _this.loadFileFinished); }; })(this); return async.each(files, this.buildIndex, after); }; DirectoryManager.prototype.buildIndex = function(file, fileProcessed) { if (this.match === null || (new RegExp(this.match)).exec(file)) { if (this.exclude === null || (new RegExp(this.exclude)).exec(file) === null) { process.output.debug("moving on to process file " + file); this.add(file, this.bin); } } return fileProcessed.call(); }; DirectoryManager.prototype.buildView = function(directory, bin, match, exclude, buildViewFinished) { this.bin = bin; this.match = match; this.exclude = exclude; this.buildViewFinished = buildViewFinished; return this.dirRead.files(directory, this.buildConcreteView); }; DirectoryManager.prototype.buildConcreteView = function(err, files) { var indexBuilt; process.output.debug("finished reading the directory files for creating the views"); indexBuilt = (function(_this) { return function() { var afterIndexed; afterIndexed = function(file, cb) { file["export"](_this.bin); return cb.call(); }; afterIndexed = afterIndexed.bind(_this); return async.each(_this.files, afterIndexed, _this.buildViewFinished); }; })(this); indexBuilt = indexBuilt.bind(this); return async.each(files, this.buildIndex, indexBuilt); }; DirectoryManager.prototype.add = function(file, bin) { var f, fm, _i, _len, _ref; fm = new FileManager(file, bin, this.files); _ref = this.files; for (_i = 0, _len = _ref.length; _i < _len; _i++) { f = _ref[_i]; if (f.name === fm.name) { return null; } } return this.files.push(fm); }; DirectoryManager.prototype.toString = function() { return "[DirectoryManager]"; }; return DirectoryManager; })(); exports.DirectoryManager = DirectoryManager; fs = require("fs"); path = require("path"); CommandLine = (function() { function CommandLine(args) { var program, _base; this.program = require("commander"); this.program.version("0.0.1").option("-w, --watch", "this will watch the directory and re-render files").option("-c, --config [value]", "This is the path to the roar.json file with the configuration").option("-r, --route", "Build the route file from the route.json in the routebuilder location").option("-p, --preview", "Flag used to build preview file").option("-v, --viewbuild", "Flag used to build preview file").parse(args); if ((_base = this.program).config == null) { _base.config = "roar.json"; } this.basedir = path.resolve(path.dirname(this.program.config)); if (fs.existsSync(this.program.config)) { this.config = JSON.parse(fs.readFileSync(this.program.config, { encoding: "utf8" })); } else { console.log("" + this.program.config + " doesn't exist"); process.exit(0); } program = this.program; if (program.preview) { this.preview(); } if (program.route) { this.routeBuilder(); } if (program.viewbuild) { this.viewBuild(); } } CommandLine.prototype.config = null; CommandLine.prototype.preview = function() { var basedir, config, dm, exclude, input, preview, viewbuilder; basedir = this.basedir; config = this.config; viewbuilder = path.resolve(basedir, config.path.viewbuilder); preview = path.resolve(basedir, config.path.preview); input = config.view.extension.input; exclude = config.view.extension.exclude; if (exclude === "") { exclude = null; } dm = new DirectoryManager(); return dm.loadFiles(viewbuilder, preview, input, exclude); }; CommandLine.prototype.routeBuilder = function() { var basedir, config, exportdir, route, routebuilder; basedir = this.basedir; config = this.config; routebuilder = path.resolve(basedir, config.path.routebuilder, "routes.json"); exportdir = path.resolve(basedir, config.path.application, "routes.json"); route = new PHPRouteBuilder(routebuilder); return route["export"](exportdir); }; CommandLine.prototype.viewBuild = function() { var basedir, config, dm, exclude, match, program, viewbuilder, viewpath; dm = new DirectoryManager(); program = this.program; basedir = this.basedir; config = this.config; match = config.view.extension.match; if (match === "") { match = null; } exclude = config.view.extension.exclude; if (exclude === "") { exclude = null; } viewbuilder = path.resolve(basedir, config.path.viewbuilder); viewpath = path.resolve(basedir, config.path.view); return dm.buildView(viewbuilder, viewpath, match, exclude, function() {}); }; CommandLine.getInstance = function() { if (typeof CommandLine["interface"] === "undefined") { CommandLine["interface"] = new CommandLine(process.argv); } return CommandLine["interface"]; }; return CommandLine; })(); exports.CommandLine = CommandLine; fs = require('fs'); Log = require('log'); process.output = new Log('debug', fs.createWriteStream('my.log')); }).call(this);