Class: Comfy::Generators::BlogGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration, Thor::Actions
Defined in:
lib/generators/comfy/blog/blog_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



12
13
14
# File 'lib/generators/comfy/blog/blog_generator.rb', line 12

def self.next_migration_number(dirname)
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#generate_initializationObject



28
29
30
31
# File 'lib/generators/comfy/blog/blog_generator.rb', line 28

def generate_initialization
  copy_file "config/initializers/comfy_blog.rb",
    "config/initializers/comfy_blog.rb"
end

#generate_migrationObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/comfy/blog/blog_generator.rb', line 16

def generate_migration
  destination   = File.expand_path("db/migrate/01_create_blog.rb", destination_root)
  migration_dir = File.dirname(destination)
  destination   = self.class.migration_exists?(migration_dir, "create_blog")

  if destination
    puts "\e[0m\e[31mFound existing create_blog migration. Remove it if you want to regenerate.\e[0m"
  else
    migration_template "db/migrate/01_create_blog.rb", "db/migrate/create_blog.rb"
  end
end

#generate_routingObject



33
34
35
36
37
38
39
# File 'lib/generators/comfy/blog/blog_generator.rb', line 33

def generate_routing
  route_string = <<-RUBY.strip_heredoc
    comfy_route :blog_admin, path: "/admin"
    comfy_route :blog, path: "/blog"
  RUBY
  route route_string
end

#generate_viewsObject



41
42
43
# File 'lib/generators/comfy/blog/blog_generator.rb', line 41

def generate_views
  directory "app/views/comfy/blog", "app/views/comfy/blog"
end

#show_readmeObject



45
46
47
# File 'lib/generators/comfy/blog/blog_generator.rb', line 45

def show_readme
  readme "lib/generators/comfy/blog/README"
end