The Plugin Generator allows you to create Padrino projects based on a template file that contains all the necessary actions needed to create the project. Plugins can also be executed within an existing Padrino application. The plugin generator provides a simple DSL in addition with leveraging Thor to make generating projects a breeze!
$ padrino g project my_project --template path/to/my_template.rb
This will generate a project based on the template file provided. You can also generate a project based on a remote url such as a gist for an additional level of convenience:
$ padrino g project my_project --template https://gist.github.com/356156
You can also execute template files directly from the official templates repo:
$ padrino g project my_project --template sampleblog
You can also apply templates as plugins to existing Padrino applications:
$ cd path/to/existing/padrino/app $ padrino g plugin path/to/my_plugin.rb
You can also execute plugin files directly from the official plugins repo:
$ cd path/to/existing/padrino/app $ padrino g plugin hoptoad
You can even get a list of available plugins with the following command:
$ padrino g plugin --list
A simple template (plugin) file might look like this:
# my_template.rb project :test => :shoulda, :orm => :activerecord generate :model, "post title:string body:text" generate :controller, "posts get:index get:new post:new" generate :migration, "AddEmailToUser email:string" require_dependencies 'nokogiri' git :init git :add, "." git :commit, "initial commit" inject_into_file "app/models/post.rb","#Hello", :after => "end\n" rake "ar:create ar:migrate" initializer :test, "# Example" app :testapp do generate :controller, "users get:index" end git :add, "." git :commit, "second commit"
Keep in mind that the template file is pure Ruby and has full access to all available thor actions.
last updated: 2016-09-04comments powered by Disqus