Module: CamaleonCms::SiteHelper
- Included in:
- CamaleonController, HtmlMailer
- Defined in:
- app/helpers/camaleon_cms/site_helper.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
Instance Method Summary collapse
-
#cama_get_list_layouts_files(post_type) ⇒ Object
get list layouts files of current theme return an array of layouts for current theme.
-
#cama_get_list_template_files(post_type) ⇒ Object
get list templates files of current theme.
-
#current_locale ⇒ Object
get locale language.
-
#current_site(site = nil) ⇒ Object
return current site or assign a site as a current site.
-
#current_theme ⇒ Object
return current theme model for current site.
-
#site_after_install(site, theme_key = nil) ⇒ Object
***************** administration HELPERS *********************** do common actions after site installation theme_key: theme slug of the theme for site.
-
#site_install_theme(key) ⇒ Object
install theme for current site.
-
#site_uninstall_theme ⇒ Object
uninstall current theme form current site.
Instance Method Details
#cama_get_list_layouts_files(post_type) ⇒ Object
get list layouts files of current theme return an array of layouts for current theme
46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 46 def cama_get_list_layouts_files(post_type) contained_files = [] Dir[File.join(current_theme.settings["path"], "views", "layouts", '*')].each do |path| f_name = File.basename(path) contained_files << f_name.split(".").first unless f_name.start_with?('_') end _args={layouts: contained_files, post_type: post_type}; hooks_run("post_get_list_layouts", _args) _args[:layouts] end |
#cama_get_list_template_files(post_type) ⇒ Object
get list templates files of current theme
34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 34 def cama_get_list_template_files(post_type) contained_files = [] Dir[File.join(current_theme.settings["path"], "views", '*')].each do |path| f_name = File.basename(path) contained_files << f_name.split(".").first if f_name.include?('template_') end _args={tempates: contained_files, post_type: post_type}; hooks_run("post_get_list_templates", _args) _args[:tempates] end |
#current_locale ⇒ Object
get locale language
59 60 61 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 59 def current_locale I18n.locale.to_s end |
#current_site(site = nil) ⇒ Object
return current site or assign a site as a current site
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 11 def current_site(site = nil) @current_site = site.decorate if site.present? return $current_site if defined?($current_site) return @current_site if defined?(@current_site) if PluginRoutes.get_sites.size == 1 site = CamaleonCms::Site.first.decorate rescue nil else host = [request.original_url.to_s.parse_domain] host << request.subdomain if request.subdomain.present? site = CamaleonCms::Site.where(slug: host).first.decorate rescue nil end r = {site: site, request: request}; cama_current_site_helper(r) rescue nil puts "============================ Please define the $current_site = CamaleonCms::Site.first.decorate " unless r[:site].present? @current_site = r[:site] end |
#current_theme ⇒ Object
return current theme model for current site
29 30 31 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 29 def current_theme @_current_theme ||= current_site.get_theme.decorate end |
#site_after_install(site, theme_key = nil) ⇒ Object
***************** administration HELPERS *********************** do common actions after site installation theme_key: theme slug of the theme for site
66 67 68 69 70 71 72 73 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 66 def site_after_install(site, theme_key = nil) theme_key ||= site.get_theme_slug _s = current_site current_site(site) PluginRoutes.system_info["default_plugins"].each{|p| plugin_install(p) } # auto install plugins site_install_theme(theme_key) current_site(_s) if _s.present? end |
#site_install_theme(key) ⇒ Object
install theme for current site
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 76 def site_install_theme(key) #uninstall previous theme site_uninstall_theme() # new theme current_site.set_option('_theme', key) theme = PluginRoutes.theme_info(key) current_site.themes.update_all(status: "inactive") theme_model = current_site.themes.where(slug: key).first_or_create!{|t| t.name = theme[:name]; } theme_model.update(status: nil) hook_run(theme, "on_active", theme_model) PluginRoutes.reload end |
#site_uninstall_theme ⇒ Object
uninstall current theme form current site
91 92 93 94 95 96 97 |
# File 'app/helpers/camaleon_cms/site_helper.rb', line 91 def site_uninstall_theme() key = current_site.get_theme_slug theme = PluginRoutes.theme_info(key) theme_model = current_site.get_theme(key) hook_run(theme, "on_inactive", theme_model) if theme_model.present? # theme_model.destroy end |