Module: RailsI18nterface::TranslateHelper
- Defined in:
- app/helpers/rails_i18nterface/translate_helper.rb
Overview
various views helpers
Instance Method Summary collapse
- #build_namespace(h) ⇒ Object
- #list_namespace(k, h) ⇒ Object
- #simple_filter(labels, param_name = 'filter') ⇒ Object
Instance Method Details
#build_namespace(h) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/rails_i18nterface/translate_helper.rb', line 22 def build_namespace(h) out = '<ul>' dirs = {} root = [] h.each do |k, v| if v.is_a? Hash dirs[k] = v else root << k end end out << '<li class="dir"><span class="display" data-id="."></span>ROOT' out << " <span class=\"num\">(#{root.length})</span>" out << '<ul>' root.each do |key| out << "<li class=\"item\" data-id=\"#{key.to_s}\">#{key}</li>" end out << '</ul>' out << '</ul>' out << list_namespace('', dirs) end |
#list_namespace(k, h) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/helpers/rails_i18nterface/translate_helper.rb', line 44 def list_namespace(k, h) out = '<ul>' k != '' && k += '.' h.each do |key, val| if val.is_a? Hash out << sprintf( '<li class="dir"><span class="display" data-id="%s"></span>%s <span class="num">(%d)</span>', k + key.to_s, key.to_s, val.length ) out << list_namespace(k + key.to_s, val) else out << sprintf('<li class="item" data-id="%s">%s', k + key.to_s, key) end out << '</li>' end out << '</ul>' end |
#simple_filter(labels, param_name = 'filter') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/helpers/rails_i18nterface/translate_helper.rb', line 8 def simple_filter(labels, param_name = 'filter') filter = [] labels.each do |label| if label.to_s == params[param_name].to_s filter << "<i>#{label}</i>" else link_params = params.merge(param_name.to_s => label) link_params.merge!('page' => nil) if param_name.to_s != 'page' filter << link_to(label, link_params) end end filter.join(' | ') end |