Skip to content

Commit

Permalink
Merge pull request #134 from withanage/master
Browse files Browse the repository at this point in the history
Added  NLM JATS disp-quote support
  • Loading branch information
Michael Aufreiter committed Oct 8, 2015
2 parents b95caa7 + 0a21ce3 commit 2d0313b
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
/node_modules/
*.sublime-*
dist/*
dist/*
.idea/*
3 changes: 2 additions & 1 deletion article/nodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ module.exports = {
"list": require("./list"),
"codeblock": require("./codeblock"),
"affiliation": require("./_affiliation"),
"footnote": require("./footnote")
"footnote": require("./footnote"),
"quote": require("./quote")
};
6 changes: 6 additions & 0 deletions article/nodes/quote/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

module.exports = {
Model: require('./quote'),
View: require('./quote_view')
};
23 changes: 23 additions & 0 deletions article/nodes/quote/quote.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

.content-node.quote > .content {
padding: 20px;
}

.document .content-node.quote .content-node.paragraph {
padding: 10px 40px 10px 40px;
border-left: 3px solid #ccc;
}

.surface.content .content-node.quote {

}

.surface.content .content-node.quote > .content {

}


.surface.content .content-node.quote > .content > .label {
font-weight: 600;
padding-bottom: 20px;
}
67 changes: 67 additions & 0 deletions article/nodes/quote/quote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"use strict";

var Document = require('../../../substance/document');
var Composite = Document.Composite;

// Lens.Quote
// -----------------
//

var Quote = function(node, doc) {
Composite.call(this, node, doc);
};

// Type definition
// -----------------
//

Quote.type = {
"id": "quote",
"parent": "content",
"properties": {
"source_id": "string",
"label": "string",
"children": ["array", "paragraph"]
}
};

// This is used for the auto-generated docs
// -----------------
//

Quote.description = {
"name": "Quote",
"remarks": ["A quote type."],
"properties": {
"label": "string",
"children": "0..n Paragraph nodes"
}
};


// Example Quote
// -----------------
//

Quote.example = {
"id": "quote_1",
"type": "quote",
"label": "Quote 1",
"children": ["paragraph_1", "paragraph_2"]
};

Quote.Prototype = function() {

this.getChildrenIds = function() {
return this.properties.children;
};

};

Quote.Prototype.prototype = Composite.prototype;
Quote.prototype = new Quote.Prototype();
Quote.prototype.constructor = Quote;

Document.Node.defineProperties(Quote);

module.exports = Quote;
35 changes: 35 additions & 0 deletions article/nodes/quote/quote_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

var NodeView = require('../node').View;
var CompositeView = require("../composite").View;
var $$ = require("../../../substance/application").$$;

// Lens.Quote.View
// ==========================================================================

var QuoteView = function(node, viewFactory) {
CompositeView.call(this, node, viewFactory);
};

QuoteView.Prototype = function() {

this.render = function() {
NodeView.prototype.render.call(this);

if (this.node.label) {
var labelEl = $$('.label', {
text: this.node.label
});
this.content.appendChild(labelEl);
}

this.renderChildren();
this.el.appendChild(this.content);
return this;
};
};

QuoteView.Prototype.prototype = CompositeView.prototype;
QuoteView.prototype = new QuoteView.Prototype();

module.exports = QuoteView;
23 changes: 20 additions & 3 deletions converter/lens_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ NlmToLensConverter.Prototype = function() {
return this.boxedText(state, child);
};
this._bodyNodes["disp-quote"] = function(state, child) {
return this.boxedText(state, child);
return this.quoteText(state, child);
};
this._bodyNodes["attrib"] = function(state, child) {
return this.paragraphGroup(state, child);
Expand Down Expand Up @@ -1269,7 +1269,23 @@ NlmToLensConverter.Prototype = function() {
return boxNode;
};

this.datasets = function(state, datasets) {
this.quoteText = function (state, quote) {
var doc = state.doc;
// Assuming that there are no nested <disp-quote> elements
var childNodes = this.bodyNodes(state, util.dom.getChildren(quote));
var quoteId = state.nextId("quote");
var quoteNode = {
"type": "quote",
"id": quoteId,
"source_id": quote.getAttribute("id"),
"label": "",
"children": _.pluck(childNodes, 'id')
};
doc.create(quoteNode);
return quoteNode;
};

this.datasets = function(state, datasets) {
var nodes = [];

for (var i=0;i<datasets.length;i++) {
Expand Down Expand Up @@ -1402,7 +1418,8 @@ NlmToLensConverter.Prototype = function() {

this.acceptedParagraphElements = {
"boxed-text": {handler: "boxedText"},
"list": { handler: "list" },
"disp-quote": {handler: "quoteText"},
"list": { handler: "list" },
"disp-formula": { handler: "formula" },
};

Expand Down

0 comments on commit 2d0313b

Please sign in to comment.