orbit-basic/lib/parsers/parser_layout.rb

50 lines
1.6 KiB
Ruby
Raw Normal View History

2011-12-23 10:34:21 +00:00
module ParserLayout
require 'radius'
include ParserCommon
def parse_layout_contents(layout)
content = layout.content.force_encoding('UTF-8')
context = parser_layout_contents(layout)
parser = Radius::Parser.new(context, :tag_prefix => 'r')
parser.parse(content)
end
def parser_layout_contents(layout)
Radius::Context.new do |c|
c.define_tag 'ad_banner' do |tag|
end
c.define_tag 'content' do |tag|
layout.layout_parts.new(:name => tag.attr['name'])
2011-12-23 10:34:21 +00:00
end
c.define_tag 'image' do |tag|
image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) }
image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image
2011-12-23 10:34:21 +00:00
end
c.define_tag 'javascripts' do |tag|
2012-02-02 01:55:09 +00:00
end
2011-12-23 10:34:21 +00:00
c.define_tag 'menu' do |tag|
layout.build_menu(:levels => 0, :values => {}) unless layout.menu
layout.menu.levels = i = tag.attr['level'].to_i
layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1
layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']})
tag.expand
end
c.define_tag 'meta' do |tag|
2011-12-23 10:34:21 +00:00
end
c.define_tag 'stylesheets' do |tag|
2011-12-23 10:34:21 +00:00
end
c.define_tag 'title' do |tag|
end
2011-12-23 10:34:21 +00:00
end
end
def parse_html_image(html)
html.scan(/(?<=\<img)(.*?)(?=\/\>)/){
$1.gsub(' ','').scan(/(?<=src=\")(.*?)(?=\")/){
return File.basename($1).gsub(/[\\\"]/, '')
}
}
end
2011-12-23 10:34:21 +00:00
end