From dcc466e4afca9d4270b18766fb4f7751c507acf5 Mon Sep 17 00:00:00 2001
From: Suzanne Soy
Date: Fri, 2 Apr 2021 15:59:20 +0100
Subject: [PATCH] Cleanup
---
git-tutorial.js | 22 ++++++++++++++++++----
index.html | 8 ++++++--
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/git-tutorial.js b/git-tutorial.js
index 91cefd9..5a0ad6e 100644
--- a/git-tutorial.js
+++ b/git-tutorial.js
@@ -561,9 +561,10 @@ function ___level(s) {
function ___get_all_code() {
var all = '';
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() {
var elem = document.getElementById('copy-all-code');
@@ -585,5 +586,18 @@ function ___level(s) {
}
}
___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;
\ No newline at end of file
+
+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();
\ No newline at end of file
diff --git a/index.html b/index.html
index 77e128f..e233aeb 100644
--- a/index.html
+++ b/index.html
@@ -30,7 +30,10 @@
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
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 a few lines of
+JavaScript.
+* empty lines and single closing braces
+excluded, a few more in total.
@@ -823,7 +826,8 @@ store_index(['README', 'src/main.scm']);
Conclusion
-This article shows that a large part of the core of GIT can be re-implemented in a few source lines of code* (copy all the code). * empty lines and single closing braces excluded, a few more in total.
+This article shows that a large part of the core of GIT can be re-implemented in a few source lines of code* (copy all the code).
+ * empty lines and single closing braces excluded, a few more in total.