/* * さわるなきけん! * DO NOT USE! * このコードを読むと失明する場合があります。 * * for 2.2 * */ (function(){ const U = liberator.plugins.libly.$U; let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; let pluginRootDirPath = io.File(pluginDirPath).parent.path; let outputDir = liberator.globalVariables.pmwriter_output_dir; const VERSIONS = '2.2 2.1 2.0 1.2'.split(/\s+/); if (!(pluginDirPath && outputDir)) return; if (!liberator.plugins.pmwriter) liberator.plugins.pmwriter = {}; // make を改造 { let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); if (!liberator.plugins.pmwriter.makeLink) { liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); } //let WikiParser = liberator.eval('WikiParser', liberator.plugins.pluginManager.list); //WikiParser.prototype.inlineParse = function (str) { // function replacer(_, s) // ({ '<': '<', '>': '>', '&': '&' })[s] || // '' + s + ''; // try { // return XMLList(str.replace(/(>|<|&|(?:https?:\/\/|mailto:)\S+)/g, replacer)); // } catch (e) { // return XMLList(str); // } //}; } let langselector =
; //''); function action () { const IOService = services.get('io'); const DOCUMENT_TITLE = 'Vimperator Plugins in CodeRepos'; const CodeRepos = 'http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/'; const CodeReposBranch = 'http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/branches/'; const CodeReposFile = 'http://github.com/vimpr/vimperator-plugins/blob/master/'; function Context (file) { this.NAME = file.leafName.replace(/\..*/, '') .replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); }; function fromUTF8Octets(octets){ return decodeURIComponent(octets.replace(/[%\x80-\xFF]/g, function(c){ return '%' + c.charCodeAt(0).toString(16); })); } function concatXML (xmls) { let result = <>; xmls.forEach(function (xml) result += xml); return result; } function langList (info, name) { let result = <>; let i = info.length(); while (i-- > 0) { if (info[i].@lang.toString()) { result += <{name} lang={info[i].@lang.toString()}>{fromUTF8Octets(info[i].toString())}; } else { result += <{name}>{fromUTF8Octets(info[i].toString())}; } } return result; } function chooseByLang(info, lang) { let result; let i = info.length(); while (i-- > 0) { let it = info[i]; if (!it.@lang) result = it; if (it.@lang.toString() == lang) { result = it; break; } } return result; } function allLang (tag, info, utf, f) { if (!f) f = function (v) v; let ff = utf ? function (v) fromUTF8Octets(f(v).toString()) : f if (!tag) tag = 'div'; let result = <>; for (let i = 0, l = info.length(); i < l; i++) { let it = info[i]; result += <{tag} class={'lang-hide '+(i==0?"lang-default ":'')+(i==l-1?'lang-ja ':'')+"lang-"+(it.@lang.toString()||'default')}>{ff(it)}; } return result; } let myname = __context__.NAME; let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); let template = liberator.eval('template', liberator.plugins.pluginManager.list); let linkTo; let tags = { __proto__: otags, name: function () {otags.name.apply(otags, arguments)} }; let files = io.File(pluginDirPath).readDirectory(); let indexHtml = <>; let allHtml = <>; let pminfos = []; files.forEach(function (file) { if (!/\.js$/.test(file.path)) return; if (!/PLUGIN_INFO/.test(io.File(file.path).read())) return; try { let context = new Context(file); let pluginName = file.leafName.replace(/\..*$/, ''); let pluginFilename = file.leafName; if (context.NAME == myname) return; let pluginInfo; let htmlFilename = pluginName + '.html'; context.watch('PLUGIN_INFO', function (n, O, N) { pluginInfo = N; throw 'STOP';}); try { services.get("subscriptLoader").loadSubScript(IOService.newFileURI(file).spec, context); } catch (e) { /* DO NOTHING */ } tags.name = function () {otags.name.apply(otags, arguments)}; let plugin = []; let (info = pluginInfo) { plugin['name'] = pluginName; 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; } } } let authors; { for each (let a in pluginInfo.author) { let hp = a.@homepage.toString(); let xml = hp ? {a.toString()} : {a.toString()} if (authors) authors += , + xml; else authors = xml; } } // infoXML { pminfos.push( {langList(pluginInfo.name, 'name')} {langList(pluginInfo.description, 'description')} {langList(pluginInfo.version, 'version')} {CodeReposFile + pluginFilename} ); } // プラグイン毎のドキュメント { //let src = pluginInfo.detail.toString(); let detailBody = allLang('div', pluginInfo.detail, false, function (v) liberator.plugins.PMWikiParser.parse(fromUTF8Octets(v.toString()))); //let detailBody = plugin.info.detail let title = allLang('span', pluginInfo.name, true, function (it) (it.toString() || '---')) let description = allLang('span', pluginInfo.description, true, function (it) (it.toString()) || '---') let versionsBody = <>; VERSIONS.forEach(function (ver) { let url = CodeReposBranch + ver + '/' + pluginFilename; let file = io.File(pluginRootDirPath); file.append('branches'); file.append(ver); file.append(pluginFilename); versionsBody += <>
{'for ' + ver}
{file.exists() ? {url} : <>not supported} ; }); versionsBody += <>
{'for Nightly'}
{CodeRepos + pluginFilename} ; //
Vimperator version
//
{(plugin.info.minVersion || '?') + ' - ' + (plugin.info.maxVersion || '?')}
//
URL
//
{CodeRepos + pluginFilename}
//
File URL
//
{CodeReposFile + pluginFilename}
let body =
{langselector}

{title}

Description
{description}
Latest version
{plugin.info.version || '???'}
Author
{authors}
License
{allLang('span', pluginInfo.license, true, function (v) (v || '--'))}

{versionsBody}
{detailBody}
; io.File(outputDir + htmlFilename).write( {pluginFilename} {body} back to index .toString() ); allHtml += body; // index.html indexHtml += {"\u2606"} {plugin.name} {description} {authors} } } catch (e) { liberator.log({filename: file.path}) liberator.log(e.stack) liberator.log(e) } }); indexHtml = {DOCUMENT_TITLE} {langselector}

{DOCUMENT_TITLE}

{indexHtml}
Name Description Author
Last updated {new Date().toLocaleFormat('%Y/%m/%d %H:%M:%S')}
; allHtml = All Plugins {allHtml} .toString(); io.File(outputDir + 'index.html').write(indexHtml.toString()); io.File(outputDir + 'all.html').write(allHtml.toString()); let infoXML = {concatXML(pminfos)}; io.File(outputDir + 'info.xml').write(infoXML.toString()); } commands.addUserCommand( ['pmwrite'], 'PMWriter', action, {}, true ); })(); // vim: sw=2 ts=2 et fdm=marker: