diff options
author | Philip Arndt <parndt@gmail.com> | 2010-08-09 16:47:56 +1200 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2010-08-09 16:47:56 +1200 |
commit | 837ea01a34a7dddeefe8086b2c6fc28e9a14616c (patch) | |
tree | 26c3c55c9026518de8b0626001cc55116bc5c87e /generators/refinery_blog | |
parent | 9a8b95e9aa71529d7b4173a3afce49b199a60615 (diff) | |
download | refinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.tar.gz refinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.tar.bz2 refinerycms-blog-837ea01a34a7dddeefe8086b2c6fc28e9a14616c.zip |
Initial commit - you can create, edit and delete a blog post and it respects the fact that it is draft or not.
Diffstat (limited to 'generators/refinery_blog')
-rw-r--r-- | generators/refinery_blog/refinery_blog_generator.rb | 46 | ||||
-rw-r--r-- | generators/refinery_blog/templates/migration.rb | 27 | ||||
-rw-r--r-- | generators/refinery_blog/templates/seed.rb | 16 |
3 files changed, 89 insertions, 0 deletions
diff --git a/generators/refinery_blog/refinery_blog_generator.rb b/generators/refinery_blog/refinery_blog_generator.rb new file mode 100644 index 0000000..0739498 --- /dev/null +++ b/generators/refinery_blog/refinery_blog_generator.rb @@ -0,0 +1,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)
\ No newline at end of file diff --git a/generators/refinery_blog/templates/migration.rb b/generators/refinery_blog/templates/migration.rb new file mode 100644 index 0000000..2ebd06e --- /dev/null +++ b/generators/refinery_blog/templates/migration.rb @@ -0,0 +1,27 @@ +class <%= migration_name %> < ActiveRecord::Migration + + def self.up<% tables.each do |table| %> + create_table :<%= table[:table_name] %> do |t| +<% table[:attributes].each do |attribute| -%> + t.<%= attribute.type %> :<%= attribute.name %> +<% end -%> + t.timestamps + end + + add_index :<%= table[:table_name] %>, :id +<% end -%> + + load(Rails.root.join('db', 'seeds', 'refinerycms_blog.rb').to_s) + end + + def self.down + UserPlugin.destroy_all({:name => "refinerycms_blog"}) + + Page.delete_all({:link_url => "/blog"}) + +<% tables.each do |table| -%> + drop_table :<%= table[:table_name] %> +<% end -%> + end + +end diff --git a/generators/refinery_blog/templates/seed.rb b/generators/refinery_blog/templates/seed.rb new file mode 100644 index 0000000..228fc7b --- /dev/null +++ b/generators/refinery_blog/templates/seed.rb @@ -0,0 +1,16 @@ +User.find(:all).each do |user| + user.plugins.create(:name => "<%= singular_name %>", + :position => (user.plugins.maximum(:position) || -1) +1) +end + +page = Page.create( + :title => "Blog", + :link_url => "/blog", + :deletable => false, + :position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1), + :menu_match => "^/blogs?(\/|\/.+?|)$" +) + +RefinerySetting.find_or_set(:default_page_parts, %w(Body Side\ Body)).each do |default_page_part| + page.parts.create(:title => default_page_part, :body => nil) +end |