bborn / communityengine

Adds basic social networking capabilities to your existing application, including users, blogs, photos, clippings, favorites, and more.

This URL has Read+Write access

bborn (author)
Mon Oct 05 11:07:38 -0700 2009
commit  5f21ca410923522a046cdc251d29f7a3076a4f16
tree    34cd580d4415adccd837bfcfbab6111a8eef8187
parent  5a7d1c5c5169a4ebb0a0bd6963eed6dd280fe6a3
communityengine / init.rb
100755 88 lines (71 sloc) 2.552 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
83
84
85
86
87
88
#reload CE in development
config.after_initialize do
  if RAILS_ENV == 'development'
    ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_once_paths.select {|path| (path =~ /(community_engine)/).nil? }
  end
end
 
 
 
#Alias Desert's routing method to preserve compatibility with Engine's
Desert::Rails::RouteSet.module_eval do
  alias_method :from_plugin, :routes_from_plugin
end
 
#Hack Desert to allow generating plugin migrations
Desert::Plugin.class_eval do
  def latest_migration
    migrations.last
  end
  
  # Returns the version numbers of all migrations for this plugin.
  def migrations
    migrations = Dir[migration_path+"/*.rb"]
    migrations.map { |p| File.basename(p).match(/0*(\d+)\_/)[1].to_i }.sort
  end
end
 
# Fix Desert's 'current_version' which tries to order by version desc, but version is a string type column, so it breaks
# sort the rows in ruby instead to make sure we get the highest numbered version
Desert::PluginMigrations::Migrator.class_eval do
  class << self
    def current_version #:nodoc:
      result = ActiveRecord::Base.connection.select_values("SELECT version FROM #{schema_migrations_table_name} WHERE plugin_name = '#{current_plugin.name}'").map(&:to_i).sort.reverse[0]
      if result
        result
      else
        # There probably isn't an entry for this plugin in the migration info table.
        0
      end
    end
  end
end
 
 
require 'community_engine'
require 's3_cache_control'
 
Module.class_eval do
  def expiring_attr_reader(method_name, value)
    class_eval(<<-EOS, __FILE__, __LINE__)
def #{method_name}
class << self; attr_reader :#{method_name}; end
@#{method_name} = eval(%(#{value}))
end
EOS
  end
end
 
class ActionView::Base
  def _(s)
    # just call the globalite localize method on the string
    s.localize
  end
end
 
module ApplicationConfiguration
  require 'ostruct'
  require 'yaml'
  if File.exists?( File.join(RAILS_ROOT, 'config', 'application.yml') )
    file = File.join(RAILS_ROOT, 'config', 'application.yml')
    users_app_config = YAML.load_file file
  end
  default_app_config = YAML.load_file(File.join(RAILS_ROOT, 'vendor', 'plugins', 'community_engine', 'config', 'application.yml'))
  
  config_hash = (users_app_config||{}).reverse_merge!(default_app_config)
 
  unless defined?(AppConfig)
    ::AppConfig = OpenStruct.new config_hash
  else
    orig_hash = AppConfig.marshal_dump
    merged_hash = config_hash.merge(orig_hash)
    
    AppConfig = OpenStruct.new merged_hash
  end
end