3 people want to do this.

Create a rails plugin


 

People doing this:

  • Columbus
  • Dublin

  • Entries

    Finished reading "Rails Plugins - Extending Rails Beyond the Core":"Rails Plugins - Extending Rails Beyond the Core" 読了 2 years ago

    (English to follow after Japanese).

    これまでプラグイン関係の情報をネットで探したり、プラグインづくりに必要なRuby テクニックを色々読んでいたのですがようやく「これだ」という一冊を見つけました。

    その名もずばり”Rails Plugins – Extending Rails Beyond the Core”.

    私がいくつかのプラグインのソースを読んでいてよくわからなかったのが、モジュールが何層にも入れ子になっているところだったのですが、この本では、プラグインの一番シンプルな形を最初に紹介し、そこから徐々にActive RecordやController, Viewを拡張する形で順をおって複雑な拡張の仕方を説明してくれているのでわかりやすかったです。

    もし以下のようなコードに以前でくわして、なにを意味するかわからない方は一読をおすすめします。 

    module ModuleName
     module ClassMethods
     end
     extend ClassMethods
     def self.included(receiver)
       receiver.extend(ClassMethods)
     end
    end

    self.includedの部分はRuby For Railsにも出ていたのですが、この本を読むまでどういう用途につかえば良いのかいまいちわかっていませんでした。

    Addison Wesleyのショートカットシリーズは150ページぐらいの少量なので、英語がにがてなかたも比較的取っ付きやすいと思います。
    私は5月の連休(イギリスは日本より格段と祝日が少ないのですが、5月は珍しく3連休が2度あります)を利用して一気に読み終わりました。

    来週からはたくさんのプラグインのソースコードを読んでいきたいです。

    I’ve spent quite a while looking for plugin related resources on net, but I finally found the one.

    This e-book is called “Rails Plugins – Extending Rails Beyond the Core”, and it’s entirely dedicated to Rails plugin and it’s exactly what I was looking for.

    I mentioned earlier that I did not understand why there are so many nested modules in plugins.

    This book started from the simplest example with no modules, then explained more detailed ones step by step.

    If you encountered this kind of syntax when you read some source code and did not know what it means, the answer is in the book.

    module ModuleName
     module ClassMethods
     end
     extend ClassMethods
     def self.included(receiver)
       receiver.extend(ClassMethods)
     end
    end

    I actually encountered this when I was reading “Ruby For Rails” , book , but did not know the right usage untill I read this book.

    Addison Wesley’s shortcut is very small ebook, so I was able to finish reading using this long weekend (it’s not as long as Japan’s “Golden week” though).

    My next goal is to read many plugin source code.



    Read DSL and Plugin related URL: DSL とプラグイン関係URL読了 2 years ago

    (English to follow after Japanese).

    前回の参考URLは量がすくなかったのですぐに読み終わりました。おすすめはJamisBuckのブログエントリーです。プラグインをどのような用途に使うか、そしてプラグインを作成するのに必要なRubyテクニック(symbols,procs,modules,eval(instance_eval, and class_eval),define/alias_method,Module#included,Class#inherited)について書いてあります。

    上記の事柄に関してはまだ勉強不足なので、また本を読み直したいと思います。ちなみに現在読んでいるのは “Ruby for Rails” です。(http://www.manning.com/black/)

    The last URLs were not so many so I finished fairly quickly.
    JamisBuck’s blog entry gave me better idea about what plugins and what else I should learn to write plugins, such as….

    symbols,procs,modules,eval(instance_eval, and class_eval),define/alias_method,Module#included,Class#inherited

    Again,back to basic and need to read more.
    I am now reading “Ruby for Rails”(http://www.manning.com/black/)



    DSL and Plugin related URL:DSLとプラグイン関係のURL 2 years ago

    (English to follow after Japanese).

    Railsはウェップ開発のDSL(Domain Specific Language: メタプログラミングみたいなものでしょうか?)だといろいろなところで言われているのですが、DSL自体の理解がいまいちなので、次回の読書リストはそれ系のものにしました。全て英語URLです。

    Many people says that Rails is DSL in web development domain. Since I will be (probably) writing a plugin to extend Rails functionality, I should know a bit more about DSL. Here are my next reading lists.

    *http://weblog.jamisbuck.org/2006/4/20/writing-domain-specific-languages
    *http://blog.nicksieger.com/articles/2006/06/24/railsconf-steven-hammond-dsls
    *http://bloggingrailsconf.com/articles/2006/06/24/domain-specific-languages-as-rails-plugins



    Read reference URLs:  参考URL読了 2 years ago

    (English to follow after Japanese)

    前回のエントリーに載せたURLは大体読み終わりました。中でもおすすめは以下の記事だと思います(注:英語記事です)。

    プラグインのコンセプトは大体以下のように理解できました。

    • “script/generate plugin #{your_plugin_name}” でプラグインディレクトリを作成。
      “app/vendor/#{your_plugin_name}/plugins/lib/#{your_plugin_name}.rb”に自分のコードを書く。
    • app/vendor/plugins/#{your_plugin_name}/init.rb で先ほど書いたコードをrequireする。

    しかしながらActiveRecord, Action View やユニットテストなどを拡張して、あたかもRailsの機能の一部分として使うには、プラグインをRailsに組み込む方法を知る必要がありそうです。

    その勉強のためにact_asなプラグインをチュートリアルのサンプルを見ながら作ってみました。

    act_asと言えばact_as_taggable(http://media.pragprog.com/titles/fr_rr/Tagging.pdf )が有名ですが、ちょっと難しそうだったので”act_as_random”というプラグインを解説しているページを参考にしてみました.

    これは「クラス名.random.コラム名」とすると、コラム名の値がランダムにかえされるものです。

    みたまんまをもとに作成して動くには動いたのですが、以下の点がいまいち理解できませんでした。

    1 モジュールが何層にも入れ子になっている。act_as_random には6つモジュールが入ってました。
    2 “included”と “extend”が多用されている。

    たぶん私のモジュールに対する理解不足だと思うので、もう一度Ruby Book にもどって勉強したいと思います。

    Okay, now I read enough urls to have brief idea about usage of plugins.

    (The below urls are the one I recommend you to read if you do not have time to go through all references).

    The concept of plugin itself looks simple.
    • Run “script/generate plugin #{your_plugin_name}”
    • Put your functionality at “app/vendor/#{your_plugin_name}/plugins/lib/#{your_plugin_name}.rb”
    • require your code at app/vendor/plugins/#{your_plugin_name}/init.rb

    However, you want to write a code to extend existing Rails functionality (ActiveRecord, Action View, Unit/Functional Test), so your code acts as if part of them. To do that, you need to know how to inject them.

    To learn that, I decided to try a tutorial to create act_as_ plugin.

    When you think about act_as*, “act_as_taggable” is very famous (http://media.pragprog.com/titles/fr_rr/Tagging.pdf), but that looks quite complicated, so I used the below tutorial to create “act_as_random”.

    The plugin worked after minor modification (It created a table called “Country”, but I had to change it to “countries”), but I found that the below points are still not so clear to me.

    1 Many nested modules = Many plugin has many nested modules (act_as_random had 6).
    2 Many “included” and “extend”

    I think it’s because my understanding about “Module” is not enough. Need to go back to Ruby book…



    LRUG video: LRUGのビデオ 2 years ago

    *English to follow after Japanese.

    TabNavの紹介をしていたLRUGですがビデオがアップされています。

    About the tabnav at April LRUG, The video is uploaded here.

    http://skillsmatter.com/menu/567



    URLs to read: 参考文献URL 2 years ago

    日本語参考URL:Japenease Reference URL
    *http://d.hatena.ne.jp/secondlife/20051101/1130850457
    *http://wiki.rails2u.com/Rails+%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3
    *http://akimichi.homeunix.net/hiki/rails/?%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3
    英語参考URL: English Reference URL
    *http://wiki.rubyonrails.org/rails/pages/Plugins
    *http://wiki.rubyonrails.com/rails/pages/HowTosPlugins

    今週中に以上の参考URLを読破するのが目標です。
    My goal of this week is to read all these urls.



    Why I decided to write a plugin : プラグインを書こうと思ったきっかけ 2 years ago

    English to follow after Japanese

    先日ロンドンRuby User Group (略してLRUG:http://www.lrug.org/meetings/2007/04/04/april-2007-meeting/)
    に行ってきたのですが、その中でPaolo Donàさんというかたが、自身の作成したTabNav(http://blog.seesaw.it/pages/tabnav)というタブを簡単に作成するためのプラグインについてプレゼンをされていました。 彼のプレゼンはとても面白くて、その後も彼のコードに使われていたProc の使用方法に関して議論が白熱していました(http://lists.lrug.org/pipermail/chat-lrug.org/2007-April/001064.html)

    とても楽しいイベントでしたが、正直Rubyのブロックの使い方や、なぜRubyがDSLやメタプログラミングに向いているか完全に理解しきれていないところがあります。

    そこでそれらに対する理解を深める目的でプラグインを書くことにしました。

    まだどんなプラグインを書くか決めていませんので何か良い案などがあればお知らせください。

    I went to April London Ruby User Group (http://www.lrug.org/meetings/2007/04/04/april-2007-meeting/ ).
    At the session, Paolo Donà san from Italy presented his plugin “tabnav” which is easy way to create a tabbed navigation in your rails view(http://blog.seesaw.it/pages/tabnav).

    His presentation was fun and it lead to interesting conversation about how to get rid of Procs(http://lists.lrug.org/pipermail/chat-lrug.org/2007-April/001064.html).

    Honestly, I still struggle to fully understand the use/benefit of blocks/closure/iterator and whole conversation about why Ruby is good for DSL/Metaprograming.

    Then I decided to write a plugin to learn mora bout Ruby’s blocks and also how it integrates into Rails.

    I haven’t even decided what kind of plugin to write, so any suggestions are welcome.




     

    I want to:
    43 Things Login