render the site from any bound hostname + display a nice error message if compressing/minifying assets fails + deploy relationships of content entries after the deployment of the localized content entries (otherwise it clears the many_to_many relationships) + pull assets with special characters in the path

did committed Apr 19, 2016
commit 34da30a54ee9df0197fccd0955225e8f6f32e3a0
Showing 7 changed files with 34 additions and 5 deletions
Gemfile +1 -1
@@ @@ -8,7 +8,7 @@ gem 'rb-fsevent', '~> 0.9.1'
# Development
# gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '257047b', require: false
# gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: 'f4ff435', require: false
- # gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'a3054f1', require: false
+ gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'fe7403c', require: false
# Local development
# gem 'locomotivecms_coal', path: '../gems/coal', require: false
locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb b/lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb +1 -1
@@ @@ -6,7 +6,7 @@ module Locomotive::Wagon
module AssetsConcern
- REGEX = /(https?:\/\/\S+)?\/sites\/[0-9a-f]{24}\/(assets|pages|theme|content_entry[0-9a-f]{24})\/(([^;.]+)\/)*([a-zA-Z_\-0-9.]+)\.([A-Za-z]{2,})(\?\w+)?/
+ REGEX = /(https?:\/\/\S+)?\/sites\/[0-9a-f]{24}\/(assets|pages|theme|content_entry[0-9a-f]{24})\/(([^;.]+)\/)*([a-zA-Z_\-0-9.%]+)\.([A-Za-z]{2,})(\?\w+)?/
# The content assets on the remote engine follows the format: /sites/<id>/assets/<type>/<file>
# This method replaces these urls by their local representation. <type>/<file>
locomotive/wagon/commands/pull_sub_commands/pull_content_types_command.rb b/lib/locomotive/wagon/commands/pull_sub_commands/pull_content_types_command.rb +5 -0
@@ @@ -46,6 +46,11 @@ module Locomotive::Wagon
ordered_options.each do |option|
locales.each { |locale| (_options[locale] ||= []) << option['name'][locale.to_s] }
end
+
+ # if all the values of a locale are nil, then no need to keep that locale
+ locales.each do |locale|
+ _options.delete(locale) if _options[locale].all? { |v| v.blank? }
+ end
end
else
ordered_options.map { |option| option['name'][default_locale] }
locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb b/lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb +1 -1
@@ @@ -7,7 +7,7 @@ module Locomotive::Wagon
alias_method :default_push, :_push
def _push
- (%i(without_relationships only_relationships) + other_locales).each do |step|
+ ([:without_relationships] + other_locales + [:only_relationships]).each do |step|
@step = step
default_push
end
locomotive/wagon/commands/push_sub_commands/push_pages_command.rb b/lib/locomotive/wagon/commands/push_sub_commands/push_pages_command.rb +5 -1
@@ @@ -117,7 +117,11 @@ module Locomotive::Wagon
def skip?(entity)
return false if @only_entities.blank?
- _path = entity.template_path[default_locale].gsub('./app/views/pages/', '')
+ template_path = entity.template_path[default_locale]
+
+ return true if template_path == false
+
+ _path = template_path.gsub('./app/views/pages/', '')
!@only_entities.any? { |regexp| regexp.match(_path) }
end
locomotive/wagon/commands/push_sub_commands/push_theme_assets_command.rb b/lib/locomotive/wagon/commands/push_sub_commands/push_theme_assets_command.rb +11 -1
@@ @@ -40,7 +40,7 @@ module Locomotive::Wagon
return unless entity.stylesheet_or_javascript?
Tempfile.new(entity.realname).tap do |file|
- content = sprockets_env[entity.short_relative_url].to_s
+ content = compress_and_minify(entity)
# replace paths to images or fonts by the absolute URL used in the Engine
replace_assets!(content)
@@ @@ -85,6 +85,16 @@ module Locomotive::Wagon
@remote_urls[resource.local_path] = "#{resource.url}?#{resource.checksum}"
end
+ def compress_and_minify(entity)
+ begin
+ sprockets_env[entity.short_relative_url].to_s
+ rescue Locomotive::Steam::YUICompressorRuntimeError => e
+ instrument :warning, message: "Unable to compress and minify it, number of errors (#{e.errors.size})\n#{e.errors.join("\n")}"
+ # use the original file instead
+ File.read(File.join(path, entity.source))
+ end
+ end
+
def sprockets_env
@sprockets_env ||= Locomotive::Steam::SprocketsEnvironment.new(File.join(path, 'public'),
minify: ENV['WAGON_NO_MINIFY_ASSETS'].present? ? false : true)
locomotive/wagon/commands/serve_command.rb b/lib/locomotive/wagon/commands/serve_command.rb +10 -0
@@ @@ -1,5 +1,7 @@
module Locomotive::Wagon
+ SiteFinder = Struct.new(:repository, :request) { def find; repository.first; end; }
+
class ServeCommand < Struct.new(:path, :options, :shell)
def initialize(path, options, shell)
@@ @@ -82,6 +84,14 @@ module Locomotive::Wagon
end
config.middleware.insert_before Rack::Lint, Locomotive::Wagon::Middlewares::ErrorPage
+
+ config.services_hook = -> (services) {
+ if services.request
+ services.defer(:site_finder) do
+ SiteFinder.new(services.repositories.site, services.request)
+ end
+ end
+ }
end
end