Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Copy code from Instadoc/instadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrovich committed May 22, 2017
1 parent 3adb1f1 commit 577957b
Show file tree
Hide file tree
Showing 27 changed files with 2,295 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
.DS_STORE
npm-debug.log
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 6
before_script:
- npm install -g gulp
3 changes: 2 additions & 1 deletion README.md
@@ -1,2 +1,3 @@
# livingstyleguides
livingstyleguides   [![Build Status](https://travis-ci.org/Instadoc/livingstyleguides.svg?branch=master)](https://travis-ci.org/Instadoc/livingstyleguides)
=================
Documentation extractor for living style guides
7 changes: 7 additions & 0 deletions gulpfile.js
@@ -0,0 +1,7 @@
var gulp = require('gulp');
var mocha = require('gulp-mocha');

gulp.task('test', function () {
return gulp.src('test/**/*test.js', { read: false })
.pipe(mocha({ reporter: 'spec' }));
});
4 changes: 4 additions & 0 deletions index.js
@@ -0,0 +1,4 @@
var rfr = require('rfr');
var Parser = rfr('src/parser');

module.exports = new Parser();
36 changes: 36 additions & 0 deletions package.json
@@ -0,0 +1,36 @@
{
"name": "livingstyleguides",
"version": "0.0.0",
"description": "Documentation extractor for living style guides",
"keywords": [
"livingstyleguide",
"living style guide",
"style guide",
"component library",
"design pattern"
],
"main": "index.js",
"scripts": {
"test": "gulp test"
},
"homepage": "https://github.com/Instadoc/livingstyleguides",
"repository": "https://github.com/Instadoc/livingstyleguides.git",
"bugs": {
"url": "https://github.com/Instadoc/livingstyleguides/issues"
},
"author": "Mike Petrovich <michael.c.petrovich@gmail.com>",
"license": "MIT",
"bundleDependencies": [
"rfr"
],
"dependencies": {
"gray-matter": "^2.1.1",
"lodash": "^4.17.2",
"rfr": "^1.2.3"
},
"devDependencies": {
"chai": "^1.10.0",
"gulp": "^3.8.10",
"gulp-mocha": "^2.0.0"
}
}
175 changes: 175 additions & 0 deletions src/doc.js
@@ -0,0 +1,175 @@
var _ = require('lodash');

/**
* @constructs
*/
function Doc() {}

/* ---------------------------------------------------------------------
* Public
* --------------------------------------------------------------------- */

/**
* @static
* @param {Array} docs
* @return {Array}
*/
Doc.merge = function(docs) {
var docsGroupedByName = _.groupBy(docs, 'name');

var docsMerged = _.map(docsGroupedByName, function(docsToMerge) {
var docMerged = new Doc();

_.forEach(docsToMerge, function(doc) {
docMerged.import(doc);
});

return docMerged;
});

return docsMerged;
};

/**
* @return {String}
*/
Doc.prototype.getName = function() {
return this.name;
};

/**
* @param {String} name
*/
Doc.prototype.setName = function(name) {
this.name = name;
};

/**
* @return {String}
*/
Doc.prototype.getCategory = function() {
return this.category;
};

/**
* @param {String} category
*/
Doc.prototype.setCategory = function(category) {
this.category = category;
};

/**
* @return {String}
*/
Doc.prototype.getDescription = function() {
return this.description;
};

/**
* @param {String} description
*/
Doc.prototype.setDescription = function(description) {
this.description = description;
};

/**
* @return {Object}
*/
Doc.prototype.getExamples = function() {
return this.examples || {};
};

/**
* @param {String} name
* @param {Array.<Object>} codeBlocks
* @param {String} codeBlocks[i].syntax
* @param {String} codeBlocks[i].code
* @param {Boolean} [codeBlocks[i].hidden]
* @param {Object} [options]
* @param {Number} [options.height]
*/
Doc.prototype.addExample = function(name, codeBlocks, options) {
this.examples = this.examples || {};
this.examples[name] = {
codeBlocks: codeBlocks,
options: options || {},
};
};

/**
* @return {Object} Set of key-value pairs
*/
Doc.prototype.getMeta = function() {
return this.meta || {};
};

/**
* @param {String} key
* @param {*} value
*/
Doc.prototype.addMeta = function(key, value) {
this.meta = this.meta || {};

if (this.meta[key]) {
this.meta[key].push(value);
}
else {
this.meta[key] = [value];
}
};

/**
* @return {String}
*/
Doc.prototype.getSource = function() {
return this.source;
};

/**
* @param {String} source
*/
Doc.prototype.setSource = function(source) {
this.source = source;
};

/**
* @return {String}
*/
Doc.prototype.getFilepath = function() {
return this.filepath;
};

/**
* @param {String} filepath
*/
Doc.prototype.setFilepath = function(filepath) {
this.filepath = filepath;
};

/**
* @param {Doc} doc
*/
Doc.prototype.import = function(doc) {
var self = this;

this.name = doc.name;
this.category = doc.category || this.category;
this.source = doc.source || this.source;
this.filepath = doc.filepath || this.filepath;

if (doc.description) {
var description = this.description ? this.description + '\n\n' : '';
this.description = description + doc.description;
}

_.each(doc.getExamples(), function(example, name) {
self.addExample(name, example.codeBlocks, example.options);
});
_.each(doc.getMeta(), function(meta, key) {
_.each(meta, function(value) {
self.addMeta(key, value);
});
});
};

module.exports = Doc;

0 comments on commit 577957b

Please sign in to comment.