This commit is contained in:
Suzanne Soy 2021-04-02 15:59:20 +01:00
parent 4d9f01eff8
commit dcc466e4af
2 changed files with 24 additions and 6 deletions

View File

@ -561,9 +561,10 @@ function ___level(s) {
function ___get_all_code() { function ___get_all_code() {
var all = ''; var all = '';
for (var i = 0; i < ___global_editors.length; i++) { for (var i = 0; i < ___global_editors.length; i++) {
all += ___global_editors[i].getValue(); var val = ___global_editors[i].getValue()
all += val + (val.endsWith('\n') ? '' : '\n') + (val.endsWith('\n\n') ? '' : '\n');
} }
return all; return all.substr(0, all.length-1/*remove last newline in the last \n\n*/);
} }
function ___copy_all_code() { function ___copy_all_code() {
var elem = document.getElementById('copy-all-code'); var elem = document.getElementById('copy-all-code');
@ -585,5 +586,18 @@ function ___level(s) {
} }
} }
___process_elements(); ___process_elements();
document.getElementById('loc-count').innerText = ___get_all_code().split('\n').filter(function (l) { return ! (/^(\s*}?)?$/.test(l)); }).length;
document.getElementById('loc-count-total').innerText = ___get_all_code().split('\n').length; function ___loc_count() {
var srclines = ___get_all_code().split('\n');
var lcv = srclines.filter(function (l) { return ! (/^(\s*}?)?$/.test(l)); }).length
var lc = document.getElementsByClassName('loc-count');
for (var i = 0; i < lc.length; i++) {
lc[i].innerText = lcv;
}
var lctv = srclines.length;
var lct = document.getElementsByClassName('loc-count-total');
for (var i = 0; i < lct.length; i++) {
lct[i].innerText = lctv;
}
}
___loc_count();

View File

@ -30,7 +30,10 @@
GIT is based on a simple model, with a lot of shorthands for common GIT is based on a simple model, with a lot of shorthands for common
use cases. This model is sometimes hard to guess just from the use cases. This model is sometimes hard to guess just from the
everyday commands. To illustrate how GIT works, we'll implement a everyday commands. To illustrate how GIT works, we'll implement a
stripped down clone of GIT in a few lines of JavaScript. stripped down clone of GIT in <span class="loc-count">a few</span> lines of
JavaScript.
<span style="font-size: small">*&nbsp;empty lines and single closing braces
excluded, <span class="loc-count-total">a few more</span> in total.</span>
</p> </p>
</section> </section>
@ -823,7 +826,8 @@ store_index(['README', 'src/main.scm']);
<section id="conclusion"> <section id="conclusion">
<h1>Conclusion</h1> <h1>Conclusion</h1>
<p>This article shows that a large part of the core of GIT can be re-implemented in <span id="loc-count">a few</span> source lines of code* (<a href="javascript:___copy_all_code(); void(0);">copy all the code</a>). <span style="font-size: small">*&nbsp;empty lines and single closing braces excluded, <span id="loc-count-total">a few more</span> in total.</span></p> <p>This article shows that a large part of the core of GIT can be re-implemented in <span class="loc-count">a few</span> source lines of code* (<a href="javascript:___copy_all_code(); void(0);">copy all the code</a>).
<span style="font-size: small">*&nbsp;empty lines and single closing braces excluded, <span class="loc-count-total">a few more</span> in total.</span></p>
<div id="copy-all-code" style="display: none;"></div> <div id="copy-all-code" style="display: none;"></div>
<ul> <ul>