Merge pull request #302 from giorgian/fix_asset_urls_importing_contents
Fix asset urls importing contents
This commit is contained in:
commit
e1d75ddac3
@ -41,6 +41,20 @@ module Locomotive
|
|||||||
def open_sample_asset(url)
|
def open_sample_asset(url)
|
||||||
File.open(File.join(self.theme_path, 'public', url))
|
File.open(File.join(self.theme_path, 'public', url))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def replace_images!(template)
|
||||||
|
return if template.blank?
|
||||||
|
|
||||||
|
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
|
||||||
|
name = File.basename($1)
|
||||||
|
|
||||||
|
if asset = site.assets.where(:source_filename => name).first
|
||||||
|
asset.source.url
|
||||||
|
else
|
||||||
|
match
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -161,7 +161,9 @@ module Locomotive
|
|||||||
field.category_items.build :name => value
|
field.category_items.build :name => value
|
||||||
end
|
end
|
||||||
value
|
value
|
||||||
else # string, text
|
when 'text'
|
||||||
|
replace_images!(value)
|
||||||
|
else # string
|
||||||
value
|
value
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ module Locomotive
|
|||||||
|
|
||||||
self.reset! if @options[:reset]
|
self.reset! if @options[:reset]
|
||||||
|
|
||||||
%w(site content_types assets snippets pages).each do |step|
|
%w(site assets content_types snippets pages).each do |step|
|
||||||
if @options[:enabled][step] != false
|
if @options[:enabled][step] != false
|
||||||
"Locomotive::Import::#{step.camelize}".constantize.process(context, @options)
|
"Locomotive::Import::#{step.camelize}".constantize.process(context, @options)
|
||||||
@worker.update_attributes :step => step if @worker
|
@worker.update_attributes :step => step if @worker
|
||||||
|
@ -147,20 +147,6 @@ module Locomotive
|
|||||||
parent || self.add_page(parent_fullpath)
|
parent || self.add_page(parent_fullpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
def replace_images!(template)
|
|
||||||
return if template.blank?
|
|
||||||
|
|
||||||
template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
|
|
||||||
name = File.basename($1)
|
|
||||||
|
|
||||||
if asset = site.assets.where(:source_filename => name).first
|
|
||||||
asset.source.url
|
|
||||||
else
|
|
||||||
match
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def pages
|
def pages
|
||||||
@pages ||= self.retrieve_pages
|
@pages ||= self.retrieve_pages
|
||||||
end
|
end
|
||||||
|
BIN
spec/fixtures/themes/default2.zip
vendored
Normal file
BIN
spec/fixtures/themes/default2.zip
vendored
Normal file
Binary file not shown.
@ -137,4 +137,20 @@ describe Locomotive::Import::Job do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a content referencing an asset' do
|
||||||
|
before(:all) do
|
||||||
|
@site = FactoryGirl.create(:site)
|
||||||
|
|
||||||
|
job = Locomotive::Import::Job.new(FixturedTheme.duplicate_and_open('default2.zip'), @site, { :samples => true, :reset => true })
|
||||||
|
job.perform
|
||||||
|
|
||||||
|
job.success nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'will fix the url inside content' do
|
||||||
|
content = @site.content_types.where(:slug => 'messages').first.contents.first
|
||||||
|
asset = @site.assets.first
|
||||||
|
content.message.should == "<img src=\"/sites/#{@site.id}/assets/#{asset.id}/#{asset.source_filename}\" />"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user