Module: Tr8n::Admin::BaseHelper
- Defined in:
- app/helpers/tr8n/admin/base_helper.rb
Overview
– Copyright © 2010-2012 Michael Berkovich, tr8n.net
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++
Instance Method Summary collapse
- #language_metric_chart(field = :user_count, limit = 20) ⇒ Object
- #tr8n_page_entries_info(collection, options = {}) ⇒ Object
- #tr8n_pretty_print_hash(hash) ⇒ Object
- #tr8n_will_filter(results) ⇒ Object
- #tr8n_will_paginate(collection = nil, options = {}) ⇒ Object
Instance Method Details
#language_metric_chart(field = :user_count, limit = 20) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/tr8n/admin/base_helper.rb', line 56 def language_metric_chart(field = :user_count, limit = 20) labels = [] label_positions = [] counts = [] Tr8n::TotalLanguageMetric.find(:all, :conditions => ["language_id <> ?", Tr8n::Config.default_language.id], :order => "#{field} desc", :limit => limit).each_with_index do |metric, index| labels << metric.language.english_name label_positions << ((index+1) * 30) counts << (metric.send(field) || 0) end max_count = counts.max max_count = 100 if max_count < 100 counts = counts.collect{|c| c/(max_count * 1.0) * 100} chart_params = [] chart_params << "chxl=1:|#{labels.join('|')}|" chart_params << "chxp=#{label_positions.join(',')}" chart_params << "chxr=0,0,#{limit}|0,0,#{max_count}" chart_params << "chxt=x,y" chart_params << "chs=1000x300" chart_params << "cht=bhs" chart_params << "chbh=10" chart_params << "chco=008000" chart_params << "chd=t:#{counts.reverse.join(',')}" image_tag("http://chart.apis.google.com/chart?#{chart_params.join('&')}") end |
#tr8n_page_entries_info(collection, options = {}) ⇒ Object
34 35 36 |
# File 'app/helpers/tr8n/admin/base_helper.rb', line 34 def tr8n_page_entries_info(collection, = {}) super(collection, .merge(:skip_decorations => true)) end |
#tr8n_pretty_print_hash(hash) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/helpers/tr8n/admin/base_helper.rb', line 38 def tr8n_pretty_print_hash(hash) return "" unless hash html = "" hash.each do |key, value| html << "<strong>" html << key << ": </strong>" if value.is_a?(Hash) html << "{" html << tr8n_pretty_print_hash(value) html << "} " else html << value.strip if value html << "; " end end html end |
#tr8n_will_filter(results) ⇒ Object
26 27 28 |
# File 'app/helpers/tr8n/admin/base_helper.rb', line 26 def tr8n_will_filter(results) will_filter_tag(results) end |
#tr8n_will_paginate(collection = nil, options = {}) ⇒ Object
30 31 32 |
# File 'app/helpers/tr8n/admin/base_helper.rb', line 30 def tr8n_will_paginate(collection = nil, = {}) super(collection, .merge(:skip_decorations => true)) end |