| Module | Engines |
| In: |
lib/engines/assets.rb
lib/engines/plugin/list.rb lib/engines/plugin/loader.rb lib/engines/plugin/locator.rb lib/engines/plugin.rb lib/engines.rb |
The Engines module has a number of public configuration parameters:
Additionally, there are a few flags which control the behaviour of some of the features the engines plugin adds to Rails:
# File lib/engines.rb, line 84
84: def init
85: load_extensions
86: Engines::Assets.initialize_base_public_directory
87: end
# File lib/engines.rb, line 93
93: def load_extensions
94: rails_extensions.each { |name| require "engines/rails_extensions/#{name}" }
95: # load the testing extensions, if we are in the test environment.
96: require "engines/testing" if RAILS_ENV == "test"
97: end
A general purpose method to mirror a directory (source) into a destination directory, including all files and subdirectories. Files will not be mirrored if they are identical already (checked via FileUtils#identical?).
# File lib/engines.rb, line 138
138: def mirror_files_from(source, destination)
139: return unless File.directory?(source)
140:
141: # TODO: use Rake::FileList#pathmap?
142: source_files = Dir[source + "/**/*"]
143: source_dirs = source_files.select { |d| File.directory?(d) }
144: source_files -= source_dirs
145:
146: unless source_files.empty?
147: base_target_dir = File.join(destination, File.dirname(source_files.first).gsub(source, ''))
148: FileUtils.mkdir_p(base_target_dir)
149: end
150:
151: source_dirs.each do |dir|
152: # strip down these paths so we have simple, relative paths we can
153: # add to the destination
154: target_dir = File.join(destination, dir.gsub(source, ''))
155: begin
156: FileUtils.mkdir_p(target_dir)
157: rescue Exception => e
158: raise "Could not create directory #{target_dir}: \n" + e
159: end
160: end
161:
162: source_files.each do |file|
163: begin
164: target = File.join(destination, file.gsub(source, ''))
165: unless File.exist?(target) && FileUtils.identical?(file, target)
166: FileUtils.cp(file, target)
167: end
168: rescue Exception => e
169: raise "Could not copy #{file} to #{target}: \n" + e
170: end
171: end
172: end
The engines plugin will, by default, mix code from controllers and helpers, allowing application code to override specific methods in the corresponding controller or helper classes and modules. However, if other file types should also be mixed like this, they can be added by calling this method. For example, if you want to include "things" within your plugin and override them from your applications, you should use the following layout:
app/
+-- things/
| +-- one_thing.rb
| +-- another_thing.rb
...
vendor/
+-- plugins/
+-- my_plugin/
+-- app/
+-- things/
+-- one_thing.rb
+-- another_thing.rb
The important point here is that your "things" are named <whatever>_thing.rb, and that they are placed within plugin/app/things (the pluralized form of ‘thing’).
It‘s important to note that you‘ll also want to ensure that the "things" are on your load path in your plugin‘s init.rb:
Rails.plugins[:my_plugin].code_paths << "app/things"
# File lib/engines.rb, line 131
131: def mix_code_from(*types)
132: self.code_mixing_file_types += types.map { |x| x.to_s.singularize }
133: end