Fix bugs in upload design and missing menu
This commit is contained in:
parent
32519f308f
commit
ab46084190
|
@ -1,6 +1,7 @@
|
||||||
class Design
|
class Design
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
include ParserLayout
|
||||||
|
|
||||||
field :title
|
field :title
|
||||||
field :author
|
field :author
|
||||||
|
@ -14,7 +15,7 @@ class Design
|
||||||
embeds_one :reset_css, :class_name => "Stylesheet", :cascade_callbacks => true
|
embeds_one :reset_css, :class_name => "Stylesheet", :cascade_callbacks => true
|
||||||
embeds_many :themes, :cascade_callbacks => true
|
embeds_many :themes, :cascade_callbacks => true
|
||||||
embeds_many :javascripts, :cascade_callbacks => true
|
embeds_many :javascripts, :cascade_callbacks => true
|
||||||
embeds_many :images, :cascade_callbacks => true
|
embeds_many :images, :as => :design_image, :cascade_callbacks => true
|
||||||
# embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true
|
# embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true
|
||||||
|
|
||||||
validates_presence_of :title
|
validates_presence_of :title
|
||||||
|
@ -65,9 +66,6 @@ class Design
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def parse_css_for_images
|
def parse_css_for_images
|
||||||
self.images.each do |image|
|
|
||||||
image.save
|
|
||||||
end
|
|
||||||
if (self.default_css && self.default_css.changed)
|
if (self.default_css && self.default_css.changed)
|
||||||
self.default_css.parse_urls
|
self.default_css.parse_urls
|
||||||
end
|
end
|
||||||
|
@ -76,6 +74,7 @@ class Design
|
||||||
theme.parse_urls
|
theme.parse_urls
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
parse_body_for_images(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Stylesheet < DesignFile
|
||||||
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
||||||
temp_file.write content.force_encoding("UTF-8")
|
temp_file.write content.force_encoding("UTF-8")
|
||||||
self.file = temp_file
|
self.file = temp_file
|
||||||
|
self.save
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ module ParserCommon
|
||||||
|
|
||||||
def menu_level(page, current, menu, edit = false)
|
def menu_level(page, current, menu, edit = false)
|
||||||
res = ''
|
res = ''
|
||||||
if current <= menu.levels
|
if menu.levels > 0 && current <= menu.levels
|
||||||
if current != 0
|
if current != 0
|
||||||
res << "<div class='rc_dm'>"
|
res << "<div class='rc_dm'>"
|
||||||
item = rand(100000)
|
item = rand(100000)
|
||||||
|
@ -74,7 +74,7 @@ module ParserCommon
|
||||||
body.css('.page_image').each do |page_image|
|
body.css('.page_image').each do |page_image|
|
||||||
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
|
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
|
||||||
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||||
image = page.design.images.detect{|image| image.name.eql?(page_image['name']) } unless image
|
image = page.design.images.detect{|image| image.name.eql?(File.basename(page_image['src'])) } unless image
|
||||||
if image
|
if image
|
||||||
res = "<img src=#{image.file.url} "
|
res = "<img src=#{image.file.url} "
|
||||||
page_image.attributes.each do |l|
|
page_image.attributes.each do |l|
|
||||||
|
|
|
@ -8,11 +8,6 @@ module ParserLayout
|
||||||
layout.layout_parts.build(:name => content['name'])
|
layout.layout_parts.build(:name => content['name'])
|
||||||
end
|
end
|
||||||
|
|
||||||
body.css('.page_image').each do |image|
|
|
||||||
image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(image.to_html)) }
|
|
||||||
image.update_attributes(:name => image['name'], :html_id => image['id'], :html_class => image['class']) if image
|
|
||||||
end
|
|
||||||
|
|
||||||
body.css('.page_menu').each do |menu|
|
body.css('.page_menu').each do |menu|
|
||||||
layout.build_menu(:levels => 0, :values => {}) unless layout.menu
|
layout.build_menu(:levels => 0, :values => {}) unless layout.menu
|
||||||
layout.menu.levels = i = menu['level'].to_i
|
layout.menu.levels = i = menu['level'].to_i
|
||||||
|
@ -22,12 +17,14 @@ module ParserLayout
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_html_image(html)
|
def parse_body_for_images(design)
|
||||||
html.scan(/(?<=\<img)(.*?)(?=\/\>)/){
|
body = Nokogiri::HTML(design.layout.body)
|
||||||
$1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){
|
|
||||||
return File.basename($1).gsub(/[\\\"]/, '')
|
body.css('.page_image').each do |page_image|
|
||||||
}
|
image = design.images.where( file: File.basename(page_image['src']))[0]
|
||||||
}
|
image.update_attributes(:name => File.basename(page_image['src']), :html_id => page_image['id'], :html_class => page_image['class']) if image
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue