Hi, I have been working a lot on getting a grasp of creating rails 3 generators. I have created some nifty generators and some Mongo Mapper and Mongo generators. Now I am considering creating a complete Rails app generator, to customize it to my needs. It seems a bit akward to use the "current" approach where you simply add on some steps at the end of the generation to remove certain files and add some extras etc. Does anyone have any idea for how to do this? I think what is required is to simply create a Thor task and installing it on the system, but how can I make this thor task call a generator in an installed gem? Hmm.. I guess I could just require the gem in the Thor task? Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
You could have the gem install the thor task for you. That way you only get the task if the gem is available. Allen Madsen http://www.allenmadsen.com On Thu, Jan 28, 2010 at 9:36 AM, Kristian Mandrup <kmandrup@gmail.com> wrote:> Hi, > > I have been working a lot on getting a grasp of creating rails 3 > generators. > I have created some nifty generators and some Mongo Mapper and Mongo > generators. > > Now I am considering creating a complete Rails app generator, to > customize it to my needs. > It seems a bit akward to use the "current" approach where you simply > add on some steps at the end of the generation to remove certain files > and add some extras etc. > > Does anyone have any idea for how to do this? > I think what is required is to simply create a Thor task and > installing it on the system, but how can I make this thor task call a > generator in an installed gem? Hmm.. I guess I could just require the > gem in the Thor task? > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Kristian Mandrup
2010-Jan-28 15:08 UTC
Re: Overriding the default rails app generator - how?
Sounds great! How would I do that exactly? http://yehudakatz.com/2008/05/12/by-thors-hammer/ -- Thor, as it exists today, has two components: * The Thor superclass, which works exactly like CLI/Hermes, except that you inherit from it instead of including it (class MyApp < Thor). * The Thor runner, which can run Thortasks that are in a local directory or installed from a remote location The thor runner allows you to make files like: # module: random class Amazing < Thor desc "describe NAME", "say that someone is amazing" method_options :forcefully => :boolean def describe(name, opts) ret = "#{name} is amazing" puts opts["forcefully"] ? ret.upcase : ret end desc "hello", "say hello" def hello puts "Hello" end end You can also install local tasks or remote tasks to your system thor cache and make them available anywhere: $ thor install task.thor -- Not sure how to integrate this with a generator gem... Fx this gem: http://github.com/kristianmandrup/mongo_model_r3 Thanks! On Jan 28, 3:40 pm, Allen Madsen <bla...@gmail.com> wrote:> You could have the gem install the thor task for you. That way you > only get the task if the gem is available. > > Allen Madsenhttp://www.allenmadsen.com >> >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.