Module: CamaleonCms::HtmlHelper

Included in:
CamaleonController
Defined in:
app/helpers/camaleon_cms/html_helper.rb

Instance Method Summary collapse

Instance Method Details

#append_asset_content(content) ⇒ Object

add asset content into custom assets content may be: <script>alert()</script> content may be: <style>ared;</style> this will be printed with <%raw cama_draw_custom_assets %>



53
54
55
# File 'app/helpers/camaleon_cms/html_helper.rb', line 53

def append_asset_content(content)
  @_assets_content << content
end

#append_asset_libraries(libraries) ⇒ Object Also known as: cama_load_custom_assets

add custom asset libraries (js, css or both) for the current request, also you can add extra css or js files for existent libraries sample: (add new library)

append_asset_libraries({"my_library_key"=> { js: [plugin_asset("js/my_js"), "plugins/myplugin/assets/js/my_js2"], css: [plugin_asset("css/my_css"), "plugins/myplugin/assets/css/my_css2"] }})

sample: (update existent library)

append_asset_libraries({"colorpicker"=>{js: [plugin_asset("js/my_custom_js")] } })

return nil



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

def append_asset_libraries(libraries)
  libraries.each do |key, library|
    @_assets_libraries[key.to_sym] = if @_assets_libraries.include?(key)
                                       @_assets_libraries[key.to_sym].merge(library)
                                     else
                                       library
                                     end
  end
end

#append_pre_asset_content(content) ⇒ Object

add pre asset content into custom assets content may be: <script>alert()</script> content may be: <style>ared;</style> this will be printed before assets_library with <%raw cama_draw_pre_asset_contents %>



61
62
63
# File 'app/helpers/camaleon_cms/html_helper.rb', line 61

def append_pre_asset_content(content)
  @_pre_assets_content << content
end

#cama_assets_library_register(key, assets = {}) ⇒ Object

register a new asset library to be included on demand calling by: cama_load_libraries(…) sample: cama_assets_library_register(“my_library”, [“url_js”, “url_js2”], css: [“url_css1”, “url_css2”])

cama_load_libraries("my_library")


12
13
14
15
16
17
18
# File 'app/helpers/camaleon_cms/html_helper.rb', line 12

def cama_assets_library_register(key, assets = {})
  key = key.to_sym
  cama_assets_libraries
  @_cama_assets_libraries[key] = { css: [], js: [] } unless @_cama_assets_libraries[key].present?
  @_cama_assets_libraries[key][:css] += assets[:css] if assets[:css].present?
  @_cama_assets_libraries[key][:js] += assets[:js] if assets[:js].present?
end

#cama_draw_custom_assetsObject

return all js libraries added [aa.js, bb,js, ..] def get_assets_js



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/helpers/camaleon_cms/html_helper.rb', line 72

def cama_draw_custom_assets
  cama_html_helpers_init unless @_assets_libraries.present?
  libs = []
  @_assets_libraries.each do |_key, assets|
    libs += assets[:css] if assets[:css].present?
  end
  stylesheets = libs.uniq
  css = stylesheet_link_tag(*stylesheets, media: 'all')

  libs = []
  @_assets_libraries.each do |_key, assets|
    libs += assets[:js] if assets[:js].present?
  end
  javascripts = libs.uniq
  js = javascript_include_tag(*javascripts)

  args = { stylesheets: stylesheets, javascripts: javascripts, js_html: js, css_html: css }
  hooks_run('draw_custom_assets', args)
  "#{args[:css_html]}\n#{args[:js_html]}\n#{@_assets_content.join('').html_safe}"
end

#cama_draw_pre_asset_contentsObject

return all scripts to be executed before import the js libraries(cama_draw_custom_assets)



66
67
68
# File 'app/helpers/camaleon_cms/html_helper.rb', line 66

def cama_draw_pre_asset_contents
  (@_pre_assets_content || []).join('').html_safe
end

#cama_get_options_html_from_items(terms, level = 0) ⇒ Object

return category tree for category dropdown each level is prefixed with - level: internal recursive control



96
97
98
99
100
101
102
103
104
# File 'app/helpers/camaleon_cms/html_helper.rb', line 96

def cama_get_options_html_from_items(terms, level = 0)
  options = []
  terms.all.each do |term|
    options << [('' * level) + term.name, term.id] unless @term.id == term.id
    children = term.children
    options += cama_get_options_html_from_items(children, level + 1) if children.size.positive?
  end
  options
end

#cama_html_helpers_initObject



3
4
5
6
7
# File 'app/helpers/camaleon_cms/html_helper.rb', line 3

def cama_html_helpers_init
  @_pre_assets_content = [] # Assets contents before the libraries import
  @_assets_libraries = {}
  @_assets_content = []
end

#cama_html_tooltip(text = 'Tooltip', location = 'left') ⇒ Object

create a html tooltip to include anywhere text: text of the tooltip location: location of the tooltip (left | right | top |bottom)



109
110
111
# File 'app/helpers/camaleon_cms/html_helper.rb', line 109

def cama_html_tooltip(text = 'Tooltip', location = 'left')
  "<a href='javascript:;' title='#{text}' data-toggle='tooltip' data-placement='#{location}'><i class='fa fa-info-circle'></i></a>"
end

#cama_load_libraries(*keys) ⇒ Object Also known as: add_asset_library

enable to load admin or registered libraries (colorpicker, datepicker, tinymce, form_ajax, cropper) sample: add_asset_library(“datepicker”, “colorpicker”) This will add this assets library in the admin head or in a custom place by calling: cama_draw_custom_assets()



23
24
25
26
27
28
# File 'app/helpers/camaleon_cms/html_helper.rb', line 23

def cama_load_libraries(*keys)
  keys.each do |key|
    library = cama_assets_libraries[key.to_sym]
    @_assets_libraries[key.to_sym] = library if library.present?
  end
end