Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 391b3ed

Browse filesBrowse files
tbranyenJohn Haley
authored andcommitted
Started working on replacing the header template
This is the initial work for porting over the header template to use Combyne instead of EJS. It adds in a few helpers that are necessary to replace missing features that EJS provides like JS boolean logic.
1 parent 60d79c7 commit 391b3ed
Copy full SHA for 391b3ed

File tree

Expand file treeCollapse file tree

7 files changed

+101
-192
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+101
-192
lines changed
Open diff view settings
Collapse file

‎generate/filters/or.js‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(value, other) {
2+
return value || other;
3+
};
Collapse file

‎generate/filters/replace.js‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(value, find, replace) {
2+
return value.replace(find, replace);
3+
};
Collapse file

‎generate/filters/upper.js‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(value) {
2+
return value.toUpperCase();
3+
};
Collapse file

‎generate/index.js‎

Copy file name to clipboardExpand all lines: generate/index.js
+25-14Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ combyne.settings.delimiters = {
99
END_RAW: "=}}"
1010
};
1111

12-
var partial = {
12+
var partials = {
1313
asyncFunction: file.read("partials/async_function.cc"),
1414
convertFromV8: file.read("partials/convert_from_v8.cc"),
1515
convertToV8: file.read("partials/convert_to_v8.cc"),
@@ -19,39 +19,50 @@ var partial = {
1919
syncFunction: file.read("partials/sync_function.cc")
2020
};
2121

22-
var template = {
23-
class: file.read("templates/class.cc"),
24-
//fs.readFileSync(local("templates/header.h")),
25-
//fs.readFileSync(local("templates/binding.gyp")),
22+
var templates = {
23+
// class: file.read("templates/class.cc"),
24+
header: file.read("templates/header.h"),
2625
binding: file.read("templates/binding.gyp"),
2726
nodegit: file.read("templates/nodegit.cc")
2827
};
2928

29+
var filters = {
30+
upper: require("./filters/upper"),
31+
replace: require("./filters/replace"),
32+
or: require("./filters/or")
33+
};
34+
3035
// Convert Buffers to Combyne templates.
31-
Object.keys(template).forEach(function(name) {
32-
template[name] = combyne(template[name]);
36+
Object.keys(templates).forEach(function(template) {
37+
templates[template] = combyne(templates[template]);
38+
39+
// Attach all filters to all templates.
40+
Object.keys(filters).forEach(function(filter) {
41+
templates[template].registerFilter(filter, filters[filter]);
42+
});
3343
});
3444

3545
// Attach all partials to select templates.
36-
Object.keys(partial).forEach(function(name) {
37-
template.class.registerPartial(name, combyne(partial[name]));
38-
});
46+
//Object.keys(partials).forEach(function(partial) {
47+
// templates.class.registerPartial(partial, combyne(partials[partial]));
48+
//});
49+
3950

4051
// Determine which definitions to actually include in the source code.
4152
var enabled = idefs.filter(function(idef) {
4253
// Additionally provide a friendly name to the actual filename.
4354
idef.name = path.basename(idef.filename, ".h");
44-
4555
return !idef.ignore;
4656
});
4757

4858
// TODO Wipe out all existing source files.
4959

5060
// Write out single purpose templates.
51-
file.write("../binding.gyp", template.binding.render(enabled));
52-
file.write("../src/nodegit.cc", template.nodegit.render(enabled));
61+
file.write("../binding.gyp", templates.binding.render(enabled));
62+
file.write("../src/nodegit.cc", templates.nodegit.render(enabled));
5363

5464
// Write out all the classes.
5565
enabled.forEach(function(idef) {
56-
file.write("../src/" + idef.name + ".cc", template.class.render(idef));
66+
//file.write("../src/" + idef.name + ".cc", templates.class.render(idef));
67+
file.write("../include/" + idef.name + ".h", templates.header.render(idef));
5768
});
Collapse file

‎generate/partials/fields.cc‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{%each fields as field%}
2+
{%if not field.ignore%}
3+
4+
NAN_METHOD({{ cppClassName }}::{{ field.cppFunctionName }}) {
5+
NanScope();
6+
<% var to = fieldInfo; -%>
7+
Handle<Value> to;
8+
9+
<%- fieldInfo.cType %> <% if (!isV8Value(fieldInfo.cppClassName)) { %>*<% } %><%- fieldInfo.name %> =
10+
<% if (!isV8Value(fieldInfo.cppClassName)) { %>&<% } %>ObjectWrap::Unwrap<<%- cppClassName %>>(args.This())->GetValue()-><%- fieldInfo.name %>;
11+
12+
<% include convertToV8.cc.ejs -%>
13+
NanReturnValue(to);
14+
}
15+
<% } -%>
16+
<% } -%>
Collapse file

‎generate/templates/header.h‎

Copy file name to clipboardExpand all lines: generate/templates/header.h
+51-66Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,103 +8,88 @@ extern "C" {
88
#include <git2.h>
99
}
1010

11-
//{%each dependencies as dependency%}
12-
#include "<%- dependencies[d] %>"
13-
//{%endeach%}
11+
{%each dependencies as dependency%}
12+
#include "{{ dependency }}"
13+
{%endeach%}
1414

15-
<% if (typeof forwardDeclare !== "undefined") { %>
15+
{%if forwardDeclare%}
1616
// Forward declaration.
17-
struct <%- cType %> {
18-
<% if (typeof fields != 'undefined') { %>
19-
<%
20-
for (var i in fields) {
21-
var fieldInfo = fields[i];
22-
if (fieldInfo.ignore || !fieldInfo.cppFunctionName) continue;
23-
-%>
24-
25-
<%- fieldInfo.structType || fieldInfo.cType -%> <%- fieldInfo.structName || fieldInfo.name %>;
26-
<% } -%>
27-
<% } -%>
28-
17+
struct {{ cType }} {
18+
{%each fields as field%}
19+
{%if not field.ignore%}
20+
{{ field.structType|or field.cType }} {{ field.structName|or field.name }};
21+
{%endif%}
22+
{%endeach%}
2923
};
30-
<% } -%>
24+
{%endif%}
3125

3226
using namespace node;
3327
using namespace v8;
3428

35-
class <%- cppClassName %> : public ObjectWrap {
29+
class {{ cppClassName }} : public ObjectWrap {
3630
public:
3731

3832
static Persistent<Function> constructor_template;
3933
static void Initialize (Handle<v8::Object> target);
4034

41-
<% if (cType != undefined) { -%>
42-
<%- cType %> *GetValue();
35+
{%if cType%}
36+
{{ cType }} *GetValue();
4337

4438
static Handle<Value> New(void *raw);
45-
<% } -%>
39+
{%endif%}
4640

4741
private:
48-
<% if (cType != undefined) { -%>
49-
<%- cppClassName %>(<%- cType %> *raw);
50-
~<%- cppClassName %>();
51-
<% } -%>
42+
{%if cType%}
43+
{{ cppClassName }}({{ cType }} *raw);
44+
~{{ cppClassName }}();
45+
{%endif%}
5246

5347
static NAN_METHOD(New);
5448

55-
<% if (typeof fields != 'undefined') { -%>
56-
<%
57-
for (var i in fields) {
58-
var fieldInfo = fields[i];
59-
if (fieldInfo.ignore || !fieldInfo.cppFunctionName) continue;
60-
-%>
61-
static NAN_METHOD(<%- fieldInfo.cppFunctionName %>);
62-
<% } -%>
63-
<% } -%>
64-
<% if (typeof functions != 'undefined') { -%>
65-
<%
66-
for (var i in functions) {
67-
var functionInfo = functions[i];
68-
if (functionInfo.ignore || !functionInfo.cppFunctionName) continue;
69-
-%>
70-
<% if (functionInfo.isAsync) { -%>
71-
72-
struct <%- functionInfo.cppFunctionName %>Baton {
49+
{%each fields as field%}
50+
{%if not field.ignore%}
51+
static NAN_METHOD({{ field.cppFunctionName }});
52+
{%endif%}
53+
{%endeach%}
54+
55+
{%each functions as function%}
56+
{%if not function.ignore%}
57+
{%if function.isAsync%}
58+
59+
struct {{ function.cppFunctionName }}Baton {
7360
int error_code;
7461
const git_error* error;
75-
<%
76-
for (var i = 0; i < functionInfo.args.length; i++) {
77-
var arg = functionInfo.args[i];
78-
-%>
79-
<% if (arg.isReturn) { -%>
80-
<%- arg.cType.replace('**', '*') %> <%- arg.name %>;
81-
<% } else { -%>
82-
<%- arg.cType %> <%- arg.name %>;
83-
<% } -%>
84-
<% } -%>
62+
{%each function.args as arg%}
63+
{%if arg.isReturn%}
64+
{{ arg.cType|replace "**" "*" }} {{ arg.name }};
65+
{%else%}
66+
{{ arg.cType }} {{ arg.name }};
67+
{%endif%}
68+
{%endeach%}
8569
};
86-
class <%- functionInfo.cppFunctionName %>Worker : public NanAsyncWorker {
70+
class {{ function.cppFunctionName }}Worker : public NanAsyncWorker {
8771
public:
88-
<%- functionInfo.cppFunctionName %>Worker(
89-
<%- functionInfo.cppFunctionName %>Baton *_baton,
72+
{{ function.cppFunctionName }}Worker(
73+
{{ function.cppFunctionName }}Baton *_baton,
9074
NanCallback *callback
9175
) : NanAsyncWorker(callback)
9276
, baton(_baton) {};
93-
~<%- functionInfo.cppFunctionName %>Worker() {};
77+
~{{ function.cppFunctionName }}Worker() {};
9478
void Execute();
9579
void HandleOKCallback();
9680

9781
private:
98-
<%- functionInfo.cppFunctionName %>Baton *baton;
82+
{{ function.cppFunctionName }}Baton *baton;
9983
};
100-
<% } -%>
101-
static NAN_METHOD(<%- functionInfo.cppFunctionName %>);
102-
<% } -%>
103-
<% } -%>
104-
<% if (cType != undefined) { -%>
105-
<%- cType %> *raw;
106-
<% } -%>
84+
{%endif%}
85+
86+
static NAN_METHOD({{ function.cppFunctionName }});
87+
{%endif%}
88+
{%endeach%}
89+
90+
{%if cType%}
91+
{{ cType }} *raw;
92+
{%endif%}
10793
};
10894

10995
#endif
110-
Collapse file

‎generate/templates/header.h.ejs‎

Copy file name to clipboardExpand all lines: generate/templates/header.h.ejs
-112Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.