Sha256: c331ccfd06d02a0e111773fe0ca61c468fea568337f6bfc4ca5881bff6a2e896

Contents?: true

Size: 1.9 KB

Versions: 17

Compression:

Stored size: 1.9 KB

Contents

require 'tinymce-rails'
require 'jquery-ui-rails'
require 'colorbox-rails'
require 'paperclip'

class ActiveRecord::Base
  # (PLU)cks a single uni(Q)ue field
  def self.pluq(field, compact = true, sort = true)    
    arr = self.uniq.pluck(field)
    return [] if arr.nil?
    arr = arr.compact if compact
    arr = arr.sort if sort
    return arr
  end  
end

module Caboose

  def Caboose.log(message, title = nil)
    if (Rails.logger.nil?)
      puts "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
      puts title.to_s unless title.nil?
      puts message
      puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
    else
      Rails.logger.debug("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
      Rails.logger.debug(title.to_s) unless title.nil?
      Rails.logger.debug(message)
      Rails.logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
    end
  end
  
  def Caboose.plugin_hook(*args)
    resp = nil
    args[0] = args[0].to_sym 
    Caboose.plugins.each do |mod|
      #resp = mod.constantize.send(*args)
      if (mod.constantize.respond_to?(args[0]))
        resp = mod.constantize.send(*args)
      end
    end
    return resp
  end
  
  def Caboose.json(obj, defaultvalue = "")
    return defaultvalue.to_json if obj.nil?
    return obj.to_json
  end
  
  # Strips html and returns the text that breaks closest to the given length
  def Caboose.teaser_text(str, length = 100)
    return "" if str.nil?    
    str2 = ActionController::Base.helpers.strip_tags(str)
    if str2.length > 200
      i = str2.index(' ', 200) - 1
      i = 200 if i.nil?
      str2 = str2[0..i]
      str2[str2.length-1] = "" if str2.ends_with?(",")
      str2 = "#{str2}..."
    end
    return str2
  end
  
  class Engine < ::Rails::Engine
    isolate_namespace Caboose
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
caboose-cms-0.3.9 lib/caboose/engine.rb
caboose-cms-0.3.8 lib/caboose/engine.rb
caboose-cms-0.3.7 lib/caboose/engine.rb
caboose-cms-0.3.6 lib/caboose/engine.rb
caboose-cms-0.3.5 lib/caboose/engine.rb
caboose-cms-0.3.4 lib/caboose/engine.rb
caboose-cms-0.3.3 lib/caboose/engine.rb
caboose-cms-0.3.2 lib/caboose/engine.rb
caboose-cms-0.3.1 lib/caboose/engine.rb
caboose-cms-0.2.104 lib/caboose/engine.rb
caboose-cms-0.2.103 lib/caboose/engine.rb
caboose-cms-0.2.102 lib/caboose/engine.rb
caboose-cms-0.2.100 lib/caboose/engine.rb
caboose-cms-0.2.99 lib/caboose/engine.rb
caboose-cms-0.2.98 lib/caboose/engine.rb
caboose-cms-0.2.97 lib/caboose/engine.rb
caboose-cms-0.2.96 lib/caboose/engine.rb