Chris@909: module Engines Chris@909: module Assets Chris@909: class << self Chris@909: @@readme = %{Files in this directory are automatically generated from your plugins. Chris@909: They are copied from the 'assets' directories of each plugin into this directory Chris@909: each time Rails starts (script/server, script/console... and so on). Chris@909: Any edits you make will NOT persist across the next server restart; instead you Chris@909: should edit the files within the /assets/ directory itself.} Chris@909: Chris@909: # Ensure that the plugin asset subdirectory of RAILS_ROOT/public exists, and Chris@909: # that we've added a little warning message to instruct developers not to mess with Chris@909: # the files inside, since they're automatically generated. Chris@909: def initialize_base_public_directory Chris@909: dir = Engines.public_directory Chris@909: unless File.exist?(dir) Chris@909: FileUtils.mkdir_p(dir) Chris@909: end Chris@909: readme = File.join(dir, "README") Chris@909: File.open(readme, 'w') { |f| f.puts @@readme } unless File.exist?(readme) Chris@909: end Chris@909: Chris@909: # Replicates the subdirectories under the plugins's +assets+ (or +public+) Chris@909: # directory into the corresponding public directory. See also Chris@909: # Plugin#public_directory for more. Chris@909: def mirror_files_for(plugin) Chris@909: return if plugin.public_directory.nil? Chris@909: begin Chris@909: Engines.mirror_files_from(plugin.public_directory, File.join(Engines.public_directory, plugin.name)) Chris@909: rescue Exception => e Chris@909: Engines.logger.warn "WARNING: Couldn't create the public file structure for plugin '#{plugin.name}'; Error follows:" Chris@909: Engines.logger.warn e Chris@909: end Chris@909: end Chris@909: end Chris@909: end Chris@909: end