seminar2_old/app/models/seminar_template_setting.rb

58 lines
2.8 KiB
Ruby
Raw Normal View History

2021-06-17 10:07:43 +00:00
class SeminarTemplateSetting
include Mongoid::Document
include Mongoid::Timestamps
DefaultMenu = ["introduction","news","registration","submission","album"]
belongs_to :seminar_main
field :enable_custom_template, type: Boolean, default: false
field :display_menu, type: Array, default: ["introduction","news","registration","submission","album"]
field :announcement_limit, type: Integer , default: 4
field :album_limit, type: Integer , default: 4
field :website_title, type: String , default: "", localize: true
field :footer_info, type: String , default: "", localize: true
field :introduction, type: String , default: "", localize: true
field :background_style, type: String , default: ""
field :content_style, type: String , default: ""
has_many :seminar_banner_images, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :seminar_banner_images, :allow_destroy => true
def self.initialize_variables
app_path = Pathname.new(__FILE__).dirname.dirname
@@background_style_infos = {}
Dir.glob("#{app_path}/assets/stylesheets/seminar/background_style/*/").each do |folder|
files = Dir.glob("#{folder}/*")
image_file = files.select{|f| File.basename(f).match(/jpg|gif|png|jpeg/i)}.first
key = File.basename(folder)
image_path = "/assets/seminar/background_style/#{key}/#{File.basename(image_file) rescue ''}"
@@background_style_infos[key] = {
"image"=>image_path,
"css"=> get_folder_content(folder,"css"),
"js"=> get_folder_content(folder,"js")
}
end
@@background_style_infos = @@background_style_infos.sort_by {|k, v| (k.match(/\d+/)[0].to_i rescue 0)}.to_h
@@content_style_infos = {}
Dir.glob("#{app_path}/assets/stylesheets/seminar/content_style/*/").each do |folder|
files = Dir.glob("#{folder}/*")
image_file = files.select{|f| File.basename(f).match(/jpg|gif|png|jpeg/i)}.first
key = File.basename(folder)
image_path = "/assets/seminar/content_style/#{key}/#{File.basename(image_file) rescue ''}"
template_info = (JSON.parse(File.read("#{folder}/info.json")) rescue {"template"=> "horizontal"})
@@content_style_infos[key] = {
"image"=>image_path,
"css"=> get_folder_content(folder,"css"),
"js"=> get_folder_content(folder,"js"),
"template"=>"#{app_path}/assets/stylesheets/seminar/templates/#{template_info["template"]}/"
}
end
@@content_style_infos = @@content_style_infos.sort_by {|k, v| (k.match(/\d+/)[0].to_i rescue 0)}.to_h
end
def self.get_folder_content(folder,content)
return Dir.glob("#{folder}#{content}/*").map{|content| content.split("app")[1..-1].join("app").sub("/stylesheets/",'/')}
end
def self.background_style_infos
@@background_style_infos
end
def self.content_style_infos
@@content_style_infos
end
initialize_variables
end