lib/rango/helpers/general.rb in rango-0.0.3 vs lib/rango/helpers/general.rb in rango-0.0.4

- old
+ new

@@ -1,9 +1,10 @@ -# coding: utf-8 +# encoding: utf-8 + require "uri" -class Rango +module Rango module Helpers # @since 0.0.1 def copyright(from) now = Time.now.year now.eql?(from) ? now : "#{from} - #{now}" @@ -34,8 +35,18 @@ def error_messages_for(model_instance) tag :ul do messages = model_instance.errors.full_messages messages.map { |message| tag :li, message } end + end + + def truncate(text, *args) + options = args.extract_options! + unless args.empty? + options[:size] = args[0] || 75 + options[:omission] = args[1] || "..." + end + options.reverse_merge!(:size => 75, :omission => "...") + text.scan(/(\S+)(\s+)/)[0..options[:size]].flatten.join << options[:omission] if text end end end