Class: WebFeed::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/web_feed/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#generate_appObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/web_feed/install_generator.rb', line 46

def generate_app
  if options.include_models?
    template "models/resource.rb.erb",  "#{Rails.root}/app/models/#{resource}.rb"
    template "models/news.rb.erb",      "#{Rails.root}/app/models/#{news}.rb"
    template "models/keyword.rb.erb",   "#{Rails.root}/app/models/#{keyword}.rb"
  end
  if options.include_controllers?
    template "controllers/resources_controller.rb.erb", "#{Rails.root}/app/controllers/#{resource.pluralize}_controller.rb"
    template "controllers/news_controller.rb.erb",      "#{Rails.root}/app/controllers/#{news.pluralize}_controller.rb"
    template "controllers/keywords_controller.rb.erb",  "#{Rails.root}/app/controllers/#{keyword.pluralize}_controller.rb"
  end
  if options.include_views?
    %w( index new edit _form).each do |file|
      template "views/resources/#{file}.html.erb", "#{Rails.root}/app/views/#{resource.pluralize}/#{file}.html.erb"
    end
    %w( index new edit _form).each do |file|
      template "views/keywords/#{file}.html.erb", "#{Rails.root}/app/views/#{keyword.pluralize}/#{file}.html.erb"
    end
    %w( index show).each do |file|
      template "views/news/#{file}.html.erb",    "#{Rails.root}/app/views/#{news.pluralize}/#{file}.html.erb"
    end
    copy_file "views/layouts/webfeed.html.erb",   "#{Rails.root}/app/views/layouts/webfeed.html.erb"
    template  "views/layouts/_webfeed.html.erb",  "#{Rails.root}/app/views/layouts/_webfeed.html.erb"
    copy_file "stylesheets/webfeed.css",          "#{Rails.root}/app/assets/stylesheets/webfeed.css"
  end
end

#generate_migrationObject



39
40
41
42
43
44
# File 'lib/generators/web_feed/install_generator.rb', line 39

def generate_migration
  generate "web_feed:resource #{resource}"
  generate "web_feed:news #{news}"
  generate "web_feed:keyword #{keyword}"
  generate "web_feed:add_image #{news}"
end

#initObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/web_feed/install_generator.rb', line 19

def init
  route <<-RES
resources :#{resource.pluralize} do
member do 
  post :read
end
  end
    RES
  route <<-NEWS
resources :#{news.pluralize} do
member do
  get "/:title(.:format)", :action => :show, :as => 'read'
  post :publish
  post :unpublish
end
  end
    NEWS
  route "resources :#{keyword.pluralize}"
end