|
3 | 3 | #include <string.h> |
4 | 4 |
|
5 | 5 | extern "C" { |
6 | | -#include <git2.h> |
7 | | -{%each cDependencies as dependency %} |
8 | | -#include <{{ dependency }}> |
9 | | -{%endeach%} |
| 6 | + #include <git2.h> |
| 7 | + {% each cDependencies as dependency %} |
| 8 | + #include <{{ dependency }}> |
| 9 | + {% endeach %} |
10 | 10 | } |
11 | 11 |
|
12 | 12 |
|
13 | 13 | #include "../include/functions/copy.h" |
14 | 14 | #include "../include/macros.h" |
15 | 15 | #include "../include/{{ filename }}.h" |
16 | 16 |
|
17 | | -{%each dependencies as dependency%} |
18 | | -#include "{{ dependency }}" |
19 | | -{%endeach%} |
| 17 | +{% each dependencies as dependency %} |
| 18 | + #include "{{ dependency }}" |
| 19 | +{% endeach %} |
20 | 20 |
|
21 | 21 | #include <iostream> |
22 | 22 |
|
23 | 23 | using namespace std; |
24 | 24 | using namespace v8; |
25 | 25 | using namespace node; |
26 | 26 |
|
27 | | -{%if cType%} |
28 | | -{{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw, bool selfFreeing) { |
29 | | - this->raw = raw; |
30 | | - this->selfFreeing = selfFreeing; |
31 | | -} |
| 27 | +{% if cType %} |
| 28 | + {{ cppClassName }}::{{ cppClassName }}({{ cType }} *raw, bool selfFreeing) { |
| 29 | + this->raw = raw; |
| 30 | + this->selfFreeing = selfFreeing; |
| 31 | + } |
32 | 32 |
|
33 | | -{{ cppClassName }}::~{{ cppClassName }}() { |
34 | | - {%if freeFunctionName%} |
35 | | - if (this->selfFreeing) { |
36 | | - {{ freeFunctionName }}(this->raw); |
| 33 | + {{ cppClassName }}::~{{ cppClassName }}() { |
| 34 | + {% if freeFunctionName %} |
| 35 | + if (this->selfFreeing) { |
| 36 | + {{ freeFunctionName }}(this->raw); |
| 37 | + } |
| 38 | + {% endif %} |
37 | 39 | } |
38 | | - {%endif%} |
39 | | -} |
40 | 40 |
|
41 | | -void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) { |
42 | | - NanScope(); |
43 | | - |
44 | | - Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New); |
45 | | - |
46 | | - tpl->InstanceTemplate()->SetInternalFieldCount(1); |
47 | | - tpl->SetClassName(NanNew<String>("{{ jsClassName }}")); |
48 | | - |
49 | | - {%each functions as function%} |
50 | | - {%if not function.ignore%} |
51 | | - {%if function.isPrototypeMethod%} |
52 | | - NODE_SET_PROTOTYPE_METHOD(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
53 | | - {%else%} |
54 | | - NODE_SET_METHOD(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
55 | | - {%endif%} |
56 | | - {%endif%} |
57 | | - {%endeach%} |
58 | | - |
59 | | - {%each fields as field%} |
60 | | - {%if not field.ignore%} |
61 | | - NODE_SET_PROTOTYPE_METHOD(tpl, "{{ field.jsFunctionName }}", {{ field.cppFunctionName }}); |
62 | | - {%endif%} |
63 | | - {%endeach%} |
64 | | - |
65 | | - Local<Function> _constructor_template = tpl->GetFunction(); |
66 | | - NanAssignPersistent(constructor_template, _constructor_template); |
67 | | - target->Set(NanNew<String>("{{ jsClassName }}"), _constructor_template); |
68 | | -} |
| 41 | + void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) { |
| 42 | + NanScope(); |
| 43 | + |
| 44 | + Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New); |
| 45 | + |
| 46 | + tpl->InstanceTemplate()->SetInternalFieldCount(1); |
| 47 | + tpl->SetClassName(NanNew<String>("{{ jsClassName }}")); |
| 48 | + |
| 49 | + {% each functions as function %} |
| 50 | + {% if not function.ignore %} |
| 51 | + {% if function.isPrototypeMethod %} |
| 52 | + NODE_SET_PROTOTYPE_METHOD(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
| 53 | + {% else %} |
| 54 | + NODE_SET_METHOD(tpl, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
| 55 | + {% endif %} |
| 56 | + {% endif %} |
| 57 | + {% endeach %} |
| 58 | + |
| 59 | + {% each fields as field %} |
| 60 | + {% if not field.ignore %} |
| 61 | + NODE_SET_PROTOTYPE_METHOD(tpl, "{{ field.jsFunctionName }}", {{ field.cppFunctionName }}); |
| 62 | + {% endif %} |
| 63 | + {% endeach %} |
| 64 | + |
| 65 | + Local<Function> _constructor_template = tpl->GetFunction(); |
| 66 | + NanAssignPersistent(constructor_template, _constructor_template); |
| 67 | + target->Set(NanNew<String>("{{ jsClassName }}"), _constructor_template); |
| 68 | + } |
69 | 69 |
|
70 | | -NAN_METHOD({{ cppClassName }}::New) { |
71 | | - NanScope(); |
| 70 | + NAN_METHOD({{ cppClassName }}::New) { |
| 71 | + NanScope(); |
72 | 72 |
|
73 | | - if (args.Length() == 0 || !args[0]->IsExternal()) { |
74 | | - {%if createFunctionName%} |
75 | | - return NanThrowError("A new {{ cppClassName }} cannot be instantiated. Use {{ jsCreateFunctionName }} instead."); |
76 | | - {%else%} |
77 | | - return NanThrowError("A new {{ cppClassName }} cannot be instantiated."); |
78 | | - {%endif%} |
| 73 | + if (args.Length() == 0 || !args[0]->IsExternal()) { |
| 74 | + {% if createFunctionName %} |
| 75 | + return NanThrowError("A new {{ cppClassName }} cannot be instantiated. Use {{ jsCreateFunctionName }} instead."); |
| 76 | + {% else %} |
| 77 | + return NanThrowError("A new {{ cppClassName }} cannot be instantiated."); |
| 78 | + {% endif %} |
| 79 | + } |
| 80 | + |
| 81 | + {{ cppClassName }}* object = new {{ cppClassName }}(static_cast<{{ cType }} *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue()); |
| 82 | + object->Wrap(args.This()); |
| 83 | + |
| 84 | + NanReturnValue(args.This()); |
79 | 85 | } |
80 | 86 |
|
81 | | - {{ cppClassName }}* object = new {{ cppClassName }}(static_cast<{{ cType }} *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue()); |
82 | | - object->Wrap(args.This()); |
| 87 | + Handle<Value> {{ cppClassName }}::New(void *raw, bool selfFreeing) { |
| 88 | + NanEscapableScope(); |
| 89 | + Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) }; |
| 90 | + return NanEscapeScope(NanNew<Function>({{ cppClassName }}::constructor_template)->NewInstance(2, argv)); |
| 91 | + } |
83 | 92 |
|
84 | | - NanReturnValue(args.This()); |
85 | | -} |
| 93 | + {{ cType }} *{{ cppClassName }}::GetValue() { |
| 94 | + return this->raw; |
| 95 | + } |
86 | 96 |
|
87 | | -Handle<Value> {{ cppClassName }}::New(void *raw, bool selfFreeing) { |
88 | | - NanEscapableScope(); |
89 | | - Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) }; |
90 | | - return NanEscapeScope(NanNew<Function>({{ cppClassName }}::constructor_template)->NewInstance(2, argv)); |
91 | | -} |
| 97 | + {{ cType }} **{{ cppClassName }}::GetRefValue() { |
| 98 | + return &this->raw; |
| 99 | + } |
92 | 100 |
|
93 | | -{{ cType }} *{{ cppClassName }}::GetValue() { |
94 | | - return this->raw; |
95 | | -} |
| 101 | +{% else %} |
96 | 102 |
|
97 | | -{{ cType }} **{{ cppClassName }}::GetRefValue() { |
98 | | - return &this->raw; |
99 | | -} |
100 | | -{%else%} |
101 | | -void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) { |
102 | | - NanScope(); |
| 103 | + void {{ cppClassName }}::InitializeComponent(Handle<v8::Object> target) { |
| 104 | + NanScope(); |
103 | 105 |
|
104 | | - Local<Object> object = NanNew<Object>(); |
| 106 | + Local<Object> object = NanNew<Object>(); |
105 | 107 |
|
106 | | - {%each functions as function%} |
107 | | - {%if not function.ignore%} |
108 | | - NODE_SET_METHOD(object, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
109 | | - {%endif%} |
110 | | - {%endeach%} |
| 108 | + {% each functions as function %} |
| 109 | + {% if not function.ignore %} |
| 110 | + NODE_SET_METHOD(object, "{{ function.jsFunctionName }}", {{ function.cppFunctionName }}); |
| 111 | + {% endif %} |
| 112 | + {% endeach %} |
111 | 113 |
|
112 | | - target->Set(NanNew<String>("{{ jsClassName }}"), object); |
113 | | -} |
114 | | -{%endif%} |
115 | | - |
116 | | -{%each functions as function %} |
117 | | - {%if not function.ignore%} |
118 | | - {%if function.isAsync%} |
119 | | - {%partial asyncFunction function %} |
120 | | - {%else%} |
121 | | - {%partial syncFunction function %} |
122 | | - {%endif%} |
123 | | - {%endif%} |
124 | | -{%endeach%} |
125 | | - |
126 | | -{%partial fields .%} |
127 | | - |
128 | | -{%if not cTypeIsUndefined %} |
129 | | -Persistent<Function> {{ cppClassName }}::constructor_template; |
130 | | -{%endif%} |
| 114 | + target->Set(NanNew<String>("{{ jsClassName }}"), object); |
| 115 | + } |
| 116 | + |
| 117 | +{% endif %} |
| 118 | + |
| 119 | +{% each functions as function %} |
| 120 | + {% if not function.ignore %} |
| 121 | + {% if function.isAsync %} |
| 122 | + {% partial asyncFunction function %} |
| 123 | + {% else %} |
| 124 | + {% partial syncFunction function %} |
| 125 | + {% endif %} |
| 126 | + {% endif %} |
| 127 | +{% endeach %} |
| 128 | + |
| 129 | +{% partial fields . %} |
| 130 | + |
| 131 | +{% if not cTypeIsUndefined %} |
| 132 | + Persistent<Function> {{ cppClassName }}::constructor_template; |
| 133 | +{% endif %} |
0 commit comments