some docs and a rake task

Oleg committed Apr 30, 2011
commit 5d434f2515f1bceccb6e793aba69f07f7aec2eab
Showing 5 changed files with 35 additions and 8 deletions
README.md +7 -1
@@ @@ -144,7 +144,13 @@ You can put this module in /config/initializers/comfortable\_mexican\_sofa.rb an
Working with Fixtures
---------------------
- TODO
+ Sofa allows you to build entire site using files instead of updating database via admin area. This significantly speeds up initial content population. To enable fixtures go to the initializer and set this: `config.enable_fixtures = true`. You may also change the folder that is used to store fixtures.
+
+ If you run `rails g cms` you should find an example set of fixtures in [/db/cms\_fixtures](https://github.com/twg/comfortable-mexican-sofa/blob/master/db/cms_fixtures). If you run multiple sites, each set of fixtures should be inside a folder named as the hostname of the site. It's optional if you only have one site.
+
+ When fixtures are enabled, database is updated with each request, but only if fixture file is newer than the database entry. Database is also purged of items that are not defined in fixtures. So be careful not to clear out your database by mistake.
+
+ When deploying to a production server don't forget to turn off fixtures. To load them into the database just run this rake task: `rake comfortable_mexican_sofa:fixtures:import`. When running multiple sites specify which one by passing argument like this: `SITE=example.com`.
Active Components
-----------------
Rakefile +1 -4
@@ @@ -11,14 +11,11 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = 'comfortable_mexican_sofa'
- gem.summary = 'ComfortableMexicanSofa is a Rails Engine CMS gem'
+ gem.summary = 'ComfortableMexicanSofa is a powerful micro CMS for Ruby on Rails 3 applications'
gem.description = ''
gem.email = 'oleg@theworkinggroup.ca'
gem.homepage = 'http://github.com/twg/comfortable-mexican-sofa'
gem.authors = ['Oleg Khabarov', 'The Working Group Inc']
- gem.add_dependency('rails', '>=3.0.3')
- gem.add_dependency('active_link_to', '>=0.0.6')
- gem.add_dependency('paperclip', '>=2.3.8')
end
Jeweler::GemcutterTasks.new
rescue LoadError
config/initializers/comfortable_mexican_sofa.rb +2 -2
@@ @@ -37,10 +37,10 @@ ComfortableMexicanSofa.configure do |config|
# Sofa allows you to setup entire site from files. Database is updated with each
# request (if nessesary). Please note that database entries are destroyed if there's
# no corresponding file. Fixtures are disabled by default.
- config.enable_fixtures = false
+ # config.enable_fixtures = false
# Path where fixtures can be located.
- config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
+ # config.fixtures_path = File.expand_path('db/cms_fixtures', Rails.root)
end
generators/cms_generator.rb b/lib/generators/cms_generator.rb +1 -1
@@ @@ -28,7 +28,7 @@ class CmsGenerator < Rails::Generators::Base
end
def generate_cms_seeds
- directory 'db/cms_seeds', 'db/cms_seeds'
+ directory 'db/cms_fixtures', 'db/cms_fixtures'
end
def show_readme
tasks/comfortable_mexican_sofa.rake b/lib/tasks/comfortable_mexican_sofa.rake +24 -0
@@ @@ -0,0 +1,24 @@
+ # Small hack to auto-run migrations during testing
+ namespace :db do
+ task :abort_if_pending_migrations => [:migrate]
+ end
+
+ namespace :comfortable_mexican_sofa do
+ namespace :fixtures do
+
+ desc 'Import Fixture data into database. (options: SITE=example.com)'
+ task :import => :environment do |task, args|
+ site = if ComfortableMexicanSofa.config.enable_multiple_sites
+ Cms::Site.find_by_hostname(args[:site])
+ else
+ Cms::Site.first
+ end
+ abort 'SITE is not found. Aborting.' if !site
+
+ puts "Syncing for #{site.hostname}"
+ ComfortableMexicanSofa::Fixtures.sync(site)
+
+ puts 'Done!'
+ end
+ end
+ end
\ No newline at end of file