aboutsummaryrefslogtreecommitdiffstats
path: root/hatenaStar.js
diff options
context:
space:
mode:
authoranekos2011-07-12 23:19:09 +0900
committeranekos2011-07-12 23:19:09 +0900
commitfb403751e21240be7c1324651ce3601551ffac8f (patch)
tree2e30ff2d331b12ee489f5de80adf5ec1be31edeb /hatenaStar.js
parent07d54b5e841a37155e0b0847718af53e3f253a33 (diff)
downloadvimperator-plugins-fb403751e21240be7c1324651ce3601551ffac8f.tar.bz2
copyright 年を修正
Diffstat (limited to 'hatenaStar.js')
0 files changed, 0 insertions, 0 deletions
id='n113' href='#n113'>113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
/*
 * さわるなきけん!
 * DO NOT USE!
 * */



(function(){
  const U = liberator.plugins.libly.$U;

  let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir;
  let outputDir = liberator.globalVariables.pmwriter_output_dir;


  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)
        ({ '<': '&lt;', '>': '&gt;', '&': '&amp;' })[s] ||
        '<a href="' + s + '" highlight="URL">' + s + '</a>';
      try {
        return XMLList(str.replace(/(>|<|&|(?:https?:\/\/|mailto:)\S+)/g, replacer));
      } catch (e) {
        return XMLList(str);
      }
    };
  }

  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/';

    function Context (file) {
      this.NAME = file.leafName.replace(/\..*/, '')
                      .replace(/-([a-z])/g, function (m, n1) n1.toUpperCase());
    };

    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 () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>
    };

    let files = io.readDirectory(pluginDirPath);
    let indexHtml = <></>;
    let allHtml = <></>;

    files.forEach(function (file) {
      if (!/\.js$/.test(file.path))
        return;

      if (!/PLUGIN_INFO/.test(io.readFile(file.path)))
        return;

      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 () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>;

      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 href={hp}>{a.toString()}</a>
                       : <span>{a.toString()}</span>
          if (authors)
            authors += <span>, </span> + xml;
          else
            authors = xml;
        }
      }

      // プラグイン毎のドキュメント
      {
        let body = <div>
              <div class="information" id="information">
                <h1>{plugin.info.name.toString()}</h1>
                <div>
                  <dl>
                    <dt>Description</dt>
                    <dd>{plugin.info.description || '---'}</dd>
                    <dt>Latest version</dt>
                    <dd>{plugin.info.version || '???'}</dd>
                    <dt>Vimperator version</dt>
                    <dd>{(plugin.info.minVersion || '?') + ' - ' + (plugin.info.maxVersion || '?')}</dd>
                    <dt>URL</dt>
                    <dd><a href={CodeRepos + pluginFilename} class="coderepos" target="_blank">{CodeRepos + pluginFilename}</a></dd>
                    <dt>File URL</dt>
                    <dd>{plugin.info.updateURL || '--'}</dd>
                    <dt>Author</dt>
                    <dd>{authors}</dd>
                    <dt>License</dt>
                    <dd>{plugin.info.license || '--'}</dd>
                  </dl>
                </div>
              </div>
              <div class="detail" id="detail">{plugin.info.detail}</div>
              </div>;

        io.writeFile(
          io.getFile(outputDir + htmlFilename),
          <html>
            <head>
              <title>{plugin.info.name.toString()}</title>
              <link rel="stylesheet" href="plugin.css" type="text/css" />
              <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
            </head>
            <body>
              {body}
            </body>
          </html>.toString()
        );
        allHtml += body;
      }

      // index.html
      {
        indexHtml += <tr class="plugin">
          <td class="name">
            <a href={CodeRepos + pluginFilename} class="coderepos" target="_blank">{"\u2606"}</a>
            <a href={htmlFilename} class="link">{plugin.name}</a>
          </td>
          <td class="description">
            {plugin.info.description}
          </td>
          <td class="author">
            {authors}
          </td>
        </tr>
      }
    });

    indexHtml = <html>
      <head>
        <title>{DOCUMENT_TITLE}</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
        <link rel="stylesheet" href="voqn.css" type="text/css" />
        <script type="text/javascript" src="http://s.hatena.ne.jp/js/HatenaStar.js" />
        <script type="text/javascript">
          Hatena.Star.Token = '48e8f4c633307a76a4dd923111e22a25e80b6e8a';
        </script>
        <style><![CDATA[
          .hatena-star-comment-container {
            display: none;
            padding: 0;
            margin: 0;
          }
        ]]></style>
        <script type="text/javascript"><![CDATA[
          Hatena.Star.SiteConfig = {
            entryNodes: {
              'tr': {
                uri: 'a.coderepos',
                title: 'td.name',
                container: 'td.name'
              }
            }
          };
        ]]></script>
      </head>
      <body>
        <h1>{DOCUMENT_TITLE}</h1>
        <table>
          <tr class="header">
            <th class="name">Name</th>
            <th class="description">Description</th>
            <th class="author">Author</th>
          </tr>
          {indexHtml}
        </table>
        <div class="last-updated">Last updated {new Date().toLocaleFormat('%Y/%m/%d %H:%M:%S')}</div>
      </body>
    </html>;

    allHtml = <html>
            <head>
              <title>All Plugins</title>
              <link rel="stylesheet" href="plugin.css" type="text/css" />
              <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
            </head>
            <body>
              {allHtml}
            </body>
          </html>.toString();

    io.writeFile(io.getFile(outputDir + 'index.html'), indexHtml.toString());
    io.writeFile(io.getFile(outputDir + 'all.html'), allHtml.toString());
  }

  commands.addUserCommand(
    ['pmwrite'],
    'PMWriter',
    action,
    {},
    true
  );

})();
// vim: sw=2 ts=2 et fdm=marker: