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



14
15
16
# File 'lib/generators/comfy/blog/blog_generator.rb', line 14

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

Instance Method Details

#generate_initializationObject



30
31
32
33
# File 'lib/generators/comfy/blog/blog_generator.rb', line 30

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

#generate_migrationObject



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

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



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

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



43
44
45
# File 'lib/generators/comfy/blog/blog_generator.rb', line 43

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

#show_readmeObject



47
48
49
# File 'lib/generators/comfy/blog/blog_generator.rb', line 47

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