Hey all, I am looking to write a plugin for merb and have a few queries about how to best go about it. I have a few questions (sorry if some are very merb newbie ones): - It seems all the plugins are gems; I can just add dependencies (my plugin will require soap4r) as per any usual gem spec? - If I want my plugin to add some new generate functionality? Is this possible? If so, are there any examples? I dont seem to be able to find any :( - The plugin needs to go into the gem dir right? So anything within the gem dir is automatically included on the app load path? - If there were some view helpers in the gem, is there way of forcing them to be included like in rails where you include them into the ActionView module so they are instantly available in views? It also seems that in version 0.4.2, doing "merb -P my_plugin" doesnt work outside a merb app? Is this a bug? Thanks for any pointers!! Cheers Tim
Hi Tim,> I am looking to write a plugin for merb and have a few queries about > how to best go about it. I have a few questions (sorry if some are > very merb newbie ones): > > - It seems all the plugins are gems; I can just add dependencies (my > plugin will require soap4r) as per any usual gem spec?Yep> - If I want my plugin to add some new generate functionality? Is this > possible? If so, are there any examples? I dont seem to be able to > find any :(Do you mean adding generators? I don''t know too much about this, but someone else on the list can probably fill you in.> - The plugin needs to go into the gem dir right? So anything within > the gem dir is automatically included on the app load path?That''s right. Although they don''t have to be in the gem dir if you don''t need. They can be installed like regular gems.> - If there were some view helpers in the gem, is there way of forcing > them to be included like in rails where you include them into the > ActionView module so they are instantly available in views?Yep. You need to mix them into the ViewContext module. The merb_helpers plugin has a good example: class Merb::ViewContext #:nodoc: include Merb::Helpers::Form end> It also seems that in version 0.4.2, doing "merb -P my_plugin" doesnt > work outside a merb app? Is this a bug?I''ve heard a few other people complain about this, but I haven''t seen it myself. It''s definitely a bug :) -- Luke
On 19 Dec 2007, at 00:41, Daniel N wrote:> - If I want my plugin to add some new generate functionality? Is this > possible? If so, are there any examples? I dont seem to be able to > find any :( > > You can look at the ORM plugins, although they are a bit different > since the subclass specific helpers in merb. To see the generators > themselves that merb uses in > http://merb.devjavu.com/browser/trunk/lib/merb/generators/merb_generator_helpers.rb > > Basically if you want a generator you would create a generator in the > > merb_generators directory. If you want one specifically for > datamapper, activerecord, sequel, rspec or test_unit you would put > it in those directories with _generator added to the end. > > eg. > activerecord_generators > datamapper_generators > rspec_generators > my_generator_name_generator.rb > templates > template1.erb > template2.erb > USAGE > > The usage file, if present will allow the generator to be listed in > a call to > script/generateOk, so just to check I understand it, my folder structure of my plugin might look something like: + some_merb_plugin + lib + merb_generators - my_demo_generator.rb + templates - template1.erb - USAGE + spec That will automatically then be included when script/generate is called? Looking at the source of the merb controller (et al) generators, there all subclasses of RubiGen::Base, so id presumably be able to copy that structure to create the generator I want?> - The plugin needs to go into the gem dir right? So anything within > the gem dir is automatically included on the app load path? > > It doesn''t have to go in there. That''s just a way to make sure your > app will see it on a shared host. You include a line in > dependencies.rb > dependency "my_plugin"Cool - I guess that negates the need for putting them in the gem dir.> - If there were some view helpers in the gem, is there way of forcing > them to be included like in rails where you include them into the > ActionView module so they are instantly available in views? > > Merb::ViewContext is the class that these should be put into. If > you put them in there. They will be avilable to your views.Sweet, that makes sense. Cheers Tim
Ok, ive got my gem, its all packaged and installed into my system gem repository. I then added it to the list of dependencies, in a fresh merb app. However, when I do script/generate, I don''t see it on the list of installed generators? Any ideas? Thanks Tim
Sorry to reply to my own message - ive fixed it, it was not packaging the generator files in the gem. You have got to change the gem spec to make sure it includes it. cheers Tim On 19 Dec 2007, at 17:17, Tim Perrett wrote:> Ok, ive got my gem, its all packaged and installed into my system gem > repository. > > I then added it to the list of dependencies, in a fresh merb app. > > However, when I do script/generate, I don''t see it on the list of > installed generators? Any ideas? > > Thanks > > Tim