lib/ab_admin/utils.rb in ab_admin-0.2.3 vs lib/ab_admin/utils.rb in ab_admin-0.3.0
- old
+ new
@@ -9,11 +9,11 @@
Dir[Rails.root.join("#{path}/**/*.rb")].each do |path|
require_dependency path
end
end
- def bm(message = "Benchmarking", options = {})
+ def bm(message = 'Benchmarking', options = {})
result = nil
ms = Benchmark.ms { result = yield }
Rails.logger.debug '%s (%.3fms)' % [message, ms]
result
end
@@ -38,12 +38,12 @@
return [] unless val
val.is_a?(Array) ? val : val.split(',').map(&:to_s).without(0)
end
def truncate_text(raw_text, size=200)
- text = raw_text.to_s.gsub(/"|«|»|'/, "'").gsub(/ /, ' ').gsub(/—/, '-').no_html.squish
- text.truncate(size, :separator => ' ')
+ text = raw_text.to_s.gsub(/"|«|»|'/, '\'').gsub(/ /, ' ').gsub(/—/, '-').no_html.squish
+ text.truncate(size, separator: ' ')
end
def l_path(locale=nil)
return '' unless locale
locale == I18n.default_locale ? '' : "/#{locale}"
@@ -69,25 +69,25 @@
"http://#{host}#{path}"
end
def js_date_data
{
- :formats => I18n.t('date.formats'),
- :day_names => I18n.t('date.day_names'),
- :abbr_day_names => I18n.t('date.common_abbr_day_names'),
- :month_names => I18n.t('date.common_month_names'),
- :standalone_month_names => I18n.t('date.standalone_month_names'),
- :abbr_month_names => I18n.t('date.abbr_month_names')
+ formats: I18n.t('date.formats'),
+ day_names: I18n.t('date.day_names'),
+ abbr_day_names: I18n.t('date.common_abbr_day_names'),
+ month_names: I18n.t('date.common_month_names'),
+ standalone_month_names: I18n.t('date.standalone_month_names'),
+ abbr_month_names: I18n.t('date.abbr_month_names')
}
end
class Sanitizer
include ActionView::Helpers::SanitizeHelper
def normalize_html(raw_html)
return '' if raw_html.blank?
- html = sanitize(raw_html.gsub(/<!--(.*?)-->[\n]?/m, ""))
+ html = sanitize(raw_html.gsub(/<!--(.*?)-->[\n]?/m, ''))
doc = Nokogiri::HTML.fragment(html)
#doc.xpath('comment()').each { |c| c.remove }
doc.search('div').each { |el| el.name = 'p' }
doc.to_html
end
@@ -114,10 +114,10 @@
when TrueClass
'+'
when FalseClass
'-'
when Date, DateTime, Time, ActiveSupport::TimeWithZone
- I18n.l(object, :format => :long)
+ I18n.l(object, format: :long)
when NilClass
''
else
AbAdmin.safe_display_name(object) || object
end
\ No newline at end of file