bar_1

contents_map

2018年12月21日金曜日

Thor アクション Actions

アクション Actions

Thorには, スクリプトやジェネレータといったタスクに役立つ, 5,6個のアクションがある. いくつかはRailsのテンプレートとしてあるので, あなたはそれらに親しんでいるかもしれない. 列挙すると: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file や, その他にも2,3ある.
Thor comes with several actions that help with script and generator tasks. You might be familiar with them since some came from Rails Templates. They are: say, ask, yes?, no?, add_file, remove_file, copy_file, template, directory, inside, run, inject_into_file and a couple more.
これらを使うには, あなたのThorクラスたちの中で Thor::Actions をincludeするだけだ:
To use them, you just need to include Thor::Actions in your Thor classes:
class App < Thor
  include Thor::Actions
  # tasks
end
ファイルをコピーするアクションなどように, アクションによっては source_root と呼ばれる, クラスメソッドがひとつ必要となるアクションもある. このクラスメソッドはあなたのテンプレートたちが配置されているべきディレクトリだ. Thor::ActionsThor::Shell::Basic のドキュメントを確認すること. たとえば:
Some actions like copy file require that a class method called source_root be defined in your class. This is the directory where your templates should be placed. Be sure to check the documentation on Thor::Actions and Thor::Shell::Basic. For instance:
class App < Thor
  include Thor::Actions

  def self.source_root
    File.dirname(__FILE__)
  end
end

0 件のコメント:

コメントを投稿

何かありましたら、どうぞ: