diff --git a/.gitignore b/.gitignore index 851f8c32..11e701b9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ tmp/* Capfile config/deploy.rb perf/test.rb +sites diff --git a/Gemfile b/Gemfile index 45efc228..12cd6b78 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,7 @@ gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git' gem 'jeweler' gem 'delayed_job', '2.1.0.pre2' gem 'delayed_job_mongoid', '1.0.0.rc' +gem 'rubyzip' # Development environment group :development do @@ -39,22 +40,22 @@ group :test, :development do gem 'ruby-debug' end -group :test do - gem 'autotest' - gem 'growl-glue' - gem 'rspec-rails', '2.0.0.beta.19' - gem 'factory_girl_rails' - gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git' - gem 'pickle-mongoid' - gem 'capybara' - - # would be nice.. - # gem 'capybara-envjs' - - gem 'database_cleaner' - gem 'cucumber' - gem 'cucumber-rails' - gem 'spork' - gem 'launchy' - gem 'mocha', :git => 'git://github.com/floehopper/mocha.git' -end \ No newline at end of file +# group :test do +# gem 'autotest' +# gem 'growl-glue' +# gem 'rspec-rails', '2.0.0.beta.19' +# gem 'factory_girl_rails' +# gem 'pickle', :git => 'http://github.com/ianwhite/pickle.git' +# gem 'pickle-mongoid' +# gem 'capybara' +# +# # would be nice.. +# # gem 'capybara-envjs' +# +# gem 'database_cleaner' +# gem 'cucumber' +# gem 'cucumber-rails' +# gem 'spork' +# gem 'launchy' +# gem 'mocha', :git => 'git://github.com/floehopper/mocha.git' +# end \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index c580f383..0d35c9a9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,3 @@ -GIT - remote: git://github.com/floehopper/mocha.git - revision: e0a00a7 - specs: - mocha (0.9.8.20100819090654) - rake - GIT remote: git://github.com/locomotivecms/custom_fields.git revision: 89c4d7d @@ -18,16 +11,6 @@ GIT specs: liquid (2.1.3) -GIT - remote: http://github.com/ianwhite/pickle.git - revision: 65ba8b7 - specs: - pickle (0.4.2) - cucumber (>= 0.8) - rake - rspec (>= 1.3) - yard - GEM remote: http://rubygems.org/ specs: @@ -62,7 +45,6 @@ GEM activesupport (3.0.0) arel (1.0.1) activesupport (~> 3.0.0) - autotest (4.3.2) aws (2.3.21) http_connection uuidtools @@ -71,30 +53,13 @@ GEM bson (1.0.4) bson_ext (1.0.4) builder (2.1.2) - capybara (0.3.9) - culerity (>= 0.2.4) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (>= 0.0.3) carrierwave (0.5.0.beta2) activesupport (>= 3.0.0.beta4) cgi_multipart_eof_fix (2.5.0) columnize (0.3.1) configuration (1.1.0) crack (0.1.8) - cucumber (0.9.0) - builder (~> 2.1.2) - diff-lcs (~> 1.1.2) - gherkin (~> 2.2.2) - json (~> 1.4.6) - term-ansicolor (~> 1.0.5) - cucumber-rails (0.3.2) - cucumber (>= 0.8.0) - culerity (0.2.12) daemons (1.1.0) - database_cleaner (0.5.2) delayed_job (2.1.0.pre2) activesupport (~> 3.0) daemons @@ -104,27 +69,15 @@ GEM devise (1.1.2) bcrypt-ruby (~> 2.1.2) warden (~> 0.10.7) - diff-lcs (1.1.2) erubis (2.6.6) abstract (>= 1.0.0) - factory_girl (1.3.2) - factory_girl_rails (1.0) - factory_girl (~> 1.3) - rails (>= 3.0.0.beta4) fastthread (1.0.7) - ffi (0.6.3) - rake (>= 0.8.7) formtastic-rails3 (1.0.0.beta3) actionpack (>= 3.0.0beta3) activesupport (>= 3.0.0beta3) gem_plugin (0.2.3) gemcutter (0.6.1) - gherkin (2.2.3) - json (~> 1.4.6) - term-ansicolor (~> 1.0.5) - trollop (~> 1.16.2) git (1.2.5) - growl-glue (1.0.7) haml (3.0.18) has_scope (0.5.0) heroku (1.10.5) @@ -142,7 +95,6 @@ GEM gemcutter (>= 0.1.0) git (>= 1.2.5) rubyforge (>= 2.0.0) - json (1.4.6) json_pure (1.4.6) launchy (0.3.7) configuration (>= 0.0.5) @@ -172,10 +124,6 @@ GEM daemons (>= 1.0.3) fastthread (>= 1.0.1) gem_plugin (>= 0.2.3) - nokogiri (1.4.3.1) - pickle-mongoid (0.1.6) - mongoid (>= 2.0.0.beta.7) - pickle (>= 0.3.0) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) @@ -200,17 +148,6 @@ GEM rest-client (1.4.2) mime-types (>= 1.16) rmagick (2.12.2) - rspec (2.0.0.beta.19) - rspec-core (= 2.0.0.beta.19) - rspec-expectations (= 2.0.0.beta.19) - rspec-mocks (= 2.0.0.beta.19) - rspec-core (2.0.0.beta.19) - rspec-expectations (2.0.0.beta.19) - diff-lcs (>= 1.1.2) - rspec-mocks (2.0.0.beta.19) - rspec-rails (2.0.0.beta.19) - rspec (= 2.0.0.beta.19) - webrat (>= 0.7.2.beta.1) ruby-debug (0.10.3) columnize (>= 0.1) ruby-debug-base (~> 0.10.3.0) @@ -219,27 +156,15 @@ GEM rubyforge (2.0.4) json_pure (>= 1.1.7) rubyzip (0.9.4) - selenium-webdriver (0.0.28) - ffi (>= 0.6.1) - json_pure - rubyzip - spork (0.8.4) - term-ansicolor (1.0.5) thor (0.14.1) treetop (1.4.8) polyglot (>= 0.3.1) - trollop (1.16.2) tzinfo (0.3.23) uuidtools (2.1.1) warden (0.10.7) rack (>= 1.0.0) - webrat (0.7.2.beta.1) - nokogiri (>= 1.2.0) - rack (>= 1.0) - rack-test (>= 0.5.3) will_paginate (3.0.pre2) xml-simple (1.0.12) - yard (0.6.1) PLATFORMS ruby @@ -247,41 +172,29 @@ PLATFORMS DEPENDENCIES RedCloth actionmailer-with-request - autotest aws bson_ext (= 1.0.4) - capybara carrierwave (= 0.5.0.beta2) cgi_multipart_eof_fix - cucumber - cucumber-rails custom_fields! - database_cleaner delayed_job (= 2.1.0.pre2) delayed_job_mongoid (= 1.0.0.rc) devise (= 1.1.2) - factory_girl_rails fastthread formtastic-rails3 (= 1.0.0.beta3) - growl-glue haml (= 3.0.18) heroku httparty (= 0.6.1) inherited_resources (= 1.1.2) jeweler - launchy liquid! mimetype-fu - mocha! mongo_session_store (= 2.0.0.pre) mongoid (= 2.0.0.beta.17) mongoid_acts_as_tree (= 0.1.5) mongrel - pickle! - pickle-mongoid rails (= 3.0.0) rmagick (= 2.12.2) - rspec-rails (= 2.0.0.beta.19) ruby-debug - spork + rubyzip warden diff --git a/README.textile b/README.textile index b14f0ecc..ba80e2b9 100644 --- a/README.textile +++ b/README.textile @@ -8,7 +8,7 @@ If we have to give only 5 main features to describe our application, there will * nice looking UI (see http://www.locomotiveapp.org for some screenshots) * flexible content types * playing smoothly with Heroku and MongoHQ -* inline editing (coming soon) +* inline editing (beta) h2. Strategy / Development status @@ -19,12 +19,13 @@ h2. Gems Here is a short list of main gems used in the application. -* Rails 3 RC -* Mongoid 2.0.0.beta 16 (with MongoDB 1.6) +* Rails 3.0 +* Mongoid 2.0.0.beta 17 (with MongoDB 1.6) * Liquid * Devise * Carrierwave * Haml +* Delayed job h2. Installation diff --git a/doc/TODO b/doc/TODO index 2e1122ee..43155b5a 100644 --- a/doc/TODO +++ b/doc/TODO @@ -18,10 +18,11 @@ BOARD: - edit images (upload new ones, ...etc) => wait for aloha or send them an email ? x customize tinyMCE: no html popup => div popup, nice icons x add images / files inside long text element (back-office side at first ?) +x create a repo for a tool "a la" vision - global regions: keyword in editable element (http://www.mongodb.org/display/DOCS/Updating) -- create a repo for a tool "a la" vision - write my first tutorial about locomotive - asset collections => liquid +- apply http://github.com/flori/json/commit/2c0f8d2c9b15a33b8d10ffcb1959aef54d320b57 - refactor slugify method (use parameterize + create a module) - [content types] the "display column" selector should not include file types diff --git a/lib/locomotive.rb b/lib/locomotive.rb index 8ecf4657..5d15de9a 100644 --- a/lib/locomotive.rb +++ b/lib/locomotive.rb @@ -12,6 +12,7 @@ require 'locomotive/admin_responder' require 'locomotive/routing' require 'locomotive/regexps' require 'locomotive/render' +require 'locomotive/import' require 'mongo_session_store/mongoid' diff --git a/lib/locomotive/import.rb b/lib/locomotive/import.rb new file mode 100644 index 00000000..ae5a73cb --- /dev/null +++ b/lib/locomotive/import.rb @@ -0,0 +1,3 @@ +require 'locomotive/import/job' +require 'locomotive/import/site' +require 'locomotive/import/content_types' \ No newline at end of file diff --git a/lib/locomotive/import/content_types.rb b/lib/locomotive/import/content_types.rb new file mode 100644 index 00000000..a810cd98 --- /dev/null +++ b/lib/locomotive/import/content_types.rb @@ -0,0 +1,47 @@ +module Locomotive + module Import + module ContentTypes + + def self.process(database, site, theme_path) + content_types = database['site']['content_types'] + + return if content_types.nil? + + content_types.each do |name, attributes| + content_type = site.content_types.where(:slug => attributes['slug']).first + + content_type ||= self.create_content_type(site, attributes.merge(:name => name)) + + self.add_or_update_fields(content_type, attributes['fields']) + + content_type.save + + puts "content_type = #{content_type.inspect}" + + site.reload + end + end + + def self.create_content_type(site, data) + attributes = { :order_by => 'manually' }.merge(data) + + attributes.delete_if { |name, value| %w{fields contents}.include?(name) } + + site.content_types.build(attributes) + end + + def self.add_or_update_fields(content_type, fields) + fields.each do |name, data| + attributes = { :_name => name, :kind => 'String' }.merge(data).symbolize_keys + + field = content_type.content_custom_fields.detect { |f| f._name == attributes[:_name] } + + field ||= content_type.content_custom_fields.build(attributes) + + field.attributes = attributes + end + end + + end + end +end \ No newline at end of file diff --git a/lib/locomotive/import/job.rb b/lib/locomotive/import/job.rb new file mode 100644 index 00000000..d5ca8913 --- /dev/null +++ b/lib/locomotive/import/job.rb @@ -0,0 +1,54 @@ +require 'zip/zipfilesystem' + +module Locomotive + module Import + class Job + + def initialize(theme_file, site = nil, options = {}) + raise "Theme zipfile not found" unless File.exists?(theme_file) + + @theme_file = theme_file + @site = site + @options = Hash.new(true).merge(options) + end + + def perform + self.unzip! + + raise "No database.yml found in the theme zipfile" if @database.nil? + + Locomotive::Import::Site.process(@database, @site, @theme_path) + + Locomotive::Import::ContentTypes.process(@database, @site, @theme_path) + end + + protected + + def unzip! + Zip::ZipFile.open(@theme_file) do |zipfile| + destination_path = File.join(Rails.root, 'tmp', 'themes', @site.id.to_s) + + zipfile.each do |entry| + next if entry.name =~ /__MACOSX/ + + if entry.name =~ /database.yml$/ + + @database = YAML.load(zipfile.read(entry.name)) + @theme_path= File.join(destination_path, entry.name.gsub('database.yml', '')) + + next + end + + puts entry.name + # + # FileUtils.mkdir_p(File.dirname(File.join(destination_path, entry.name))) + # + # zipfile.extract(entry, File.join(destination_path, entry.name)) + end + end + + end + + end + end +end \ No newline at end of file diff --git a/lib/locomotive/import/site.rb b/lib/locomotive/import/site.rb new file mode 100644 index 00000000..af3084c0 --- /dev/null +++ b/lib/locomotive/import/site.rb @@ -0,0 +1,17 @@ +module Locomotive + module Import + module Site + + def self.process(database, site, theme_path) + attributes = database['site'].clone.delete_if { |name, value| %w{pages content_types asset_collections}.include?(name) } + + site.attributes = attributes + + site.save! + + puts "site errors = #{site.errors.inspect}" + end + + end + end +end \ No newline at end of file