Slide 1

Slide 1 text

or: How I Learned to Stop Worrying and Love the Automation

Slide 2

Slide 2 text

Our Awesomeness

Slide 3

Slide 3 text

Our Awesomeness Our Awesomeness ‣ We Maintain... ‣ ruby-progressbar ‣ chicken_soup ‣ apple_cart ‣ validates_truthiness

Slide 4

Slide 4 text

Our Awesomeness Our Awesomeness ‣ Contributed To... ‣ rails ‣ rspec ‣ cucumber-rails ‣ bundler ‣ simple_form ‣ capybara ‣ chronic ‣ wizardly ‣ fuubar ‣ fuubar-cucumber ‣ rspec-rails-mocha ‣ thor ‣ useragent

Slide 5

Slide 5 text

Overview

Slide 6

Slide 6 text

Overview ‣ Two Paths ‣ Template Files ‣ AppBuilder Files Overview

Slide 7

Slide 7 text

Overview ‣ Rails Templates ‣ The process of auto-generating a Rails app ‣ Template Files ‣ A specific method of auto-generating a Rails app Terminology

Slide 8

Slide 8 text

Template Files

Slide 9

Slide 9 text

Template Files ‣ Straightforward ‣ Resembles a Simple Script ‣ Been Around the Block ‣ Since Rails 1.0 Template Files

Slide 10

Slide 10 text

Template Files ‣ Extremely Popular ‣ Used By Majority of Template Gems ‣ Suspenders ‣ Prologue ‣ Hobo < 1.3 ‣ Apple Cart < 1.0 Template Files

Slide 11

Slide 11 text

Template Files ‣ It’s extremely easy ‣ It gets the job done Why?

Slide 12

Slide 12 text

Template Files ‣ Rails::Generators::Action Helper Methods ‣ gem ‣ generate ‣ git ‣ initializer ‣ lib ‣ log ‣ plugin ‣ rake ‣ rakefile ‣ readme ‣ route ‣ vendor ‣ empty_directory_with_gitkeep

Slide 13

Slide 13 text

Template Files ‣ Thor::Actions Helper Methods ‣ yes?/no? ‣ file_collision ‣ mute ‣ say (with feeling) ‣ create_file ‣ get ‣ insert_into_file ‣ comment/uncomment lines ‣ pick items from a list

Slide 14

Slide 14 text

say "Removing Extra Rails Files..." remove_file "public/index.html" remove_file "public/images/rails.png" # my_template.rb Template Files Simple Example

Slide 15

Slide 15 text

$ rails new my_cool_app # from the command line Template Files How Will This Work? $ rails new my_cool_app ➥ -m http://gist.github.com/my_template.rb -m my_template.rb

Slide 16

Slide 16 text

Template Files How Will This Work?

Slide 17

Slide 17 text

if( yes? "Would you like me to .example your .yml file?" ) end # my_template_2.rb Template Files Intermediate Example copy_file "config/database.yml", "config/database.yml.example" remove_file "config/database.yml" link_file "some_path/database.yml.postgres", "config/database.yml" append_to_file ".gitignore" do "config/database.yml" end

Slide 18

Slide 18 text

test_framework = ask "Which testing framework would you like?" # my_template_3.rb Template Files Advanced Example if test_framework == "rspec" elsif test_framework == "foo" ... gem "rspec-rails", :group => :test run "rvm use ruby-1.9.2@#{app_name}" run "bundle install" copy_file ".rspec", :force => true generate "rspec:install" directory "spec/support" end

Slide 19

Slide 19 text

Template Files ‣ Never do manually what a generator will do for you. ‣ Keep things script-like. Tips

Slide 20

Slide 20 text

App Builders

Slide 21

Slide 21 text

App Builders ‣ Hooks directly into rails new instead of post-processing ‣ Helps to modularize your application generation ‣ More useful for major Rails customizations App Builders

Slide 22

Slide 22 text

App Builders ‣ AppGenerator contains pass-through methods Background $ rails new def create_database build(:database_yaml) end def database_yaml copy_file "database.yml" end ‣ Argument becomes the method called on the AppBuilder ➤ Rails::Generators::AppGenerator.start

Slide 23

Slide 23 text

$ rails new my_cool_app # from the command line App Builders How Will This Work? -m my_template.rb -b my_builder.rb

Slide 24

Slide 24 text

Revisit .example... Example App Builders if( yes? "Would you like me to .example your .yml file?" ) copy_file "config/database.yml", "config/database.yml.example" remove_file "config/database.yml" link_file "some_path/database.yml.postgres", "config/database.yml" append_to_file ".gitignore" do "config/database.yml" end end

Slide 25

Slide 25 text

Revisit .example... Example App Builders if( yes? "Would you like me to .example your .yml file?" ) copy_file "config/database.yml", "config/database.yml.example" remove_file "config/database.yml" link_file "some_path/database.yml.postgres", "config/database.yml" append_to_file ".gitignore" do "config/database.yml" end end class MyAppBuilder < Rails::AppBuilder def database_yml end end template "config/database.#{@options[:database]}.yml" "config/database.yml.example"

Slide 26

Slide 26 text

Revisit .example... Example App Builders if( yes? "Would you like me to .example your .yml file?" ) link_file "some_path/database.yml.postgres", "config/database.yml" append_to_file ".gitignore" do "config/database.yml" end end class MyAppBuilder < Rails::AppBuilder def database_yml end end template "config/database.#{@options[:database]}.yml" "config/database.yml.example" copy_file "#{dest_root}/config/database.yml.example", "#{dest_root}/config/database.yml"

Slide 27

Slide 27 text

Revisit .example... Example App Builders if( yes? "Would you like me to .example your .yml file?" ) append_to_file ".gitignore" do "config/database.yml" end end class MyAppBuilder < Rails::AppBuilder def database_yml end end template "config/database.#{@options[:database]}.yml" "config/database.yml.example" unless @options[:skip_git] end copy_file "#{dest_root}/config/database.yml.example", "#{dest_root}/config/database.yml"

Slide 28

Slide 28 text

Revisit .example... Example App Builders if( yes? "Would you like me to .example your .yml file?" ) append_to_file ".gitignore" do "config/database.yml" end end class MyAppBuilder < Rails::AppBuilder def database_yml end end template "config/database.#{@options[:database]}.yml" "config/database.yml.example" unless @options[:skip_git] end copy_file "#{dest_root}/config/database.yml.example", "#{dest_root}/config/database.yml" else super

Slide 29

Slide 29 text

def finish_template build(:leftovers) end # app_generator.rb:296 App Builders Playing With Your Leftovers ‣ Not implemented in AppBuilder class MyAppBuilder < AppBuilder def leftovers end end # Do some stuff here... maybe copy RSpec support files? # Create an .rvmrc file?

Slide 30

Slide 30 text

$ rails new my_cool_app -m my_template.rb -b my_builder.rb # from the command line App Builders Combine Them

Slide 31

Slide 31 text

Getting Started

Slide 32

Slide 32 text

Getting Started Getting Started ‣ Helpful Resources ‣ guides.rubyonrails.org ‣ railswizard.org ‣ youvegotrails.com (2.3 templates) ‣ suspenders ‣ prologue ‣ apple_cart ‣ Hobo (hobocentral.net)

Slide 33

Slide 33 text

Our Awesomeness Please Stalk Me Jeff Felchner jefffelchner.com @jfelchner The Kompanee thekompanee.com @thekompanee

Slide 34

Slide 34 text

Thanks!