Thor - RSLA - 13oct2009
Upcoming SlideShare
Loading in...5
×
 

Thor - RSLA - 13oct2009

on

  • 2,497 views

José Valim talks in portuguese about Code Generation with Thor and Rails 3.0 at Rails Summit Latin America 2009

José Valim talks in portuguese about Code Generation with Thor and Rails 3.0 at Rails Summit Latin America 2009

Statistics

Views

Total Views
2,497
Views on SlideShare
2,157
Embed Views
340

Actions

Likes
1
Downloads
15
Comments
0

5 Embeds 340

http://blog.plataformatec.com.br 315
http://feeds.feedburner.com 17
http://localhost 4
http://www.slideshare.net 3
http://web.archive.org 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Thor - RSLA - 13oct2009 Thor - RSLA - 13oct2009 Presentation Transcript

  • Geradores de código com Thor @josevalim http://plataformatec.com.br jose@plataformatec.com.br Plataforma Tecnologia, José Valim 2009
  • Quem sou? Plataforma Tecnologia, José Valim 2009
  • Desenvolvedor líder na Plataforma Tecnologia Plataforma Tecnologia, José Valim 2009
  • 22 anos, Engenheiro pela Escola Politécnica Plataforma Tecnologia, José Valim 2009
  • Desenvolvedor ruby há quase 3 anos Plataforma Tecnologia, José Valim 2009
  • Google Summer of Code Student e contribuidor ativo do Rails Core Plataforma Tecnologia, José Valim 2009
  • Inherited Resources Plataforma Tecnologia, José Valim 2009
  • Inherited Resources Rails Footnotes Plataforma Tecnologia, José Valim 2009
  • Inherited Resources Rails Footnotes Remarkable Plataforma Tecnologia, José Valim 2009
  • Inherited Resources Rails Footnotes Remarkable Formtastic Plataforma Tecnologia, José Valim 2009
  • O que está errado com os geradores do Rails 2.x? Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold ActiveRecord TestUnit ERB Plataforma Tecnologia, José Valim 2009
  • script/generate rspec_scaffold Plataforma Tecnologia, José Valim 2009
  • script/generate rspec_scaffold ActiveRecord Rspec ERB Plataforma Tecnologia, José Valim 2009
  • script/generate dm_scaffold Plataforma Tecnologia, José Valim 2009
  • script/generate dm_scaffold DataMapper TestUnit ERB Plataforma Tecnologia, José Valim 2009
  • script/generate dm_rspec_scaffold Plataforma Tecnologia, José Valim 2009
  • script/generate dm_rspec_scaffold DataMapper Rspec ERB Plataforma Tecnologia, José Valim 2009
  • Agnosticismo? Plataforma Tecnologia, José Valim 2009
  • Remarkable + Inherited Resources + Formtastic Plataforma Tecnologia, José Valim 2009
  • Remarkable + Inherited Resources + Formtastic = Plataforma Tecnologia, José Valim 2009
  • Remarkable + Inherited Resources + Formtastic = script/generate remarkable_inherited_formta stic_scaffold Plataforma Tecnologia, José Valim 2009
  • Remarkable + Inherited Resources + Formtastic = script/generate remarkable_inherited_formta stic_scaffold FAIL? Plataforma Tecnologia, José Valim 2009
  • script/generate nifty_scaffold script/generate dry_scaffold Plataforma Tecnologia, José Valim 2009
  • Pouca reutilização de código Plataforma Tecnologia, José Valim 2009
  • Sem divisão de responsabilidades Plataforma Tecnologia, José Valim 2009
  • Plataforma Tecnologia, José Valim 2009
  • Por quê Thor? Plataforma Tecnologia, José Valim 2009
  • class AppGenerator < Thor::Group def create_app_folders empty_directory “app/models” empty_directory “app/controllers” end def copy_config_files copy_file “config/routes.rb” end end Plataforma Tecnologia, José Valim 2009
  • class AppGenerator < Thor::Group def create_app_folders empty_directory “app/models” empty_directory “app/controllers” end def copy_config_files copy_file “config/routes.rb” end end Plataforma Tecnologia, José Valim 2009
  • class AppGenerator < Thor::Group def create_app_folders empty_directory “app/models” empty_directory “app/controllers” end def copy_config_files copy_file “config/routes.rb” end end Plataforma Tecnologia, José Valim 2009
  • Execute tudo... AppGenerator.start Plataforma Tecnologia, José Valim 2009
  • ou selecione! app_tasks = AppGenerator.new app_tasks.create_app_folders app_tasks.copy_config_files Plataforma Tecnologia, José Valim 2009
  • Herança Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ScaffoldGenerator < ResourceGenerator # generation end end Plataforma Tecnologia, José Valim 2009
  • Argumentos Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold User name:string --no-layout -o datamapper -t rspec Plataforma Tecnologia, José Valim 2009
  • self.class_name script/generate scaffold User name:string --no-layout -o datamapper -t rspec Plataforma Tecnologia, José Valim 2009
  • self.attributes script/generate scaffold User name:string --no-layout -o datamapper -t rspec Plataforma Tecnologia, José Valim 2009
  • Opções Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold User name:string --no-layout -o datamapper -t rspec Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold User name:string --no-layout -o datamapper -t rspec self.options[:orm] #=> “datamapper” Plataforma Tecnologia, José Valim 2009
  • script/generate scaffold User name:string --no-layout -o datamapper -t rspec self.options.layout? #=> false Plataforma Tecnologia, José Valim 2009
  • :type => :string --orm=activerecord Plataforma Tecnologia, José Valim 2009
  • :type => :numeric --rails=3.0 Plataforma Tecnologia, José Valim 2009
  • :type => :boolean --layout --no-helpers Plataforma Tecnologia, José Valim 2009
  • :type => :array --actions=index new create Plataforma Tecnologia, José Valim 2009
  • :type => :hash --actions=name:string age:index Plataforma Tecnologia, José Valim 2009
  • :required, :desc, :optional Plataforma Tecnologia, José Valim 2009
  • Invocações Plataforma Tecnologia, José Valim 2009
  • class ResourceGenerator < Thor::Group def run_dependencies invoke ModelGenerator invoke ControllerGenerator invoke “testunit:resource” end end Plataforma Tecnologia, José Valim 2009
  • class ResourceGenerator < Thor::Group def run_dependencies invoke ModelGenerator invoke ControllerGenerator invoke “testunit:resource” end end Plataforma Tecnologia, José Valim 2009
  • invoke ModelGenerator Plataforma Tecnologia, José Valim 2009
  • invoke ModelGenerator ModelGenerator.start Plataforma Tecnologia, José Valim 2009
  • invoke ModelGenerator != ModelGenerator.start Plataforma Tecnologia, José Valim 2009
  • Shell Plataforma Tecnologia, José Valim 2009
  • Gerencia input e output Plataforma Tecnologia, José Valim 2009
  • Thor::Shell::Basic Plataforma Tecnologia, José Valim 2009
  • Thor::Shell::Basic Apenas para Windows Plataforma Tecnologia, José Valim 2009
  • Thor::Shell::Color Plataforma Tecnologia, José Valim 2009
  • Thor::Shell::Web Plataforma Tecnologia, José Valim 2009
  • Thor::Shell::Web ? Plataforma Tecnologia, José Valim 2009
  • Plataforma Tecnologia, José Valim 2009
  • Qual a diferença entre geradores de código e tarefas (como rake)? Plataforma Tecnologia, José Valim 2009
  • Geradores de código são um grupo de tarefas Plataforma Tecnologia, José Valim 2009
  • class Alphabet < Thor def a print :a end def b print :b end end $ thor alphabet:a #=> “a” $ thor alphabet:b #=> “b” Plataforma Tecnologia, José Valim 2009
  • class Alphabet < Thor def a print :a end def b print :b end end $ thor alphabet:a #=> “a” $ thor alphabet:b #=> “b” Plataforma Tecnologia, José Valim 2009
  • class Alphabet < Thor def a print :a end def b print :b end end $ thor alphabet:a #=> “a” $ thor alphabet:b #=> “b” Plataforma Tecnologia, José Valim 2009
  • class Alphabet < Thor::Group def a print :a end def b print :b end end $ thor alphabet #=> “ab” Plataforma Tecnologia, José Valim 2009
  • class Alphabet < Thor::Group def a print :a end def b print :b end end $ thor alphabet #=> “ab” Plataforma Tecnologia, José Valim 2009
  • Thor Plataforma Tecnologia, José Valim 2009
  • Thor = Plataforma Tecnologia, José Valim 2009
  • Thor = Rake Plataforma Tecnologia, José Valim 2009
  • Thor = Rake + Sake Plataforma Tecnologia, José Valim 2009
  • Thor = Rake + Sake + Rubigen Plataforma Tecnologia, José Valim 2009
  • Thor = Rake + Sake + Rubigen + RailsTemplates Plataforma Tecnologia, José Valim 2009
  • Thor::Actions == RailsTemplates Plataforma Tecnologia, José Valim 2009
  • create_file “users_helper.rb”, <<-END module UsersHelper end END Plataforma Tecnologia, José Valim 2009
  • copy_file “doc/README”, “doc/README” copy_file “doc/README” Plataforma Tecnologia, José Valim 2009
  • Thor.source_root copy_file “doc/README”, “doc/README” copy_file “doc/README” Plataforma Tecnologia, José Valim 2009
  • Dir.pwd copy_file “doc/README”, “doc/README” copy_file “doc/README” Plataforma Tecnologia, José Valim 2009
  • get “http://pastie.org/2.txt”, “pastie.rb” get “http://pastie.org/2.txt” do |content| content =~ /class (w)+/ “#{$1 || 'content'}.rb” end Plataforma Tecnologia, José Valim 2009
  • template “doc/README”, “doc/README” template “doc/README.tt” Plataforma Tecnologia, José Valim 2009
  • chmod “script/*”, 755 Plataforma Tecnologia, José Valim 2009
  • prepend_file “environments/test.rb” “config.gem "rspec"” prepend_file “environments/test.rb” do “config.gem "rspec"” end Plataforma Tecnologia, José Valim 2009
  • append_file “environments/test.rb” “config.gem "rspec"” append_file “environments/test.rb” do “config.gem "rspec"” end Plataforma Tecnologia, José Valim 2009
  • flag = "Rails::Initializer.run do |config|n" inject_into_file "config/environment.rb", "config.gem :thor", :after => flag Plataforma Tecnologia, José Valim 2009
  • inject_into_class “users_controller.rb” UsersController, “before_filter :authenticate” Plataforma Tecnologia, José Valim 2009
  • remove_file “doc/README” Plataforma Tecnologia, José Valim 2009
  • empty_directory “doc” Plataforma Tecnologia, José Valim 2009
  • directory “script”, “script” directory “script” Plataforma Tecnologia, José Valim 2009
  • inside “doc” do copy_file “README” end Plataforma Tecnologia, José Valim 2009
  • apply "http://gist.github.com/103208.txt" Plataforma Tecnologia, José Valim 2009
  • run “ln -s ~/edge rails” Plataforma Tecnologia, José Valim 2009
  • Actions específicas do Rails em: Rails::Generators::Actions Plataforma Tecnologia, José Valim 2009
  • Thor unifica APIs de geradores de código, tarefas e templates do Rails Plataforma Tecnologia, José Valim 2009
  • Rails::Generators Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • module Rails::Generators class ControllerGenerator < NamedBase argument :actions, :type => :array, :default => [] check_class_collision :suffix => "Controller" def create_controller_files destination = File.join('app/controllers', class_path, "#{file_name}_controller.rb") template 'controller.rb', destination end hook_for :template_engine, :test_framework, :helper end end Plataforma Tecnologia, José Valim 2009
  • hook_for :test_framework Plataforma Tecnologia, José Valim 2009
  • hook_for :test_framework --test_framework=rspec Plataforma Tecnologia, José Valim 2009
  • hook_for :test_framework --test_framework=rspec invoke “rspec:controller” Plataforma Tecnologia, José Valim 2009
  • Thorfile Plataforma Tecnologia, José Valim 2009
  • Thor::RakeCompat Plataforma Tecnologia, José Valim 2009
  • require File.join(File.dirname(__FILE__), 'config', 'boot') require 'rake/testtask' require 'rake/rdoctask' require 'thor/rake_compat' class Default < Thor include Thor::RakeCompat require 'rails/tasks' end Plataforma Tecnologia, José Valim 2009
  • require File.join(File.dirname(__FILE__), 'config', 'boot') require 'rake/testtask' require 'rake/rdoctask' require 'thor/rake_compat' class Default < Thor include Thor::RakeCompat require 'rails/tasks' end Plataforma Tecnologia, José Valim 2009
  • require File.join(File.dirname(__FILE__), 'config', 'boot') require 'rake/testtask' require 'rake/rdoctask' require 'thor/rake_compat' class Default < Thor include Thor::RakeCompat require 'rails/tasks' end Plataforma Tecnologia, José Valim 2009
  • require File.join(File.dirname(__FILE__), 'config', 'boot') require 'rake/testtask' require 'rake/rdoctask' require 'thor/rake_compat' class Default < Thor include Thor::RakeCompat require 'rails/tasks' end Plataforma Tecnologia, José Valim 2009
  • Show me the code! Plataforma Tecnologia, José Valim 2009
  • ?! @josevalim http://plataformatec.com.br jose@plataformatec.com.br Plataforma Tecnologia, José Valim 2009
  • blog.plataformatec.com.br @josevalim http://plataformatec.com.br jose@plataformatec.com.br Plataforma Tecnologia, José Valim 2009