@codesnippets/codesnippets
Version:
Open source code snippets and examples.
45 lines (39 loc) • 1.16 kB
text/typescript
import fs = require('fs');
import path = require('path');
import { Snippet } from './snippet';
export class Language {
/**
* Creates a new Language instance.
* @param name name of the language.
* @param shortName short name of the language, used for syntax highlighting
* @param files a list of files to use.
*/
public constructor(public readonly name: string, private obj: any) {}
/**
* Searches for a Snippet.
* @param name the name of the snippet to search for
* @returns the snippet or undefined if no snippet was found.
*/
public getSnippet(name: string): Snippet {
if (this.obj[name]) {
return new Snippet(name, this, this.obj[name]);
}
/*
for (let file of this.files) {
let filename = path.basename(file).split('.');
if (filename[0] == name)
return new Snippet(file, filename[0]);
}*/
}
/**
* Returns a list of snippet names.
* @returns list of names
*/
public getSnippets(): string[] {
let snippetNames = [];
for (let file of Object.keys(this.obj)) {
snippetNames.push(path.basename(file).split('.')[0]);
}
return snippetNames;
}
}