diff options
author | anekos | 2009-01-12 17:44:25 +0000 |
---|---|---|
committer | anekos | 2009-01-12 17:44:25 +0000 |
commit | 627b30dc502aa277e53e93962e91f8f770ac335b (patch) | |
tree | 413b9c1e0064ba93f7ab4b71c64b2d46df593215 /PMWriter.js | |
parent | 06f1822c89ff09d6b117b00f675878b51bc7c6e4 (diff) | |
download | vimperator-plugins-627b30dc502aa277e53e93962e91f8f770ac335b.tar.bz2 |
はてなスターに対応
表示を簡潔に
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@28346 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'PMWriter.js')
-rw-r--r-- | PMWriter.js | 207 |
1 files changed, 140 insertions, 67 deletions
diff --git a/PMWriter.js b/PMWriter.js index 66855a2..132cb8f 100644 --- a/PMWriter.js +++ b/PMWriter.js @@ -4,89 +4,162 @@ * DO NOT USE! * */ -liberator.plugins.pmwriter = {}; -let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; -let outputDir = liberator.globalVariables.pmwriter_output_dir; + (function(){ + let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; + let outputDir = liberator.globalVariables.pmwriter_output_dir; + if (!(pluginDirPath && outputDir)) return; - let U = liberator.plugins.libly.$U; - - let myname = __context__.NAME; - - let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); - let template = liberator.eval('template', liberator.plugins.pluginManager.list); - - // makeLink を無理矢理修正 - let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); - liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); - liberator.log(makeLink) - liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); - - let linkTo; - let tags = { - __proto__: otags, - name: function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a> + let AUTHORS = { + Trapezoid: 'http://unsigned.g.hatena.ne.jp/Trapezoid/', + anekos: 'http://d.hatena.ne.jp/nokturnalmortum/', + "halt feits": 'http://project-p.jp/halt/', + hogelog: 'http://d.hatena.ne.jp/hogelog/', + janus_wel: 'http://d.hatena.ne.jp/janus_wel/', + mattn: 'http://mattn.kaoriya.net', + pekepeke: 'http://d.hatena.ne.jp/pekepekesamurai/', + pekepekesamurai: 'http://d.hatena.ne.jp/pekepekesamurai/', + suVene: 'http://d.zeromemory.info/', + teramako: 'http://d.hatena.ne.jp/teramako/', }; - let ioService = services.get("io"); - let files = io.readDirectory(pluginDirPath); - let i = 0; - let xml = <></>; - let xml_index = <></>; - files.forEach(function (file) { - if (!/\.js$/.test(file.path)) - return; - let src = io.readFile(file.path); - if (!/PLUGIN_INFO/.test(src)) - return; - //if (i++ > 0) return; + function action () { - let uri = ioService.newFileURI(file); + liberator.plugins.pmwriter = {}; + let U = liberator.plugins.libly.$U; - function Context (file) { - this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); - }; - let context = new Context(file); - let PLUGIN_INFO; - let detailFilename = context.NAME + '.html'; - linkTo = detailFilename; - - if (context.NAME == myname) - return; - - context.watch('PLUGIN_INFO', function (n,N,O) { PLUGIN_INFO = O; throw 'STOP';}); + let myname = __context__.NAME; - try { services.get("subscriptLoader").loadSubScript(uri.spec, context); } catch (e) {} + let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); + let template = liberator.eval('template', liberator.plugins.pluginManager.list); - let info = PLUGIN_INFO; - tags.name = function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>; + // makeLink を無理矢理修正 + let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); + liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); + liberator.log(makeLink) + liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); - let plugin = [ ]; - plugin['name'] = context.NAME; - plugin['info'] = {}; - plugin['orgInfo'] = {}; + let linkTo; + let tags = { + __proto__: otags, + name: function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a> + }; - for (let tag in tags){ - plugin.orgInfo[tag] = info[tag]; - let value = tags[tag](info); - if (value && value.toString().length > 0){ - plugin.push([tag, value]); - plugin.info[tag] = value; + let ioService = services.get("io"); + let files = io.readDirectory(pluginDirPath); + let i = 0; + let xml = <></>; + let xml_index = <></>; + + files.forEach(function (file) { + if (!/\.js$/.test(file.path)) + return; + let src = io.readFile(file.path); + if (!/PLUGIN_INFO/.test(src)) + return; + //if (i++ > 0) return; + + let uri = ioService.newFileURI(file); + + function Context (file) { + this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); + }; + let context = new Context(file); + let PLUGIN_INFO; + let detailFilename = context.NAME + '.html'; + + if (context.NAME == myname) + return; + + context.watch('PLUGIN_INFO', function (n,N,O) { PLUGIN_INFO = O; throw 'STOP';}); + + try { services.get("subscriptLoader").loadSubScript(uri.spec, context); } catch (e) {} + + let info = PLUGIN_INFO; + tags.name = function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>; + + let plugin = [ ]; + plugin['name'] = context.NAME; + plugin['info'] = {}; + plugin['orgInfo'] = {}; + + for (let tag in tags){ + plugin.orgInfo[tag] = info[tag]; + let value = tags[tag](info); + if (value && value.toString().length > 0){ + plugin.push([tag, value]); + plugin.info[tag] = value; + } } - } - - xml = template.table(plugin.name, plugin); - io.writeFile(io.getFile(outputDir + detailFilename), xml.toString()); - - let data = plugin.filter(function($_) /name|description|author/.test($_[0])); - xml_index += template.table(plugin.name, data); - }); - io.writeFile(io.getFile(outputDir + 'index.html'), xml_index.toString()); + xml = template.table(plugin.name, plugin); + io.writeFile(io.getFile(outputDir + detailFilename), xml.toString()); + + let link = 'http://vimperator.kurinton.net/' + detailFilename; + let alink = AUTHORS[info.author]; + let data = plugin.filter(function($_) /name|description|author/.test($_[0])); + xml_index += <tr class="plugin"> + <td class="name"><a href={link} class="link">{plugin.name}</a></td> + <td class="description">{plugin.info.description}</td> + <td class="author"><a href={alink}>{info.author}</a></td> + </tr> + //xml_index += template.table(plugin.name, data); + }); + + let js = "" + +""; + let style = "table {border: solid 1px black; empty-cells: show;}"; + let title = "Vimperator Plugins in CodeRepos"; + + xml_index = <html> + <head> + <title>{title}</title> + <style><![CDATA[ + {style} + ]]></style> + <script type="text/javascript" src="http://s.hatena.ne.jp/js/HatenaStar.js"></script> + <script type="text/javascript"> + Hatena.Star.Token = '48e8f4c633307a76a4dd923111e22a25e80b6e8a'; + </script> + <script type="text/javascript"><![CDATA[ + Hatena.Star.SiteConfig = { + entryNodes: { + 'tr': { + uri: "a.link", + title: 'td.name', + container: 'td.name' + } + } + }; + ]]></script> + </head> + <body> + <h1>{title}</h1> + <table> + <tr> + <td>Name</td> + <td>Description</td> + <td>Author</td> + </tr> + {xml_index} + </table> + </body> + </html>; + + io.writeFile(io.getFile(outputDir + 'index.html'), xml_index.toString()); + } + + commands.addUserCommand( + ['pmwrite'], + 'PMWriter', + action, + {}, + true + ); })(); // vim: sw=2 ts=2 et fdm=marker: |