Skip to content

Commit 351798b

Browse files
committed
Create model and view folders
1 parent 9b71c37 commit 351798b

16 files changed

+80
-27
lines changed

.eslintrc.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
{
2-
"extends": ["eslint-config-node-roboleary"]
2+
"extends": ["eslint-config-node-roboleary"],
3+
"env": {
4+
"mocha": true
5+
},
6+
"settings": {
7+
"import/core-modules": [ "vscode" ]
8+
},
9+
"rules": {
10+
"node/no-missing-require": ["error", {
11+
"allowModules": [ "vscode"]
12+
}]
13+
}
314
}

src/environment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require("fs");
33
// eslint-disable-next-line import/no-unresolved
44
const vscode = require("vscode");
55
const glob = require("glob");
6-
const ExtensionSnippets = require("./extension-snippets-collection");
6+
const ExtensionCollection = require("./model/extension-collection");
77

88
/**
99
* Environment information.
@@ -136,7 +136,7 @@ class Environment {
136136
packageJSON.contributes &&
137137
packageJSON.contributes.snippets
138138
) {
139-
let extensionSnippets = new ExtensionSnippets(
139+
let extensionSnippets = new ExtensionCollection(
140140
packageJSON.name,
141141
packageJSON.displayName,
142142
packageJSON.publisher

src/extension.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @ts-nocheck
22
/* eslint-disable import/no-unresolved, import/no-useless-path-segments, no-template-curly-in-string, no-unused-vars */
33
const vscode = require("vscode");
4-
const View = require("./view");
5-
const Snippet = require("./snippet");
4+
const View = require("./view/view");
5+
const Snippet = require("./model/snippet");
66
const SnippetsEditor = require("./snippets-editor");
77

88
// this is included for webpack, so that it picks up the CSS file
9-
const styles = require("../src/css/styles.css");
9+
const styles = require("../src/view/styles.css");
1010

1111
function activate(context) {
1212
context.subscriptions.push(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Snippets for a particular programming language.
33
*/
4-
class SnippetsCollection {
4+
class Collection {
55
constructor(path, type, scoped, snippets, language = "" ) {
66
this.path = path;
77
this.type = type;
@@ -11,4 +11,4 @@ class SnippetsCollection {
1111
}
1212
}
1313

14-
module.exports = SnippetsCollection;
14+
module.exports = Collection;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Snippets for a particular extension. An Extension can have snippets declared in
33
* different files. One snippet file can be associated with 1 or more languages.
44
*/
5-
class ExtensionSnippetsCollection {
5+
class ExtensionCollection {
66
constructor(name, displayName, publisher) {
77
this.name = name;
88
this.displayName = displayName;
@@ -33,4 +33,4 @@ class ExtensionSnippetsCollection {
3333
}
3434
}
3535

36-
module.exports = ExtensionSnippetsCollection;
36+
module.exports = ExtensionCollection;

src/snippet.js renamed to src/model/snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-underscore-dangle */
2-
const formatter = require("./formatter");
2+
const formatter = require("../formatter");
33

44
/**
55
* VS Code Snippet.

src/snippets-fetcher.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const fs = require("fs");
22
const jsonc = require("jsonc-parser");
33
const Environment = require("./environment");
4-
const SnippetsCollection = require("./snippets-collection");
5-
const Snippet = require("./snippet");
4+
const Collection = require("./model/collection");
5+
const Snippet = require("./model/snippet");
66

77
/**
88
* Fetch the Snippets from the file system.
@@ -29,7 +29,7 @@ class SnippetsFetcher {
2929
let language = Environment.getFilename(filepaths[index]);
3030
let scoped = hasScopeField(flatSnippets);
3131

32-
let snippetsCollection = new SnippetsCollection(
32+
let snippetsCollection = new Collection(
3333
filepaths[index],
3434
type,
3535
scoped,

src/util.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// eslint-disable-next-line import/no-unresolved
21
const vscode = require("vscode");
32
const fs = require("fs");
43

File renamed without changes.

src/view/table-of-contents.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* A HTML Table of Contents created from data.
3+
*/
4+
class TableOfContents {
5+
constructor(data) {
6+
this.data = data;
7+
}
8+
9+
/**
10+
* Get the Table of Contents as HTML.
11+
*/
12+
getTableOfContents() {
13+
let html = `<div id="toc">
14+
<h2>Table of Contents</h2>
15+
<ul>
16+
<li><a href="#project">Project Snippets</a></li>`;
17+
html += this.createTableOfContentsEntry(this.projectIDs);
18+
html += `<li><a href="#user">User Snippets</a></li>`;
19+
html += this.createTableOfContentsEntry(this.userIDs);
20+
html += `<li><a href="#extension">Extension Snippets</a></li>`;
21+
html += this.createTableOfContentsEntry(this.extensionIDs);
22+
html += `<li><a href="#app">VS Code Snippets</a></li>`;
23+
html += this.createTableOfContentsEntry(this.appIDs);
24+
html += `</ul></div>`;
25+
return html;
26+
}
27+
28+
/**
29+
* Get the Table of Contents entry for Extension snippets as HTML.
30+
*/
31+
createTableOfContentsEntry(array) {
32+
let html = "<ul>";
33+
34+
array.forEach((obj) => {
35+
html += `<li><a href=#${obj.id}>${obj.name}</a>`;
36+
});
37+
38+
html += "</ul>";
39+
40+
return html;
41+
}
42+
}
43+
44+
module.exports = TableOfContents;

0 commit comments

Comments
 (0)