Sha256: f9b0017a5f661c5dd58425da26e8c7768f05636325d3cbe75ce40d37030977b8

Contents?: true

Size: 1.73 KB

Versions: 33

Compression:

Stored size: 1.73 KB

Contents

class BrowserCmsDemoSiteGenerator < Rails::Generator::Base
  
  def source_root
    "/"
  end
  
  def templates_dir(file=nil)
    f = File.expand_path(File.join(File.dirname(__FILE__), "templates", file))
    Cms.scrub_path(f)
  end
  
  def manifest
    record do |m|
      # Copy all public files
      Dir["#{Cms.root}/public/themes/blue_steel/**/*"].each do |f|
        if File.file?(f)
          file_name = f.sub("#{Cms.root}/", '')
          m.directory File.dirname(file_name)
          m.file Cms.scrub_path(f), file_name
        end
      end
      
      m.migration_template templates_dir('migration.rb'), 'db/migrate', :assigns => {
        :data => data,
        :page_templates => page_templates,
        :page_partials => page_partials
      }, :migration_file_name => "load_demo_site_data"
      
    end
  end
  
  def data
    open(File.join(Cms.root, "db", "demo", "data.rb")){|f| f.read}
  end
  
  # Returns an array of strings that are ruby code.
  # Each string is a hash that should be passed to the create_page_template method
  # in the migration
  def page_templates
    Dir["#{Cms.root}/db/demo/page_templates/*.erb"].map do |f|
      name, format, handler = File.basename(f).split('.')
      %Q{create_page_template(:#{name}, 
        :name => "#{name}", :format => "#{format}", :handler => "#{handler}", 
        :body => <<-HTML
#{open(f){|f| f.read}}
      HTML
      )}
    end
  end
  
  def page_partials
    Dir["#{Cms.root}/db/demo/page_partials/*.erb"].map do |f|
      name, format, handler = File.basename(f).split('.')
      %Q{create_page_partial(:#{name}, 
        :name => "#{name}", :format => "#{format}", :handler => "#{handler}", 
        :body => <<-HTML
#{open(f){|f| f.read}}
      HTML
      )}
    end
  end
  
end

Version data entries

33 entries across 33 versions & 10 rubygems

Version Path
SFEley-browsercms-3.0.2 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
buzzware-browsercms-3.0.2 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
coredumplings-browsercms-3.0.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
we5-browsercms-3.0.1.1 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
webficient-browsercms-3.0.1 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
webficient-browsercms-3.0.2 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
webficient-browsercms-3.0.3 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
webficient-browsercms-3.0.4 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.5 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.4 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.3 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
bf4-browsercms-3.1.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
drujensen-browsercms-3.2.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercmsi-3.1.2 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.2 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.1 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercmsi-3.1.1 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercmsi-3.1.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
browsercms-3.1.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb
we5-browsercms-3.1.0 rails_generators/browser_cms_demo_site/browser_cms_demo_site_generator.rb