fix a couple of bugs when cloning/pulling a site (wrong path to the local assets, theme assets at the wrong place, ...etc) + better error message if no remote site was found when deploying a Wagon site

did committed Oct 11, 2015
commit ffb78fb3f60eb0fceb5a944bd9aeecf86bdb3857
Showing 7 changed files with 19 additions and 12 deletions
Gemfile +1 -1
@@ @@ -8,7 +8,7 @@ gem 'rb-fsevent', '~> 0.9.1'
gem 'therubyracer'
# Development
- gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'f1cfcf0', require: false
+ gem 'locomotivecms_steam', github: 'locomotivecms/steam', ref: 'c487443', require: false
# gem 'locomotivecms_coal', github: 'locomotivecms/coal', ref: '32b2844', require: false
# gem 'locomotivecms_common', github: 'locomotivecms/common', ref: '3046b79893', require: false
locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb b/lib/locomotive/wagon/commands/pull_sub_commands/concerns/assets_concern.rb +6 -6
@@ @@ -4,7 +4,7 @@ module Locomotive::Wagon
module AssetsConcern
- REGEX = /\/sites\/[0-9a-f]{24}\/(assets|pages|theme|content_entry[0-9a-f]{24})\/(([^;.]+)\/)*([a-zA-Z_\-0-9.]+)\.([A-Za-z]{2,3})/
+ 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,})/
# 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>
@@ @@ -15,15 +15,15 @@ module Locomotive::Wagon
return '' if content.blank?
content.force_encoding('utf-8').gsub(REGEX) do |url|
- filename = "#{$4}.#{$5}"
- folder = case $1
- when 'assets', 'pages' then File.join('samples', $1)
- when 'theme' then $3
+ filename = "#{$5}.#{$6}"
+ folder = case $2
+ when 'assets', 'pages' then File.join('samples', $2)
+ when 'theme' then $4
when /\Acontent_entry/ then File.join('samples', 'content_entries')
end
if filepath = write_asset(url, File.join(path, 'public', folder, filename))
- File.join('', folder, File.basename(filepath))
+ File.join('', folder, File.basename(filepath)).to_s
else
''
end
locomotive/wagon/commands/pull_sub_commands/pull_content_entries_command.rb b/lib/locomotive/wagon/commands/pull_sub_commands/pull_content_entries_command.rb +1 -1
@@ @@ -47,7 +47,7 @@ module Locomotive::Wagon
def fetch_content_types(&block)
api_client.content_types.all.each do |content_type|
content_type.attributes['localized_names'] = content_type.fields.map { |f| f['localized'] ? f['name'] : nil }.compact
- content_type.attributes['urls_names'] = content_type.fields.map { |f| %w(file text).include?(f['type']) ? f['name'] : nil }.compact
+ content_type.attributes['urls_names'] = content_type.fields.map { |f| %w(file string text).include?(f['type']) ? f['name'] : nil }.compact
yield(content_type)
end
end
locomotive/wagon/commands/pull_sub_commands/pull_content_types_command.rb b/lib/locomotive/wagon/commands/pull_sub_commands/pull_content_types_command.rb +1 -1
@@ @@ -26,7 +26,7 @@ module Locomotive::Wagon
end
def field_yaml_attributes(field)
- attributes = field.slice('label', 'type', 'required', 'hint', 'localized', 'select_options', 'class_name', 'inverse_of', 'ui_enabled')
+ attributes = field.slice('label', 'type', 'required', 'hint', 'localized', 'select_options', 'target', 'inverse_of', 'ui_enabled')
clean_attributes(attributes)
locomotive/wagon/commands/pull_sub_commands/pull_theme_assets_command.rb b/lib/locomotive/wagon/commands/pull_sub_commands/pull_theme_assets_command.rb +1 -1
@@ @@ -21,7 +21,7 @@ module Locomotive::Wagon
private
def theme_asset_filepath(asset)
- File.join('public', asset.folder, asset.local_path)
+ File.join('public', asset.local_path)
end
end
locomotive/wagon/commands/push_command.rb b/lib/locomotive/wagon/commands/push_command.rb +8 -1
@@ @@ -131,7 +131,14 @@ module Locomotive::Wagon
def remote_site
return @remote_site if @remote_site
- attributes = @api_site_client.current_site.get.attributes
+ attribute = nil
+
+ begin
+ attributes = @api_site_client.current_site.get.attributes
+ rescue Locomotive::Coal::UnknownResourceError
+ raise 'Sorry, we were unable to find your site on the remote platform. Check the information in your config/deploy.yml file.'
+ end
+
_site = Locomotive::Steam::Site.new(attributes)
@remote_site = SiteDecorator.new(_site)
end
locomotive/wagon/decorators/site_decorator.rb b/lib/locomotive/wagon/decorators/site_decorator.rb +1 -1
@@ @@ -29,7 +29,7 @@ module Locomotive
end
def edited?
- self[:content_version].try(:to_i) > 0
+ (self[:content_version].try(:to_i) || 0) > 0
end
end