Docs: Write documentation for #import/export JSON/SVG, for both Item and Project.

This commit is contained in:
Jürg Lehni 2013-06-27 18:03:49 -07:00
parent e63edba0b5
commit 41746d2d25
4 changed files with 86 additions and 45 deletions

View file

@ -1443,6 +1443,49 @@ var Item = Base.extend(Callback, /** @lends Item# */{
}
},
/**
* {@grouptitle Import / Export to JSON & SVG}
*
* Exports (serializes) the item with its content and child items to a JSON
* data string.
*
* @name Item#exportJSON
* @function
* @param {Object} [options={ precision: 5 }] the serialization options
* @return {String} the exported JSON data
*/
/**
* Imports (deserializes) the stored JSON data into this item's
* {@link Item#children} list. Note that the item is not cleared first.
* You can call {@link Item#removeChildren()} to do so.
*
* @param {String} json the JSON data to import from.
*/
importJSON: function(json) {
return this.addChild(Base.importJSON(json));
},
/**
* Exports the item with its content and child items as an SVG DOM.
*
* @name Item#exportSVG
* @function
* @param {Boolean} [asString=false] wether to convert the SVG node directly
* to a string
* @return {SVGSVGElement} the item converted to an SVG node
*/
/**
* Converts the SVG node and all its child nodes into Paper.js items and
* adds them as children to the this item.
*
* @name Item#importSVG
* @function
* @param {SVGSVGElement} node the SVG node to import
* @return {Item} the imported Paper.js parent item
*/
/**
* {@grouptitle Hierarchy Operations}
* Adds the specified item as a child of this item at the end of the
@ -2376,14 +2419,6 @@ var Item = Base.extend(Callback, /** @lends Item# */{
this.setBounds(newBounds);
},
// DOCS: document exportJSON (documented in @private Base)
// DOCS: document importJSON
// DOCS: Figure out a way to group these together with importSVG / exportSVG
importJSON: function(json) {
return this.addChild(Base.importJSON(json));
},
/**
* {@grouptitle Event Handlers}
* Item level handler function to be called on each frame of an animation.

View file

@ -263,15 +263,51 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
return null;
},
// DOCS: document exportJSON (documented in @private Base)
// DOCS: document importJSON
// DOCS: Figure out a way to group these together with importSVG / exportSVG
/**
* {@grouptitle Import / Export to JSON & SVG}
*
* Exports (serializes) the project with all its layers and child items to
* a JSON data string.
*
* @name Project#exportJSON
* @function
* @param {Object} [options={ precision: 5 }] the serialization options
* @return {String} the exported JSON data
*/
/**
* Imports (deserializes) the stored JSON data into the project. Note that
* the project is not cleared first. You can call {@link Project#clear()} to
* do so.
*
* @param {String} json the JSON data to import from.
*/
importJSON: function(json) {
this.activate();
return Base.importJSON(json);
},
/**
* Exports the project with all its layers and child items as an SVG DOM,
* all contained in one top level SVG group node.
*
* @name Project#exportSVG
* @function
* @param {Boolean} [asString=false] wether to convert the SVG node directly
* to a string
* @return {SVGSVGElement} the project converted to an SVG node
*/
/**
* Converts the SVG node and all its child nodes into Paper.js items and
* adds them to the active layer of this project.
*
* @name Project#importSVG
* @function
* @param {SVGSVGElement} node the SVG node to import
* @return {Item} the imported Paper.js parent item
*/
/**
* {@grouptitle Project Hierarchy}
*

View file

@ -500,29 +500,13 @@ new function() {
return node && applyStyle(item, node);
}
Item.inject(/** @lends Item# */{
/**
* {@grouptitle SVG Conversion}
*
* Exports the item and all its children as an SVG DOM, all contained
* in one top level SVG node.
*
* @return {SVGSVGElement} the item converted to an SVG node
*/
Item.inject({
exportSVG: function(asString) {
return exportDefinitions(exportSVG(this), asString);
}
});
Project.inject(/** @lends Project# */{
/**
* {@grouptitle SVG Conversion}
*
* Exports the project and all its layers and child items as an SVG DOM,
* all contained in one top level SVG group node.
*
* @return {SVGSVGElement} the project converted to an SVG node
*/
Project.inject({
exportSVG: function(asString) {
var layers = this.layers,
size = this.view.getSize(),

View file

@ -498,27 +498,13 @@ new function() {
return item;
}
Item.inject(/** @lends Item# */{
/**
* Converts the passed node node into a Paper.js item and adds it to the
* children of this item.
*
* @param {SVGSVGElement} node the SVG DOM node to convert
* @return {Item} the converted Paper.js item
*/
Item.inject({
importSVG: function(node) {
return this.addChild(importSVG(node, true));
}
});
Project.inject(/** @lends Project# */{
/**
* Converts the passed node node into a Paper.js item and adds it to the
* active layer of this project.
*
* @param {SVGSVGElement} node the SVG DOM node to convert
* @return {Item} the converted Paper.js item
*/
Project.inject({
importSVG: function(node) {
this.activate();
return importSVG(node, true);