Module: CamaleonCms::HtmlHelper

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

Overview

encoding: utf-8

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 %>


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

def append_asset_content(content)
  @_assets_content << content
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 %>


70
71
72
# File 'app/helpers/camaleon_cms/html_helper.rb', line 70

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")

20
21
22
23
24
25
26
# File 'app/helpers/camaleon_cms/html_helper.rb', line 20

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


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/camaleon_cms/html_helper.rb', line 81

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
  css = stylesheet_link_tag *libs.uniq, media: "all"

  libs = []
  @_assets_libraries.each do |key, assets|
    libs += assets[:js] if assets[:js].present?
  end
  js = javascript_include_tag *libs.uniq
  css + "\n" + js + "\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)


75
76
77
# File 'app/helpers/camaleon_cms/html_helper.rb', line 75

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


100
101
102
103
104
105
106
107
108
# File 'app/helpers/camaleon_cms/html_helper.rb', line 100

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 > 0
  end
  options
end

#cama_html_helpers_initObject


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

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)


113
114
115
# File 'app/helpers/camaleon_cms/html_helper.rb', line 113

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_custom_assets(libraries) ⇒ Object Also known as: append_asset_libraries

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


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

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

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

enable to load admin or registered libraries (colorpicker, datepicker, form_builder, 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()


31
32
33
34
35
36
# File 'app/helpers/camaleon_cms/html_helper.rb', line 31

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