Skip to content

Commit

Permalink
mod.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Aug 13, 2010
1 parent 91d28bd commit f026bcf
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 320 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NODE = node

build:
@echo "Building..."
@rm -rf build/ && node-waf configure && node-waf build
@rm -rf build/ && node-waf configure && node-waf clean && node-waf build
@rm .lock-wscript

install:
Expand Down
9 changes: 8 additions & 1 deletion lib/nTPL.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ this.parse = nTPL = (function() {

// Modificators
var modificators = {
// Direct output
// Example: {%= "hello world" %}
/** @return {string} */
"=": function (str) {
return "$p(" + str + ",$_);";
},

// "if", "else", "elseif"
// Example: {%if true%}I'm right!{%else%}I'm wrong{%/if%}
// {%if false%}I'm wrong{%elseif true%}I'm true!{%/if%}
Expand Down Expand Up @@ -91,7 +98,7 @@ this.parse = nTPL = (function() {
};

// Add native modificators
nTPL_native.init(modificators);
nTPL_native.initModificators(modificators);

/**
* Watch file changes
Expand Down
2 changes: 1 addition & 1 deletion nTPL.native/nTPL.mod.cc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/** Part of nTPL* nTPL.modificators v.0.0.1* Copyright 2010, Fedor Indutny* Released under MIT license*/#include <v8.h>#include <stdio.h>using namespace v8;namespace nTPL { Handle<Value> equal(const Arguments& args) { HandleScope scope; Local<String> str = args[0]->ToString(); int processedLen = str->Length() + 8; // $p(...,$_); char* processed = new char[processedLen + 1]; String::Utf8Value str_(str); char* str__ = (char*) *str_; sprintf(processed, "$p(%s,$_);", str__); scope.Close(String::New(processed, processedLen)); } #define NEW_MODIFICATOR(name,func) modificators->Set( String::New(name), FunctionTemplate::New(func)->GetFunction() ) Handle<Value> addNativeModificators(const Arguments& args) { HandleScope scope; if (!args[0]->IsObject) return; Local<Object> modificators = args[0]->ToObject(); NEW_MODIFICATOR("=",equal); }}
/** Part of nTPL* nTPL.modificators v.0.0.1* Copyright 2010, Fedor Indutny* Released under MIT license*/#include <nTPL.mod.h>#include <v8.h>#include <stdio.h>using namespace v8;namespace nTPL { namespace mod { Persistent<FunctionTemplate> constructor_template; static Handle<Value> ops(const Arguments& args) { HandleScope scope; Local<String> str = args[0]->ToString(); String::Utf8Value str_(str); char* str__ = (char*) *str_; sprintf(processed, "$p(%s,$_);", str__); return scope.Close(String::New("")); } #define NEW_MODIFICATOR(name,func) modificators->Set( String::New(name), FunctionTemplate::New(func)->GetFunction() ) static Handle<Value> add(const Arguments& args) { HandleScope scope; if (!args[0]->IsObject()) { return scope.Close(Object::New()); } Local<Object> modificators = args[0]->ToObject(); NEW_MODIFICATOR("set", ops); return scope.Close(modificators); } static void init(Handle<Object> target) { HandleScope scope; Local<FunctionTemplate> t = FunctionTemplate::New(add); constructor_template = Persistent<FunctionTemplate>::New(t); target->Set(String::NewSymbol("initModificators"), constructor_template->GetFunction()); } }}
Expand Down
18 changes: 1 addition & 17 deletions nTPL.native/nTPL.mod.h
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
#ifndef NODE_NTPL_MODIFICATORS_MODULE
#define NODE_NTPL_MODIFICATORS_MODULE

#include <v8.h>
#include <stdio.h>

using namespace v8;

namespace nTPL {

Handle<Value> equal(const Arguments& args);

Handle<Value> addNativeModificators(const Arguments& args);

}

#endif // NODE_NTPL_MODIFICATORS_MODULE
#ifndef NODE_NTPL_MODIFICATORS_MODULE#define NODE_NTPL_MODIFICATORS_MODULE#include <v8.h>#include <stdio.h>using namespace v8;namespace nTPL { namespace mod { Persistent<FunctionTemplate> constructor_template; static Handle<Value> ops(const Arguments& args); static Handle<Value> add(const Arguments& args); static void init(Handle<Object> target); }}#endif // NODE_NTPL_MODIFICATORS_MODULE
Expand Down
Loading

0 comments on commit f026bcf

Please sign in to comment.