API Methods

MAIN FUNCTIONS FOR FRONTEND  
the_head show custom assets added by plugins
show respond js and html5shiv
breadcrumb_draw draw the breadcrumb as html list
breadcrumb_add(label, url = "", prepend = false) add breadcrumb item at the end
label => label of the link
url: url for the link
draw_menu(args = {}) draw the menus on frontend as html. These are the default values
{
menu_slug: 'main_menu', #slug for the menu
container: 'ul', #type of container for the menu
container_id: '', #container id for the menu
container_class: 'nav navbar-nav nav-menu', #container class for the menu
item_container: 'li', #type of container for the items
item_current: 'current-item', #class for current menu item
item_class: 'menu-item', # class for all menu items
item_class_parent:"dropdown", # class for all menu items that contain sub items
sub_container: 'ul', #type of container for sub items
sub_class: 'dropdown-menu', # class for sub container
callback_item: lambda{|args| },
# callback executed for each item (args = { menu_item, link, level, settings, has_children, link_attrs = "", index}).
# menu_item: (Object) Menu object
# link: (Hash) link data: {link: '', name: ''}
# level: (Integer) current level
# has_children: (boolean) if this item contain sub menus
# settings: (Hash) menu settings
# index: (Integer) Index Position of this menu
# link_attrs: (String) Here you can add your custom attrs for current link, sample: id='my_id' data-title='#{args[:link][:name]}'
# In settings you can change the values for this item, like after, before, ..:
# sample: lambda{|args| args[:settings][:after] = "<span class='caret'></span>" if args[:has_children]; args[:link_attrs] = "id='#{menu_item.id}'"; }
# sample: lambda{|args| args[:settings][:before] = "<i class='fa fa-home'></i>" if args[:level] == 0 && args[:index] == 0; }
before: '', # content before link text
after: '', # content after link text
link_current: 'current-link', # class for current menu link
link_before: '', # content before link
link_after: '', # content after link
link_class: 'menu_link', # class for all menu links
link_class_parent:"dropdown-toggle", # class for all menu links that contain sub items
levels: -1, # max of levels to recover, -1 => return all levels
container_prepend: '', # content prepend for menu container
container_append: '' # content append for menu container
}
to register this, go to admin -> appearance -> menus
is_home? Check if current request visited is the home page or index page
is_page? Check if current request is for a page, like: post or page or ....
is_ajax? Check if current request is for ajax
is_search? Check if current request is a search 
is_post_type? Check if current request is for a post type 
is_post_tag? Check if current request is for a post tag
is_category? Check if current request is for a category 
current_site  Return current site
current_theme Return current theme for current site
I18n.locale Return the current locale
   
 THEMES  
theme_layout(layout_name, theme_name = nil) 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_asset_path(asset = nil, theme_name = nil) 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>
theme_view(theme_key, view_name) return theme full view path
theme_key: theme folder name
view_name: name of the view or template. Sample: theme_view(self_theme_key, "admin/settings")
self_theme_key return theme key for current theme file. valid only if you call to this from a file within the theme
   
 ASSETS  
add_asset_library(*keys)  enable to load admin libraries (colorpicker, datepicker, tinymce)
append_asset_libraries(libraries) add asset libraries (js, css)
{ library_key2:{ js: [], css: [] }, library_key1:{ js: [], css: [] }, ...}
append_asset_content(content) add asset content into custom assets
content may be: <script>alert()</script>
content may be: <style>a{color: red;}</style>
this will be printed with <%raw draw_custom_assets %>
draw_custom_assets return all js libraries added [aa.js, bb,js, ..]
def get_assets_js
site_current_url return current request url
site_current_path return current url visited as path
https://localhost:9001/category/cat-post-2 => /category/cat-post-2
ct(key, language = nil)  theme common translation text
key: key for translation
language: language for the translation, if it is nil, then will use current site language
valid only for common translations, If you can to use other translations for themes or plugins,
you can use the default of rails (I18n.t)
url_to_fixed(url_to, *args)  fix for url_to or url_path or any other who need add automatically current locale in the url
sample: url_to_fixed("root_url", data: "asdasd", y: 12)
=> https://localhost/fr?data=asdasd&y=12
note: if current locale is the default language, then locale is not added in the url
verify_front_visibility(active_record)  

add where conditionals to filter private/hidden/expired/drafts/unpublished
note: only for post records

posts_user_10 = verify_front_visibility(@category.posts.where(user_id: 10))
CAPTCHA  
captcha_tag(len = 5, img_args = {alt: ""}, input_args = {}) build a captcha tag (image with captcha)
img_args: attributes for image_tag
captcha_verified? verify captcha value
captcha_under_attack?(key) check if the current visitor was submitted 5+ times
key: a string to represent a url or form view
key must be the same as the form "captcha_tags_if_under_attack(key, ...)"
captcha_verify_if_under_attack(key) verify captcha values if this key is under attack
key: a string to represent a url or form view
captcha_increment_attack(key) increment attempts for key by 1
captcha_reset_attack(key) reset the attacks counter for key
key: a string to represent a url or form view
captcha_total_attacks(key) return a number of attempts for key
key: a string to represent a url or form view

captcha_tags_if_under_attack(key, captcha_parmas =

[5, {}, {class: "form-control required"}])

show captcha if under attack
key: a string to represent a url or form view
   
CONTENTS  
content_prepend(content) prepend content for admin or frontend (after <body>)
content_append(content) append content for admin or frontend (before </body>)
content_before_draw draw all before contents. Call this method after open <body> to include custom contents generated by plugins.
content_after_draw draw all after contents. Call this method before close </body> to include custom contents generated by plugins.
HOOKS  
hook_run(plugin, hook_key, params = nil) execute hooks for plugin_key with action name hook_key
non public method
plugin: plugin configuration (config.json)
hook_key: hook key
params: params for hook
hooks_run(hook_key, params = nil) execute all hooks from enabled plugins with key hook_key
non public method
hook_key: hook key
params: params for hook
hook_skip(hook_function_name) skip hook function with name: hook_function_name. You can call this in your hooks.
   
HTML  
 add_asset_library(*keys) enable to load admin libraries (colorpicker, datepicker, form_builder, tinymce, form_ajax, cropper)
 append_asset_libraries(libraries) add asset libraries (js, css)
{ library_key2:{ js: [], css: [] }, library_key1:{ js: [], css: [] }, ...} 
append_asset_content(content) add asset content into custom assets
content may be: <script>alert()</script>
content may be: <style>a{color: red;}</style>
this will be printed with <%raw draw_custom_assets %>
draw_custom_assets return all js libraries added [aa.js, bb,js, ..]
def get_assets_js
   
FILE UPLOADS  
upload_file(uploaded_io, settings = {}) upload a file into server
settings:
folder: Directory where the file will be saved (default: current_site.upload_directory)
sample: temporal => will save in /rails_path/public/temporal
maximum: maximum bytes permitted to upload (default: 1000MG)
formats: extensions permitted, sample: jpg,png,... or generic: images | videos | audios | documents (default *)
create_folder: auto create folder if it doesn't exist (default: true)
temporal_time: if great than 0 seconds, then this file will expire (removed) in that time (default: 0)
To manage jobs, please check https://edgeguides.rubyonrails.org/active_job_basics.html
Note: if you are using temporal_time, you will need to copy the file to another directory later
sample: upload_file(params[:my_file], {formats: "images", folder: "temporal"})
sample: upload_file(params[:my_file], {formats: "jpg,png,gif,mp3,mp4", temporal_time: 10.minutes, maximum: 10.megabytes})
uploader_verify_name(file_path) helper to find an available filename for file_path in that directory
sample: uploader_verify_name("/var/www/my_image.jpg")
return "/var/www/my_image_1.jpg" => if "/var/www/my_image.jpg" exist
return "/var/www/my_image.jpg" => if "/var/www/my_image.jpg" doesn't exist
file_path_to_url(file_path) convert downloaded file path into public url
crop_image(file, w, h, w_offset, h_offset, resize = nil ) crop and image and saved as imagename_crop.ext
file: file path
w: new width
h: new height
w_offset: left offset
w_offset: top offset
resize: true/false
(true => resize the image to this dimension)
(false => crop the image with this dimension)
PLUGINS  
plugin_layout(plugin_key, layout_name) return plugin full layout path
plugin_key: plugin name
plugin_view(plugin_key, view_name) return plugin full view path
plugin_key: plugin name
plugin_asset_path(plugin_key, asset = nil) return plugin full asset path
plugin_key: plugin name
if asset is present return full path to this asset
sample: <script src="<%= plugin_asset_path("my_plugin", "js/admin.js") %>"></script>
plugin_load_helpers(plugin) auto load all helpers of this plugin
self_plugin_key return plugin key for current plugin file (helper|controller|view)
current_plugin return the plugin model for current site
Note: method called only from files within plugins directory
plugin_install(plugin_key)

install a plugin for current site
plugin_key: key of the plugin
return model of the plugin. Sample:

plugin_install("slider_basic");
current_site.slider_basics.create(name: "Home Slider",
slug: "home_slider", kind: "image")
plugin_uninstall(plugin_key) uninstall a plugin from current site
plugin_key: key of the plugin
return model of the plugin
plugin_destroy(plugin_key) remove a plugin from current site
plugin_key: key of the plugin
return model of the plugin removed
   
SESSIONS  
login_user(user, remember_me = false, redirect_url = nil) log in the user in to system
user: User model
remember_me: true/false (remember session permanently)
session_switch_user(user, redirect_url = nil) switch current session user into other (user)
after switched, this will be redirected to redirect_url or admin dashboard
session_back_to_parent(redirect_url = nil) switch current session into parent session called by session_switch_user
after returned into parent session, this will be redirected to redirect_url or admin dashboard
logout_user logout current user
signin? check if current user is already signed
current_role return the role for current user
if not logged in, then return 'public'
current_user return current user logged in
authenticate(redirect_uri = nil) check if a visitor was logged in
if the user was not logged in, then redirect to login url
   
SHORTCODES  Sample: https://camaleon.website/shortcode-sample.html
shortcode_add(key, template = nil, descr = '') add shortcode
key: chortcode key
template: template to render, if nil will render "shortcode_templates/<key>"
descr: description for shortcode
shortcode_change_template(key, template = nil) add or update shortcode template
key: chortcode key to add or update
template: template to render, if nil will render "shortcode_templates/<key>"
shortcode_delete(key) delete shortcode
key: chortcode key to delete
do_shortcode(content) run all shortcodes in the content
render_shortcode(shortcode, template = nil) render direct a shortcode
template: custom template to be rendered for this short code (default nil to use the main template)
sample: render_shortcode("[slider_basic my_slug]")
sample2: render_shortcode("[slider_basic my_slug2]", theme_view("custom_slider"))
   
ADMIN MODULE  
current_site return current site visited
admin_menu_add_menu(key, menu) add menu item to admin menu at the the end
key: key for menu
menu: is hash like this: {icon: "dashboard", title: "My title", url: my_path, items: [sub menus]}
- icon: font-awesome icon (it is already included "fa fa-")
- title: title for the menu
- url: url for the menu
- items: is an recursive array of the menus without a key
admin_menu_append_menu_item(key, menu) append sub menu to menu with key = key
menu: is hash like this: {icon: "dashboard", title: "My title", url: my_path, items: [sub menus]}
admin_menu_prepend_menu_item(key, menu) prepend sub menu to menu with key = key
menu: is hash like this: {icon: "dashboard", title: "My title", url: my_path, items: [sub menus]}
 admin_menu_insert_menu_before(key_target, key_menu, menu) add menu before menu with key = key_target
key_menu: key for menu
menu: is hash like this: {icon: "dashboard", title: "My title", url: my_path, items: [sub menus]} 
admin_menu_insert_menu_after(key_target, key_menu, menu) add menu after menu with key = key_target
key_menu: key for menu
menu: is hash like this: {icon: "dashboard", title: "My title", url: my_path, items: [sub menus]}