{"id":21765959,"url":"https://github.com/narazaka/miyojs-filter-property","last_synced_at":"2026-05-06T08:31:11.685Z","repository":{"id":21775279,"uuid":"25097583","full_name":"Narazaka/miyojs-filter-property","owner":"Narazaka","description":"property - executable property in Miyo dictionary","archived":false,"fork":false,"pushed_at":"2014-11-17T17:03:59.000Z","size":156,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T22:52:59.419Z","etag":null,"topics":["miyojs","ukagaka"],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Narazaka.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-11T22:25:22.000Z","updated_at":"2023-10-16T15:44:43.000Z","dependencies_parsed_at":"2022-08-19T16:50:56.985Z","dependency_job_id":null,"html_url":"https://github.com/Narazaka/miyojs-filter-property","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narazaka%2Fmiyojs-filter-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narazaka%2Fmiyojs-filter-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narazaka%2Fmiyojs-filter-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Narazaka%2Fmiyojs-filter-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Narazaka","download_url":"https://codeload.github.com/Narazaka/miyojs-filter-property/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244741513,"owners_count":20502296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["miyojs","ukagaka"],"created_at":"2024-11-26T13:14:34.867Z","updated_at":"2026-05-06T08:31:11.621Z","avatar_url":"https://github.com/Narazaka.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"property - 実行可能なプロパティ\r\n========================================\r\n\r\nこれはなにか\r\n----------------------------------------\r\n\r\nこれは伺か用SHIORIサブシステムである美代(Miyo)の辞書フィルタプラグインです。\r\n\r\n辞書で使われる(得にフィルタで使われる)任意のプロパティをプログラムコードとして扱える機能を提供します。\r\n\r\nこのフィルタは提供するメソッドを主に他のフィルタ内部で使うことを想定しています。\r\n\r\nインストール\r\n----------------------------------------\r\n\r\n### 一般\r\n\r\n    npm install miyojs-filter-property\r\n\r\n### ゴーストに追加する場合\r\n\r\nghost/masterをカレントディレクトリとして同様に\r\n\r\n    npm install miyojs-filter-property\r\n\r\n含まれるフィルタ\r\n----------------------------------------\r\n\r\n### property_initialize\r\n\r\nMiyoの初期化時に実行するフィルタです。\r\n\r\n依存\r\n----------------------------------------\r\n\r\nこのフィルタが依存するものはありません。\r\n\r\n使用方法\r\n----------------------------------------\r\n\r\n機能を使用可能にするためMiyoの初期化時にproperty_initializeを実行します。\r\n\r\n    _load:\r\n    \tfilters: [..., property_initialize, ...]\r\n    \targument:\r\n    \t\tproperty_initialize:\r\n    \t\t\thandlers:\r\n    \t\t\t\t- coffee\r\n    \t\t\t\t- jse\r\n    \t\t\t\t- js\r\n\r\n引数にproperty_initialize.handlersを指定します。\r\n\r\nproperty_initialize.handlersの配列に指定されたハンドラをこの順番の優先度で適用するという指定です。\r\n\r\nproperty_initializeを実行した時点で、Miyoインスタンスに次のメソッドが追加されています。\r\n\r\n### property(property_base, property_name, request, id, stash, pre_hook)\r\n\r\n    var option = this.property(argument.my_filter, 'option', request, id, stash, pre_hook);\r\n\r\nproperty_baseの下のproperty_nameプロパティを返します。\r\n\r\nプロパティの後ろに.js等のハンドラ名がついている場合、そのハンドラに対応したプログラムコードとして実行された結果が返ります。\r\n\r\nそのようなプロパティが複数ある場合はproperty_initializeで定義したハンドラの優先度に従って実行されます。\r\n\r\n後ろに何もつかないプロパティはただの文字列として扱われます。\r\n\r\n    _load:\r\n    \tfilters: [..., property_initialize, ...]\r\n    \targument:\r\n    \t\tproperty_initialize:\r\n    \t\t\thandlers:\r\n    \t\t\t\t- jse\r\n    \t\t\t\t- js\r\n    OnTest:\r\n    \tfilters: [my_filter]\r\n    \targument:\r\n    \t\tmy_filter:\r\n    \t\t\toption: 3\r\n    \t\t\toption.jse: this.variables.my_filter + 2\r\n    \t\t\toption.js: return this.variables.my_filter + 2\r\n    \r\n    # var option = this.property(argument.my_filter, 'option', request, id, stash);\r\n\r\nこの場合option.jseが実行された結果が返されます。\r\n\r\nプロパティは一度目の呼び出し時に文字列からコードにコンパイルされ、以降はそのコードが実行されるので、option.jse等の値を実行中に書き換えることは結果が保証されず推奨されません。\r\n\r\nこれら.js等がついたコードはMiyoのインスタンスをthisとして引数request, id, stashとrequire(node.js)が渡されて実行されます。\r\n\r\n### コードの定義\r\n\r\nコードはYAMLに文字列として扱われますが、`:`等の文字が含まれているとYAMLパーサーが単純な文字列として扱ってくれない可能性があります。\r\n\r\nなので可読性の観点も含め長いコードはブロック定義にするのが望ましいと思われます。\r\n\r\n    option.coffee: -|\r\n    \tif stash?.id?\r\n    \t\tstr = 'id = ' + stash.id\r\n    \telse\r\n    \t\tstr = 'id = ' + id\r\n    \treturn str\r\n\r\n### pre_hook\r\n\r\npre_hookはこれらのオプションがコードとしてパースされる前の文字列を受け取って整形するための関数を渡します。\r\n引数にプロパティ、request, id, stashが渡されて実行されるので、プロパティとして扱う文字列を返してください。\r\n\r\npre_hookにはハンドラ名をキーにした関数群のオブジェクトか、単一の関数、あるいは単一の関数にハンドラ名をキーにした関数群を定義したものを渡せます。\r\n\r\n    _load:\r\n    \tfilters: [..., property_initialize, ...]\r\n    \targument:\r\n    \t\tproperty_initialize:\r\n    \t\t\thandlers:\r\n    \t\t\t\t- jse\r\n    \t\t\t\t- js\r\n    OnTest:\r\n    \tfilters: [my_filter]\r\n    \targument:\r\n    \t\tmy_filter:\r\n    \t\t\toption: shiori\r\n    \r\n    # var pre_hook = function(property, request, id, stash){return property + 'jk'};\r\n    # var option = this.property(argument.my_filter, 'option', request, id, stash, pre_hook);\r\n    # var option = this.property(argument.my_filter, 'option', request, id, stash, {plain: pre_hook});\r\n    # var pre_hook_2 = function(property, request, id, stash){return 'dummy'};\r\n    # pre_hook_2.plain = function(property, request, id, stash){return property + 'jk'};\r\n    # var option = this.property(argument.my_filter, 'option', request, id, stash, pre_hook_2);\r\n    # var pre_hook_3 = function(property, request, id, stash){return property + 'jk'};\r\n    # pre_hook_3.js = function(property, request, id, stash){return 'dummy'};\r\n    # var option = this.property(argument.my_filter, 'option', request, id, stash, pre_hook_3);\r\n\r\nこの場合全て'shiorijk'が返されます。\r\n\r\nplainは特別なハンドラ名で、.js等がつかないものの場合に適用されます。\r\n\r\nplainの場合はどんな値を返しても問題になりませんが、コードとして適用されるプロパティの場合は文法エラー等になる文字列を渡せばエラーとなりますので注意してください。\r\n\r\n### has_property(property_base, property_name)\r\n\r\n    var has_option = this.has_property(argument.my_filter, 'option');\r\n\r\nproperty_baseの下のproperty_nameプロパティの存在確認をします。真偽値が返ります。\r\n\r\n有効なハンドラの指定によって結果は変わります。\r\n\r\n    _load:\r\n    \tfilters: [..., property_initialize, ...]\r\n    \targument:\r\n    \t\tproperty_initialize:\r\n    \t\t\thandlers:\r\n    \t\t\t\t- jse\r\n    \t\t\t\t- js\r\n    OnTest:\r\n    \tfilters: [my_filter]\r\n    \targument:\r\n    \t\tmy_filter:\r\n    \t\t\toption1: 3\r\n    \t\t\toption2.coffee: @variables.my_filter + 2\r\n    \t\t\toption3.js: return this.variables.my_filter + 2\r\n\r\nこの場合option1とoption3についてはtrue、option2についてはfalseとなります。\r\n\r\n### compiled_property(property_base, compiled_property_name, request, id, stash)\r\n\r\nコンパイル済みのプロパティを実行します。\r\n\r\n内部的に使われます。\r\n\r\n### set_compiled_property(property_base, compiled_property_name, compiled_property, compiled_handler_name)\r\n\r\nコンパイル済みのプロパティを設定します。\r\n\r\n内部的に使われます。\r\n\r\nハンドラ\r\n----------------------------------------\r\n\r\n組み込みのハンドラは以下の通りです。\r\n\r\n### plain\r\n\r\n文字列として評価します。\r\n\r\nハンドラを示す後ろの文字列がない場合にこれが使われます。\r\n\r\n### js\r\n\r\nJavaScriptのコードとして評価します。\r\n\r\n単純に関数に包まれたコードとして実行されるので、適切にreturn文を入れてください。\r\n\r\n### jse\r\n\r\nJavaScriptの式として評価します。\r\n\r\nコードの冒頭に`return `を付加して関数に包んだコードとして実行されるので、return文はいりませんが、必ず最初の式が返されます。\r\n\r\nなので次のようなコードでも`;`のあとは実行されません。\r\n\r\n    option.jse: id == 'OnTest'; return dummy;\r\n\r\n### coffee\r\n\r\nCoffeeScriptのコードとして評価します。\r\n\r\nこれを使用する場合はCoffeeScriptをインストールしておいてください。\r\n\r\nゴーストへのインストールはghost/masterをカレントディレクトリとして\r\n\r\n    npm install coffee-script\r\n\r\nでインストールできます。\r\n\r\nCoffeeScriptではreturnか最後に評価された値が必ず返り値になるのでJavaScriptのようなjs,jseの違いは必要有りません。\r\n\r\nハンドラを自分で定義する\r\n----------------------------------------\r\n\r\nMiyoインスタンスのfilters.property_handlerにハンドラは定義されています。\r\n\r\n自作のハンドラを定義する場合は、コンパイルハンドラと実行ハンドラを定義する必要があります。\r\n\r\nプロパティが呼ばれる場合には、一度目の実行の場合コンパイルハンドラでプロパティの文字列がコンパイルされてキャッシュされた後、実行ハンドラに渡されます。\r\n二度目以降はキャッシュを使って実行ハンドラのみが実行されます。\r\n\r\n### コンパイルハンドラ\r\n\r\nまずfilters.property_handlerにプロパティの後ろにつける文字列と同名のキーでコンパイルハンドラ関数を定義します。\r\n\r\n仮にoption.myという文字列で実行させたいハンドラを定義する場合以下のようにします。\r\n\r\n    this.filters.property_handler.my = function(property, request, id, stash){...};\r\n\r\nthisはMiyoインスタンスです。\r\n\r\nコンパイルハンドラ関数はMiyoインスタンスをthisとして実行され、プロパティの文字列とrequest, id, stashを受け取り、プロパティの実行可能オブジェクト等と実行ハンドラ名を返します。\r\n\r\n    this.filters.property_handler.my = function(property, request, id, stash){\r\n    \treturn [new Function(property, 'id'), 'compiled_my'];\r\n    };\r\n\r\n返されたプロパティと実行ハンドラ名はキャッシュされます。\r\n\r\n### 実行ハンドラ\r\n\r\nfilters.property_handlerにコンパイルハンドラが返す名前と同名のキーで実行ハンドラ関数を定義します。\r\n\r\n前述のmyハンドラに対応するハンドラを定義する場合以下のようにします。\r\n\r\n    this.filters.property_handler.compiled_my = function(compiled_property, request, id, stash){...};\r\n\r\nthisはMiyoインスタンスです。\r\n\r\n実行ハンドラ関数はMiyoインスタンスをthisとして実行され、コンパイルされたプロパティとrequest, id, stashを受け取り、最終的なプロパティの値を返します。\r\n\r\n    this.filters.property_handler.compiled_my = function(compiled_property, request, id, stash){\r\n    \treturn compiled_property.call(this, id);\r\n    };\r\n\r\n### 注意\r\n\r\nnode.jsではモジュールのロード等にrequireがしばしば使われますが、requireはグローバルではないゆえに何もしなければFunctionオブジェクト内では参照できなくなります。\r\nrequireを出来るようにしたければFunctionにrequireを渡すことが必要です。\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarazaka%2Fmiyojs-filter-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnarazaka%2Fmiyojs-filter-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnarazaka%2Fmiyojs-filter-property/lists"}