the power of rails 2.3 engines & templates
TRANSCRIPT
The Power of Rails 2.3 Engines & Templates
Tse-Ching Ho2009/03/10
Rails app used to be
rails engines_demo
cd engines_demo
script/generate scaffold product serial_number:string price:float discount:float quantity:integer name:string remark:string
rake db:migrate
sudo gem install png
script/plugin install git://github.com/toretore/barby.git
script/server
Use Template
rails <app> -m ~/template.rb
rails <app> -m http://gist.github.com/12345.txt
rake rails:template LOCATION=~/template.rb
Commands for Templateplugin(name, options)
gem(name, options = {})
rake(command, options = {})
generate(what, *args)
route(routing_code)
run(command, log_action = true)
git(command = {})
inside(dir = '', &block)
ask(question)
yes?(question)
no?(question)
capify!
freeze!
initializer(filename, data = nil, &block)
lib(filename, data = nil, &block)
rakefile(filename, data = nil, &block)
vendor(filename, data = nil, &block)
file(filename, data = nil, log_action = true, &block)
load_template(template)
environment(data = nil, &block)
gsub_file(relative_destination, regexp, *args, &block)
rails-2.3.0/lib/rails_generator/generators/applications/app/template_runner.rb
Lessons for Template
hooks related commands of one gem or plugin
groups hooked commands into functional sets
files one set in one template
writes scaffold generation template for project
combines templates for each project
Start the Engine
script/generate plugin <your-plugin>
cd vendor/plugins/<your-plugin>
mkdir app config db
move codes to your plugin
Issues in Rails 2.3 GemApp routes.rb not loaded when both engine and inflections present
Allow ActionMailer to use view_paths from plugins
Improve view performance in development and reinstate template reloading in production
rake rails:freeze:edge
Rake tasks for run engine migrations
Demo
Authlogic_Bundle
http://github.com/tsechingho/authlogic_bundle
Engines + template
i18n + authlogic + open_id_authentication + declarative_authorization
barcode creator : barby
http://github.com/toretore/barby
created from template
make into engines
Q & A
Referenceshttp://guides.rubyonrails.org/2_3_release_notes.html
http://m.onkey.org/2008/12/4/rails-templates
http://railscasts.com/episodes/148-app-templates-in-rails-2-3
http://railscasts.com/episodes/149-rails-engines
http://github.com/pixels-and-bits/strappy/
http://github.com/tsechingho/authlogic_bundle/
http://github.com/jeremymcanally/rails-templates/tree/master
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets?q=engines