Skip to content

Commit 3166ea9

Browse files
committed
clean up primary templates
1 parent 84cd2a0 commit 3166ea9

7 files changed

Lines changed: 284 additions & 271 deletions

File tree

generate/templates/binding.gyp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# This is a generated file, modify: generate/templates/binding.gyp.
1+
# // This is a generated file, modify: generate/templates/binding.gyp.
2+
23
{
34
"targets": [
45
{
@@ -12,11 +13,11 @@
1213
"src/nodegit.cc",
1314
"src/wrapper.cc",
1415
"src/functions/copy.cc",
15-
{%each%}
16+
{% each %}
1617
{% if type != "enum" %}
17-
"src/{{ name }}.cc",
18+
"src/{{ name }}.cc",
1819
{% endif %}
19-
{%endeach%}
20+
{% endeach %}
2021
],
2122

2223
"include_dirs": [

generate/templates/class_content.cc

Lines changed: 100 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,128 +3,131 @@
33
#include <string.h>
44

55
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 %}
1010
}
1111

1212

1313
#include "../include/functions/copy.h"
1414
#include "../include/macros.h"
1515
#include "../include/{{ filename }}.h"
1616

17-
{%each dependencies as dependency%}
18-
#include "{{ dependency }}"
19-
{%endeach%}
17+
{% each dependencies as dependency %}
18+
#include "{{ dependency }}"
19+
{% endeach %}
2020

2121
#include <iostream>
2222

2323
using namespace std;
2424
using namespace v8;
2525
using namespace node;
2626

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+
}
3232

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 %}
3739
}
38-
{%endif%}
39-
}
4040

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+
}
6969

70-
NAN_METHOD({{ cppClassName }}::New) {
71-
NanScope();
70+
NAN_METHOD({{ cppClassName }}::New) {
71+
NanScope();
7272

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());
7985
}
8086

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+
}
8392

84-
NanReturnValue(args.This());
85-
}
93+
{{ cType }} *{{ cppClassName }}::GetValue() {
94+
return this->raw;
95+
}
8696

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+
}
92100

93-
{{ cType }} *{{ cppClassName }}::GetValue() {
94-
return this->raw;
95-
}
101+
{% else %}
96102

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();
103105

104-
Local<Object> object = NanNew<Object>();
106+
Local<Object> object = NanNew<Object>();
105107

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 %}
111113

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

Comments
 (0)