From a4a76397625f478a689a8e33df24bd65de193f7d Mon Sep 17 00:00:00 2001
From: Lars Trieloff <trieloff@adobe.com>
Date: Mon, 23 Apr 2018 07:17:31 +0000
Subject: [PATCH] change readme template from imperative to functional

---
 .gitignore                       |  1 +
 examples/docs/README.md          |  1 +
 spec/examples/README.md          |  1 +
 spec/lib/integrationTest.spec.js | 66 +++++++++++++++++---------------
 templates/md/readme.ejs          |  7 ++--
 5 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/.gitignore b/.gitignore
index 48d1406..cd34b53 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,3 +28,4 @@ npm-debug.log
 
 # instanbul code coverage
 coverage
+/examples/tmp-docs
diff --git a/examples/docs/README.md b/examples/docs/README.md
index 896a8a1..68536b7 100644
--- a/examples/docs/README.md
+++ b/examples/docs/README.md
@@ -25,3 +25,4 @@
 ## /subdir/
 
 * [Subdir](./subdir/subdir.schema.md) – `https://example.com/schemas/subdir/subdir`
+
diff --git a/spec/examples/README.md b/spec/examples/README.md
index 896a8a1..68536b7 100644
--- a/spec/examples/README.md
+++ b/spec/examples/README.md
@@ -25,3 +25,4 @@
 ## /subdir/
 
 * [Subdir](./subdir/subdir.schema.md) – `https://example.com/schemas/subdir/subdir`
+
diff --git a/spec/lib/integrationTest.spec.js b/spec/lib/integrationTest.spec.js
index 76afa36..e9952f8 100644
--- a/spec/lib/integrationTest.spec.js
+++ b/spec/lib/integrationTest.spec.js
@@ -11,50 +11,28 @@ beforeEach(function() {
 });
 
 describe('Compare results', () => {
-  it('Run jsonschema2md on example schemas', done => {
+
+  it('Run jsonschema2md for custom file extension', done => {
     const ls = spawn('node', [
       'cli.js',
       '-d',
       'examples/schemas',
       '-o',
-      'examples/docs',
+      'examples/tmp-docs',
       '-x',
       'examples/generated-schemas',
-      '-m',
-      'template=reference',
-      '-m',
-      'foo=bar',
-      '--link-abstract',
-      'abstract.md',
-      '--link-status',
-      'status.md'
+      '-e',
+      'js'
     ]);
 
     ls.on('close', code => {
       expect(code).toEqual(0);
-
-      const files = readdirSync('./spec/examples');
-
-      files.forEach(file => {
-        if (statSync('./spec/examples/' + file).isFile()) {
-          it('Comparing ' + file, indone => {
-            console.log('file ' + file);
-            readFile('./spec/examples/' + file, (err, expectedbuf) => {
-              expect(err).toBeNull();
-              readFile('./examples/docs/' + file, (err, actualbuf) => {
-                expect(err).toBeNull();
-                expect(actualbuf.toString()).toEqual(expectedbuf.toString());
-                indone();
-              });
-            });
-          });
-        }
-      });
       done();
     });
   });
 
-  it('Run jsonschema2md for custom file extension', done => {
+
+  it('Run jsonschema2md on example schemas', done => {
     const ls = spawn('node', [
       'cli.js',
       '-d',
@@ -63,13 +41,39 @@ describe('Compare results', () => {
       'examples/docs',
       '-x',
       'examples/generated-schemas',
-      '-e',
-      'js'
+      '-m',
+      'template=reference',
+      '-m',
+      'foo=bar',
+      '--link-abstract',
+      'abstract.md',
+      '--link-status',
+      'status.md'
     ]);
 
     ls.on('close', code => {
       expect(code).toEqual(0);
+
+      const files = readdirSync('./spec/examples');
+      expect(files.length).toEqual(17);
       done();
     });
   });
+
+  const files = readdirSync('./spec/examples');
+  files.forEach(file => {
+    if (statSync('./spec/examples/' + file).isFile()) {
+      it('Comparing ' + file, indone => {
+        console.log('file ' + file);
+        readFile('./spec/examples/' + file, (err, expectedbuf) => {
+          expect(err).toBeNull();
+          readFile('./examples/docs/' + file, (err, actualbuf) => {
+            expect(err).toBeNull();
+            expect(actualbuf.toString()).toEqual(expectedbuf.toString());
+            indone();
+          });
+        });
+      });
+    }
+  });
 });
diff --git a/templates/md/readme.ejs b/templates/md/readme.ejs
index 7fc4096..bb22497 100644
--- a/templates/md/readme.ejs
+++ b/templates/md/readme.ejs
@@ -7,8 +7,9 @@
 
  # Readme
 
-<% for(group in groups) {%>
 
+<% _.forIn(groups, (schemas, group) => { %>
 ## <%= group %>
-<% for(let i=0; i<groups[group].length; i++) { %>
-* [<%= groups[group][i].title %>](.<%= groups[group][i].relative %>.schema.md) – `<%= groups[group][i].id %>`<% }} %>
+<% _.forEach(schemas, schema => { %>
+* [<%= schema.title %>](.<%= schema.relative %>.schema.md) – `<%= schema.id %>`<% }); %>
+<% }); %>
-- 
GitLab