Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 6a32f6dde4b7b908263b612f2ba14a06be1cdc6d @dimsmol committed Jun 30, 2011
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules/
@@ -0,0 +1,2 @@
+.DS_Store
+.git*
@@ -0,0 +1,19 @@
+# TODO
+
+* extend readme.md
+
+* write usage for bin/ojster
+* add template examples
+
+* ensure ojster can be used with jQuery and other libraries, at least skipping module-related stuff (without maintaining compatibility with Node and Closure)
+* fs watcher for autocompilation (needs some kind of config - which src and dst paths to use, which options)
+* perform JS-linting after template compilation
+
+* make Tokenizer extendable (allow to add new commands)
+
+* fix single file compilation support for path_compiler (works partially)
+
+## GoogRenderer
+
+* make usage of goog.scope an option
+* fix handling of module subObjects (prohibited now)
@@ -0,0 +1,41 @@
+#!/usr/bin/env node
+
+var argv = require('optimist').argv;
+var ojster = require('../');
+
+var args = argv._;
+var l = args.length;
+if (l < 1) {
+ abort('srcPath argument required');
+}
+
+var srcPath = args[0];
+var dstPath = null;
+if (l >= 2) {
+ dstPath = args[1];
+}
+
+var generatorClass = null;
+if (argv.goog) {
+ generatorClass = ojster.generators.GoogGenerator;
+}
+
+var options = {};
+if (generatorClass != null) {
+ options.generator = options.generator || {};
+ options.generator.generatorClass = generatorClass;
+}
+
+ojster.compile_path(srcPath, dstPath, options, function(err, results) {
+ if (err) {
+ process.exit(1);
+ }
+
+ process.exit(0);
+});
+
+
+function abort(str) {
+ console.error(str);
+ process.exit(1);
+}
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/ojster');
@@ -0,0 +1,27 @@
+
+var inherits = require('util').inherits;
+var strTools = require('../tools/str_tools');
+
+var CompilationError = function(ctx, msg) {
+ this.ctx = ctx;
+ this.msg = msg;
+};
+CompilationError.prototype.toString = function(src) {
+ if (src != null) {
+ var lineNumStr = strTools.padLeft(this.ctx.lineNumber, 5) + ': ';
+ var lineEndPos = strTools.indexOfAny(src, ['\n', '\r'], this.ctx.lineStartPos);
+ if (lineEndPos == -1) {
+ lineEndPos = undefined;
+ }
+ return [
+ lineNumStr, src.substring(this.ctx.lineStartPos, lineEndPos), '\n',
+ strTools.repeat(' ', this.ctx.linePos - 1 + lineNumStr.length), '^\n',
+ strTools.repeat(' ', lineNumStr.length), this.msg
+ ].join('');
+ }
+ return ['@', this.ctx.lineNumber, ':', this.ctx.linePos, ' ', this.msg].join('');
+};
+
+module.exports = {
+ CompilationError: CompilationError
+};
@@ -0,0 +1,17 @@
+
+var Block = function(name, buffer) {
+ this.name = name;
+ this.buffer = buffer;
+
+ this.sequenceOpened = false;
+};
+
+module.exports = Block;
+
+Block.prototype.append = function() {
+ this.buffer.append.apply(this.buffer, arguments);
+};
+
+Block.prototype.getValue = function() {
+ return this.buffer.getValue();
+};
@@ -0,0 +1,14 @@
+
+var Buffer = function() {
+ this.buff = [];
+};
+
+module.exports = Buffer;
+
+Buffer.prototype.append = function() {
+ this.buff.push.apply(this.buff, arguments);
+};
+
+Buffer.prototype.getValue = function() {
+ return this.buff.join('');
+};
@@ -0,0 +1,68 @@
+
+var inherits = require('util').inherits;
+var CompilationError = require('../compilation_errors').CompilationError;
+
+var GenerationError = function() {
+ CompilationError.apply(this, arguments);
+};
+inherits(GenerationError, CompilationError);
+
+var DuplicateBlockName = function(ctx, blockName) {
+ GenerationError.call(this, ctx,
+ ['Block name "', blockName, '" already used'].join(''));
+};
+inherits(DuplicateBlockName, GenerationError);
+
+var BlockOpeningMissed = function(ctx, blockName) {
+ var msg = (blockName == null ? 'Block opening is missed or mismatched' : ['Block "', blockName,'" opening is missed or mismatched'].join(''));
+ GenerationError.call(this, ctx,
+ msg);
+};
+inherits(BlockOpeningMissed, GenerationError);
+
+var FragmentBeyondBlock = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Fragment must be placed within block');
+};
+inherits(FragmentBeyondBlock, GenerationError);
+
+var ExpressionBeyondBlock = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Expression must be placed within block');
+};
+inherits(ExpressionBeyondBlock, GenerationError);
+
+var RequireWithinBlock = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Require cannot be placed within block');
+};
+inherits(RequireWithinBlock, GenerationError);
+
+var TemplateInfoWithinBlock = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Template description cannot be placed within block');
+};
+inherits(TemplateInfoWithinBlock, GenerationError);
+
+var DuplicateTemplateInfo = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Template description duplicated');
+};
+inherits(DuplicateTemplateInfo, GenerationError);
+
+var InheritanceInfoWithinBlock = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Inheritance description cannot be placed within block');
+};
+inherits(InheritanceInfoWithinBlock, GenerationError);
+
+var DuplicateInheritanceInfo = function(ctx) {
+ GenerationError.call(this, ctx,
+ 'Inheritance description duplicated');
+};
+inherits(DuplicateInheritanceInfo, GenerationError);
+
+module.exports = {
+ GenerationError: GenerationError,
+ BlockOpeningMissed: BlockOpeningMissed
+};
Oops, something went wrong.

0 comments on commit 6a32f6d

Please sign in to comment.