first and unfinished draft of the import tool
This commit is contained in:
parent
1e1c3bd97b
commit
39886427e0
1
.gitignore
vendored
1
.gitignore
vendored
@ -25,3 +25,4 @@ tmp/*
|
||||
Capfile
|
||||
config/deploy.rb
|
||||
perf/test.rb
|
||||
sites
|
||||
|
39
Gemfile
39
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
|
||||
# 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
|
89
Gemfile.lock
89
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
|
||||
|
@ -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
|
||||
|
||||
|
3
doc/TODO
3
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
|
||||
|
@ -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'
|
||||
|
||||
|
3
lib/locomotive/import.rb
Normal file
3
lib/locomotive/import.rb
Normal file
@ -0,0 +1,3 @@
|
||||
require 'locomotive/import/job'
|
||||
require 'locomotive/import/site'
|
||||
require 'locomotive/import/content_types'
|
47
lib/locomotive/import/content_types.rb
Normal file
47
lib/locomotive/import/content_types.rb
Normal file
@ -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
|
54
lib/locomotive/import/job.rb
Normal file
54
lib/locomotive/import/job.rb
Normal file
@ -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
|
17
lib/locomotive/import/site.rb
Normal file
17
lib/locomotive/import/site.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user