· 1 min read
Screencast: Eigene Rails 3 Generatoren erstellen
Download:
Download(14 MB, 10:07) Alternativer Downloadfür iPod & Apple TV(13.8 MB, 10:07)
Resourcen:
Quellcode:
[bash] rails g generator —help rails g generator layout rails g layout —help rails g layout admin rails g layout foo —skip-stylesheet [/bash]
[ruby] # lib/generators/layout/layout_generator.rb class LayoutGenerator < Rails::Generators::Base source_root File.expand_path(‘../templates’, __FILE__) argument :layout_name, :type => :string, :default => “application” class_option :stylesheet, :type => :boolean, :default => true, :desc => “Include stylesheet file.” def generate_layout copy_file “stylesheet.css”, “public/stylesheets/#{file_name}.css” if options.stylesheet? template “layout.html.erb”, “app/views/layouts/#{file_name}.html.erb” end private def file_name layout_name.underscore end end [/ruby]
[html] # lib/generators/layout/templates/layout.html.erb