Changes between Version 2 and Version 3 of WikiMacros
- Timestamp:
- Dec 31, 2005, 4:43:10 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WikiMacros
v2 v3 1 = Wiki マクロ=2 Wiki マクロとは、Python で書かれた 'カスタム関数' によって Trac の Wiki エンジンを拡張するプラグインです。 WikiFormatting エンジンがサポートするあらゆるコンテクストにおいて、マクロを使用することによって、動的なHTMLデータが挿入されます。 1 = Wiki Macros = 2 Trac macros are plugins to extend the Trac engine with custom 'functions' written in Python. A macro inserts dynamic HTML data in any context supporting WikiFormatting. 3 3 4 もう1種類のマクロは WikiProcessors です。これは通常、Wiki以外のマークアップ形式と表示を取り扱うために使用し、多くは、(ソースコードハイライトのような)より大きいブロックに使用します。参考: WikiProcessors 4 Another kind of macros are WikiProcessors. They typically deal with alternate markup formats and representation of larger blocks of information (like source code highlighting). 5 5 6 == マクロの利用==7 マクロ呼び出しは、二つの ''角括弧 (square brackets) '' で括られた箇所です。Python関数のように、マクロは引数を取ることができ、括弧 (parenthesis) の中に、カンマで区切ったリストで表記します。 6 == Using Macros == 7 Macro calls are enclosed in two ''square brackets''. Like python functions, macros can also have arguments, a comma separated list within parentheses. 8 8 9 === 利用例===9 === Examples === 10 10 11 11 {{{ 12 12 [[Timestamp]] 13 13 }}} 14 は、以下のように表示されます:14 Display: 15 15 [[Timestamp]] 16 16 … … 18 18 [[HelloWorld(Testing)]] 19 19 }}} 20 は、以下のように表示されます:20 Display: 21 21 [[HelloWorld(Testing)]] 22 22 23 == Available Macros == 23 24 24 == 利用可能なマクロ == 25 マクロは現在のところ新機能の扱いです。利用可能な (そして配布対象となっている) マクロの一覧は、まだそれほど充実していません。 26 今後の Trac のリリースででは、役に立つマクロライブラリの構築を考えています。マクロを寄贈してもらえるのであれば、喜んで配布に含めます (詳しくは下をご覧下さい) 。 25 ''Note that the following list will only contain the macro documentation if you've not enabled `-OO` optimizations, or not set the `PythonOptimize` option for [wiki:TracModPython mod_python].'' 27 26 28 * '''HelloWorld''' -- マクロの例。これからマクロを書きたいときに参考になります。 29 * '''Timestamp''' -- 現在の日時を挿入する。 30 31 32 ---- 33 27 [[MacroList]] 34 28 35 29 == Macros from around the world == 36 30 The [http://projects.edgewall.com/trac/ Trac Project] has a section dedicated to user-contributed macros, [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar]. If you're looking for new macros, or have written new ones to share with the world, don't hesitate adding it to the [http://projects.edgewall.com/trac/wiki/MacroBazaar MacroBazaar] wiki page. 37 31 38 http://projects.edgewall.com/trac/wiki/MacroBazaar39 40 41 32 ---- 42 33 34 == Developing Custom Macros == 35 Macros, like Trac itself, are written in the [http://www.python.org/ Python programming language]. They are very simple modules, identified by the filename and should contain a single ''entry point'' function. Trac will display the returned data inserted into the HTML where the macro was called. 43 36 44 == 新しいマクロを開発する == 45 マクロは、 Trac 自身と同じように [http://www.python.org/ Python programming language] で書かれています。とてもシンプルなモジュールで、たった一つの ''インタフェース (entry point) '' 関数だけを持ちます。マクロの識別はファイル名で行います。Trac は、呼び出されたマクロが返却したデータをHTMLに挿入して表示を行います。 46 47 最も簡単なマクロの例です: 37 It's easiest to learn from an example: 48 38 {{{ 39 #!python 49 40 # MyMacro.py -- The world's simplest macro 50 41 … … 53 44 }}} 54 45 55 === 上級トピック: Template-enabled Macros === 56 高度な用途のために、マクロでは HDF 形式での構造化出力をサポートしています。これは、 Trac が生成するページと同じように clearSilver テンプレートを使って HTML を生成することができます。要するに、これは普遍的かつ、よく設計された高度なマクロを可能にします。 57 58 マクロでは、メインとなる HDF ツリーに直接アクセスし、自由に操作することができます。 59 60 例: 46 You can also use the environment (`env`) object, for example to access configuration data and the database, for example: 61 47 {{{ 62 def execute(hdf, args, env): 63 # Currently hdf is set only when the macro is called 64 # From a wiki page 65 if hdf: 66 hdf.setValue('wiki.macro.greeting', 'Hello World') 67 68 # args will be null if the macro is called without parentesis. 69 args = args or 'No arguments' 70 return 'Hello World, args = ' + args 71 }}} 72 73 また、environment (env) オブジェクトによって、コンフィグデータへのアクセスも提供されています。 74 75 例: 76 {{{ 48 #!python 77 49 def execute(hdf, txt, env): 78 50 return env.get_config('trac', 'repository_dir') 79 51 }}} 52 53 Note that since version 0.9, wiki macros can also be written as TracPlugins. This gives them some capabilities than “classic” macros do not have, such as directly access the HTTP request. 54 55 For more information about developing macros, see the [http://projects.edgewall.com/trac/wiki/TracDev development resources] on the main project site. 56 80 57 ---- 81 参考: WikiProcessors, WikiFormatting, TracGuide58 See also: WikiProcessors, WikiFormatting, TracGuide