Changeset 29369

Show
Ignore:
Timestamp:
02/01/09 05:42:29 (4 years ago)
Author:
anekos
Message:

複数のソースを指定できるようにした。
HEAD で正しく補完されるように修正。
PLUGIN_INFO 追加。

Files:
1 modified

Legend:

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

    r25706 r29369  
    1 // ==VimperatorPlugin== 
    2 // @name           Kawase 
    3 // @description-ja 外国為替換算 
    4 // @license        Creative Commons 2.1 (Attribution + Share Alike) 
    5 // @version        1.0 
    6 // @author         anekos (anekos@snca.net) 
    7 // ==/VimperatorPlugin== 
    8 // 
    9 // Usage-ja: 
    10 //  引数書式 
    11 //    :kawase[!] <金額> [<ソース> [<ターゲット>]] 
    12 //  ソースをターゲットに換算します。 
    13 //  "!" 指定でクリップボードにコピーされます。 
    14 // 
    15 // Exsample: 
    16 //    :kawase 30000 JPY THB 
     1/* {{{ 
     2Copyright (c) 2008, anekos. 
     3All rights reserved. 
     4 
     5Redistribution and use in source and binary forms, with or without modification, 
     6are permitted provided that the following conditions are met: 
     7 
     8    1. Redistributions of source code must retain the above copyright notice, 
     9       this list of conditions and the following disclaimer. 
     10    2. Redistributions in binary form must reproduce the above copyright notice, 
     11       this list of conditions and the following disclaimer in the documentation 
     12       and/or other materials provided with the distribution. 
     13    3. The names of the authors may not be used to endorse or promote products 
     14       derived from this software without specific prior written permission. 
     15 
     16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
     17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
     18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
     19IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
     20INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
     21BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     22DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
     23LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
     24OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
     25THE POSSIBILITY OF SUCH DAMAGE. 
     26 
     27 
     28################################################################################### 
     29# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license       # 
     30# に参考になる日本語訳がありますが、有効なのは上記英文となります。                # 
     31################################################################################### 
     32 
     33}}} */ 
     34 
     35// PLUGIN_INFO {{{ 
     36let PLUGIN_INFO = 
     37<VimperatorPlugin> 
     38  <name>Exchange Converter</name> 
     39  <name lang="ja">外国為替換算</name> 
     40  <description>for exchangeconvertion</description> 
     41  <description lang="ja">為替換算をします</description> 
     42  <version>1.1</version> 
     43  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> 
     44  <license>new BSD License (Please read the source code comments of this plugin)</license> 
     45  <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license> 
     46  <minVersion>2.0pre</minVersion> 
     47  <maxVersion>2.0pre</maxVersion> 
     48  <detail><![CDATA[ 
     49    == Usage == 
     50      :kawase[!] <VALUE> [<SOURCE> [<TARGET>]]: 
     51      :kawase[!] <VALUE> <SOURCE1> <SOURCE2> ... <TARGET>: 
     52        Convert <SOURCE> to <TARGET>. 
     53        When used with "!", copy result to clipboard. 
     54    === Example === 
     55       :kawase 30000 JPY THB 
     56    == Global Variables == 
     57      - g:umihara_default_source 
     58      - g:umihara_default_target 
     59      === Example === 
     60      >|| 
     61        let g:umihara_default_source="USD" 
     62        let g:umihara_default_target="JPY" 
     63      ||< 
     64  ]]></detail> 
     65  <detail lang="ja"><![CDATA[ 
     66    == Usage == 
     67      :kawase[!] <金額> [<ソース> [<ターゲット>]]: 
     68      :kawase[!] <金額> <ソース1> <ソース2> ... <ターゲット>: 
     69        ソースをターゲットに換算します。 
     70        "!" 指定でクリップボードにコピーされます。 
     71      === Example === 
     72        >|| 
     73          :kawase 30000 JPY THB 
     74        ||< 
     75    == Global Variables == 
     76      引数省略時のデフォルト値を設定します 
     77      - g:umihara_default_source 
     78      - g:umihara_default_target 
     79      === Example === 
     80        >|| 
     81          let g:umihara_default_source="USD" 
     82          let g:umihara_default_target="JPY" 
     83        ||< 
     84  ]]></detail> 
     85</VimperatorPlugin>; 
     86// }}} 
    1787 
    1888(function () { 
     
    65135  ]; 
    66136 
     137  function echo (msg) { 
     138    liberator.echo(<pre>{msg}</pre>); 
     139  } 
     140 
     141  let resultBuffer = ''; 
     142 
    67143  function kawase (value, clipboard, from, to) { 
    68144    [from, to] = [from || defaultSource, to || defaultTarget].map(function (it) it.toUpperCase()); 
     145    if (from == '-') 
     146      from = defaultSource; 
     147    if (to == '-') 
     148      to = defaultTarget; 
    69149    let url = 'http://quote.yahoo.co.jp/m5?a=' + value + '&s=' + from + '&t=' + to; 
    70150    var req = new XMLHttpRequest(); 
     
    79159                     '\n rate: ' + m[2] + 
    80160                     '\n time: ' + m[1]; 
    81           liberator.echo(text); 
    82           if (clipboard) 
    83             liberator.modules.util.copyToClipboard(text); 
     161          echo(text); 
     162          if (clipboard) { 
     163            resultBuffer += text + '\n'; 
     164            util.copyToClipboard(resultBuffer); 
     165          } 
    84166        } else { 
    85           //liberator.open(url); 
    86167          liberator.echoerr('parse error'); 
    87168        } 
     
    95176    bang: true, 
    96177    completer: function (context, args) { 
    97       let last = context.contextList.slice(-1)[0]; 
    98       context.title = ['Country Code', 'Country Name']; 
    99       context.advance(last.offset - last.caret); 
    100       context.completions = ContryCodes; 
     178      if (args.length == 1) { 
     179        // TODO - history 
     180      } else { 
     181        let  def = args.length < 3 ? defaultSource 
     182                                   : defaultTarget; 
     183        context.title = ['Country Code', 'Country Name']; 
     184        context.completions = [['-', def]].concat(ContryCodes); 
     185      } 
    101186    } 
    102187  }; 
    103188 
    104   //commands.removeUserCommand('kawase'); 
    105189  commands.addUserCommand( 
    106190    ['kawase'], 
    107191    'Umihara Kawase Meow', 
    108192    function (args) { 
    109       let [value, from, to] = args; 
    110       value = eval(value); 
    111       kawase(value, args.bang, from, to); 
     193      let as = args; 
     194      resultBuffer = ''; 
     195      liberator.echo('<<Results>>\n') 
     196      for (let i = 1, l = args.length - 1; i < l; i++) { 
     197        let [value, from, to] = [as[0], as[i], l == i ? '-' : as[l]]; 
     198        value = eval(value); 
     199        kawase(value, args.bang, from, to); 
     200      } 
    112201    }, 
    113202    extra, 
     
    116205 
    117206})(); 
     207 
     208 
     209// vim:sw=2 ts=2 et si fdm=marker: