module Linkr::Helpers include Linkr::Models include Linkr::Controllers def current_user @env[Linkr.remote_user_property_name] || 'anonymous' end def markup(body) text RedCloth.new(h(body), [:hard_breaks]).to_html end def h(str) str.gsub("<", "<").gsub(">", ">") end def ago(from) #stolen from Rails DateHelper t = (((Time.now - from).abs)/60).round case t when 0..1 then 'less than a minute' when 2..44 then "#{t} minutes" when 45..89 then 'about 1 hour' when 90..1439 then "about #{(t.to_f / 60.0).round} hours" when 1440..2879 then '1 day' else "#{(t / 1440).round} days" end + ' ago' end def link_to_vote(link, dir, active) a :id => "vote_#{link.id}_#{dir}", :href => 'javascript:void(0);', :class => "arrow #{dir} #{active ? 'active' : ''}", :onclick => "vote('#{link.id}', '#{dir}')" end def pluralize(count, word) case count when 0 then "no #{word}" when 1 then "1 #{word}" else "#{count} #{word.pluralize}" end end def text_field(object, method, options={}) label method.to_s + (options.delete(:optional) ? ' (optional)' : ''), :for => "#{object}_#{method}"; br input({ :id => "#{object}_#{method}", :type => 'text', :name => method.to_s, :value => eval("@#{object}.#{method}") }.merge(options)) end def per_page Link::PER_PAGE end end