From 351798b51fd3ca260ef38672c1b98fa42521ee75 Mon Sep 17 00:00:00 2001 From: Rob O'Leary <3703647+robole@users.noreply.github.com> Date: Mon, 16 Oct 2023 03:38:00 +0200 Subject: [PATCH] Create model and view folders --- .eslintrc.json | 13 +++++- src/environment.js | 4 +- src/extension.js | 6 +-- .../collection.js} | 4 +- .../extension-collection.js} | 4 +- src/{ => model}/snippet.js | 2 +- src/snippets-fetcher.js | 6 +-- src/util.js | 1 - src/{css => view}/styles.css | 0 src/view/table-of-contents.js | 44 +++++++++++++++++++ src/{ => view}/view.js | 14 +++--- test/suite/snippet.test.js | 2 +- test/view-contrast.html | 2 +- test/view-dark.html | 2 +- test/view-light.html | 2 +- todo.md | 1 + 16 files changed, 80 insertions(+), 27 deletions(-) rename src/{snippets-collection.js => model/collection.js} (77%) rename src/{extension-snippets-collection.js => model/extension-collection.js} (89%) rename src/{ => model}/snippet.js (93%) rename src/{css => view}/styles.css (100%) create mode 100644 src/view/table-of-contents.js rename src/{ => view}/view.js (94%) diff --git a/.eslintrc.json b/.eslintrc.json index 33927da..ffb9ed2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,14 @@ { - "extends": ["eslint-config-node-roboleary"] + "extends": ["eslint-config-node-roboleary"], + "env": { + "mocha": true + }, + "settings": { + "import/core-modules": [ "vscode" ] + }, + "rules": { + "node/no-missing-require": ["error", { + "allowModules": [ "vscode"] + }] + } } diff --git a/src/environment.js b/src/environment.js index 7f63418..748f840 100644 --- a/src/environment.js +++ b/src/environment.js @@ -3,7 +3,7 @@ const fs = require("fs"); // eslint-disable-next-line import/no-unresolved const vscode = require("vscode"); const glob = require("glob"); -const ExtensionSnippets = require("./extension-snippets-collection"); +const ExtensionCollection = require("./model/extension-collection"); /** * Environment information. @@ -136,7 +136,7 @@ class Environment { packageJSON.contributes && packageJSON.contributes.snippets ) { - let extensionSnippets = new ExtensionSnippets( + let extensionSnippets = new ExtensionCollection( packageJSON.name, packageJSON.displayName, packageJSON.publisher diff --git a/src/extension.js b/src/extension.js index 5e1e1ac..37dcecb 100644 --- a/src/extension.js +++ b/src/extension.js @@ -1,12 +1,12 @@ // @ts-nocheck /* eslint-disable import/no-unresolved, import/no-useless-path-segments, no-template-curly-in-string, no-unused-vars */ const vscode = require("vscode"); -const View = require("./view"); -const Snippet = require("./snippet"); +const View = require("./view/view"); +const Snippet = require("./model/snippet"); const SnippetsEditor = require("./snippets-editor"); // this is included for webpack, so that it picks up the CSS file -const styles = require("../src/css/styles.css"); +const styles = require("../src/view/styles.css"); function activate(context) { context.subscriptions.push( diff --git a/src/snippets-collection.js b/src/model/collection.js similarity index 77% rename from src/snippets-collection.js rename to src/model/collection.js index 570506e..22aaa5f 100644 --- a/src/snippets-collection.js +++ b/src/model/collection.js @@ -1,7 +1,7 @@ /** * Snippets for a particular programming language. */ -class SnippetsCollection { +class Collection { constructor(path, type, scoped, snippets, language = "" ) { this.path = path; this.type = type; @@ -11,4 +11,4 @@ class SnippetsCollection { } } -module.exports = SnippetsCollection; +module.exports = Collection; diff --git a/src/extension-snippets-collection.js b/src/model/extension-collection.js similarity index 89% rename from src/extension-snippets-collection.js rename to src/model/extension-collection.js index bb2de48..e73a828 100644 --- a/src/extension-snippets-collection.js +++ b/src/model/extension-collection.js @@ -2,7 +2,7 @@ * Snippets for a particular extension. An Extension can have snippets declared in * different files. One snippet file can be associated with 1 or more languages. */ -class ExtensionSnippetsCollection { +class ExtensionCollection { constructor(name, displayName, publisher) { this.name = name; this.displayName = displayName; @@ -33,4 +33,4 @@ class ExtensionSnippetsCollection { } } -module.exports = ExtensionSnippetsCollection; +module.exports = ExtensionCollection; diff --git a/src/snippet.js b/src/model/snippet.js similarity index 93% rename from src/snippet.js rename to src/model/snippet.js index 38639d1..5d8ba3f 100644 --- a/src/snippet.js +++ b/src/model/snippet.js @@ -1,5 +1,5 @@ /* eslint-disable no-underscore-dangle */ -const formatter = require("./formatter"); +const formatter = require("../formatter"); /** * VS Code Snippet. diff --git a/src/snippets-fetcher.js b/src/snippets-fetcher.js index 2613d0a..c124916 100644 --- a/src/snippets-fetcher.js +++ b/src/snippets-fetcher.js @@ -1,8 +1,8 @@ const fs = require("fs"); const jsonc = require("jsonc-parser"); const Environment = require("./environment"); -const SnippetsCollection = require("./snippets-collection"); -const Snippet = require("./snippet"); +const Collection = require("./model/collection"); +const Snippet = require("./model/snippet"); /** * Fetch the Snippets from the file system. @@ -29,7 +29,7 @@ class SnippetsFetcher { let language = Environment.getFilename(filepaths[index]); let scoped = hasScopeField(flatSnippets); - let snippetsCollection = new SnippetsCollection( + let snippetsCollection = new Collection( filepaths[index], type, scoped, diff --git a/src/util.js b/src/util.js index 817f173..47950ed 100644 --- a/src/util.js +++ b/src/util.js @@ -1,4 +1,3 @@ -// eslint-disable-next-line import/no-unresolved const vscode = require("vscode"); const fs = require("fs"); diff --git a/src/css/styles.css b/src/view/styles.css similarity index 100% rename from src/css/styles.css rename to src/view/styles.css diff --git a/src/view/table-of-contents.js b/src/view/table-of-contents.js new file mode 100644 index 0000000..4fc939c --- /dev/null +++ b/src/view/table-of-contents.js @@ -0,0 +1,44 @@ +/** + * A HTML Table of Contents created from data. + */ +class TableOfContents { + constructor(data) { + this.data = data; + } + + /** + * Get the Table of Contents as HTML. + */ + getTableOfContents() { + let html = `
+

Table of Contents

+
`; + return html; + } + + /** + * Get the Table of Contents entry for Extension snippets as HTML. + */ + createTableOfContentsEntry(array) { + let html = ""; + + return html; + } +} + +module.exports = TableOfContents; diff --git a/src/view.js b/src/view/view.js similarity index 94% rename from src/view.js rename to src/view/view.js index 084c591..98abf7e 100644 --- a/src/view.js +++ b/src/view/view.js @@ -1,13 +1,11 @@ -/* eslint-disable class-methods-use-this */ -// @ts-nocheck -// eslint-disable-next-line import/no-unresolved const vscode = require("vscode"); const { basename } = require("path"); const path = require("path"); -const SnippetsFetcher = require("./snippets-fetcher"); -const Formatter = require("./formatter"); -const Window = require("./window"); -const SnippetsEditor = require("./snippets-editor"); +const SnippetsFetcher = require("../snippets-fetcher"); +const Formatter = require("../formatter"); +const Window = require("../window"); +const SnippetsEditor = require("../snippets-editor"); +const Collection = require("../model/collection"); const notFoundHTML = `

Oucho Gaucho! 🌵 Nothing to round up! 🤠

`; @@ -137,7 +135,7 @@ class View { /** * Creates the HTML output for the section for a snippets set associated with a language. * It has a title and a table listing all of the snippets. - * @param {LanguageSnippets} languageSnippets The LanguageSnippets you want the section for + * @param {Collection} languageSnippets The collection you want the section for * @param {String} type The type of snippets. Values can be "user" or "app". */ createLanguageSection(languageSnippets, type) { diff --git a/test/suite/snippet.test.js b/test/suite/snippet.test.js index c5892e6..46475ba 100644 --- a/test/suite/snippet.test.js +++ b/test/suite/snippet.test.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const Snippet = require("../../src/snippet"); +const Snippet = require("../../src/model/snippet"); describe("Snippet", () => { it("should create an empty object if no arguments given to constructor", () => { diff --git a/test/view-contrast.html b/test/view-contrast.html index d00a00d..da8aeaa 100644 --- a/test/view-contrast.html +++ b/test/view-contrast.html @@ -460,7 +460,7 @@ " > - + - + - +