Modification in Design structure_css -> default_css
This commit is contained in:
parent
07ccacb7d7
commit
4db88282a1
|
@ -101,12 +101,18 @@ class Admin::DesignsController < ApplicationController
|
|||
filename = File.basename(entry.to_s)
|
||||
temp_file = File.new(dir + '/' + filename, 'w+')
|
||||
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
|
||||
design.default_css = temp_file
|
||||
default_css = design.build_default_css
|
||||
default_css.file = temp_file
|
||||
default_css.file_filename = filename
|
||||
default_css.to_save = true
|
||||
when /\A(#{zip_name})\/(reset\.css)\z/ #for reset css
|
||||
filename = File.basename(entry.to_s)
|
||||
temp_file = File.new(dir + '/' + filename, 'w+')
|
||||
temp_file.write (zip_file.read entry ).force_encoding('UTF-8')
|
||||
design.reset_css = temp_file
|
||||
reset_css = design.build_reset_css
|
||||
reset_css.file = temp_file
|
||||
reset_css.file_filename = filename
|
||||
reset_css.to_save = true
|
||||
when /\A(#{zip_name})\/(layout\.html)\z/ #for layout html
|
||||
filename = File.basename(entry.to_s)
|
||||
temp_file = File.new(dir + '/' + filename, 'w+')
|
||||
|
|
|
@ -58,24 +58,13 @@ class Admin::PurchasesController < ApplicationController
|
|||
design = Design.new.from_json(orig_zip.read("#{zip_name}/#{zip_name}.json"))
|
||||
Dir.mktmpdir('f_path') { |dir|
|
||||
|
||||
title = design.layout.file_filename
|
||||
temp = File.new(dir + '/' + title, 'w+')
|
||||
temp.write orig_zip.read(zip_name + '/' + title)
|
||||
design.layout.file = temp
|
||||
design.layout.to_save = true
|
||||
|
||||
title = design.default_css_filename
|
||||
temp = File.new(dir + '/' + title, 'w+')
|
||||
temp.write orig_zip.read(zip_name + '/' + title)
|
||||
design.default_css = temp
|
||||
build_file(orig_zip, zip_name, dir, design.layout) if design.layout
|
||||
build_file(orig_zip, zip_name, dir, design.default_css) if design.default_css
|
||||
build_file(orig_zip, zip_name, dir, design.reset_css) if design.reset_css
|
||||
|
||||
['themes', 'javascripts', 'images'].each do |type|
|
||||
design.send(type).each do |object|
|
||||
title = object.file_filename
|
||||
temp = File.new(dir + '/' + title, 'w+')
|
||||
temp.write orig_zip.read(zip_name + '/' + type + '/' + title)
|
||||
object.file = temp
|
||||
object.to_save = true
|
||||
build_file(orig_zip, zip_name, dir, object, type)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
@ -86,5 +75,13 @@ class Admin::PurchasesController < ApplicationController
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
def build_file(orig_zip, zip_name, dir, object, type = nil)
|
||||
title = object.file_filename
|
||||
temp = File.new(dir + '/' + title, 'w+')
|
||||
temp.write orig_zip.read(zip_name + '/' + (type ? (type + '/') : '') + title)
|
||||
object.file = temp
|
||||
object.to_save = true
|
||||
end
|
||||
|
||||
end
|
|
@ -7,12 +7,11 @@ class Design
|
|||
field :intro
|
||||
field :version
|
||||
|
||||
mount_uploader :default_css, AssetUploader
|
||||
mount_uploader :reset_css, AssetUploader
|
||||
|
||||
has_many :pages
|
||||
|
||||
embeds_one :layout
|
||||
embeds_one :default_css, :class_name => "Stylesheet"
|
||||
embeds_one :reset_css, :class_name => "Stylesheet"
|
||||
embeds_many :stylesheets
|
||||
embeds_many :themes
|
||||
embeds_many :javascripts
|
||||
|
@ -78,10 +77,14 @@ class Design
|
|||
self.layout.save
|
||||
self.layout.parse_urls
|
||||
end
|
||||
self.themes.each do |theme|
|
||||
to_parse_url = theme.to_save ? true : false
|
||||
process_object(theme)
|
||||
theme.parse_urls if to_parse_url
|
||||
[[self.default_css], [self.reset_css], self.themes].each do |objects|
|
||||
objects.each do |object|
|
||||
if object
|
||||
to_parse_url = object.to_save ? true : false
|
||||
process_object(object)
|
||||
object.parse_urls if to_parse_url
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,35 @@
|
|||
class Stylesheet < DesignFile
|
||||
embedded_in :design
|
||||
mount_uploader :file_orig, AssetUploader
|
||||
|
||||
def parse_urls
|
||||
orig_content = content = self.file.read.force_encoding("UTF-8")
|
||||
self.remove_file!
|
||||
self.remove_file_orig!
|
||||
names = []
|
||||
images = self.design.images
|
||||
content.scan(/(?<=url)(.*?)(?=\))/){
|
||||
css_name = $1.gsub(' ','').gsub('(','')
|
||||
name = File.basename(css_name).gsub(/[\\\"]/, '')
|
||||
file_name = images.detect{ |i| i.file_filename.eql?(name) }.file_url rescue nil
|
||||
names << [css_name, file_name]
|
||||
}
|
||||
names.each do |name|
|
||||
content.gsub!(name[0], name[1]) if name[1]
|
||||
end
|
||||
Dir.mktmpdir('f_path') { |dir|
|
||||
orig_file_name = self.file_filename
|
||||
|
||||
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
||||
temp_file.write orig_content.force_encoding("UTF-8")
|
||||
self.file_orig = temp_file
|
||||
|
||||
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
||||
temp_file.write content.force_encoding("UTF-8")
|
||||
self.file = temp_file
|
||||
|
||||
self.save
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,40 +1,9 @@
|
|||
class Theme < Stylesheet
|
||||
embedded_in :design
|
||||
field :name
|
||||
mount_uploader :file_orig, AssetUploader
|
||||
|
||||
before_save :set_name
|
||||
|
||||
def parse_urls
|
||||
orig_content = content = self.file.read.force_encoding("UTF-8")
|
||||
self.remove_file!
|
||||
self.remove_file_orig!
|
||||
names = []
|
||||
images = self.design.images
|
||||
content.scan(/(?<=url)(.*?)(?=\))/){
|
||||
css_name = $1.gsub(' ','').gsub('(','')
|
||||
name = File.basename(css_name).gsub(/[\\\"]/, '')
|
||||
file_name = images.detect{ |i| i.file_filename.eql?(name) }.file_url rescue nil
|
||||
names << [css_name, file_name]
|
||||
}
|
||||
names.each do |name|
|
||||
content.gsub!(name[0], name[1])
|
||||
end
|
||||
Dir.mktmpdir('f_path') { |dir|
|
||||
orig_file_name = self.file_filename
|
||||
|
||||
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
||||
temp_file.write orig_content.force_encoding("UTF-8")
|
||||
self.file_orig = temp_file
|
||||
|
||||
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
||||
temp_file.write content.force_encoding("UTF-8")
|
||||
self.file = temp_file
|
||||
|
||||
self.save
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_name
|
||||
|
|
|
@ -30,9 +30,12 @@
|
|||
<p>
|
||||
<%= f.label "default_css", t('admin.default_css') %>
|
||||
<% if @design.default_css.blank? %>
|
||||
<%= f.file_field :default_css %>
|
||||
<%= fields_for 'design[default_css]' do |f| %>
|
||||
<%= f.file_field :file %>
|
||||
<%= f.hidden_field :to_save, :value => true %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= File.basename (@design.default_css.url) %>
|
||||
<%= File.basename (@design.default_css.file.url) %>
|
||||
<% end %>
|
||||
</p>
|
||||
<p>
|
||||
|
|
|
@ -65,8 +65,8 @@ module Parser
|
|||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='#{page.design.reset_css.url}' rel='stylesheet' type='text/css' />"
|
||||
res << "<link href='#{page.design.default_css.url}' rel='stylesheet' type='text/css' /> "
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />"
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' /> "
|
||||
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
|
||||
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />" if theme
|
||||
res
|
||||
|
@ -175,8 +175,8 @@ module Parser
|
|||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='#{page.design.reset_css.url}' rel='stylesheet' type='text/css' />"
|
||||
res << "<link href='#{page.design.default_css.url}' rel='stylesheet' type='text/css' />"
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />"
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />"
|
||||
theme = page.design.themes.detect{ |d| d.id == page.theme_id }
|
||||
res << "<link href='#{theme.file.url}' rel='stylesheet' type='text/css' />" if theme
|
||||
res
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace :dev do
|
|||
|
||||
design = Design.new(:title => "Fraisier", :author => "Paul", :intro => "Strawberry cake")
|
||||
|
||||
design.default_css = File.open("#{Rails.root}/lib/fraisier/default.css")
|
||||
design.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css"))
|
||||
|
||||
# image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif"))
|
||||
#
|
||||
|
@ -81,9 +81,9 @@ namespace :dev do
|
|||
design.build_layout
|
||||
design.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
|
||||
|
||||
design.layout.save
|
||||
theme.save
|
||||
theme_1.save
|
||||
design.layout
|
||||
theme
|
||||
theme_1
|
||||
# image.save
|
||||
# js.save
|
||||
|
||||
|
@ -93,7 +93,7 @@ namespace :dev do
|
|||
|
||||
design_1 = Design.new(:title => "Bob", :author => "Me", :intro => "Moran")
|
||||
|
||||
design_1.default_css = File.open("#{Rails.root}/lib/fraisier/default.css")
|
||||
design_1.build_default_css(:file => File.open("#{Rails.root}/lib/fraisier/default.css"))
|
||||
|
||||
# image = design.images.build(:file => File.open("#{Rails.root}/lib/fraisier/img/buttons.gif"))
|
||||
#
|
||||
|
@ -105,9 +105,9 @@ namespace :dev do
|
|||
design_1.build_layout
|
||||
design_1.layout.file = File.open("#{Rails.root}/lib/fraisier/layout.html")
|
||||
|
||||
design_1.layout.save
|
||||
theme.save
|
||||
theme_1.save
|
||||
design_1.layout
|
||||
theme
|
||||
theme_1
|
||||
# image.save
|
||||
# js.save
|
||||
|
||||
|
|
Loading…
Reference in New Issue