summaryrefslogtreecommitdiffstats
path: root/lib/backbone/glossary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-04-22 11:00:21 +0200
committerSamy Pessé <samypesse@gmail.com>2016-04-22 11:00:21 +0200
commit4336fdb2414d460ffee68a0cc87c0cb0c85cf56e (patch)
tree279f711ab98666c892c19a7b9e4073a094f03f98 /lib/backbone/glossary.js
parent87db7cf1d412fa6fbd18e9a7e4f4755f2c0c5547 (diff)
downloadgitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.zip
gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.gz
gitbook-4336fdb2414d460ffee68a0cc87c0cb0c85cf56e.tar.bz2
Base
Diffstat (limited to 'lib/backbone/glossary.js')
-rw-r--r--lib/backbone/glossary.js99
1 files changed, 0 insertions, 99 deletions
diff --git a/lib/backbone/glossary.js b/lib/backbone/glossary.js
deleted file mode 100644
index cc0fdce..0000000
--- a/lib/backbone/glossary.js
+++ /dev/null
@@ -1,99 +0,0 @@
-var _ = require('lodash');
-var util = require('util');
-var BackboneFile = require('./file');
-
-// Normalize a glossary entry name into a unique id
-function nameToId(name) {
- return name.toLowerCase()
- .replace(/[\/\\\?\%\*\:\;\|\"\'\\<\\>\#\$\(\)\!\.\@]/g, '')
- .replace(/ /g, '_')
- .trim();
-}
-
-
-/*
-A glossary entry is represented by a name and a short description
-An unique id for the entry is generated using its name
-*/
-function GlossaryEntry(name, description) {
- if (!(this instanceof GlossaryEntry)) return new GlossaryEntry(name, description);
-
- this.name = name;
- this.description = description;
-
- Object.defineProperty(this, 'id', {
- get: _.bind(this.getId, this)
- });
-}
-
-// Normalizes a glossary entry's name to create an ID
-GlossaryEntry.prototype.getId = function() {
- return nameToId(this.name);
-};
-
-
-/*
-A glossary is a list of entries stored in a GLOSSARY.md file
-*/
-function Glossary() {
- BackboneFile.apply(this, arguments);
-
- this.entries = [];
-}
-util.inherits(Glossary, BackboneFile);
-
-Glossary.prototype.type = 'glossary';
-
-// Get templating context
-Glossary.prototype.getContext = function() {
- if (!this.path) return {};
-
- return {
- glossary: {
- path: this.path
- }
- };
-};
-
-// Parse the readme content
-Glossary.prototype.parse = function(content) {
- var that = this;
-
- return this.parser.glossary(content)
- .then(function(entries) {
- that.entries = _.map(entries, function(entry) {
- return new GlossaryEntry(entry.name, entry.description);
- });
- });
-};
-
-// Return an entry by its id
-Glossary.prototype.get = function(id) {
- return _.find(this.entries, {
- id: id
- });
-};
-
-// Find an entry by its name
-Glossary.prototype.find = function(name) {
- return this.get(nameToId(name));
-};
-
-// Return false if glossary has entries (and exists)
-Glossary.prototype.isEmpty = function(id) {
- return _.size(this.entries) === 0;
-};
-
-// Convert the glossary to a list of annotations
-Glossary.prototype.annotations = function() {
- return _.map(this.entries, function(entry) {
- return {
- id: entry.id,
- name: entry.name,
- description: entry.description,
- href: '/' + this.path + '#' + entry.id
- };
- }, this);
-};
-
-module.exports = Glossary;