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

Instance Method Details

#cama_get_list_layouts_filesObject

get list layouts files of current theme return an array of layouts for current theme


60
61
62
63
64
65
66
67
# File 'app/helpers/camaleon_cms/site_helper.rb', line 60

def cama_get_list_layouts_files
  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
  contained_files
end

#cama_get_list_template_filesObject

get list templates files of current theme


49
50
51
52
53
54
55
56
# File 'app/helpers/camaleon_cms/site_helper.rb', line 49

def cama_get_list_template_files
  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
  contained_files
end

#cama_site_check_existenceObject

check if current site exist, if not, this will be redirected to main domain


32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/camaleon_cms/site_helper.rb', line 32

def cama_site_check_existence()
  if !current_site.present?
    if (PluginRoutes.main_site).present?
      base_domain = PluginRoutes.system_info["base_domain"]
      redirect_to cama_root_url(host: base_domain.split(":").first, port: (base_domain.split(":")[1] rescue nil))
    else
      redirect_to cama_admin_installers_path
    end
  end
end

#current_localeObject

get locale language


72
73
74
# File 'app/helpers/camaleon_cms/site_helper.rb', line 72

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
27
28
29
# 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
  else
    host = request.original_url.to_s.parse_domain
    if host == PluginRoutes.system_info["base_domain"]
      site = CamaleonCms::Site.first.decorate rescue nil
    else
      s = [host]
      s << request.subdomain if request.subdomain.present?
      site = CamaleonCms::Site.where(slug: s).first.decorate rescue nil
    end
  end
  puts "============================ Please define the $current_site = CamaleonCms::Site.first.decorate " unless site.present?
  @current_site = site
end

#current_themeObject

return current theme model for current site


44
45
46
# File 'app/helpers/camaleon_cms/site_helper.rb', line 44

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


79
80
81
82
83
84
85
86
# File 'app/helpers/camaleon_cms/site_helper.rb', line 79

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_console_switch(site = nil) ⇒ Object

ONLY FOR CONSOLE #################### switch console sessions and redefine current for the console session site: Site model used as current site return nil


126
127
128
129
# File 'app/helpers/camaleon_cms/site_helper.rb', line 126

def site_console_switch(site = nil)
  $current_site = site
  site_load_custom_models($current_site)
end

#site_install_theme(key) ⇒ Object

install theme for current site


89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/camaleon_cms/site_helper.rb', line 89

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_load_custom_models(site) ⇒ Object

load all custom models customized by plugins or templates in custom_models.rb


114
115
116
117
118
119
120
# File 'app/helpers/camaleon_cms/site_helper.rb', line 114

def site_load_custom_models(site)
  PluginRoutes.enabled_apps(site).each{ |app|
    next unless app["path"].present?
    s = File.join(app["path"], "config", "custom_models.rb")
    eval(File.read(s)) if File.exist?(s)
  }
end

#site_uninstall_themeObject

uninstall current theme form current site


104
105
106
107
108
109
110
# File 'app/helpers/camaleon_cms/site_helper.rb', line 104

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