Module: Plugins::CamaLanguageEditor::MainHelper
- Included in:
- AdminController
- Defined in:
- app/helpers/plugins/cama_language_editor/main_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#cama_language_editor_on_active(plugin) ⇒ Object
here all actions on going to active you can run sql commands like this: results = ActiveRecord::Base.connection.execute(query); plugin: plugin model.
-
#cama_language_editor_on_inactive(plugin) ⇒ Object
here all actions on going to inactive plugin: plugin model.
-
#cama_language_editor_on_upgrade(plugin) ⇒ Object
here all actions to upgrade for a new version plugin: plugin model.
-
#cama_language_get_hash_value(g, keys) ⇒ Object
return the value of a hash with a recursive keys keys: (Array of keys) [:a, :b, :c] g: Hash with all values from where get the value.
- #cama_language_get_hash_value2(g, keys) ⇒ Object
- #cama_language_plugin_options(args) ⇒ Object
- #cama_language_render_item_translations(groups, base_key = nil, res = [], p_keys = []) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
2 3 4 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 2 def self.included(klass) # klass.helper_method [:my_helper_method] rescue "" # here your methods accessible from views end |
Instance Method Details
#cama_language_editor_on_active(plugin) ⇒ Object
here all actions on going to active you can run sql commands like this: results = ActiveRecord::Base.connection.execute(query); plugin: plugin model
10 11 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 10 def cama_language_editor_on_active(plugin) end |
#cama_language_editor_on_inactive(plugin) ⇒ Object
here all actions on going to inactive plugin: plugin model
15 16 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 15 def cama_language_editor_on_inactive(plugin) end |
#cama_language_editor_on_upgrade(plugin) ⇒ Object
here all actions to upgrade for a new version plugin: plugin model
20 21 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 20 def cama_language_editor_on_upgrade(plugin) end |
#cama_language_get_hash_value(g, keys) ⇒ Object
return the value of a hash with a recursive keys keys: (Array of keys) [:a, :b, :c] g: Hash with all values from where get the value
64 65 66 67 68 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 64 def cama_language_get_hash_value(g, keys) k = keys.shift g = g[k.to_sym] (keys.any? ? cama_language_get_hash_value(g || {}, keys) : g) || {} end |
#cama_language_get_hash_value2(g, keys) ⇒ Object
70 71 72 73 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 70 def cama_language_get_hash_value2(g, keys) k = keys.shift (keys.any? ? cama_language_get_hash_value(g[k] || {}, keys) : g[keys]) || {} end |
#cama_language_plugin_options(args) ⇒ Object
23 24 25 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 23 def (args) args[:links] << link_to('Access to Editor', admin_plugins_cama_language_editor_index_url) end |
#cama_language_render_item_translations(groups, base_key = nil, res = [], p_keys = []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/plugins/cama_language_editor/main_helper.rb', line 27 def cama_language_render_item_translations(groups, base_key = nil, res = [], p_keys = []) res_html = groups.map{|g| "" } all_attrs = PluginRoutes.static_system_info['available_languages'].map{|_l| cama_language_get_hash_value(I18n.backend.send(:translations)[_l.to_sym], base_key.split(':') + p_keys) } all_attrs.map{|g| g.keys || [] }.flatten.uniq.sort_by{|k| groups.map{|_g| _g[k].is_a?(Hash) ? 1 : 0 }.reduce(&:+) }.each do |key| key_ori = key; key = 'no' if key === false; key = 'yes' if key === true key = key.to_s has_children = false _groups = [] groups.each_with_index do |g, index| res[index] = {} if res[index].nil? _g = p_keys.present? ? cama_language_get_hash_value(res[index], p_keys.dup) : res[index] _g[key] = g[key.to_sym] || g[key_ori] || {} _groups[index] = _g[key] end all_attrs.each{|_g| has_children = true if _g[key.to_sym].is_a?(Hash) } # check if there exist any key with sub items if has_children cama_language_render_item_translations(_groups, base_key, res, p_keys + [key]).each_with_index do |html_g, index| res_html[index] << "<li data-class='#{(p_keys+[key]).join('_')}' class='branch #{(p_keys+[key]).join('_')}'> <i class='indicator glyphicon glyphicon-minus-sign'></i> <label>#{' ' * (((p_keys.size+1)*2)-1)}#{key}: </label> <ul class='list-group'> #{html_g} </ul> </li>" end else _groups.each_with_index do |g_val, index| res_html[index] << "<li><div class='input-group form-control'><span class='input-group-addon' style='text-align: left !important;'><b>#{' ' * ((p_keys.size+1)*2)}#{key}: </b></span><input type='text' class='form-control' value='#{(g_val.is_a?(Hash) ? '' : g_val).gsub("'", "\\\'") }'></div></li>" end end end # res res_html end |