Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a001966
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2014 azu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Created by azu on 2014/01/18. | ||
* LICENSE : MIT | ||
*/ | ||
var xml = require("xml"); | ||
function createOutlines(outlines) { | ||
var outlines = outlines.map(function (outline) { | ||
var oneLine = Object.keys(outline).map(function (key) { | ||
var object = {}; | ||
object[key] = outline[key]; | ||
return object; | ||
}); | ||
return { | ||
"outline": oneLine | ||
}; | ||
}); | ||
return xml({ | ||
"outline": outlines | ||
}); | ||
} | ||
function createHeader(header) { | ||
var headerObject = Object.keys(header).map(function (key) { | ||
var object = {}; | ||
var value = header[key]; | ||
if (key === "date" && value instanceof Date) { | ||
object[key] = value.toUTCString(); | ||
} else { | ||
object[key] = value; | ||
} | ||
return object; | ||
}); | ||
return xml({ | ||
"head": headerObject | ||
}); | ||
} | ||
/** | ||
* | ||
* @param header | ||
* @param outlines | ||
*/ | ||
module.exports = function (header, outlines) { | ||
var headerXML = createHeader(header); | ||
var outlinesXML = createOutlines(outlines); | ||
return headerXML + outlinesXML; | ||
}; | ||
module.exports.createHeader = createHeader; | ||
module.exports.createOutlines = createOutlines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "opml-generator", | ||
"version": "1.0.0", | ||
"description": "opml generator for node.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/azu/opml-generator.git" | ||
}, | ||
"keywords": [ | ||
"opml", | ||
"rss", | ||
"feeds" | ||
], | ||
"author": "azu", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/azu/opml-generator/issues" | ||
}, | ||
"homepage": "https://github.com/azu/opml-generator", | ||
"dependencies": { | ||
"power-assert": "~0.3.1", | ||
"mocha": "~1.17.0", | ||
"xml": "0.0.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Created by azu on 2014/01/18. | ||
* LICENSE : MIT | ||
*/ | ||
var assert = require("power-assert"); | ||
var opml = require("../opml-generator"); | ||
describe("opml", function () { | ||
describe("module", function () { | ||
it("should concat header + outlines", function () { | ||
var header = { | ||
"title": "title-text", | ||
"date": new Date(2014, 2, 9), | ||
"ownerName": "azu" | ||
}; | ||
var headerXML = opml.createHeader(header); | ||
var outlines = [ | ||
{ | ||
text: "txt", | ||
title: "title-text", | ||
type: "rss", | ||
"xmlUrl": "http://example.com/rss", | ||
"htmlUrl": "http://example.com/" | ||
}, | ||
{ | ||
text: "txt", | ||
title: "title-text", | ||
type: "rss", | ||
"xmlUrl": "http://example.com/rss", | ||
"htmlUrl": "http://example.com/" | ||
} | ||
]; | ||
var outlinesXML = opml.createOutlines(outlines); | ||
assert.strictEqual(opml(header, outlines), headerXML + outlinesXML); | ||
}); | ||
}); | ||
describe("header", function () { | ||
it("should create <head /> string", function () { | ||
var results = opml.createHeader({ | ||
"title": "title-text", | ||
"date": new Date(2014, 2, 9), | ||
"ownerName": "azu" | ||
}); | ||
assert.strictEqual(results, '<head><title>title-text</title><date>Sat, 08 Mar 2014 15:00:00 GMT</date><ownerName>azu</ownerName></head>') | ||
}); | ||
}); | ||
describe("outline", function () { | ||
it("should create <outline /> string", function () { | ||
var results = opml.createOutlines([ | ||
{ | ||
text: "txt", | ||
title: "title-text", | ||
type: "rss", | ||
"xmlUrl": "http://example.com/rss", | ||
"htmlUrl": "http://example.com/" | ||
}, | ||
{ | ||
text: "txt", | ||
title: "title-text", | ||
type: "rss", | ||
"xmlUrl": "http://example.com/rss", | ||
"htmlUrl": "http://example.com/" | ||
} | ||
]); | ||
assert.strictEqual(results, '<outline>' + | ||
'<outline><text>txt</text><title>title-text</title><type>rss</type><xmlUrl>http://example.com/rss</xmlUrl><htmlUrl>http://example.com/</htmlUrl></outline>' + | ||
'<outline><text>txt</text><title>title-text</title><type>rss</type><xmlUrl>http://example.com/rss</xmlUrl><htmlUrl>http://example.com/</htmlUrl></outline>' + | ||
'</outline>') | ||
}); | ||
}); | ||
}); |