locomotive_cms 0.0.4 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +15 -13
- data/README.textile +5 -4
- data/app/controllers/admin/api_contents_controller.rb +10 -1
- data/app/controllers/admin/base_controller.rb +2 -2
- data/app/controllers/admin/cross_domain_sessions_controller.rb +7 -4
- data/app/controllers/admin/current_sites_controller.rb +2 -0
- data/app/controllers/admin/imports_controller.rb +13 -19
- data/app/controllers/admin/installation_controller.rb +79 -0
- data/app/controllers/admin/pages_controller.rb +1 -1
- data/app/controllers/admin/passwords_controller.rb +2 -2
- data/app/controllers/admin/sessions_controller.rb +2 -2
- data/app/controllers/admin/sites_controller.rb +2 -0
- data/app/controllers/admin/theme_assets_controller.rb +1 -1
- data/app/controllers/application_controller.rb +1 -1
- data/app/helpers/admin/assets_helper.rb +0 -6
- data/app/helpers/admin/{login_helper.rb → box_helper.rb} +7 -3
- data/app/helpers/admin/custom_fields_helper.rb +2 -2
- data/app/models/asset_collection.rb +15 -3
- data/app/models/content_instance.rb +19 -0
- data/app/models/content_type.rb +21 -3
- data/app/models/extensions/page/tree.rb +63 -7
- data/app/models/page.rb +2 -0
- data/app/models/site.rb +15 -3
- data/app/uploaders/asset_uploader.rb +1 -1
- data/app/uploaders/theme_asset_uploader.rb +12 -1
- data/app/uploaders/theme_uploader.rb +19 -0
- data/app/views/admin/asset_collections/edit.html.haml +2 -2
- data/app/views/admin/asset_collections/new.html.haml +1 -1
- data/app/views/admin/assets/_form.html.haml +2 -2
- data/app/views/admin/content_types/_form.html.haml +2 -2
- data/app/views/admin/content_types/new.html.haml +1 -1
- data/app/views/admin/contents/_form.html.haml +2 -2
- data/app/views/admin/contents/index.html.haml +1 -1
- data/app/views/admin/cross_domain_sessions/new.html.haml +1 -1
- data/app/views/admin/current_sites/_form.html.haml +3 -3
- data/app/views/admin/current_sites/edit.html.haml +1 -1
- data/app/views/admin/errors/no_page.html.haml +1 -0
- data/app/views/admin/errors/no_site.html.haml +1 -0
- data/app/views/admin/imports/new.html.haml +11 -0
- data/app/views/admin/imports/show.html.haml +1 -1
- data/app/views/admin/installation/step_1.html.haml +24 -0
- data/app/views/admin/installation/step_2.html.haml +26 -0
- data/app/views/admin/installation/step_3.html.haml +23 -0
- data/app/views/{layouts/admin → admin/layouts}/application.html.haml +0 -0
- data/app/views/admin/layouts/box.html.haml +21 -0
- data/app/views/admin/layouts/error.html.haml +1 -0
- data/app/views/admin/my_accounts/edit.html.haml +1 -1
- data/app/views/admin/pages/_form.html.haml +2 -3
- data/app/views/admin/pages/_page.html.haml +4 -2
- data/app/views/admin/pages/index.html.haml +1 -1
- data/app/views/admin/passwords/edit.html.haml +2 -2
- data/app/views/admin/passwords/new.html.haml +2 -2
- data/app/views/admin/sessions/new.html.haml +2 -2
- data/app/views/admin/shared/_head.html.haml +4 -5
- data/app/views/admin/shared/menu/_contents.html.haml +1 -1
- data/app/views/admin/sites/_form.html.haml +3 -3
- data/app/views/admin/snippets/_form.html.haml +2 -2
- data/app/views/admin/theme_assets/_form.html.haml +2 -2
- data/app/views/admin/theme_assets/index.html.haml +1 -1
- data/config/application.rb +1 -3
- data/config/assets.yml +96 -0
- data/config/environments/development.rb +1 -6
- data/config/environments/production.rb +1 -1
- data/config/environments/test.rb +1 -5
- data/config/initializers/carrierwave.rb +17 -0
- data/config/initializers/locomotive.rb +14 -0
- data/config/locales/admin_ui_en.yml +33 -1
- data/config/locales/admin_ui_fr.yml +34 -1
- data/config/locales/default_en.yml +1 -0
- data/config/locales/default_fr.yml +1 -0
- data/config/locales/flash.en.yml +1 -0
- data/config/locales/flash.fr.yml +1 -0
- data/config/mongoid.yml +13 -5
- data/config/routes.rb +6 -1
- data/lib/generators/locomotive/install/install_generator.rb +18 -10
- data/lib/generators/locomotive/install/templates/README +23 -13
- data/lib/generators/locomotive/install/templates/locomotive.rb +15 -1
- data/lib/locomotive/carrierwave.rb +1 -0
- data/lib/locomotive/configuration.rb +3 -1
- data/lib/locomotive/custom_fields.rb +0 -1
- data/lib/locomotive/delayed_job.rb +1 -2
- data/lib/locomotive/engine.rb +24 -7
- data/lib/locomotive/heroku.rb +1 -0
- data/lib/locomotive/httparty/webservice.rb +12 -1
- data/lib/locomotive/import.rb +2 -0
- data/lib/locomotive/import/asset_collections.rb +40 -8
- data/lib/locomotive/import/assets.rb +20 -12
- data/lib/locomotive/import/base.rb +46 -0
- data/lib/locomotive/import/content_types.rb +51 -15
- data/lib/locomotive/import/job.rb +106 -11
- data/lib/locomotive/import/logger.rb +13 -0
- data/lib/locomotive/import/pages.rb +79 -26
- data/lib/locomotive/import/site.rb +3 -5
- data/lib/locomotive/import/snippets.rb +6 -8
- data/lib/locomotive/inherited_resources.rb +1 -0
- data/lib/locomotive/liquid/drops/asset_collections.rb +4 -4
- data/lib/locomotive/liquid/drops/contents.rb +21 -16
- data/lib/locomotive/liquid/drops/page.rb +4 -0
- data/lib/locomotive/liquid/filters/html.rb +15 -29
- data/lib/locomotive/liquid/tags/consume.rb +1 -1
- data/lib/locomotive/liquid/tags/nav.rb +48 -17
- data/lib/locomotive/liquid/tags/paginate.rb +3 -3
- data/lib/locomotive/middlewares/fonts.rb +3 -11
- data/lib/locomotive/misc_form_builder.rb +2 -7
- data/lib/locomotive/railties/tasks.rake +16 -0
- data/lib/locomotive/regexps.rb +1 -1
- data/lib/locomotive/render.rb +9 -3
- data/lib/locomotive/routing/site_dispatcher.rb +10 -6
- data/lib/locomotive/version.rb +1 -1
- data/public/images/admin/box/buttons/right_bg.png +0 -0
- data/public/javascripts/admin/aloha/VERSION.txt +1 -1
- data/public/javascripts/admin/aloha/aloha-nodeps.js +140 -101
- data/public/javascripts/admin/aloha/aloha.js +193 -105
- data/public/javascripts/admin/aloha/css/aloha.css +65 -4
- data/public/javascripts/admin/aloha/deps/prettyPhoto/resources/css/prettyPhoto.css +2 -2
- data/public/javascripts/admin/aloha/i18n/de.dict +2 -0
- data/public/javascripts/admin/aloha/i18n/en.dict +2 -0
- data/public/javascripts/admin/aloha/i18n/pl.dict +5 -0
- data/public/javascripts/admin/aloha/images/base.png +0 -0
- data/public/javascripts/admin/aloha/images/base_big.png +0 -0
- data/public/javascripts/admin/aloha/images/base_multi.png +0 -0
- data/public/javascripts/admin/aloha/images/fade_in.png +0 -0
- data/public/javascripts/admin/aloha/images/fade_out.png +0 -0
- data/public/javascripts/admin/aloha/images/gentics_logo.png +0 -0
- data/public/javascripts/admin/aloha/images/grabhandle.png +0 -0
- data/public/javascripts/admin/aloha/images/maximize.png +0 -0
- data/public/javascripts/admin/aloha/images/pin.png +0 -0
- data/public/javascripts/admin/aloha/images/removeformat.png +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.css +86 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.html +44 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/de.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/en.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/fr.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/plugin.js +1 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/product.js +1 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/2xu-wetsuit.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/asics-noosa.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/fivefingers-kso.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/kuota-kueen-k.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/mizuno-wave-musha2.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product.css +69 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product_button.gif +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/simplon-mrt.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trek-fuel-ex.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trisports.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/zoggs-predator.jpg +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/de.dict +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/en.dict +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/fi.dict +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/fr.dict +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/i18n/it.dict +0 -0
- data/public/javascripts/admin/aloha/plugins/{com.example.aloha.DummySave → com.example.aloha.plugins.Save}/plugin.js +0 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.css +48 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.html +69 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/de.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/en.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/plugin.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/i18n/pl.dict +30 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/LinkList.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/delicious.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/i18n/pl.dict +4 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/css/LinkChecker.css +14 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.css +49 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.html +82 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/i18n/en.dict +27 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/plugin.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/proxy.php +235 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.List/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/plugin.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/wordpastehandler.js +7 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/de.dict +1 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/en.dict +1 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/de.dict +2 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/en.dict +2 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/pl.dict +12 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/plugin.js +1 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/table.css +28 -110
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_green.png +0 -0
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_red.png +0 -0
- data/public/javascripts/admin/asset_collections.js +11 -7
- data/public/javascripts/admin/contents.js +3 -1
- data/public/javascripts/admin/site.js +9 -3
- data/public/javascripts/admin/snippets.js +1 -1
- data/public/javascripts/admin/utils.js +5 -3
- data/public/stylesheets/admin/application.css +1 -1
- data/public/stylesheets/admin/box.css +5 -5
- data/public/stylesheets/admin/buttons.css +0 -5
- data/public/stylesheets/admin/formtastic_changes.css +5 -12
- data/public/stylesheets/admin/inline_editor.css +22 -5
- data/public/stylesheets/admin/installation.css +50 -0
- data/public/stylesheets/admin/layout.css +9 -4
- data/public/stylesheets/admin/safari.css +15 -0
- metadata +188 -131
- data/app/controllers/home_controller.rb +0 -7
- data/app/views/admin/snippets/index.html.haml +0 -15
- data/app/views/home/show.html.haml +0 -4
- data/app/views/layouts/admin/box.html.haml +0 -19
- data/app/views/layouts/application.html.haml +0 -7
- data/lib/generators/locomotive/copy_assets/copy_assets_generator.rb +0 -14
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/de.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/en.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/eo.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fi.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fr.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/it.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/plugin.js +0 -7
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/de.dict +0 -20
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/en.dict +0 -20
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/eo.dict +0 -16
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fi.dict +0 -20
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fr.dict +0 -16
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/it.dict +0 -20
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/plugin.js +0 -7
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/css/jquery.autocomplete.css +0 -48
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/deps/jquery.autocomplete.js +0 -1
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressource.js +0 -7
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourcedummy.js +0 -7
- data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourceregistry.js +0 -7
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Loader/plugin.js +0 -1
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/en.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fi.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fr.dict +0 -2
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/person.css +0 -3
- data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/plugin.js +0 -1
- data/public/javascripts/admin/aloha/plugins/simpletable/plugin.js.deactivated +0 -2330
@@ -1,24 +1,26 @@
|
|
1
1
|
module Locomotive
|
2
2
|
module Import
|
3
|
-
|
3
|
+
class Assets < Base
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def process
|
6
|
+
whitelist = self.build_regexps_in_withlist(database['site']['assets']['whitelist']) rescue nil
|
7
7
|
|
8
|
-
|
8
|
+
self.log "white list = #{whitelist.inspect}"
|
9
9
|
|
10
|
-
self.add_theme_assets(
|
10
|
+
self.add_theme_assets(whitelist)
|
11
11
|
|
12
|
-
self.add_other_assets
|
12
|
+
self.add_other_assets
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
protected
|
16
|
+
|
17
|
+
def add_theme_assets(whitelist)
|
16
18
|
%w(images media fonts javascripts stylesheets).each do |kind|
|
17
19
|
Dir[File.join(theme_path, 'public', kind, '**/*')].each do |asset_path|
|
18
20
|
|
19
21
|
next if File.directory?(asset_path)
|
20
22
|
|
21
|
-
visible = self.check_against_whitelist(whitelist, asset_path.gsub(File.join(theme_path, 'public'), ''))
|
23
|
+
visible = self.check_against_whitelist(whitelist, asset_path.gsub(File.join(theme_path, 'public'), '').gsub(/^\//, ''))
|
22
24
|
|
23
25
|
folder = asset_path.gsub(File.join(theme_path, 'public'), '').gsub(File.basename(asset_path), '').gsub(/^\//, '').gsub(/\/$/, '')
|
24
26
|
|
@@ -28,27 +30,33 @@ module Locomotive
|
|
28
30
|
|
29
31
|
asset.attributes = { :source => File.open(asset_path), :performing_plain_text => false, :hidden => !visible }
|
30
32
|
|
31
|
-
|
33
|
+
begin
|
34
|
+
asset.save!
|
35
|
+
rescue Exception => e
|
36
|
+
self.log "!ERROR! = #{e.message}, #{asset_path}"
|
37
|
+
end
|
32
38
|
|
33
39
|
site.reload
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
|
-
def
|
44
|
+
def add_other_assets
|
39
45
|
collection = AssetCollection.find_or_create_internal(site)
|
40
46
|
|
41
47
|
Dir[File.join(theme_path, 'public', 'samples', '*')].each do |asset_path|
|
42
48
|
|
43
49
|
next if File.directory?(asset_path)
|
44
50
|
|
51
|
+
self.log "other asset = #{asset_path}"
|
52
|
+
|
45
53
|
name = File.basename(asset_path, File.extname(asset_path)).parameterize('_')
|
46
54
|
|
47
55
|
collection.assets.create! :name => name, :source => File.open(asset_path)
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
51
|
-
def
|
59
|
+
def build_regexps_in_withlist(rules)
|
52
60
|
rules.collect do |rule|
|
53
61
|
if rule.start_with?('^')
|
54
62
|
Regexp.new(rule.gsub('/', '\/'))
|
@@ -58,7 +66,7 @@ module Locomotive
|
|
58
66
|
end
|
59
67
|
end
|
60
68
|
|
61
|
-
def
|
69
|
+
def check_against_whitelist(whitelist, path)
|
62
70
|
(whitelist || []).each do |rule|
|
63
71
|
case rule
|
64
72
|
when Regexp
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Locomotive
|
2
|
+
module Import
|
3
|
+
class Base
|
4
|
+
|
5
|
+
include Logger
|
6
|
+
|
7
|
+
attr_reader :context, :options
|
8
|
+
|
9
|
+
def initialize(context, options)
|
10
|
+
@context = context
|
11
|
+
@options = options
|
12
|
+
self.log "*** starting to process ***"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.process(context, options)
|
16
|
+
self.new(context, options).process
|
17
|
+
end
|
18
|
+
|
19
|
+
def process
|
20
|
+
raise 'this method has to be overidden'
|
21
|
+
end
|
22
|
+
|
23
|
+
def log(message)
|
24
|
+
super(message, self.class.name.demodulize.underscore)
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def site
|
30
|
+
@context[:site]
|
31
|
+
end
|
32
|
+
|
33
|
+
def database
|
34
|
+
@context[:database]
|
35
|
+
end
|
36
|
+
|
37
|
+
def theme_path
|
38
|
+
@context[:theme_path]
|
39
|
+
end
|
40
|
+
|
41
|
+
def open_sample_asset(url)
|
42
|
+
File.open(File.join(self.theme_path, 'public', url))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,20 +1,16 @@
|
|
1
1
|
module Locomotive
|
2
2
|
module Import
|
3
|
-
|
4
|
-
|
5
|
-
def self.process(context)
|
6
|
-
site, database = context[:site], context[:database]
|
7
|
-
|
8
|
-
content_types = database['site']['content_types']
|
3
|
+
class ContentTypes < Base
|
9
4
|
|
5
|
+
def process
|
10
6
|
return if content_types.nil?
|
11
7
|
|
12
8
|
content_types.each do |name, attributes|
|
13
|
-
|
9
|
+
self.log "[content_types] slug = #{attributes['slug']}"
|
14
10
|
|
15
11
|
content_type = site.content_types.where(:slug => attributes['slug']).first
|
16
12
|
|
17
|
-
content_type ||= self.build_content_type(
|
13
|
+
content_type ||= self.build_content_type(attributes.merge(:name => name))
|
18
14
|
|
19
15
|
self.add_or_update_fields(content_type, attributes['fields'])
|
20
16
|
|
@@ -24,21 +20,31 @@ module Locomotive
|
|
24
20
|
|
25
21
|
self.set_group_by_value(content_type)
|
26
22
|
|
23
|
+
if options[:samples] && attributes['contents']
|
24
|
+
self.insert_samples(content_type, attributes['contents'])
|
25
|
+
end
|
26
|
+
|
27
27
|
content_type.save!
|
28
28
|
|
29
29
|
site.reload
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
protected
|
34
|
+
|
35
|
+
def content_types
|
36
|
+
database['site']['content_types']
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_content_type(data)
|
40
|
+
attributes = { :group_by_field_name => data.delete('group_by') }.merge(data)
|
35
41
|
|
36
42
|
attributes.delete_if { |name, value| %w{fields contents}.include?(name) }
|
37
43
|
|
38
44
|
site.content_types.build(attributes)
|
39
45
|
end
|
40
46
|
|
41
|
-
def
|
47
|
+
def add_or_update_fields(content_type, fields)
|
42
48
|
fields.each_with_index do |data, position|
|
43
49
|
name, data = data.keys.first, data.values.first
|
44
50
|
|
@@ -54,24 +60,54 @@ module Locomotive
|
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
|
-
def
|
63
|
+
def insert_samples(content_type, contents)
|
64
|
+
contents.each_with_index do |data, position|
|
65
|
+
value, attributes = data.is_a?(Array) ? [data.first, data.last] : [data.keys.first, data.values.first]
|
66
|
+
|
67
|
+
# build with default attributes
|
68
|
+
content = content_type.contents.build(content_type.highlighted_field_name.to_sym => value, :_position_in_list => position)
|
69
|
+
|
70
|
+
attributes.each do |name, value|
|
71
|
+
field = content_type.content_custom_fields.detect { |f| f._alias == name }
|
72
|
+
|
73
|
+
value = (case field.kind.downcase
|
74
|
+
when 'file' then self.open_sample_asset(value)
|
75
|
+
when 'boolean' then Boolean.set(value)
|
76
|
+
else
|
77
|
+
value
|
78
|
+
end)
|
79
|
+
|
80
|
+
content.send("#{name}=", value)
|
81
|
+
end
|
82
|
+
|
83
|
+
content.save
|
84
|
+
|
85
|
+
self.log "insert content '#{content.send(content_type.highlighted_field_name.to_sym)}'"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_highlighted_field_name(content_type)
|
58
90
|
field = content_type.content_custom_fields.detect { |f| f._alias == content_type.highlighted_field_name }
|
59
91
|
|
60
92
|
content_type.highlighted_field_name = field._name if field
|
61
93
|
end
|
62
94
|
|
63
|
-
def
|
95
|
+
def set_order_by_value(content_type)
|
96
|
+
self.log "order by #{content_type.order_by}"
|
97
|
+
|
64
98
|
order_by = (case content_type.order_by
|
65
99
|
when 'manually', '_position_in_list' then '_position_in_list'
|
66
|
-
when '
|
100
|
+
when 'default', 'created_at' then 'created_at'
|
67
101
|
else
|
68
102
|
content_type.content_custom_fields.detect { |f| f._alias == content_type.order_by }._name rescue nil
|
69
103
|
end)
|
70
104
|
|
105
|
+
self.log "order by (after) #{order_by}"
|
106
|
+
|
71
107
|
content_type.order_by = order_by || '_position_in_list'
|
72
108
|
end
|
73
109
|
|
74
|
-
def
|
110
|
+
def set_group_by_value(content_type)
|
75
111
|
return if content_type.group_by_field_name.blank?
|
76
112
|
|
77
113
|
field = content_type.content_custom_fields.detect { |f| f._alias == content_type.group_by_field_name }
|
@@ -4,12 +4,21 @@ module Locomotive
|
|
4
4
|
module Import
|
5
5
|
class Job
|
6
6
|
|
7
|
-
|
8
|
-
raise "Theme zipfile not found" unless File.exists?(theme_file)
|
7
|
+
include Logger
|
9
8
|
|
10
|
-
|
9
|
+
def initialize(zipfile, site, options = {})
|
11
10
|
@site = site
|
12
|
-
@
|
11
|
+
@options = {
|
12
|
+
:reset => false,
|
13
|
+
:samples => false,
|
14
|
+
:enabled => {}
|
15
|
+
}.merge(options)
|
16
|
+
|
17
|
+
@identifier = self.store_zipfile(zipfile)
|
18
|
+
|
19
|
+
raise "Theme identifier not found" if @identifier.blank?
|
20
|
+
|
21
|
+
@uploader = nil # fix issue with Ruby 1.9.2 and serialization
|
13
22
|
end
|
14
23
|
|
15
24
|
def before(worker)
|
@@ -17,7 +26,7 @@ module Locomotive
|
|
17
26
|
end
|
18
27
|
|
19
28
|
def perform
|
20
|
-
|
29
|
+
self.log "theme identifier #{@identifier}"
|
21
30
|
|
22
31
|
self.unzip!
|
23
32
|
|
@@ -31,23 +40,96 @@ module Locomotive
|
|
31
40
|
:worker => @worker
|
32
41
|
}
|
33
42
|
|
43
|
+
self.reset! if @options[:reset]
|
44
|
+
|
34
45
|
%w(site content_types assets asset_collections snippets pages).each do |step|
|
35
|
-
if @enabled[step] != false
|
36
|
-
"Locomotive::Import::#{step.camelize}".constantize.process(context)
|
46
|
+
if @options[:enabled][step] != false
|
47
|
+
"Locomotive::Import::#{step.camelize}".constantize.process(context, @options)
|
37
48
|
@worker.update_attributes :step => step if @worker
|
38
49
|
else
|
39
|
-
|
50
|
+
self.log "skipping #{step}"
|
40
51
|
end
|
41
52
|
end
|
42
53
|
end
|
43
54
|
|
55
|
+
def success(worker)
|
56
|
+
self.log 'deleting original zip file'
|
57
|
+
|
58
|
+
uploader = self.get_uploader(@site)
|
59
|
+
|
60
|
+
uploader.retrieve_from_store!(@identifier)
|
61
|
+
|
62
|
+
uploader.remove!
|
63
|
+
|
64
|
+
self.log 'deleting working folder'
|
65
|
+
|
66
|
+
FileUtils.rm_rf(themes_folder) rescue nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.run!(zipfile, site, options = {})
|
70
|
+
job = self.new(zipfile, site, options)
|
71
|
+
|
72
|
+
if Locomotive.config.delayed_job
|
73
|
+
Delayed::Job.enqueue job, { :site => site, :job_type => 'import' }
|
74
|
+
else
|
75
|
+
job.perform
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
44
79
|
protected
|
45
80
|
|
81
|
+
def themes_folder
|
82
|
+
File.join(Rails.root, 'tmp', 'themes', @site.id.to_s)
|
83
|
+
end
|
84
|
+
|
85
|
+
def prepare_folder
|
86
|
+
FileUtils.rm_rf self.themes_folder if File.exists?(self.themes_folder)
|
87
|
+
|
88
|
+
FileUtils.mkdir_p(self.themes_folder)
|
89
|
+
end
|
90
|
+
|
91
|
+
def store_zipfile(zipfile)
|
92
|
+
return nil if zipfile.blank?
|
93
|
+
|
94
|
+
file = CarrierWave::SanitizedFile.new(zipfile)
|
95
|
+
|
96
|
+
uploader = self.get_uploader(@site)
|
97
|
+
|
98
|
+
begin
|
99
|
+
uploader.store!(file)
|
100
|
+
uploader.identifier
|
101
|
+
rescue CarrierWave::IntegrityError
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def retrieve_zipfile
|
107
|
+
uploader = self.get_uploader(@site)
|
108
|
+
|
109
|
+
uploader.retrieve_from_store!(@identifier)
|
110
|
+
|
111
|
+
if uploader.file.respond_to?(:url)
|
112
|
+
self.log 'file from remote storage'
|
113
|
+
|
114
|
+
@theme_file = File.join(self.themes_folder, @identifier)
|
115
|
+
|
116
|
+
File.open(@theme_file, 'w') { |f| f.write(uploader.file.read) }
|
117
|
+
else # local filesystem
|
118
|
+
self.log 'file from local storage'
|
119
|
+
|
120
|
+
@theme_file = uploader.path
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
46
124
|
def unzip!
|
47
|
-
|
48
|
-
|
125
|
+
self.prepare_folder
|
126
|
+
|
127
|
+
self.retrieve_zipfile
|
128
|
+
|
129
|
+
self.log "unzip #{@theme_file}"
|
49
130
|
|
50
|
-
|
131
|
+
Zip::ZipFile.open(@theme_file) do |zipfile|
|
132
|
+
destination_path = self.themes_folder
|
51
133
|
|
52
134
|
zipfile.each do |entry|
|
53
135
|
next if entry.name =~ /__MACOSX/
|
@@ -65,7 +147,20 @@ module Locomotive
|
|
65
147
|
zipfile.extract(entry, File.join(destination_path, entry.name))
|
66
148
|
end
|
67
149
|
end
|
150
|
+
end
|
68
151
|
|
152
|
+
def reset!
|
153
|
+
@site.pages.destroy_all
|
154
|
+
@site.theme_assets.destroy_all
|
155
|
+
@site.content_types.destroy_all
|
156
|
+
@site.asset_collections.destroy_all
|
157
|
+
end
|
158
|
+
|
159
|
+
def get_uploader(site)
|
160
|
+
unless Locomotive.config.delayed_job
|
161
|
+
ThemeUploader.storage = :file
|
162
|
+
end
|
163
|
+
@uploader ||= ThemeUploader.new(site)
|
69
164
|
end
|
70
165
|
|
71
166
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Locomotive
|
2
2
|
module Import
|
3
|
-
|
4
|
-
|
5
|
-
def self.process(context)
|
6
|
-
site, pages, theme_path = context[:site], context[:database]['pages'], context[:theme_path]
|
3
|
+
class Pages < Base
|
7
4
|
|
5
|
+
def process
|
8
6
|
context[:done] = {} # initialize the hash storing pages already processed
|
9
7
|
|
10
|
-
self.add_index_and_404
|
8
|
+
self.add_index_and_404
|
11
9
|
|
12
10
|
Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
|
13
11
|
|
@@ -15,43 +13,50 @@ module Locomotive
|
|
15
13
|
|
16
14
|
next if %w(index 404).include?(fullpath)
|
17
15
|
|
18
|
-
self.add_page(fullpath
|
16
|
+
self.add_page(fullpath)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
|
-
|
23
|
-
puts "....adding #{fullpath}"
|
20
|
+
protected
|
24
21
|
|
22
|
+
def add_page(fullpath)
|
25
23
|
page = context[:done][fullpath]
|
26
24
|
|
27
25
|
return page if page # already added, so skip it
|
28
26
|
|
29
|
-
site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
|
30
|
-
|
31
27
|
template = File.read(File.join(theme_path, 'templates', "#{fullpath}.liquid")) rescue "Unable to find #{fullpath}.liquid"
|
32
28
|
|
33
|
-
self.
|
29
|
+
self.replace_images!(template)
|
34
30
|
|
35
|
-
|
31
|
+
self.build_parent_template(template)
|
36
32
|
|
37
|
-
|
33
|
+
parent = self.find_parent(fullpath)
|
38
34
|
|
39
35
|
attributes = {
|
40
36
|
:title => fullpath.split('/').last.humanize,
|
41
37
|
:slug => fullpath.split('/').last,
|
42
38
|
:parent => parent,
|
43
|
-
:raw_template => template
|
44
|
-
|
39
|
+
:raw_template => template,
|
40
|
+
:published => true
|
41
|
+
}.merge(self.pages[fullpath] || {}).symbolize_keys
|
45
42
|
|
46
43
|
# templatized ?
|
47
44
|
if content_type_slug = attributes.delete(:content_type)
|
48
|
-
|
45
|
+
fullpath.gsub!(/\/template$/, '/content_type_template')
|
46
|
+
attributes.merge!({
|
47
|
+
:templatized => true,
|
48
|
+
:content_type => site.content_types.where(:slug => content_type_slug).first
|
49
|
+
})
|
49
50
|
end
|
50
51
|
|
52
|
+
page = site.pages.where(:fullpath => fullpath).first || site.pages.build
|
53
|
+
|
51
54
|
page.attributes = attributes
|
52
55
|
|
53
56
|
page.save!
|
54
57
|
|
58
|
+
self.log "adding #{page.fullpath} / #{page.position}"
|
59
|
+
|
55
60
|
site.reload
|
56
61
|
|
57
62
|
context[:done][fullpath] = page
|
@@ -59,7 +64,7 @@ module Locomotive
|
|
59
64
|
page
|
60
65
|
end
|
61
66
|
|
62
|
-
def
|
67
|
+
def build_parent_template(template)
|
63
68
|
# just check if the template contains the extends keyword
|
64
69
|
fullpath = template.scan(/\{% extends (\w+) %\}/).flatten.first
|
65
70
|
|
@@ -68,13 +73,11 @@ module Locomotive
|
|
68
73
|
|
69
74
|
return if fullpath == 'parent'
|
70
75
|
|
71
|
-
self.add_page(fullpath
|
76
|
+
self.add_page(fullpath)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
75
|
-
def
|
76
|
-
site = context[:site]
|
77
|
-
|
80
|
+
def find_parent(fullpath)
|
78
81
|
segments = fullpath.split('/')
|
79
82
|
|
80
83
|
return site.pages.index.first if segments.size == 1
|
@@ -86,12 +89,10 @@ module Locomotive
|
|
86
89
|
# look for a local index page in db
|
87
90
|
parent = site.pages.where(:fullpath => parent_fullpath).first
|
88
91
|
|
89
|
-
parent || self.add_page(parent_fullpath
|
92
|
+
parent || self.add_page(parent_fullpath)
|
90
93
|
end
|
91
94
|
|
92
|
-
def
|
93
|
-
site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
|
94
|
-
|
95
|
+
def add_index_and_404
|
95
96
|
%w(index 404).each_with_index do |slug, position|
|
96
97
|
page = site.pages.where({ :slug => slug, :depth => 0 }).first
|
97
98
|
|
@@ -99,7 +100,11 @@ module Locomotive
|
|
99
100
|
|
100
101
|
template = File.read(File.join(theme_path, 'templates', "#{slug}.liquid"))
|
101
102
|
|
102
|
-
|
103
|
+
self.replace_images!(template)
|
104
|
+
|
105
|
+
page.attributes = { :raw_template => template }.merge(self.pages[slug] || {})
|
106
|
+
|
107
|
+
page.position = position
|
103
108
|
|
104
109
|
page.save! rescue nil # TODO better error handling
|
105
110
|
|
@@ -109,6 +114,54 @@ module Locomotive
|
|
109
114
|
end
|
110
115
|
end
|
111
116
|
|
117
|
+
def replace_images!(template)
|
118
|
+
return if template.blank?
|
119
|
+
|
120
|
+
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
|
121
|
+
name = $1
|
122
|
+
|
123
|
+
collection = AssetCollection.find_or_create_internal(site)
|
124
|
+
|
125
|
+
if asset = collection.assets.detect { |a| a.source_filename == name }
|
126
|
+
asset.source.url
|
127
|
+
else
|
128
|
+
match
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def pages
|
134
|
+
@pages ||= self.retrieve_pages
|
135
|
+
end
|
136
|
+
|
137
|
+
def retrieve_pages
|
138
|
+
pages = context[:database]['site']['pages']
|
139
|
+
|
140
|
+
if pages.is_a?(Array) # ordered list of pages
|
141
|
+
tmp, positions = {}, Hash.new(0)
|
142
|
+
pages.each do |data|
|
143
|
+
position = nil
|
144
|
+
fullpath = data.keys.first.to_s
|
145
|
+
|
146
|
+
unless %w(index 404).include?(fullpath)
|
147
|
+
(segments = fullpath.split('/')).pop
|
148
|
+
position_key = segments.empty? ? 'index' : segments.join('/')
|
149
|
+
|
150
|
+
position = positions[position_key]
|
151
|
+
|
152
|
+
positions[position_key] += 1
|
153
|
+
end
|
154
|
+
|
155
|
+
attributes = (data.values.first || {}).merge(:position => position)
|
156
|
+
|
157
|
+
tmp[fullpath] = attributes
|
158
|
+
end
|
159
|
+
pages = tmp
|
160
|
+
end
|
161
|
+
|
162
|
+
pages
|
163
|
+
end
|
164
|
+
|
112
165
|
end
|
113
166
|
end
|
114
167
|
end
|