diff --git a/README.md b/README.md index 4af247e..a2436ba 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,30 @@ Here are the names of the defaults: } ``` +## Extending and Creating Elements + +You can extend current elements or create new ones. + +```js +var Inky = require('inky').Inky; +var format = require('util').format; + +Inky.prototype.componentLibrary.box = function (element) { + var classes = ['container']; + if (element.attr('class')) { + classes = classes.concat(element.attr('class').split(' ')); + } + + return format('
%s
', classes.join(' '), element.html()); +}; + +var inky = new Inky({ + components: { + box: 'box' + } +}); +``` + ## Programmatic Use The Inky parser can be accessed directly for programmatic use. It takes in a [Cheerio](https://github.com/cheeriojs/cheerio) object of HTML, and gives you back a converted Cheerio object. diff --git a/lib/componentFactory.js b/lib/componentFactory.js index 0361e4d..2804f80 100644 --- a/lib/componentFactory.js +++ b/lib/componentFactory.js @@ -1,136 +1,28 @@ var format = require('util').format; var $ = require('cheerio'); +var getKeyByValue = function(obj, val) { + for (var key in obj) { + if (obj[key] === val) { + return key; + } + } + return false; +}; + /** * Returns output for desired custom element * @param {object} element - Element as a Cheerio object. * @returns {string} HTML converted from a custom element to table syntax. */ module.exports = function(element) { - var inner = element.html(); - - switch (element[0].name) { - // - case this.components.columns: - return this.makeColumn(element, 'columns'); - - // - case this.components.row: - var classes = ['row']; - if (element.attr('class')) { - classes = classes.concat(element.attr('class').split(' ')); - } - - return format('%s
', classes.join(' '), inner); - - //