From ffee024a9618a9c9d626049ba4be98d6c94886eb Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Sat, 18 Feb 2012 01:57:06 +0100 Subject: [PATCH] a little bit of cleaning + prepare the engine to make it work with the hosting extensions --- Rakefile | 92 --------------- config/assets.yml | 105 ------------------ config/initializers/carrierwave.rb | 38 ------- config/initializers/dragonfly.rb | 31 ------ config/initializers/inflections.rb | 14 --- config/initializers/mime_types.rb | 5 - config/initializers/rspec_generator.rb | 8 -- config/initializers/secret_token.rb | 10 -- .../install/templates/locomotive.rb | 16 --- lib/locomotive.rb | 21 ++-- lib/locomotive/configuration.rb | 1 - spec/dummy/config/initializers/locomotive.rb | 11 -- spec/lib/locomotive/configuration_spec.rb | 7 ++ spec/spec_helper.rb | 4 - spec/support/cells.rb | 27 +---- spec/support/locomotive.rb | 6 +- 16 files changed, 18 insertions(+), 378 deletions(-) delete mode 100644 config/assets.yml delete mode 100644 config/initializers/carrierwave.rb delete mode 100644 config/initializers/dragonfly.rb delete mode 100644 config/initializers/inflections.rb delete mode 100644 config/initializers/mime_types.rb delete mode 100644 config/initializers/rspec_generator.rb delete mode 100644 config/initializers/secret_token.rb diff --git a/Rakefile b/Rakefile index dc824eee..f5231f31 100644 --- a/Rakefile +++ b/Rakefile @@ -31,95 +31,3 @@ load 'lib/tasks/cucumber.rake' # === Default task === task :default => [:spec, :cucumber] - - - - - - -# begin -# require 'rdoc/task' -# rescue LoadError -# require 'rdoc/rdoc' -# require 'rake/rdoctask' -# RDoc::Task = Rake::RDocTask -# end - - -# # require File.expand_path('../config/application', __FILE__) -# -# require 'rubygems' -# -# require 'rake/dsl_definition' -# require 'rake' -# require 'rdoc/task' -# require 'rubygems/package_task' -# -# # Locomotive::Application.load_tasks -# -# gemspec = eval(File.read('locomotive_cms.gemspec')) -# Gem::PackageTask.new(gemspec) do |pkg| -# pkg.gem_spec = gemspec -# end -# -# desc 'build the gem and release it to rubygems.org' -# task :release => :gem do -# sh "gem push pkg/custom_fields-#{gemspec.version}.gem" -# end -# -# task :default => [:spec, :cucumber] -# -# # only for running the tests suite in the order observed in *nix systems -# task :spec_nix do -# files = %w( -# lib/core_ext_spec.rb -# lib/locomotive/routing/site_dispatcher_spec.rb -# lib/locomotive/bushido_spec.rb -# lib/locomotive/render_spec.rb -# lib/locomotive/httparty/patches_spec.rb -# lib/locomotive/httparty/webservice_spec.rb -# lib/locomotive/configuration_spec.rb -# lib/locomotive/liquid/tags/consume_spec.rb -# lib/locomotive/liquid/tags/with_scope_spec.rb -# lib/locomotive/liquid/tags/nav_spec.rb -# lib/locomotive/liquid/tags/editable/content_spec.rb -# lib/locomotive/liquid/tags/editable/short_text_spec.rb -# lib/locomotive/liquid/tags/seo_spec.rb -# lib/locomotive/liquid/tags/paginate_spec.rb -# lib/locomotive/liquid/drops/content_spec.rb -# lib/locomotive/liquid/drops/contents_spec.rb -# lib/locomotive/liquid/drops/page_spec.rb -# lib/locomotive/liquid/drops/site_spec.rb -# lib/locomotive/liquid/filters/resize_spec.rb -# lib/locomotive/liquid/filters/html_spec.rb -# lib/locomotive/liquid/filters/date_spec.rb -# lib/locomotive/liquid/filters/text_spec.rb -# lib/locomotive/liquid/filters/misc_spec.rb -# lib/locomotive/heroku_spec.rb -# models/content_entry_spec.rb -# models/editable_element_spec.rb -# models/account_spec.rb -# models/content_type_spec.rb -# models/snippet_spec.rb -# models/ability_spec.rb -# models/membership_spec.rb -# models/page_spec.rb -# models/asset_spec.rb -# models/theme_asset_spec.rb -# models/site_spec.rb -# cells/admin/main_menu_cell_spec.rb -# cells/admin/global_actions_spec.rb -# cells/admin/settings_menu_cell_spec.rb -# requests/seo_trailing_slash_spec.rb -# ).collect { |f| File.join('spec', f) }.join(' ') -# -# sh "bundle exec rspec #{files}" -# end -# -# task :travis do -# ["rspec spec", "cucumber -b"].each do |cmd| -# puts "Starting to run #{cmd}..." -# system("export DISPLAY=:99.0 && bundle exec #{cmd}") -# raise "#{cmd} failed!" unless $?.exitstatus == 0 -# end -# end diff --git a/config/assets.yml b/config/assets.yml deleted file mode 100644 index 40d1bc2b..00000000 --- a/config/assets.yml +++ /dev/null @@ -1,105 +0,0 @@ -embed_assets: off -# compress_assets: off -# package_assets: off - -s3_bucket: <%= ENV['S3_BUCKET'] %> -s3_access_key_id: <%= ENV['S3_KEY_ID'] %> -s3_secret_access_key: <%= ENV['S3_SECRET_KEY'] %> - -javascripts: - box: - - public/javascripts/admin/jquery.js - installation: - - public/javascripts/admin/jquery.js - - public/javascripts/admin/installation.js - common: - - public/javascripts/admin/jquery.js - - public/javascripts/admin/jquery.ui.js - - public/javascripts/admin/rails.js - - public/javascripts/admin/utils.js - - public/javascripts/admin/plugins/cmd.js - - public/javascripts/admin/plugins/subscribe.js - - public/javascripts/admin/plugins/shortcut.js - - public/javascripts/admin/plugins/toggle.js - - public/javascripts/admin/plugins/growl.js - - public/javascripts/admin/plugins/cookie.js - - public/javascripts/admin/locales/datepicker_de.js - - public/javascripts/admin/locales/datepicker_fr.js - - public/javascripts/admin/locales/datepicker_pt-BR.js - - public/javascripts/admin/locales/datepicker_it.js - - public/javascripts/admin/application.js - - public/javascripts/admin/guiders-1.1.0.js - - public/javascripts/admin/tutorial.js - custom_fields: - - public/javascripts/admin/plugins/fancybox.js - - public/javascripts/admin/plugins/mustache.js - - public/javascripts/admin/custom_fields.js - edit_custom_fields: - - public/javascripts/admin/plugins/tiny_mce/tinymce.js - - public/javascripts/admin/plugins/json2.js - - public/javascripts/admin/plugins/fancybox.js - - public/javascripts/admin/plugins/mustache.js - - public/javascripts/admin/custom_fields/category.js - - public/javascripts/admin/custom_fields/has_many.js - contents: - - public/javascripts/admin/plugins/tiny_mce/tinymce.js - - public/javascripts/admin/contents.js - content_types: - - public/javascripts/admin/plugins/codemirror/codemirror.min.js - - public/javascripts/admin/content_types.js - site: - - public/javascripts/admin/site.js - - public/javascripts/admin/plugins/codemirror/codemirror.min.js - import: - - public/javascripts/admin/plugins/json2.js - - public/javascripts/admin/plugins/smartupdater.js - - public/javascripts/admin/import.js - account: - - public/javascripts/admin/account.js - pages: - - public/javascripts/admin/pages.js - - public/javascripts/admin/plugins/menu_toggler.js - edit_page: - - public/javascripts/admin/plugins/tiny_mce/tinymce.js - - public/javascripts/admin/editable_elements.js - - public/javascripts/admin/pages.js - image_picker: - - public/javascripts/admin/plugins/json2.js - - public/javascripts/admin/plugins/scrollTo.js - - public/javascripts/admin/plugins/codemirror/codemirror.min.js - - public/javascripts/admin/plugins/fancybox.js - - public/javascripts/admin/plugins/plupload/plupload.full.js - - public/javascripts/admin/plugins/imagepicker.js - snippets: - - public/javascripts/admin/snippets.js - theme_assets: - - public/javascripts/admin/theme_assets.js - -stylesheets: - ie: - - public/stylesheets/admin/blueprint/ie.css - box: - - public/stylesheets/admin/blueprint/screen.css - - public/stylesheets/admin/box.css - - public/stylesheets/admin/safari.css - common: - - public/stylesheets/admin/blueprint/screen.css - - public/stylesheets/admin/layout.css - - public/stylesheets/admin/jquery/ui.css - - public/stylesheets/admin/plugins/toggle.css - - public/stylesheets/admin/menu.css - - public/stylesheets/admin/buttons.css - - public/stylesheets/admin/formtastic.css - - public/stylesheets/admin/formtastic_changes.css - - public/stylesheets/admin/assets.css - - public/stylesheets/admin/sites_picker.css - - public/stylesheets/admin/application.css - - public/stylesheets/admin/safari.css - - public/stylesheets/admin/guiders-1.1.0.css - fancybox: - - public/stylesheets/admin/plugins/fancybox.css - - public/stylesheets/admin/fancybox_changes.css - installation: - - public/stylesheets/admin/installation.css - editable_elements: - - public/stylesheets/admin/editable_elements.css \ No newline at end of file diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb deleted file mode 100644 index 09f75c6f..00000000 --- a/config/initializers/carrierwave.rb +++ /dev/null @@ -1,38 +0,0 @@ -# require 'locomotive' -# -# # TODO: Make this store to RAILS_ROOT/permanent -# -# # On bushido, the app directory is destroyed on every update, so everything is lost. -# # The only place this doesn't happen is the RAILS_ROOT/permanent folder. -# # Also, RAILS_ROOT/permanent/store is symlinked to RAILS_ROOT/public/store on every update, -# # so store your publicly-accessible files here (e.g. templates, etc.) -# -# CarrierWave.configure do |config| -# -# config.cache_dir = File.join(Rails.root, 'tmp', 'uploads') -# -# case Rails.env.to_sym -# -# when :development -# config.storage = :file -# config.root = File.join(Rails.root, 'public') -# -# when :production -# if Locomotive.bushido? -# config.storage = :file -# config.root = File.join(Rails.root, 'public') -# config.store_dir = 'store' -# else -# config.storage = :s3 -# config.s3_access_key_id = ENV['S3_KEY_ID'] -# config.s3_secret_access_key = ENV['S3_SECRET_KEY'] -# config.s3_bucket = ENV['S3_BUCKET'] -# # config.s3_cname = 'ENV['S3_CNAME'] -# -# # settings for the local filesystem -# # config.storage = :file -# # config.root = File.join(Rails.root, 'public') -# end -# end -# -# end unless Locomotive.engine? diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb deleted file mode 100644 index 6a8c6ad2..00000000 --- a/config/initializers/dragonfly.rb +++ /dev/null @@ -1,31 +0,0 @@ -# require 'locomotive' -# -# unless Locomotive.engine? -# -# require 'dragonfly' -# -# ## initialize Dragonfly ## -# -# app = Dragonfly[:images] -# app.configure_with(:rails) -# app.configure_with(:imagemagick) -# -# ## configure it ## -# -# Dragonfly[:images].configure do |c| -# # Convert absolute location needs to be specified -# # to avoid issues with Phusion Passenger not using $PATH -# convert = `which convert`.strip.presence || "/usr/local/bin/convert" -# c.convert_command = convert -# c.identify_command = convert -# -# c.allow_fetch_url = true -# c.allow_fetch_file = true -# -# c.url_format = '/images/dynamic/:job/:basename.:format' -# end -# -# end -# -# -# diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb deleted file mode 100644 index 436d3e60..00000000 --- a/config/initializers/inflections.rb +++ /dev/null @@ -1,14 +0,0 @@ -# # Be sure to restart your server when you modify this file. -# -# # Add new inflection rules using the following format -# # (all these examples are active by default): -# # ActiveSupport::Inflector.inflections do |inflect| -# # inflect.plural /^(ox)$/i, '\1en' -# # inflect.singular /^(ox)en/i, '\1' -# # inflect.irregular 'person', 'people' -# # inflect.uncountable %w( fish sheep ) -# # end -# -# ActiveSupport::Inflector.inflections do |inflect| -# end -# diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e4..00000000 --- a/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/config/initializers/rspec_generator.rb b/config/initializers/rspec_generator.rb deleted file mode 100644 index 7a56a129..00000000 --- a/config/initializers/rspec_generator.rb +++ /dev/null @@ -1,8 +0,0 @@ -# if Rails.env.test? && defined?(Locomotive::Application) # does not need it for the engine version -# Locomotive::Application.configure do -# config.generators do |g| -# g.integration_tool :rspec -# g.test_framework :rspec -# end -# end -# end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index 814df916..00000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,10 +0,0 @@ -# # Be sure to restart your server when you modify this file. -# require 'digest/sha1' -# -# # Your secret key for verifying the integrity of signed cookies. -# # If you change this key, all old signed cookies will become invalid! -# # Make sure the secret is at least 30 characters and all random, -# # no regular words or you'll be exposed to dictionary attacks. -# token = ENV['BUSHIDO_SALT'] || 'aa84844b97e90edda8e005a686d82c3bef1f8e20a1255301f1d0886fc592a45ef2393d64b0c3d3ea858b1f6406ad6f15305666264716a79fcfa17de93ad0d69d' -# -# Rails.application.config.secret_token = Digest::SHA1.hexdigest(token) diff --git a/lib/generators/locomotive/install/templates/locomotive.rb b/lib/generators/locomotive/install/templates/locomotive.rb index 1f078c65..e5c4db19 100644 --- a/lib/generators/locomotive/install/templates/locomotive.rb +++ b/lib/generators/locomotive/install/templates/locomotive.rb @@ -16,22 +16,6 @@ Locomotive.configure do |config| # end config.multi_sites = false - # configure the hosting target for the production environment. LocomotiveCMS can be installed in: - # - your own server - # - Heroku (you need to create an account in this case) - # - Bushi.do (see the bushi.do website for more explanations) - # - # the possible options are: server, heroku, bushido or auto (default) - # if you select 'auto', LocomotiveCMS will look after specific ENV variables to check - # the matching platform (Heroku and Bushido set their own ENV variables). - # - config.hosting = :auto - - # In case you host LocomotiveCMS in Heroku, the engine uses the heroku api to add / remove domains. - # config.heroku = { - # :api_key => ' - # } - # configure how many items we display in sub menu in the "Contents" section. # config.ui = { # :latest_entries_nb => 5, diff --git a/lib/locomotive.rb b/lib/locomotive.rb index d7784644..d0ec7c6d 100644 --- a/lib/locomotive.rb +++ b/lib/locomotive.rb @@ -31,18 +31,6 @@ module Locomotive end end - def self.engine? - self.const_defined?('Engine') - end - - def self.default_site_template_present? - File.exists?(self.default_site_template_path) - end - - def self.default_site_template_path - File.join(Rails.root, 'tmp/default_site_template.zip') - end - def self.configure self.config ||= Configuration.new @@ -76,6 +64,9 @@ module Locomotive rescue ::Mongoid::Errors::InvalidDatabase => e # let assume it's because of the first install (meaning no config.yml file) end + + # enable the hosting solution if both we are not in test or dev and that the config.hosting option has been filled up + self.enable_hosting end def self.add_middlewares @@ -101,6 +92,12 @@ module Locomotive end end + def self.enable_hosting + if (!Rails.env.test? && !Rails.env.development?) && !self.config.hosting.blank? && self.respond_to?(:"enable_#{self.config.hosting}") + self.send(:"enable_#{self.config.hosting}") + end + end + def self.define_subdomain_and_domains_options if self.config.multi_sites? self.config.manage_subdomain = self.config.manage_domains = true diff --git a/lib/locomotive/configuration.rb b/lib/locomotive/configuration.rb index 512a5364..8bf70d41 100644 --- a/lib/locomotive/configuration.rb +++ b/lib/locomotive/configuration.rb @@ -11,7 +11,6 @@ module Locomotive :site_locales => %w{en de fr pt-BR it nl no es ru}, :cookie_key => '_locomotive_session', :enable_logs => false, - :hosting => :auto, :delayed_job => false, :default_locale => :en, :mailer_sender => 'support@example.com', diff --git a/spec/dummy/config/initializers/locomotive.rb b/spec/dummy/config/initializers/locomotive.rb index 4b133e3f..ad405316 100644 --- a/spec/dummy/config/initializers/locomotive.rb +++ b/spec/dummy/config/initializers/locomotive.rb @@ -17,17 +17,6 @@ Locomotive.configure do |config| end # config.multi_sites = false - # configure the hosting target for the production environment. Locomotive can be installed in: - # - your own server - # - Heroku (you need to create an account in this case) - # - Bushi.do (see the bushi.do website for more explanations) - # - # the possible options are: server, heroku, bushido or auto (default) - # if you select 'auto', Locomotive will look after specific ENV variables to check - # the matching platform (Heroku and Bushido set their own ENV variables). - # - config.hosting = :server - # In case you host Locomotive in Heroku, the engine uses the heroku api to add / remove domains. # there are 2 ways of passing heroku credentials to Locomotive # - from ENV variables: HEROKU_LOGIN & HEROKU_PASSWORD diff --git a/spec/lib/locomotive/configuration_spec.rb b/spec/lib/locomotive/configuration_spec.rb index 8539ada7..faaa26f1 100644 --- a/spec/lib/locomotive/configuration_spec.rb +++ b/spec/lib/locomotive/configuration_spec.rb @@ -12,6 +12,13 @@ describe Locomotive::Configuration do Locomotive.config.reserved_subdomains.should == ['empty'] end + it 'calls the hosting enabler if provided' do + Rails.env.stubs(:test?).returns(false) + Locomotive.expects(:enable_bushido).once + Locomotive.config.hosting = :bushido + Locomotive.enable_hosting + end + after(:each) do Locomotive.config = @old_config end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f93ea2b8..7256eb21 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -22,10 +22,6 @@ RSpec.configure do |config| Locomotive.configure_for_test(true) end - config.before(:each) do - Locomotive.config.heroku = false - end - config.before(:suite) do DatabaseCleaner.strategy = :truncation DatabaseCleaner.orm = 'mongoid' diff --git a/spec/support/cells.rb b/spec/support/cells.rb index 40f63fc3..cc79ecdf 100644 --- a/spec/support/cells.rb +++ b/spec/support/cells.rb @@ -1,28 +1,3 @@ require 'rspec-cells' require 'cell/test_case' -require 'rspec/rails/example/cell_example_group' - -# -# module CellsResetter -# -# def self.method_missing(meth, *args) -# if meth =~ /^new_(.*)_klass/ -# name = $1 -# -# klass_name = name.camelize -# -# ::Locomotive.send(:remove_const, klass_name) -# load "locomotive/#{name}.rb" -# -# "::Locomotive::#{klass_name}".constantize.any_instance.stubs(:sections).returns(args.first) -# end -# end -# -# def self.clean! -# [:menu_cell, :main_menu_cell, :global_actions_cell, :settings_menu_cell].each do |name| -# ::Locomotive.send(:remove_const, "#{name.to_s.camelize}") -# load "locomotive/#{name}.rb" -# end -# end -# -# end +require 'rspec/rails/example/cell_example_group' \ No newline at end of file diff --git a/spec/support/locomotive.rb b/spec/support/locomotive.rb index 9288ef9c..6e3be8f1 100644 --- a/spec/support/locomotive.rb +++ b/spec/support/locomotive.rb @@ -17,16 +17,12 @@ def Locomotive.configure_for_test(force = false) Locomotive.configure do |config| config.multi_sites do |multi_sites| multi_sites.domain = 'example.com' - multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites) + multi_sites.reserved_subdomains = %w(www admin locomotive email blog webmail mail support help site sites) end - config.hosting = :none - config.enable_logs = true if force - ENV['APP_TLD'] = ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil - Locomotive.define_subdomain_and_domains_options Locomotive.send(:remove_const, 'Site') if Locomotive.const_defined?('Site')