From d2c2e174ac88a9f5b1dd0e69b0f96fd9a0d6e67b Mon Sep 17 00:00:00 2001 From: Kaito Date: Tue, 16 Aug 2011 17:10:16 +0800 Subject: [PATCH] uploading is ok,checking parsing result is needed --- app/controllers/admin/designs_controller.rb | 25 +++++++++++---------- lib/parser.rb | 23 ++++++++++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/designs_controller.rb b/app/controllers/admin/designs_controller.rb index 3228eb6a..2876bc49 100644 --- a/app/controllers/admin/designs_controller.rb +++ b/app/controllers/admin/designs_controller.rb @@ -31,29 +31,30 @@ class Admin::DesignsController < ApplicationController themes_entries = [] javascripts_entries = [] images_entries = [] - temp_file4layout = File.new(dir + '/' + zip_name+'-1', 'w+') - temp_file4layout.binmode #dir/zip_name - temp_file4structure = File.new(dir + '/' + zip_name+'-2', 'w+') - temp_file4structure.binmode #dir/zip_name - zip_file.entries.each do |entry| case (path = entry.to_s) when /\A(#{zip_name})\/[^\/]*(\.css)\z/ #for structure css - # struct_css_entry = entry + filename = File.basename(entry.to_s,".css") + temp_file4structure = File.new(dir + '/' + filename, 'w+') + temp_file4structure.binmode temp_file4structure.write (zip_file.read entry ) design.structure_css = temp_file4structure when /\A(#{zip_name})\/[^\/]*(\.html)\z/ #for layout html - # layout_entry = entry + filename = File.basename(entry.to_s,".css") + temp_file4layout = File.new(dir + '/' + filename, 'w+') + temp_file4layout.binmode temp_file4layout.write (zip_file.read entry ) - design.layout.file = temp_file4structure + design.layout.file = temp_file4layout design.layout.to_save=true - when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ #for themes css + when /\A(#{zip_name})\/(themes)\/.*(\.css)\z/ + #for themes css themes_entries << entry - when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ #for js + when /\A(#{zip_name})\/(javascripts)\/.*(\.js)\z/ + #for js javascripts_entries << entry - when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img + when /\A(#{zip_name})\/(images)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img images_entries << entry end end @@ -68,7 +69,7 @@ class Admin::DesignsController < ApplicationController build_and_store = eval("design.#{type}").build build_and_store.file = temp_file build_and_store.file_filename = filename - build_and_store._type = (File.extname entry.to_s).delete '.' +# build_and_store._type = (File.extname entry.to_s).delete '.' build_and_store.to_save = true end end diff --git a/lib/parser.rb b/lib/parser.rb index fe9467a0..7812d551 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -63,6 +63,10 @@ module Parser end res end + c.define_tag 'stylesheets' do |tag| + contents = tag.expand + contents.to_html + end c.define_tag 'image' do |tag| asset = Asset.find(tag.attr['id']) if asset @@ -158,6 +162,10 @@ module Parser res << '>' end end + c.define_tag 'stylesheets' do |tag| + contents = tag.expand + contents.to_html + end c.define_tag 'layout_part' do |tag| part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } ret = '' @@ -191,8 +199,13 @@ module Parser parser.parse(layout_content) end - def parser_context_code(page) + def parser_context_code(page) #context should be interpretd as the orginally one Radius::Context.new do |c| + c.define_tag 'stylesheets' do |tag| + res << "" + res << tag.expand.to_s + res << "" + end c.define_tag 'layout_part' do |tag| part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } res = '' @@ -216,6 +229,14 @@ module Parser def parser_layout_layout_part(layout ) Radius::Context.new do |c| + c.define_tag 'javascripts' do |tag| + contents = tag.expand + contents.to_s + end + c.define_tag 'stylesheets' do |tag| + contents = tag.expand + contents.to_s + end c.define_tag 'layout_part' do |tag| data={} data[:class_tag]=tag.attr['class'].to_s