annotate .svn/pristine/40/40fb7c915312a0bec722da5f4b2c6582d58a02b9.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 require 'active_support'
Chris@909 2 require File.join(File.dirname(__FILE__), 'engines/plugin')
Chris@909 3 require File.join(File.dirname(__FILE__), 'engines/plugin/list')
Chris@909 4 require File.join(File.dirname(__FILE__), 'engines/plugin/loader')
Chris@909 5 require File.join(File.dirname(__FILE__), 'engines/plugin/locator')
Chris@909 6 require File.join(File.dirname(__FILE__), 'engines/assets')
Chris@909 7 require File.join(File.dirname(__FILE__), 'engines/rails_extensions/rails')
Chris@909 8
Chris@909 9 # == Parameters
Chris@909 10 #
Chris@909 11 # The Engines module has a number of public configuration parameters:
Chris@909 12 #
Chris@909 13 # [+public_directory+] The directory into which plugin assets should be
Chris@909 14 # mirrored. Defaults to <tt>RAILS_ROOT/public/plugin_assets</tt>.
Chris@909 15 # [+schema_info_table+] The table to use when storing plugin migration
Chris@909 16 # version information. Defaults to +plugin_schema_info+.
Chris@909 17 #
Chris@909 18 # Additionally, there are a few flags which control the behaviour of
Chris@909 19 # some of the features the engines plugin adds to Rails:
Chris@909 20 #
Chris@909 21 # [+disable_application_view_loading+] A boolean flag determining whether
Chris@909 22 # or not views should be loaded from
Chris@909 23 # the main <tt>app/views</tt> directory.
Chris@909 24 # Defaults to false; probably only
Chris@909 25 # useful when testing your plugin.
Chris@909 26 # [+disable_application_code_loading+] A boolean flag determining whether
Chris@909 27 # or not to load controllers/helpers
Chris@909 28 # from the main +app+ directory,
Chris@909 29 # if corresponding code exists within
Chris@909 30 # a plugin. Defaults to false; again,
Chris@909 31 # probably only useful when testing
Chris@909 32 # your plugin.
Chris@909 33 # [+disable_code_mixing+] A boolean flag indicating whether all plugin
Chris@909 34 # copies of a particular controller/helper should
Chris@909 35 # be loaded and allowed to override each other,
Chris@909 36 # or if the first matching file should be loaded
Chris@909 37 # instead. Defaults to false.
Chris@909 38 #
Chris@909 39 module Engines
Chris@909 40 # The set of all loaded plugins
Chris@909 41 mattr_accessor :plugins
Chris@909 42 self.plugins = Engines::Plugin::List.new
Chris@909 43
Chris@909 44 # List of extensions to load, can be changed in init.rb before calling Engines.init
Chris@909 45 mattr_accessor :rails_extensions
Chris@909 46 self.rails_extensions = %w(asset_helpers form_tag_helpers migrations dependencies)
Chris@909 47
Chris@909 48 # The name of the public directory to mirror public engine assets into.
Chris@909 49 # Defaults to <tt>RAILS_ROOT/public/plugin_assets</tt>.
Chris@909 50 mattr_accessor :public_directory
Chris@909 51 self.public_directory = File.join(RAILS_ROOT, 'public', 'plugin_assets')
Chris@909 52
Chris@909 53 # The table in which to store plugin schema information. Defaults to
Chris@909 54 # "plugin_schema_info".
Chris@909 55 mattr_accessor :schema_info_table
Chris@909 56 self.schema_info_table = "plugin_schema_info"
Chris@909 57
Chris@909 58 #--
Chris@909 59 # These attributes control the behaviour of the engines extensions
Chris@909 60 #++
Chris@909 61
Chris@909 62 # Set this to true if views should *only* be loaded from plugins
Chris@909 63 mattr_accessor :disable_application_view_loading
Chris@909 64 self.disable_application_view_loading = false
Chris@909 65
Chris@909 66 # Set this to true if controller/helper code shouldn't be loaded
Chris@909 67 # from the application
Chris@909 68 mattr_accessor :disable_application_code_loading
Chris@909 69 self.disable_application_code_loading = false
Chris@909 70
Chris@909 71 # Set this to true if code should not be mixed (i.e. it will be loaded
Chris@909 72 # from the first valid path on $LOAD_PATH)
Chris@909 73 mattr_accessor :disable_code_mixing
Chris@909 74 self.disable_code_mixing = false
Chris@909 75
Chris@909 76 # This is used to determine which files are candidates for the "code
Chris@909 77 # mixing" feature that the engines plugin provides, where classes from
Chris@909 78 # plugins can be loaded, and then code from the application loaded
Chris@909 79 # on top of that code to override certain methods.
Chris@909 80 mattr_accessor :code_mixing_file_types
Chris@909 81 self.code_mixing_file_types = %w(controller helper)
Chris@909 82
Chris@909 83 class << self
Chris@909 84 def init(initializer)
Chris@909 85 load_extensions
Chris@909 86 Engines::Assets.initialize_base_public_directory
Chris@909 87 end
Chris@909 88
Chris@909 89 def logger
Chris@909 90 RAILS_DEFAULT_LOGGER
Chris@909 91 end
Chris@909 92
Chris@909 93 def load_extensions
Chris@909 94 rails_extensions.each { |name| require "engines/rails_extensions/#{name}" }
Chris@909 95 # load the testing extensions, if we are in the test environment.
Chris@909 96 require "engines/testing" if RAILS_ENV == "test"
Chris@909 97 end
Chris@909 98
Chris@909 99 def select_existing_paths(paths)
Chris@909 100 paths.select { |path| File.directory?(path) }
Chris@909 101 end
Chris@909 102
Chris@909 103 # The engines plugin will, by default, mix code from controllers and helpers,
Chris@909 104 # allowing application code to override specific methods in the corresponding
Chris@909 105 # controller or helper classes and modules. However, if other file types should
Chris@909 106 # also be mixed like this, they can be added by calling this method. For example,
Chris@909 107 # if you want to include "things" within your plugin and override them from
Chris@909 108 # your applications, you should use the following layout:
Chris@909 109 #
Chris@909 110 # app/
Chris@909 111 # +-- things/
Chris@909 112 # | +-- one_thing.rb
Chris@909 113 # | +-- another_thing.rb
Chris@909 114 # ...
Chris@909 115 # vendor/
Chris@909 116 # +-- plugins/
Chris@909 117 # +-- my_plugin/
Chris@909 118 # +-- app/
Chris@909 119 # +-- things/
Chris@909 120 # +-- one_thing.rb
Chris@909 121 # +-- another_thing.rb
Chris@909 122 #
Chris@909 123 # The important point here is that your "things" are named <whatever>_thing.rb,
Chris@909 124 # and that they are placed within plugin/app/things (the pluralized form of 'thing').
Chris@909 125 #
Chris@909 126 # It's important to note that you'll also want to ensure that the "things" are
Chris@909 127 # on your load path by including them in Rails load path mechanism, e.g. in init.rb:
Chris@909 128 #
Chris@909 129 # ActiveSupport::Dependencies.load_paths << File.join(File.dirname(__FILE__), 'app', 'things'))
Chris@909 130 #
Chris@909 131 def mix_code_from(*types)
Chris@909 132 self.code_mixing_file_types += types.map { |x| x.to_s.singularize }
Chris@909 133 end
Chris@909 134
Chris@909 135 # A general purpose method to mirror a directory (+source+) into a destination
Chris@909 136 # directory, including all files and subdirectories. Files will not be mirrored
Chris@909 137 # if they are identical already (checked via FileUtils#identical?).
Chris@909 138 def mirror_files_from(source, destination)
Chris@909 139 return unless File.directory?(source)
Chris@909 140
Chris@909 141 # TODO: use Rake::FileList#pathmap?
Chris@909 142 source_files = Dir[source + "/**/*"]
Chris@909 143 source_dirs = source_files.select { |d| File.directory?(d) }
Chris@909 144 source_files -= source_dirs
Chris@909 145
Chris@909 146 unless source_files.empty?
Chris@909 147 base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
Chris@909 148 FileUtils.mkdir_p(base_target_dir)
Chris@909 149 end
Chris@909 150
Chris@909 151 source_dirs.each do |dir|
Chris@909 152 # strip down these paths so we have simple, relative paths we can
Chris@909 153 # add to the destination
Chris@909 154 target_dir = File.join(destination, dir.gsub(source, ''))
Chris@909 155 begin
Chris@909 156 FileUtils.mkdir_p(target_dir)
Chris@909 157 rescue Exception => e
Chris@909 158 raise "Could not create directory #{target_dir}: \n" + e
Chris@909 159 end
Chris@909 160 end
Chris@909 161
Chris@909 162 source_files.each do |file|
Chris@909 163 begin
Chris@909 164 target = File.join(destination, file.gsub(source, ''))
Chris@909 165 unless File.exist?(target) && FileUtils.identical?(file, target)
Chris@909 166 FileUtils.cp(file, target)
Chris@909 167 end
Chris@909 168 rescue Exception => e
Chris@909 169 raise "Could not copy #{file} to #{target}: \n" + e
Chris@909 170 end
Chris@909 171 end
Chris@909 172 end
Chris@909 173 end
Chris@909 174 end