Module: CamaleonCms::ThemeHelper
- Included in:
- RuntimeShortcodeThemeConcern
- Defined in:
- app/helpers/camaleon_cms/theme_helper.rb
Instance Method Summary collapse
-
#self_theme_key(index = 0) ⇒ Object
return theme key for current theme file (helper|controller|view) DEPRECATED, instead use: current_theme index: internal control.
-
#theme_asset_file_path(asset = nil, theme_name = nil) ⇒ Object
returns the filesystem path to theme asset theme_name: theme name, if nil, then will use the current theme asset: asset file name, if asset is present, return the full path to this asset sample: theme_asset_file_path('images/foo.jpg') => return: /home/camaleon/my-site/app/apps/themes/default/assets/images/foo.jpg.
-
#theme_asset_path(asset = nil, theme_name = nil) ⇒ Object
(also: #theme_asset, #theme_gem_asset)
return theme full asset path theme_name: theme name, if nil, then will use current theme asset: asset file name, if asset is present return the full path to this asset sample: <script src="<%= theme_asset_path("js/admin.js") %>"> => return: /assets/themes/my_theme/assets/js/admin-54505620f.js.
-
#theme_asset_url(asset, theme_name = nil) ⇒ Object
return the full url for asset of the current theme: asset: (String) asset name theme_name: (optional) theme name, default (current theme caller to this function) sample: theme_asset_url("css/main.css") => return: https://myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css.
-
#theme_home_page ⇒ Object
Returns a default message if no pages exist.
- #theme_init ⇒ Object
-
#theme_layout(layout_name, _theme_name = nil) ⇒ Object
assign the layout for this request asset: asset file name, if asset is present return the full path to this asset layout_name: layout name.
-
#theme_view(view_name, deprecated_attr = '') ⇒ Object
return the theme view path including the path of current theme view_name: name of the view or template sample: theme_view("index") => "themes/my_theme/index".
Instance Method Details
#self_theme_key(index = 0) ⇒ Object
return theme key for current theme file (helper|controller|view) DEPRECATED, instead use: current_theme index: internal control
73 74 75 76 77 78 79 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 73 def self_theme_key(index = 0) k = '/themes/' f = caller[index] return unless f.include?(k) f.split(k).last.split('/').first end |
#theme_asset_file_path(asset = nil, theme_name = nil) ⇒ Object
returns the filesystem path to theme asset theme_name: theme name, if nil, then will use the current theme asset: asset file name, if asset is present, return the full path to this asset sample: theme_asset_file_path('images/foo.jpg') => return: /home/camaleon/my-site/app/apps/themes/default/assets/images/foo.jpg
87 88 89 90 91 92 93 94 95 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 87 def theme_asset_file_path(asset = nil, theme_name = nil) theme_path = if theme_name && (theme = Theme.where(name: theme_name).first) theme.settings['path'] else current_theme.settings['path'] end "#{theme_path}/assets/#{asset}" end |
#theme_asset_path(asset = nil, theme_name = nil) ⇒ Object Also known as: theme_asset, theme_gem_asset
return theme full asset path theme_name: theme name, if nil, then will use current theme asset: asset file name, if asset is present return the full path to this asset sample: <script src="<%= theme_asset_path("js/admin.js") %>"> => return: /assets/themes/my_theme/assets/js/admin-54505620f.js
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 12 def theme_asset_path(asset = nil, theme_name = nil) return theme_asset_url(theme_name, current_theme.slug) if theme_name.present? && theme_name.include?('/') settings = theme_name.present? ? PluginRoutes.theme_info(theme_name) : current_theme.settings folder_name = settings['key'] if settings['gem_mode'] "themes/#{folder_name}/#{asset}" else "themes/#{folder_name}/assets/#{asset}" end end |
#theme_asset_url(asset, theme_name = nil) ⇒ Object
return the full url for asset of the current theme: asset: (String) asset name theme_name: (optional) theme name, default (current theme caller to this function) sample:
theme_asset_url("css/main.css") =>
return: https://myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css
32 33 34 35 36 37 38 39 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 32 def theme_asset_url(asset, theme_name = nil) p = theme_asset_path(asset, theme_name) begin ActionController::Base.helpers.asset_url(p) rescue NoMethodError p end end |
#theme_home_page ⇒ Object
Returns a default message if no pages exist
98 99 100 101 102 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 98 def theme_home_page current_site.the_post(current_theme.get_field('home_page')) || current_site.the_posts('page').first || CamaleonCms::Post.new(title: 'Hello World!', content: 'Please add a page.', status: 'published') end |
#theme_init ⇒ Object
3 4 5 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 3 def theme_init camaleon_theme_state[:front_breadcrumb] = [] end |
#theme_layout(layout_name, _theme_name = nil) ⇒ Object
assign the layout for this request asset: asset file name, if asset is present return the full path to this asset layout_name: layout name
62 63 64 65 66 67 68 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 62 def theme_layout(layout_name, _theme_name = nil) if current_theme.settings['gem_mode'] "themes/#{current_theme.slug}/layouts/#{layout_name}" else "themes/#{current_theme.slug}/views/layouts/#{layout_name}" end end |
#theme_view(view_name, deprecated_attr = '') ⇒ Object
return the theme view path including the path of current theme view_name: name of the view or template sample: theme_view("index") => "themes/my_theme/index"
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 44 def theme_view(view_name, deprecated_attr = '') if deprecated_attr.present? ActiveSupport::Deprecation._instance.warn( 'Passing theme view name as the second argument to #theme_view is deprecated. ' \ 'Pass the view name as the first argument instead.' ) view_name = deprecated_attr end if current_theme.settings['gem_mode'] "themes/#{current_theme.slug}/#{view_name}" else "themes/#{current_theme.slug}/views/#{view_name}" end end |