Clean the parsers and introduce the metas
This commit is contained in:
parent
472744fc87
commit
a126935d2c
|
@ -0,0 +1,11 @@
|
|||
class Meta
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
field :value, :default => nil
|
||||
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class Meta
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
field :value, :default => nil
|
||||
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class PageMeta < Meta
|
||||
|
||||
belongs_to :page
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class SiteMeta < Meta
|
||||
|
||||
belongs_to :site
|
||||
|
||||
end
|
|
@ -6,11 +6,13 @@ class Page < Item
|
|||
|
||||
belongs_to :design
|
||||
belongs_to :module_app
|
||||
has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :page_parts, :autosave => true, :dependent => :destroy
|
||||
has_many :page_contexts, :autosave => true, :dependent => :destroy
|
||||
has_many :page_metas, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
||||
|
||||
before_save :create_parts
|
||||
before_save :create_parts, :set_key
|
||||
|
||||
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
|
||||
|
||||
|
@ -18,6 +20,10 @@ class Page < Item
|
|||
self.parent ? false : true
|
||||
end
|
||||
|
||||
def title
|
||||
@title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def create_parts
|
||||
|
@ -27,4 +33,10 @@ class Page < Item
|
|||
end
|
||||
end
|
||||
|
||||
def set_key
|
||||
if title.new_record?
|
||||
title.key = 'title'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -13,6 +13,8 @@ class Site
|
|||
field :school
|
||||
field :department
|
||||
|
||||
has_many :site_metas, :autosave => true, :dependent => :destroy
|
||||
|
||||
def generate_keys
|
||||
private_key = OpenSSL::PKey::RSA.generate(2048)
|
||||
self.public_key = private_key.public_key.to_s
|
||||
|
|
|
@ -13,63 +13,6 @@ module ParserBackEnd
|
|||
|
||||
def parser_context_edit(page, attributes = {})
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'snippet' do |tag|
|
||||
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
||||
if snippet
|
||||
snippet.content
|
||||
else
|
||||
t('nothing')
|
||||
end
|
||||
end
|
||||
c.define_tag 'language_bar' do
|
||||
@site.in_use_locales.map{ |locale|
|
||||
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
|
||||
if I18n.locale.to_s.eql?(locale)
|
||||
lang
|
||||
else
|
||||
"<a href='?locale=#{locale}'>#{lang}</a>"
|
||||
end
|
||||
}.join(' | ')
|
||||
end
|
||||
c.define_tag 'css' do |tag|
|
||||
assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
|
||||
res = ''
|
||||
assets.each do |asset|
|
||||
res << "<link href='#{asset.data.file.url}' rel='stylesheet' type='text/css' /> " if asset.data.file.content_type.eql?('text/css')
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'image' do |tag|
|
||||
# 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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||
if image
|
||||
res = "<img src=#{image.file.url} "
|
||||
tag.attr.each do |l|
|
||||
res << "#{l[0]}='#{l[1]}' "
|
||||
end
|
||||
res << '>'
|
||||
end
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.reset_css
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.default_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
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
res << "<script type='text/javascript' src='/static/jquery.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/kernel.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/event.js'></script>"
|
||||
page.design.javascripts.each do |js|
|
||||
res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'ad_banner' do |tag|
|
||||
res = ''
|
||||
ad_banner = AdBanner.find(tag.attr["id"]) rescue nil
|
||||
|
@ -89,13 +32,6 @@ module ParserBackEnd
|
|||
res << "</div>"
|
||||
end
|
||||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
|
||||
ret = ''
|
||||
ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}'>"
|
||||
ret << tag.expand
|
||||
ret << '</div>'
|
||||
end
|
||||
c.define_tag 'content' do |tag|
|
||||
ret = ''
|
||||
if (tag.attributes["main"] == "true" && !page.module_app.nil?)
|
||||
|
@ -125,6 +61,39 @@ module ParserBackEnd
|
|||
ret << '</div>'
|
||||
end
|
||||
end
|
||||
c.define_tag 'image' do |tag|
|
||||
# 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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||
if image
|
||||
res = "<img src=#{image.file.url} "
|
||||
tag.attr.each do |l|
|
||||
res << "#{l[0]}='#{l[1]}' "
|
||||
end
|
||||
res << '>'
|
||||
end
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
res << "<script type='text/javascript' src='/static/jquery.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/kernel.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/event.js'></script>"
|
||||
page.design.javascripts.each do |js|
|
||||
res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'language_bar' do
|
||||
@site.in_use_locales.map{ |locale|
|
||||
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
|
||||
if I18n.locale.to_s.eql?(locale)
|
||||
lang
|
||||
else
|
||||
"<a href='?locale=#{locale}'>#{lang}</a>"
|
||||
end
|
||||
}.join(' | ')
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
ret = ''
|
||||
|
@ -139,6 +108,20 @@ module ParserBackEnd
|
|||
menu = page.design.layout.menu
|
||||
menu_level(home, 0, menu, true)
|
||||
end
|
||||
c.define_tag 'meta' do |tag|
|
||||
"<meta name='bob' content=#{@site.school} />"
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.reset_css
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.default_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
|
||||
end
|
||||
c.define_tag 'title' do |tag|
|
||||
"<title>#{page.title ? page.title : page.i18n_variable[I18n.locale]}</title>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,88 +4,6 @@ module ParserFrontEnd
|
|||
|
||||
def parser_context(page, attributes = {}, id = nil)
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'snippet' do |tag|
|
||||
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
|
||||
if snippet
|
||||
snippet.content
|
||||
else
|
||||
t('nothing')
|
||||
end
|
||||
end
|
||||
c.define_tag 'language_bar' do
|
||||
@site.in_use_locales.map{ |locale|
|
||||
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
|
||||
if I18n.locale.to_s.eql?(locale)
|
||||
lang
|
||||
else
|
||||
"<a href='?locale=#{locale}'>#{lang}</a>"
|
||||
end
|
||||
}.join(' | ')
|
||||
end
|
||||
c.define_tag 'locale' do |tag|
|
||||
case attributes[:locale]
|
||||
when 'create'
|
||||
var = I18nVariable.new(:key => (tag.attr['name'] rescue nil), :document_class => 'Text')
|
||||
@site.valid_locales.each do |locale|
|
||||
var[locale] = tag.attr[locale] rescue nil
|
||||
end
|
||||
var.save!
|
||||
res = ''
|
||||
res << "<r:locale id='#{var.id}' "
|
||||
res << "name='#{var.key}' " if var.key
|
||||
@site.valid_locales.each do |locale|
|
||||
res << "#{locale}='#{var[locale]}' "
|
||||
end
|
||||
res << '/>'
|
||||
when 'show'
|
||||
var = I18nVariable.find(tag.attr['id'])
|
||||
res = ''
|
||||
res << "<r:locale "
|
||||
res << "name='#{var.key}' " if var.key
|
||||
@site.valid_locales.each do |locale|
|
||||
res << "#{locale}='#{var[locale]}' "
|
||||
end
|
||||
res << '/>'
|
||||
when 'destroy'
|
||||
var = I18nVariable.find(tag.attr['id'])
|
||||
var.destroy
|
||||
end
|
||||
end
|
||||
c.define_tag 'css' do |tag|
|
||||
assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
|
||||
res = ''
|
||||
assets.each do |asset|
|
||||
res << "<link href='#{asset.data.file.url}' rel='stylesheet' type='text/css' /> " if asset.data.file.content_type.eql?('text/css')
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='/assets/bootstrap.css.erb' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='/assets/style.css.erb' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.reset_css
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' /> " if page.design.default_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
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
res << "<script type='text/javascript' src='/static/jquery.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/kernel.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/bootstrap.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/jquery.tinyscrollbar.min.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/jquery.isotope.min.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/orbit-1.0.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/orbit_bar.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/event.js'></script>"
|
||||
page.design.javascripts.each do |js|
|
||||
# res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'ad_banner' do |tag|
|
||||
res = ''
|
||||
ad_banner = AdBanner.find(tag.attr["id"]) rescue nil
|
||||
|
@ -106,22 +24,6 @@ module ParserFrontEnd
|
|||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'image' do |tag|
|
||||
# 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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||
if image
|
||||
res = "<img src=#{image.file.url} "
|
||||
tag.attr.each do |l|
|
||||
res << "#{l[0]}='#{l[1]}' "
|
||||
end
|
||||
res << '>'
|
||||
end
|
||||
end
|
||||
c.define_tag 'layout_part' do |tag|
|
||||
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
|
||||
part.content
|
||||
end
|
||||
c.define_tag 'content' do |tag|
|
||||
ret = ''
|
||||
if (tag.attributes["main"] == "true" && !page.module_app.nil?)
|
||||
|
@ -149,6 +51,44 @@ module ParserFrontEnd
|
|||
end
|
||||
ret
|
||||
end
|
||||
c.define_tag 'image' do |tag|
|
||||
# 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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||
if image
|
||||
res = "<img src=#{image.file.url} "
|
||||
tag.attr.each do |l|
|
||||
res << "#{l[0]}='#{l[1]}' "
|
||||
end
|
||||
res << '>'
|
||||
end
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
res = ''
|
||||
res << "<script type='text/javascript' src='/static/jquery.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
|
||||
res << "<script type='text/javascript' src='/static/kernel.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/bootstrap.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/jquery.tinyscrollbar.min.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/jquery.isotope.min.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/orbit-1.0.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/orbit_bar.js'></script>"
|
||||
res << "<script type='text/javascript' src='/assets/event.js'></script>"
|
||||
page.design.javascripts.each do |js|
|
||||
# res << "<script type='text/javascript' src='#{js.file.url}'></script>"
|
||||
end
|
||||
res
|
||||
end
|
||||
c.define_tag 'language_bar' do
|
||||
@site.in_use_locales.map{ |locale|
|
||||
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
|
||||
if I18n.locale.to_s.eql?(locale)
|
||||
lang
|
||||
else
|
||||
"<a href='?locale=#{locale}'>#{lang}</a>"
|
||||
end
|
||||
}.join(' | ')
|
||||
end
|
||||
c.define_tag 'link' do |tag|
|
||||
item = Item.first(:conditions => { :full_name => tag.attr['name'] })
|
||||
ret = ''
|
||||
|
@ -161,6 +101,24 @@ module ParserFrontEnd
|
|||
menu = page.design.layout.menu
|
||||
menu_level(home, 0, menu)
|
||||
end
|
||||
c.define_tag 'meta' do |tag|
|
||||
res = ''
|
||||
#res << "<meta name='bob' content='#{@site.school}' />"
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
res = ''
|
||||
res << "<link href='/assets/bootstrap.css.erb' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='/assets/style.css.erb' rel='stylesheet' type='text/css'/>"
|
||||
res << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />" if page.design.reset_css
|
||||
res << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' /> " if page.design.default_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
|
||||
end
|
||||
c.define_tag 'title' do |tag|
|
||||
"<title>#{page.title ? page.title[I18n.locale] : page.i18n_variable[I18n.locale]}</title>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,19 +11,8 @@ module ParserLayout
|
|||
|
||||
def parser_layout_contents(layout)
|
||||
Radius::Context.new do |c|
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
end
|
||||
c.define_tag 'ad_banner' do |tag|
|
||||
end
|
||||
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 'content' do |tag|
|
||||
layout.layout_parts.new(:name => tag.attr['name'])
|
||||
end
|
||||
|
@ -31,6 +20,22 @@ module ParserLayout
|
|||
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
|
||||
end
|
||||
c.define_tag 'javascripts' do |tag|
|
||||
end
|
||||
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|
|
||||
end
|
||||
c.define_tag 'stylesheets' do |tag|
|
||||
end
|
||||
c.define_tag 'title' do |tag|
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue