aboutsummaryrefslogtreecommitdiffstats
path: root/generators/refinery_blog/refinery_blog_generator.rb
blob: 073949863479c5f5310c008b92f462d61edb5252 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class RefineryBlogGenerator < Rails::Generator::NamedBase

  def initialize(*runtime_args)
    # set argument for the user.
    runtime_args[0] = %w(refinerycms_blog)
    super(*runtime_args)
  end

  def banner
    "Usage: script/generate refinery_blog"
  end

  def manifest
    tables = %w(posts comments categories).map{|t| "blog_#{t}"}
    record do |m|
      m.template('seed.rb', 'db/seeds/refinerycms_blog.rb')

      m.migration_template('migration.rb', 'db/migrate',
        :migration_file_name => "create_blog_structure",
        :assigns => {
          :migration_name => "CreateBlogStructure",
          :tables => [{
            :table_name => tables.first,
            :attributes => [
              Rails::Generator::GeneratedAttribute.new("title", "string"),
              Rails::Generator::GeneratedAttribute.new("body", "text"),
              Rails::Generator::GeneratedAttribute.new("draft", "boolean")
            ]
          },{
            :table_name => tables.second,
            :attributes => [
              Rails::Generator::GeneratedAttribute.new("name", "string"),
              Rails::Generator::GeneratedAttribute.new("email", "string"),
              Rails::Generator::GeneratedAttribute.new("body", "text")
            ]
          },{
            :table_name => tables.third,
            :attributes => [
              Rails::Generator::GeneratedAttribute.new("title", "string")
            ]
          }]
        })
    end
  end

end if defined?(Rails::Generator::NamedBase)