| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + --style=linux | ||
| 2 | + --indent=spaces=2 | ||
| 3 | + --attach-namespaces | ||
| 4 | + --attach-classes | ||
| 5 | + --attach-inlines | ||
| 6 | + --attach-extern-c | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,21 @@ const file = require("./util/file"); | |||
| 4 | 4 | const idefs = require("./idefs"); | |
| 5 | 5 | const promisify = require("promisify-node"); | |
| 6 | 6 | const fse = promisify(require("fs-extra")); | |
| 7 | + const js_beautify = require('js-beautify').js_beautify; | ||
| 8 | + const beautify = function (input) { | ||
| 9 | + return js_beautify(input, { | ||
| 10 | + "brace_style": "end-expand", | ||
| 11 | + "max_preserve_newlines": 2, | ||
| 12 | + "preserve_newlines": true, | ||
| 13 | + "indent_size": 2, | ||
| 14 | + "indent_char": " " | ||
| 15 | + }); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + var exec = promisify(function(command, opts, callback) { | ||
| 20 | + return require("child_process").exec(command, opts, callback); | ||
| 21 | + }); | ||
| 7 | 22 | ||
| 8 | 23 | // Customize the delimiters so as to not process `{{{` or `}}}`. | |
| 9 | 24 | combyne.settings.delimiters = { | |
@@ -83,7 +98,7 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { | |||
| 83 | 98 | return fse.copy(path.resolve(__dirname, "./manual/"), path.resolve(__dirname, "../")); | |
| 84 | 99 | }).then(function() { | |
| 85 | 100 | // Write out single purpose templates. | |
| 86 | - file.write("../binding.gyp", templates.binding.render(enabled)); | ||
| 101 | + file.write("../binding.gyp", beautify(templates.binding.render(enabled))); | ||
| 87 | 102 | file.write("../src/nodegit.cc", templates.nodegit.render(enabled)); | |
| 88 | 103 | ||
| 89 | 104 | ||
@@ -106,5 +121,22 @@ fse.remove(path.resolve(__dirname, "../src")).then(function() { | |||
| 106 | 121 | } | |
| 107 | 122 | }); | |
| 108 | 123 | ||
| 109 | - file.write("../lib/enums.js", templates.enums.render(enabled)); | ||
| 124 | + | ||
| 125 | + file.write("../lib/enums.js", beautify(templates.enums.render(enabled))); | ||
| 126 | + }).then(function() { | ||
| 127 | + return exec('command -v astyle').then(function(astyle) { | ||
| 128 | + if (astyle) { | ||
| 129 | + return exec( | ||
| 130 | + 'astyle --options=\".astylerc\" ' | ||
| 131 | + + path.resolve(__dirname, "../src") + "/*.cc " | ||
| 132 | + + path.resolve(__dirname, "../include") + "/*.h" | ||
| 133 | + ).then(function() { | ||
| 134 | + return exec( | ||
| 135 | + 'rm ' | ||
| 136 | + + path.resolve(__dirname, "../src") + "/*.cc.orig " | ||
| 137 | + + path.resolve(__dirname, "../include") + "/*.h.orig " | ||
| 138 | + ); | ||
| 139 | + }); | ||
| 140 | + } | ||
| 141 | + }) | ||
| 110 | 142 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,9 @@ | |||
| 1 | 1 | ||
| 2 | - {%partial doc .%} | ||
| 2 | + {% partial doc . %} | ||
| 3 | 3 | NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { | |
| 4 | 4 | NanScope(); | |
| 5 | - {%partial guardArguments .%} | ||
| 5 | + {% partial guardArguments . %} | ||
| 6 | + | ||
| 6 | 7 | if (args.Length() == {{args|jsArgsCount}} || !args[{{args|jsArgsCount}}]->IsFunction()) { | |
| 7 | 8 | return NanThrowError("Callback is required and must be a Function."); | |
| 8 | 9 | } | |
@@ -12,87 +13,85 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) { | |||
| 12 | 13 | baton->error_code = GIT_OK; | |
| 13 | 14 | baton->error = NULL; | |
| 14 | 15 | ||
| 15 | - {%each args|argsInfo as arg %} | ||
| 16 | - {%if not arg.isReturn %} | ||
| 17 | - {%if arg.isSelf %} | ||
| 18 | - baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue(); | ||
| 19 | - {%elsif arg.name %} | ||
| 20 | - {%partial convertFromV8 arg%} | ||
| 21 | - {%if not arg.isPayload %} | ||
| 22 | - baton->{{ arg.name }} = from_{{ arg.name }}; | ||
| 23 | - {%endif%} | ||
| 24 | - {%endif%} | ||
| 25 | - {%elsif arg.shouldAlloc %} | ||
| 26 | - baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }})); | ||
| 27 | - {%endif%} | ||
| 28 | - {%endeach%} | ||
| 16 | + {% each args|argsInfo as arg %} | ||
| 17 | + {% if not arg.isReturn %} | ||
| 18 | + {% if arg.isSelf %} | ||
| 19 | + baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue(); | ||
| 20 | + {% elsif arg.name %} | ||
| 21 | + {% partial convertFromV8 arg %} | ||
| 22 | + {% if not arg.isPayload %} | ||
| 23 | + baton->{{ arg.name }} = from_{{ arg.name }}; | ||
| 24 | + {% endif %} | ||
| 25 | + {% endif %} | ||
| 26 | + {% elsif arg.shouldAlloc %} | ||
| 27 | + baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }})); | ||
| 28 | + {% endif %} | ||
| 29 | + {% endeach %} | ||
| 29 | 30 | ||
| 30 | 31 | NanCallback *callback = new NanCallback(Local<Function>::Cast(args[{{args|jsArgsCount}}])); | |
| 31 | 32 | {{ cppFunctionName }}Worker *worker = new {{ cppFunctionName }}Worker(baton, callback); | |
| 32 | - {%each args|argsInfo as arg %} | ||
| 33 | - {%if not arg.isReturn %} | ||
| 34 | - {%if arg.isSelf %} | ||
| 33 | + {% each args|argsInfo as arg %} | ||
| 34 | + {% if not arg.isReturn %} | ||
| 35 | + {% if arg.isSelf %} | ||
| 35 | 36 | worker->SaveToPersistent("{{ arg.name }}", args.This()); | |
| 36 | - {%else%} | ||
| 37 | + {% else %} | ||
| 37 | 38 | if (!args[{{ arg.jsArg }}]->IsUndefined() && !args[{{ arg.jsArg }}]->IsNull()) | |
| 38 | 39 | worker->SaveToPersistent("{{ arg.name }}", args[{{ arg.jsArg }}]->ToObject()); | |
| 39 | - {%endif%} | ||
| 40 | - {%endif%} | ||
| 41 | - {%endeach%} | ||
| 40 | + {% endif %} | ||
| 41 | + {% endif %} | ||
| 42 | + {% endeach %} | ||
| 42 | 43 | ||
| 43 | 44 | NanAsyncQueueWorker(worker); | |
| 44 | 45 | NanReturnUndefined(); | |
| 45 | 46 | } | |
| 46 | 47 | ||
| 48 | + // startexecute {{ cppFunctionName }} | ||
| 47 | 49 | void {{ cppClassName }}::{{ cppFunctionName }}Worker::Execute() { | |
| 48 | - {%if .|hasReturnType %} | ||
| 49 | - {{ return.cType }} result = {{ cFunctionName }}( | ||
| 50 | - {%else%} | ||
| 51 | - {{ cFunctionName }}( | ||
| 52 | - {%endif%} | ||
| 53 | - {%-- Insert Function Arguments --%} | ||
| 54 | - {%each args|argsInfo as arg %} | ||
| 55 | - {%-- turn the pointer into a ref --%} | ||
| 56 | - {%if arg.isReturn|and arg.cType|isDoublePointer %}&{%endif%}baton->{{ arg.name }}{%if not arg.lastArg %},{%endif%} | ||
| 57 | - | ||
| 58 | - {%endeach%} | ||
| 59 | - ); | ||
| 60 | - | ||
| 61 | - {%if return.isErrorCode %} | ||
| 62 | - baton->error_code = result; | ||
| 63 | - | ||
| 64 | - if (result != GIT_OK && giterr_last() != NULL) { | ||
| 65 | - baton->error = git_error_dup(giterr_last()); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - {%elsif not return.cType == 'void' %} | ||
| 69 | - | ||
| 70 | - baton->result = result; | ||
| 71 | - | ||
| 72 | - {%endif%} | ||
| 50 | + {% if .|hasReturnType %} | ||
| 51 | + {{ return.cType }} result = {{ cFunctionName }} | ||
| 52 | + {% else %} | ||
| 53 | + {{ cFunctionName }} | ||
| 54 | + {% endif %} | ||
| 55 | + ( | ||
| 56 | + | ||
| 57 | + {% each .args|argsInfo as arg %} | ||
| 58 | + {% if arg.isReturn|and arg.cType|isDoublePointer %}&{% endif %}baton->{{ arg.name }}{% if not arg.lastArg %},{% endif %} | ||
| 59 | + {% endeach %} | ||
| 60 | + ); | ||
| 61 | + | ||
| 62 | + {% if return.isErrorCode %} | ||
| 63 | + baton->error_code = result; | ||
| 64 | + | ||
| 65 | + if (result != GIT_OK && giterr_last() != NULL) { | ||
| 66 | + baton->error = git_error_dup(giterr_last()); | ||
| 67 | + } | ||
| 68 | + {% elsif not return.cType == 'void' %} | ||
| 69 | + baton->result = result; | ||
| 70 | + {% endif %} | ||
| 73 | 71 | } | |
| 72 | + // done | ||
| 74 | 73 | ||
| 75 | 74 | void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { | |
| 76 | 75 | TryCatch try_catch; | |
| 77 | 76 | ||
| 78 | 77 | if (baton->error_code == GIT_OK) { | |
| 79 | - {%if not .|returnsCount %} | ||
| 78 | + {% if not .|returnsCount %} | ||
| 80 | 79 | Handle<Value> result = NanUndefined(); | |
| 81 | - {%else%} | ||
| 80 | + {% else %} | ||
| 82 | 81 | Handle<Value> to; | |
| 83 | - {%if .|returnsCount > 1 %} | ||
| 82 | + {% if .|returnsCount > 1 %} | ||
| 84 | 83 | Handle<Object> result = NanNew<Object>(); | |
| 85 | - {%endif%} | ||
| 86 | - {%each .|returnsInfo 0 1 as _return %} | ||
| 87 | - {%partial convertToV8 _return %} | ||
| 88 | - {%if .|returnsCount > 1 %} | ||
| 84 | + {% endif %} | ||
| 85 | + {% each .|returnsInfo 0 1 as _return %} | ||
| 86 | + {% partial convertToV8 _return %} | ||
| 87 | + {% if .|returnsCount > 1 %} | ||
| 89 | 88 | result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to); | |
| 90 | - {%endif%} | ||
| 91 | - {%endeach%} | ||
| 92 | - {%if .|returnsCount == 1 %} | ||
| 89 | + {% endif %} | ||
| 90 | + {% endeach %} | ||
| 91 | + {% if .|returnsCount == 1 %} | ||
| 93 | 92 | Handle<Value> result = to; | |
| 94 | - {%endif%} | ||
| 95 | - {%endif%} | ||
| 93 | + {% endif %} | ||
| 94 | + {% endif %} | ||
| 96 | 95 | Handle<Value> argv[2] = { | |
| 97 | 96 | NanNull(), | |
| 98 | 97 | result | |
@@ -111,26 +110,26 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() { | |||
| 111 | 110 | callback->Call(0, NULL); | |
| 112 | 111 | } | |
| 113 | 112 | ||
| 114 | - {%each args as arg %} | ||
| 115 | - {%if arg.shouldAlloc %} | ||
| 113 | + {% each args as arg %} | ||
| 114 | + {% if arg.shouldAlloc %} | ||
| 116 | 115 | free((void*)baton->{{ arg.name }}); | |
| 117 | - {%endif%} | ||
| 118 | - {%endeach%} | ||
| 116 | + {% endif %} | ||
| 117 | + {% endeach %} | ||
| 119 | 118 | } | |
| 120 | 119 | ||
| 121 | 120 | if (try_catch.HasCaught()) { | |
| 122 | 121 | node::FatalException(try_catch); | |
| 123 | 122 | } | |
| 124 | 123 | ||
| 125 | - {%each args|argsInfo as arg %} | ||
| 126 | - {%if arg.isCppClassStringOrArray %} | ||
| 127 | - {%if arg.freeFunctionName %} | ||
| 124 | + {% each args|argsInfo as arg %} | ||
| 125 | + {% if arg.isCppClassStringOrArray %} | ||
| 126 | + {% if arg.freeFunctionName %} | ||
| 128 | 127 | {{ arg.freeFunctionName }}(baton->{{ arg.name }}); | |
| 129 | - {%else%} | ||
| 128 | + {% else %} | ||
| 130 | 129 | free((void *)baton->{{ arg.name }}); | |
| 131 | - {%endif%} | ||
| 132 | - {%endif%} | ||
| 133 | - {%endeach%} | ||
| 130 | + {% endif %} | ||
| 131 | + {% endif %} | ||
| 132 | + {% endeach %} | ||
| 134 | 133 | ||
| 135 | 134 | delete baton; | |
| 136 | 135 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,51 +1,53 @@ | |||
| 1 | - {%if not isPayload %} | ||
| 1 | + {% if not isPayload %} | ||
| 2 | 2 | {{ cType }} from_{{ name }}; | |
| 3 | - {%if isOptional %} | ||
| 4 | - | ||
| 5 | - if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) { | ||
| 6 | - {%endif%} | ||
| 7 | - {%if cppClassName == 'String'%} | ||
| 8 | - | ||
| 9 | - String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString()); | ||
| 10 | - from_{{ name }} = ({{ cType }}) strdup(*{{ name }}); | ||
| 11 | - {%elsif cppClassName == 'Wrapper'%} | ||
| 12 | - | ||
| 13 | - String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString()); | ||
| 14 | - from_{{ name }} = ({{ cType }}) strdup(*{{ name }}); | ||
| 15 | - {%elsif cppClassName == 'Array'%} | ||
| 16 | - | ||
| 17 | - Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]); | ||
| 18 | - from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }})); | ||
| 19 | - for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) { | ||
| 20 | - {%-- | ||
| 21 | - // FIXME: should recursively call convertFromv8. | ||
| 22 | - --%} | ||
| 3 | + {% if isOptional %} | ||
| 4 | + if (args[{{ jsArg }}]->Is{{ cppClassName|cppToV8 }}()) { | ||
| 5 | + {% endif %} | ||
| 6 | + | ||
| 7 | + {% if cppClassName == 'String' %} | ||
| 8 | + | ||
| 9 | + String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString()); | ||
| 10 | + from_{{ name }} = ({{ cType }}) strdup(*{{ name }}); | ||
| 11 | + | ||
| 12 | + {% elsif cppClassName == 'Wrapper' %} | ||
| 13 | + | ||
| 14 | + String::Utf8Value {{ name }}(args[{{ jsArg }}]->ToString()); | ||
| 15 | + from_{{ name }} = ({{ cType }}) strdup(*{{ name }}); | ||
| 16 | + | ||
| 17 | + {% elsif cppClassName == 'Array' %} | ||
| 18 | + | ||
| 19 | + Array *tmp_{{ name }} = Array::Cast(*args[{{ jsArg }}]); | ||
| 20 | + from_{{ name }} = ({{ cType }})malloc(tmp_{{ name }}->Length() * sizeof({{ cType|replace '**' '*' }})); | ||
| 21 | + for (unsigned int i = 0; i < tmp_{{ name }}->Length(); i++) { | ||
| 22 | + | ||
| 23 | + {%-- FIXME: should recursively call convertFromv8. --%} | ||
| 23 | 24 | from_{{ name }}[i] = ObjectWrap::Unwrap<{{ arrayElementCppClassName }}>(tmp_{{ name }}->Get(NanNew<Number>(static_cast<double>(i)))->ToObject())->GetValue(); | |
| 24 | - } | ||
| 25 | - {%elsif cppClassName == 'Function'%} | ||
| 26 | - {%elsif cppClassName == 'Buffer'%} | ||
| 27 | - | ||
| 28 | - from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject()); | ||
| 29 | - {%elsif cppClassName|isV8Value %} | ||
| 30 | - | ||
| 31 | - {%if cType|isPointer %} | ||
| 32 | - *from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value(); | ||
| 33 | - {%else%} | ||
| 34 | - from_{{ name }} = ({{ cType }}) {{ cast }} {%if isEnum %}(int){%endif%} args[{{ jsArg }}]->To{{ cppClassName }}()->Value(); | ||
| 35 | - {%endif%} | ||
| 36 | - {%else%} | ||
| 37 | - {%if cType|isDoublePointer %} | ||
| 38 | - from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue(); | ||
| 39 | - {%else%} | ||
| 40 | - from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue(); | ||
| 41 | - {%endif%} | ||
| 42 | - {%endif%} | ||
| 43 | - | ||
| 44 | - {%if isOptional %} | ||
| 45 | - } | ||
| 46 | - else { | ||
| 47 | - from_{{ name }} = 0; | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - {%endif%} | ||
| 51 | - {%endif%} | ||
| 25 | + } | ||
| 26 | + {% elsif cppClassName == 'Function' %} | ||
| 27 | + | ||
| 28 | + {% elsif cppClassName == 'Buffer' %} | ||
| 29 | + | ||
| 30 | + from_{{ name }} = Buffer::Data(args[{{ jsArg }}]->ToObject()); | ||
| 31 | + | ||
| 32 | + {% elsif cppClassName|isV8Value %} | ||
| 33 | + {% if cType|isPointer %} | ||
| 34 | + *from_{{ name }} = ({{ cType|unPointer }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value(); | ||
| 35 | + {% else %} | ||
| 36 | + from_{{ name }} = ({{ cType }}) {{ cast }} {% if isEnum %}(int){% endif %} args[{{ jsArg }}]->To{{ cppClassName }}()->Value(); | ||
| 37 | + {% endif %} | ||
| 38 | + {% else %} | ||
| 39 | + {% if cType|isDoublePointer %} | ||
| 40 | + from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetRefValue(); | ||
| 41 | + {% else %} | ||
| 42 | + from_{{ name }} = ObjectWrap::Unwrap<{{ cppClassName }}>(args[{{ jsArg }}]->ToObject())->GetValue(); | ||
| 43 | + {% endif %} | ||
| 44 | + {% endif %} | ||
| 45 | + | ||
| 46 | + {% if isOptional %} | ||
| 47 | + } | ||
| 48 | + else { | ||
| 49 | + from_{{ name }} = 0; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + {% endif %} | ||
| 53 | + {% endif %} | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments