Module: CamaleonCms::SiteHelper

Included in:
CamaleonController, HtmlMailer, PluginsHelper
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



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

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



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

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



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

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)


120
121
122
# File 'app/helpers/camaleon_cms/site_helper.rb', line 120

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

#current_localeObject

get locale language



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

def current_locale
  I18n.locale.to_s
end

#current_site(site = nil) ⇒ Object

return current site or assign a site as a current site



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/camaleon_cms/site_helper.rb', line 4

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 = begin
      CamaleonCms::Site.first.decorate
    rescue StandardError
      nil
    end
  else
    host = [request.original_url.to_s.parse_domain]
    host << request.subdomain if request.subdomain.present?
    site = begin
      CamaleonCms::Site.where(slug: host).first.decorate
    rescue StandardError
      nil
    end
  end
  r = { site: site, request: begin
    request
  rescue StandardError
    nil
  end }
  begin
    cama_current_site_helper(r)
  rescue StandardError
    nil
  end
  unless r[:site].present?
    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)
  end
  @current_site = r[:site]
end

#current_themeObject

return current theme model for current site



41
42
43
# File 'app/helpers/camaleon_cms/site_helper.rb', line 41

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



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

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



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

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



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

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