Module: CamaleonCms::SiteHelper

Included in:
CamaleonController, HtmlMailer
Defined in:
app/helpers/camaleon_cms/site_helper.rb

Instance Method Summary collapse

Instance Method Details

#cama_current_site_host_port(args) ⇒ Object

add host + port to args of the current site visited (only if the request is coming from console or tasks i.e. not web browser) args: Hash sample: {} will return ‘localhost’, port: 3000



94
95
96
97
# File 'app/helpers/camaleon_cms/site_helper.rb', line 94

def cama_current_site_host_port(args)
  args[:host], args[:port] = current_site.try(:get_domain).to_s.split(':') if cama_is_test_request?
  args
end

#cama_get_list_layouts_files(post_type) ⇒ Object

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



38
39
40
41
42
43
44
45
46
# File 'app/helpers/camaleon_cms/site_helper.rb', line 38

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



26
27
28
29
30
31
32
33
34
# File 'app/helpers/camaleon_cms/site_helper.rb', line 26

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

#cama_is_test_request?Boolean

check if the request created by draper or request is not defined

Returns:

  • (Boolean)


100
101
102
# File 'app/helpers/camaleon_cms/site_helper.rb', line 100

def cama_is_test_request?
  (request && defined?(ActionController::TestRequest) && request.is_a?(ActionController::TestRequest)) || !request
end

#current_localeObject

get locale language



51
52
53
# File 'app/helpers/camaleon_cms/site_helper.rb', line 51

def current_locale
  I18n.locale.to_s
end

#current_site(site = nil) ⇒ Object

return current site or assign a site as a current site



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/camaleon_cms/site_helper.rb', line 3

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
  Rails.logger.error 'Camaleon CMS - Please define your current site: $current_site = CamaleonCms::Site.first.decorate or map your domains: http://camaleon.tuzitio.com/documentation/category/139779-examples/how.html'.cama_log_style(:red) if !r[:site].present?
  @current_site = r[:site]
end

#current_themeObject

return current theme model for current site



21
22
23
# File 'app/helpers/camaleon_cms/site_helper.rb', line 21

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



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

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



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/camaleon_cms/site_helper.rb', line 68

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_themeObject

uninstall current theme form current site



83
84
85
86
87
88
89
# File 'app/helpers/camaleon_cms/site_helper.rb', line 83

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