Changeset 28346

Show
Ignore:
Timestamp:
01/13/09 02:44:25 (4 years ago)
Author:
anekos
Message:

はてなスターに対応
表示を簡潔に

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/PMWriter.js

    r28337 r28346  
    55 * */ 
    66 
    7 liberator.plugins.pmwriter = {}; 
    8 let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; 
    9 let outputDir = liberator.globalVariables.pmwriter_output_dir; 
     7 
    108 
    119(function(){ 
     10  let pluginDirPath = liberator.globalVariables.pmwriter_plugin_dir; 
     11  let outputDir = liberator.globalVariables.pmwriter_output_dir; 
     12 
    1213  if (!(pluginDirPath && outputDir)) 
    1314    return; 
    1415 
    15   let U = liberator.plugins.libly.$U; 
    16  
    17   let myname = __context__.NAME; 
    18  
    19   let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); 
    20   let template = liberator.eval('template', liberator.plugins.pluginManager.list); 
    21  
    22   // makeLink を無理矢理修正 
    23   let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); 
    24   liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); 
    25   liberator.log(makeLink) 
    26   liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); 
    27  
    28   let linkTo; 
    29   let tags = { 
    30     __proto__: otags, 
    31     name: function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a> 
     16  let AUTHORS = { 
     17    Trapezoid:        'http://unsigned.g.hatena.ne.jp/Trapezoid/', 
     18    anekos:           'http://d.hatena.ne.jp/nokturnalmortum/', 
     19    "halt feits":     'http://project-p.jp/halt/', 
     20    hogelog:          'http://d.hatena.ne.jp/hogelog/', 
     21    janus_wel:        'http://d.hatena.ne.jp/janus_wel/', 
     22    mattn:            'http://mattn.kaoriya.net', 
     23    pekepeke:         'http://d.hatena.ne.jp/pekepekesamurai/', 
     24    pekepekesamurai:  'http://d.hatena.ne.jp/pekepekesamurai/', 
     25    suVene:           'http://d.zeromemory.info/', 
     26    teramako:         'http://d.hatena.ne.jp/teramako/', 
    3227  }; 
    3328 
    34   let ioService = services.get("io"); 
    35   let files = io.readDirectory(pluginDirPath); 
    36   let i = 0; 
    37   let xml = <></>; 
    38   let xml_index = <></>; 
    3929 
    40   files.forEach(function (file) { 
    41     if (!/\.js$/.test(file.path)) 
    42       return; 
    43     let src = io.readFile(file.path); 
    44     if (!/PLUGIN_INFO/.test(src)) 
    45       return; 
    46     //if (i++ > 0) return; 
     30  function action () { 
    4731 
    48     let uri = ioService.newFileURI(file); 
     32    liberator.plugins.pmwriter = {}; 
     33    let U = liberator.plugins.libly.$U; 
    4934 
    50     function Context (file) { 
    51       this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); 
     35    let myname = __context__.NAME; 
     36 
     37    let otags = liberator.eval('tags', liberator.plugins.pluginManager.list); 
     38    let template = liberator.eval('template', liberator.plugins.pluginManager.list); 
     39 
     40    // makeLink を無理矢理修正 
     41    let makeLink = liberator.eval('makeLink', liberator.plugins.pluginManager.list); 
     42    liberator.plugins.pmwriter.makeLink = function (str) makeLink(str, true); 
     43    liberator.log(makeLink) 
     44    liberator.eval('makeLink = liberator.plugins.pmwriter.makeLink ', liberator.plugins.pluginManager.list); 
     45 
     46    let linkTo; 
     47    let tags = { 
     48      __proto__: otags, 
     49      name: function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a> 
    5250    }; 
    53     let context = new Context(file); 
    54     let PLUGIN_INFO; 
    55     let detailFilename = context.NAME + '.html'; 
    56     linkTo = detailFilename; 
    5751 
    58     if (context.NAME == myname) 
    59       return; 
     52    let ioService = services.get("io"); 
     53    let files = io.readDirectory(pluginDirPath); 
     54    let i = 0; 
     55    let xml = <></>; 
     56    let xml_index = <></>; 
    6057 
    61     context.watch('PLUGIN_INFO', function (n,N,O) { PLUGIN_INFO = O; throw 'STOP';}); 
     58    files.forEach(function (file) { 
     59      if (!/\.js$/.test(file.path)) 
     60        return; 
     61      let src = io.readFile(file.path); 
     62      if (!/PLUGIN_INFO/.test(src)) 
     63        return; 
     64      //if (i++ > 0) return; 
    6265 
    63     try { services.get("subscriptLoader").loadSubScript(uri.spec, context); } catch (e) {} 
     66      let uri = ioService.newFileURI(file); 
    6467 
    65     let info = PLUGIN_INFO; 
    66     tags.name = function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>; 
     68      function Context (file) { 
     69        this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()); 
     70      }; 
     71      let context = new Context(file); 
     72      let PLUGIN_INFO; 
     73      let detailFilename = context.NAME + '.html'; 
    6774 
    68     let plugin = [ ]; 
    69     plugin['name'] = context.NAME; 
    70     plugin['info'] = {}; 
    71     plugin['orgInfo'] = {}; 
     75      if (context.NAME == myname) 
     76        return; 
    7277 
    73     for (let tag in tags){ 
    74       plugin.orgInfo[tag] = info[tag]; 
    75       let value = tags[tag](info); 
    76       if (value && value.toString().length > 0){ 
    77         plugin.push([tag, value]); 
    78         plugin.info[tag] = value; 
     78      context.watch('PLUGIN_INFO', function (n,N,O) { PLUGIN_INFO = O; throw 'STOP';}); 
     79 
     80      try { services.get("subscriptLoader").loadSubScript(uri.spec, context); } catch (e) {} 
     81 
     82      let info = PLUGIN_INFO; 
     83      tags.name = function () <a href={linkTo}>{otags.name.apply(otags, arguments)}</a>; 
     84 
     85      let plugin = [ ]; 
     86      plugin['name'] = context.NAME; 
     87      plugin['info'] = {}; 
     88      plugin['orgInfo'] = {}; 
     89 
     90      for (let tag in tags){ 
     91        plugin.orgInfo[tag] = info[tag]; 
     92        let value = tags[tag](info); 
     93        if (value && value.toString().length > 0){ 
     94          plugin.push([tag, value]); 
     95          plugin.info[tag] = value; 
     96        } 
    7997      } 
    80     } 
    8198 
    82     xml = template.table(plugin.name, plugin); 
    83     io.writeFile(io.getFile(outputDir + detailFilename), xml.toString()); 
     99      xml = template.table(plugin.name, plugin); 
     100      io.writeFile(io.getFile(outputDir + detailFilename), xml.toString()); 
    84101 
    85     let data = plugin.filter(function($_) /name|description|author/.test($_[0])); 
    86     xml_index += template.table(plugin.name, data); 
    87   }); 
     102      let link = 'http://vimperator.kurinton.net/' + detailFilename; 
     103      let alink = AUTHORS[info.author]; 
     104      let data = plugin.filter(function($_) /name|description|author/.test($_[0])); 
     105      xml_index += <tr class="plugin"> 
     106        <td class="name"><a href={link} class="link">{plugin.name}</a></td> 
     107        <td class="description">{plugin.info.description}</td> 
     108        <td class="author"><a href={alink}>{info.author}</a></td> 
     109      </tr> 
     110      //xml_index += template.table(plugin.name, data); 
     111    }); 
    88112 
    89   io.writeFile(io.getFile(outputDir + 'index.html'), xml_index.toString()); 
     113    let js = "" + 
     114""; 
     115    let style = "table {border: solid 1px black; empty-cells: show;}"; 
     116    let title = "Vimperator Plugins in CodeRepos"; 
     117 
     118    xml_index = <html> 
     119      <head> 
     120        <title>{title}</title> 
     121        <style><![CDATA[ 
     122          {style} 
     123        ]]></style> 
     124        <script type="text/javascript" src="http://s.hatena.ne.jp/js/HatenaStar.js"></script> 
     125        <script type="text/javascript"> 
     126        Hatena.Star.Token = '48e8f4c633307a76a4dd923111e22a25e80b6e8a'; 
     127        </script> 
     128        <script type="text/javascript"><![CDATA[ 
     129          Hatena.Star.SiteConfig = { 
     130            entryNodes: { 
     131              'tr': { 
     132                uri: "a.link", 
     133                title: 'td.name', 
     134                container: 'td.name' 
     135              } 
     136            } 
     137          }; 
     138        ]]></script> 
     139      </head> 
     140      <body> 
     141        <h1>{title}</h1> 
     142        <table> 
     143          <tr> 
     144            <td>Name</td> 
     145            <td>Description</td> 
     146            <td>Author</td> 
     147          </tr> 
     148          {xml_index} 
     149        </table> 
     150      </body> 
     151    </html>; 
     152 
     153    io.writeFile(io.getFile(outputDir + 'index.html'), xml_index.toString()); 
     154  } 
     155 
     156  commands.addUserCommand( 
     157    ['pmwrite'], 
     158    'PMWriter', 
     159    action, 
     160    {}, 
     161    true 
     162  ); 
    90163 
    91164})();