Module: CamaleonCms::ThemeHelper
- Included in:
- CamaleonController
- Defined in:
- app/helpers/camaleon_cms/theme_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
-
#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 file system path to theme asset theme_name: theme name, if nil, then will use current theme asset: asset file name, if asset is present return 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 full path to this asset sample: <script src=“<%= theme_asset_path(”js/admin.js“) %>”></script> => 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 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: myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css.
- #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 full path to this asset layout_name: layout name.
-
#theme_view(view_name, deprecated_attr = "") ⇒ Object
return 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
75 76 77 78 79 80 81 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 75 def self_theme_key(index = 0) k = "/themes/" f = caller[index] if f.include?(k) f.split(k).last.split("/").first end end |
#theme_asset_file_path(asset = nil, theme_name = nil) ⇒ Object
returns file system path to theme asset theme_name: theme name, if nil, then will use current theme asset: asset file name, if asset is present return 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 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 87 def theme_asset_file_path(asset = nil, theme_name = nil) theme_path = current_theme.settings['path'] if theme_name && theme = Theme.where(name: theme_name).first theme_path = 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 full path to this asset sample: <script src=“<%= theme_asset_path(”js/admin.js“) %>”></script> => return: /assets/themes/my_theme/assets/js/admin-54505620f.js
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 18 def theme_asset_path(asset = nil, theme_name = nil) if theme_name.present? && theme_name.include?("/") return theme_asset_url(theme_name, current_theme.slug) end settings = theme_name.present? ? PluginRoutes.theme_info(theme_name) : current_theme.settings folder_name = settings["key"] if settings["gem_mode"] p = "themes/#{folder_name}/#{asset}" else p = "themes/#{folder_name}/assets/#{asset}" end p end |
#theme_asset_url(asset, theme_name = nil) ⇒ Object
return the full url for asset of 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: http://myhost.com/assets/themes/my_theme/assets/css/main-54505620f.css
40 41 42 43 44 45 46 47 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 40 def theme_asset_url(asset, theme_name = nil) p = theme_asset_path(asset, theme_name) begin asset_url(p) rescue NoMethodError => e p end end |
#theme_init ⇒ Object
10 11 12 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 10 def theme_init() @_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 full path to this asset layout_name: layout name
64 65 66 67 68 69 70 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 64 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 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”
52 53 54 55 56 57 58 59 |
# File 'app/helpers/camaleon_cms/theme_helper.rb', line 52 def theme_view(view_name, deprecated_attr = "") view_name = deprecated_attr if deprecated_attr.present? if current_theme.settings["gem_mode"] "themes/#{current_theme.slug}/#{view_name}" else "themes/#{current_theme.slug}/views/#{view_name}" end end |