the power of rails 2.3 engines & templates

12

Click here to load reader

Upload: tse-ching-ho

Post on 30-May-2015

3.487 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: The Power of Rails 2.3 Engines & Templates

The Power of Rails 2.3 Engines & Templates

Tse-Ching Ho2009/03/10

Page 2: The Power of Rails 2.3 Engines & Templates

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

Page 3: The Power of Rails 2.3 Engines & Templates

Use Template

rails <app> -m ~/template.rb

rails <app> -m http://gist.github.com/12345.txt

rake rails:template LOCATION=~/template.rb

Page 4: The Power of Rails 2.3 Engines & Templates

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

Page 5: The Power of Rails 2.3 Engines & Templates

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

Page 6: The Power of Rails 2.3 Engines & Templates

Start the Engine

script/generate plugin <your-plugin>

cd vendor/plugins/<your-plugin>

mkdir app config db

move codes to your plugin

Page 7: The Power of Rails 2.3 Engines & Templates

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

Page 8: The Power of Rails 2.3 Engines & Templates

Demo

Page 10: The Power of Rails 2.3 Engines & Templates

barcode creator : barby

http://github.com/toretore/barby

created from template

make into engines

Page 11: The Power of Rails 2.3 Engines & Templates

Q & A