parlement 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +16 -0
  2. data/README +36 -3
  3. data/Rakefile +8 -12
  4. data/app/controllers/account_controller.rb +2 -0
  5. data/app/controllers/elt_controller.rb +1 -5
  6. data/app/controllers/subscriber_controller.rb +1 -1
  7. data/app/helpers/elt_helper.rb +30 -10
  8. data/app/models/elt.rb +2 -1
  9. data/app/models/mail.rb +41 -41
  10. data/app/models/mail_notify.rb +27 -10
  11. data/app/views/account/_login.rhtml +9 -7
  12. data/app/views/account/_show.rhtml +4 -4
  13. data/app/views/elt/_elt.rhtml +52 -51
  14. data/app/views/elt/_list.rhtml +22 -14
  15. data/app/views/elt/new.rhtml +1 -1
  16. data/app/views/elt/show.rhtml +15 -16
  17. data/app/views/layouts/top.rhtml +13 -1
  18. data/app/views/person/show.rhtml +1 -7
  19. data/config/boot.rb +32 -7
  20. data/config/database.yml +3 -0
  21. data/config/environment.rb +3 -1
  22. data/config/environments/development.rb +1 -1
  23. data/db/ROOT/parlement/ddRing.txt +14 -0
  24. data/db/ROOT/parlement/top-politics.txt +12 -0
  25. data/db/ROOT/perso.txt +1 -1
  26. data/db/development_structure.sql +30 -16
  27. data/db/schema.rb +18 -10
  28. data/db/schema.sql +34 -34
  29. data/public/javascripts/application.js +2 -0
  30. data/public/javascripts/blank.gif +0 -0
  31. data/public/javascripts/borders.js +687 -0
  32. data/public/javascripts/controls.js +95 -30
  33. data/public/javascripts/dragdrop.js +161 -21
  34. data/public/javascripts/effects.js +310 -211
  35. data/public/javascripts/ie7-load.htc +1 -0
  36. data/public/javascripts/prototype.js +228 -28
  37. data/test/fixtures/attachments.yml +3 -0
  38. data/test/fixtures/mail/mail_ruby +1 -0
  39. data/test/fixtures/people.yml +14 -0
  40. data/test/functional/account_controller_test.rb +3 -2
  41. data/test/unit/mail_notify_test.rb +2 -0
  42. data/test/unit/mail_test.rb +59 -6
  43. data/test/unit/person_test.rb +1 -1
  44. data/vendor/plugins/engines/CHANGELOG +92 -0
  45. data/vendor/plugins/engines/MIT-LICENSE +21 -0
  46. data/vendor/plugins/engines/README +325 -39
  47. data/vendor/plugins/engines/generators/engine/USAGE +26 -0
  48. data/vendor/plugins/engines/generators/engine/engine_generator.rb +199 -0
  49. data/vendor/plugins/engines/generators/engine/templates/README +85 -0
  50. data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +13 -0
  51. data/vendor/plugins/engines/generators/engine/templates/install.erb +4 -0
  52. data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +6 -0
  53. data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +18 -0
  54. data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +19 -0
  55. data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +22 -0
  56. data/vendor/plugins/engines/generators/engine/templates/licenses/None +1 -0
  57. data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
  58. data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
  59. data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
  60. data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +13 -0
  61. data/vendor/plugins/engines/init.rb +18 -3
  62. data/vendor/plugins/engines/lib/bundles/require_resource.rb +124 -0
  63. data/vendor/plugins/engines/lib/bundles.rb +77 -0
  64. data/vendor/plugins/engines/lib/{action_mailer_extensions.rb → engines/action_mailer_extensions.rb} +15 -36
  65. data/vendor/plugins/engines/lib/{action_view_extensions.rb → engines/action_view_extensions.rb} +40 -33
  66. data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +19 -0
  67. data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +118 -0
  68. data/vendor/plugins/engines/lib/engines/migration_extensions.rb +53 -0
  69. data/vendor/plugins/engines/lib/{ruby_extensions.rb → engines/ruby_extensions.rb} +14 -28
  70. data/vendor/plugins/engines/lib/engines/testing_extensions.rb +323 -0
  71. data/vendor/plugins/engines/lib/engines.rb +258 -148
  72. data/vendor/plugins/engines/tasks/engines.rake +161 -0
  73. data/vendor/plugins/engines/test/action_view_extensions_test.rb +9 -0
  74. data/vendor/plugins/engines/test/ruby_extensions_test.rb +24 -3
  75. data/vendor/plugins/guid/README.TXT +14 -4
  76. data/vendor/plugins/guid/init.rb +9 -2
  77. data/vendor/plugins/guid/lib/uuidtools.rb +22 -15
  78. data/vendor/plugins/login_engine/CHANGELOG +14 -0
  79. data/vendor/plugins/login_engine/README +93 -7
  80. data/vendor/plugins/login_engine/app/controllers/user_controller.rb +30 -20
  81. data/vendor/plugins/login_engine/app/helpers/user_helper.rb +1 -1
  82. data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +2 -2
  83. data/vendor/plugins/login_engine/db/migrate/001_initial_schema.rb +25 -0
  84. data/vendor/plugins/login_engine/install.rb +4 -0
  85. data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +11 -5
  86. data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +15 -9
  87. data/vendor/plugins/login_engine/lib/login_engine.rb +7 -3
  88. data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +22 -19
  89. data/vendor/plugins/login_engine/test/test_helper.rb +4 -8
  90. data/vendor/plugins/login_engine/test/unit/user_test.rb +31 -11
  91. metadata +60 -57
  92. data/app/models/attachment.rb +0 -6
  93. data/public/attachment/file/architecture.png +0 -0
  94. data/public/attachment/file/architecture.svg +0 -8972
  95. data/public/attachment/file/security.svg +0 -8960
  96. data/public/engine_files/login_engine/stylesheets/login_engine.css +0 -81
  97. data/public/oldREADME +0 -190
  98. data/public/stylesheets/default.css +0 -235
  99. data/public/stylesheets/live_tree.css +0 -62
  100. data/public/stylesheets/scaffold.css +0 -74
  101. data/script/about +0 -3
  102. data/script/benchmarker +0 -19
  103. data/script/breakpointer +0 -3
  104. data/script/console +0 -3
  105. data/script/create_db +0 -7
  106. data/script/destroy +0 -3
  107. data/script/generate +0 -3
  108. data/script/performance/benchmarker +0 -3
  109. data/script/performance/profiler +0 -3
  110. data/script/plugin +0 -3
  111. data/script/process/reaper +0 -3
  112. data/script/process/spawner +0 -3
  113. data/script/process/spinner +0 -3
  114. data/script/profiler +0 -34
  115. data/script/runner +0 -3
  116. data/script/server +0 -3
  117. data/test/unit/user_test.rb +0 -94
  118. data/vendor/plugins/engines/lib/dependencies_extensions.rb +0 -56
  119. data/vendor/plugins/engines/lib/testing_extensions.rb +0 -33
  120. data/vendor/plugins/login_engine/db/schema.rb +0 -25
  121. data/vendor/plugins/login_engine/test/fixtures/templates/users.yml +0 -41
  122. /data/public/images/{eltBackground.png → eltBackground.jng} +0 -0
@@ -1,37 +1,64 @@
1
- #--
2
- # Copyright (c) 2005 James Adam
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ require 'logger'
23
2
 
24
- require 'ruby_extensions'
25
- require 'dependencies_extensions'
26
- require 'action_view_extensions'
27
- require 'action_mailer_extensions'
28
- require 'testing_extensions'
3
+ # load this before doing ANYTHING freaky with the reloading.
4
+ begin
5
+ require 'rails_version' # Rails 1.0, 1.1.0
6
+ rescue LoadError, Gem::Exception
7
+ require 'rails/version' # renamed as of Rails 1.1.1
8
+ end
29
9
 
10
+ require 'engines/ruby_extensions'
11
+ # ... further files are required at the bottom of this file
30
12
 
31
13
  # Holds the Rails Engine loading logic and default constants
32
- module ::Engines
14
+ module Engines
15
+
16
+ class << self
17
+ # Return the version string for this plugin
18
+ def version
19
+ "#{Version::Major}.#{Version::Minor}.#{Version::Release}"
20
+ end
21
+ end
22
+
23
+ # The DummyLogger is a class which might pass through to a real Logger
24
+ # if one is assigned. However, it can gracefully swallow any logging calls
25
+ # if there is now Logger assigned.
26
+ class LoggerWrapper
27
+ def initialize(logger=nil)
28
+ set_logger(logger)
29
+ end
30
+ # Assign the 'real' Logger instance that this dummy instance wraps around.
31
+ def set_logger(logger)
32
+ @logger = logger
33
+ end
34
+ # log using the appropriate method if we have a logger
35
+ # if we dont' have a logger, ignore completely.
36
+ def method_missing(name, *args)
37
+ if @logger && @logger.respond_to?(name)
38
+ @logger.send(name, *args)
39
+ end
40
+ end
41
+ end
42
+
43
+ LOGGER = Engines::LoggerWrapper.new
44
+
45
+ class << self
46
+ # Create a new Logger instance for Engines, with the given outputter and level
47
+ def create_logger(outputter=STDOUT, level=Logger::INFO)
48
+ LOGGER.set_logger(Logger.new(outputter, level))
49
+ end
50
+ # Sets the Logger instance that Engines will use to send logging information to
51
+ def set_logger(logger)
52
+ Engines::LOGGER.set_logger(logger) # TODO: no need for Engines:: part
53
+ end
54
+ # Retrieves the current Logger instance
55
+ def log
56
+ Engines::LOGGER # TODO: no need for Engines:: part
57
+ end
58
+ alias :logger :log
59
+ end
33
60
 
34
- # An array of active engines (actually paths to active engines)
61
+ # An array of active engines. This should be accessed via the Engines.active method.
35
62
  ActiveEngines = []
36
63
 
37
64
  # The root directory for engines
@@ -59,8 +86,6 @@ module ::Engines
59
86
  #
60
87
  # Options can include:
61
88
  # * :copy_files => true | false
62
- # * :engine_name => the name within the plugins directory this engine resides, if
63
- # different from the first parameter
64
89
  #
65
90
  # Note that if a list of engines is given, the options will apply to ALL engines.
66
91
  def start(*args)
@@ -69,7 +94,6 @@ module ::Engines
69
94
 
70
95
  if args.empty?
71
96
  start_all
72
- return
73
97
  else
74
98
  args.each do |engine_name|
75
99
  start_engine(engine_name, options)
@@ -79,72 +103,81 @@ module ::Engines
79
103
 
80
104
  # Starts all available engines. Plugins are considered engines if they
81
105
  # include an init_engine.rb file, or they are named <something>_engine.
82
- def start_all()
106
+ def start_all
83
107
  plugins = Dir[File.join(config(:root), "*")]
84
- RAILS_DEFAULT_LOGGER.debug "considering plugins: #{plugins.inspect}"
108
+ Engines.log.debug "considering plugins: #{plugins.inspect}"
85
109
  plugins.each { |plugin|
86
110
  engine_name = File.basename(plugin)
87
- if File.exist?(File.join(plugin, "init_engine.rb")) or
88
- (engine_name =~ /_engine$/)
89
- # start the engine...
90
- start(engine_name)
111
+ if File.exist?(File.join(plugin, "init_engine.rb")) || # if the directory contains an init_engine.rb file
112
+ (engine_name =~ /_engine$/) || # or it engines in '_engines'
113
+ (engine_name =~ /_bundle$/) # or even ends in '_bundle'
114
+
115
+ start(engine_name) # start the engine...
116
+
91
117
  end
92
118
  }
93
119
  end
94
120
 
95
121
  def start_engine(engine_name, options={})
96
-
97
- current_engine = Engine.new
98
- current_engine.name = options[:engine_name] || engine_name
99
- current_engine.root = get_engine_dir(engine_name)
100
122
 
101
- #engine_name = options[:engine_name] || engine
102
- #engine_dir = get_engine_dir(engine_name)
123
+ # Create a new Engine and put this engine at the front of the ActiveEngines list
124
+ current_engine = Engine.new(engine_name)
125
+ Engines.active.unshift current_engine
126
+ Engines.log.info "Starting engine '#{current_engine.name}' from '#{File.expand_path(current_engine.root)}'"
103
127
 
104
- RAILS_DEFAULT_LOGGER.debug "Trying to start engine '#{current_engine.name}' from '#{File.expand_path(current_engine.root)}'"
128
+ # add the code directories of this engine to the load path
129
+ add_engine_to_load_path(current_engine)
105
130
 
106
- # put this engine at the front of the ActiveEngines list
107
- Engines::ActiveEngines.unshift current_engine #engine_dir
131
+ # add the controller & component path to the Dependency system
132
+ engine_controllers = File.join(current_engine.root, 'app', 'controllers')
133
+ engine_components = File.join(current_engine.root, 'components')
108
134
 
109
- # add the code directories of this engine to the load path
110
- add_engine_to_load_path(current_engine) #engine_dir)
135
+
136
+ # This mechanism is no longer required in Rails trunk
137
+ if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge)
138
+ Controllers.add_path(engine_controllers) if File.exist?(engine_controllers)
139
+ Controllers.add_path(engine_components) if File.exist?(engine_components)
140
+ end
141
+
142
+ # copy the files unless indicated otherwise
143
+ if options[:copy_files] != false
144
+ current_engine.mirror_engine_files
145
+ end
111
146
 
112
147
  # load the engine's init.rb file
113
148
  startup_file = File.join(current_engine.root, "init_engine.rb")
114
149
  if File.exist?(startup_file)
115
150
  eval(IO.read(startup_file), binding, startup_file)
116
- #require startup_file
151
+ # possibly use require_dependency? Hmm.
117
152
  else
118
- RAILS_DEFAULT_LOGGER.warn "WARNING: No init_engines.rb file found for engine '#{current_engine.name}'..."
119
- end
120
-
121
- # add the controller path to the Dependency system
122
- Controllers.add_path(File.join(current_engine.root, 'app', 'controllers'))
123
-
124
- # copy the files unless indicated otherwise
125
- if options[:copy_files] != false
126
- copy_engine_files(current_engine)
153
+ Engines.log.debug "No init_engines.rb file found for engine '#{current_engine.name}'..."
127
154
  end
128
155
  end
129
156
 
130
157
  # Adds all directories in the /app and /lib directories within the engine
131
158
  # to the load path
132
159
  def add_engine_to_load_path(engine)
160
+
161
+ # remove the lib directory added by load_plugin, and place it in the corrent
162
+ # location *after* the application/lib. This can be removed when
163
+ # http://dev.rubyonrails.org/ticket/2910 is fixed.
164
+ app_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, "lib"))
165
+ engine_lib = File.join(engine.root, "lib")
166
+ if app_lib_index
167
+ $LOAD_PATH.delete(engine_lib)
168
+ $LOAD_PATH.insert(app_lib_index+1, engine_lib)
169
+ end
170
+
133
171
  # Add ALL paths under the engine root to the load path
134
- app_dirs = [engine.root + "/app/controllers", engine.root + "/app/models",
135
- engine.root + "/app/helpers"]
136
- lib_dirs = Dir[engine.root + "/lib/**/*"] + [engine.root, "lib"]
137
- load_paths = (app_dirs + lib_dirs).select { |d|
172
+ app_dirs = Dir[engine.root + "/app/**/*"] # maybe only models?
173
+ component_dir = Dir[engine.root + "/components"]
174
+ lib_dirs = Dir[engine.root + "/lib/**/*"]
175
+ load_paths = (app_dirs + component_dir + lib_dirs).select { |d|
138
176
  File.directory?(d)
139
177
  }
140
178
 
141
- # Remove other engines from the $LOAD_PATH bby matching against the engine.root values
179
+ # Remove other engines from the $LOAD_PATH by matching against the engine.root values
142
180
  # in ActiveEngines. Store the removed engines in the order they came off.
143
- #
144
- # This is a hack - if Ticket http://dev.rubyonrails.com/ticket/2817 is accepted, then
145
- # a new Engines system can be developed which only modifies load paths in one sweep,
146
- # thus avoiding this.
147
- #
148
181
 
149
182
  old_plugin_paths = []
150
183
  # assumes that all engines are at the bottom of the $LOAD_PATH
@@ -156,8 +189,9 @@ module ::Engines
156
189
  # add these LAST on the load path.
157
190
  load_paths.reverse.each { |dir|
158
191
  if File.directory?(dir)
159
- RAILS_DEFAULT_LOGGER.debug "adding #{File.expand_path(dir)} to the load path"
160
- $LOAD_PATH.push(File.expand_path(dir))
192
+ Engines.log.debug "adding #{File.expand_path(dir)} to the load path"
193
+ #$LOAD_PATH.push(File.expand_path(dir))
194
+ $LOAD_PATH.push dir
161
195
  end
162
196
  }
163
197
 
@@ -167,18 +201,16 @@ module ::Engines
167
201
  $LOAD_PATH.uniq!
168
202
  end
169
203
 
170
- # Replicates the subdirectories under the engine's /public directory into
171
- # the corresponding public directory.
172
- def copy_engine_files(engine)
173
-
174
- #engine_dir = get_engine_dir(engine)
175
-
176
- # create the /public/frameworks directory if it doesn't exist
177
- public_engine_dir = File.expand_path(File.join(RAILS_ROOT, "public", Engines.config(:public_dir)))
178
-
204
+ # Returns the directory in which all engine public assets are mirrored.
205
+ def public_engine_dir
206
+ File.expand_path(File.join(RAILS_ROOT, "public", Engines.config(:public_dir)))
207
+ end
208
+
209
+ # create the /public/engine_files directory if it doesn't exist
210
+ def create_base_public_directory
179
211
  if !File.exists?(public_engine_dir)
180
212
  # create the public/engines directory, with a warning message in it.
181
- RAILS_DEFAULT_LOGGER.debug "Creating public engine files directory '#{public_engine_dir}'"
213
+ Engines.log.debug "Creating public engine files directory '#{public_engine_dir}'"
182
214
  FileUtils.mkdir(public_engine_dir)
183
215
  File.open(File.join(public_engine_dir, "README"), "w") do |f|
184
216
  f.puts <<EOS
@@ -186,107 +218,185 @@ Files in this directory are automatically generated from your Rails Engines.
186
218
  They are copied from the 'public' directories of each engine into this directory
187
219
  each time Rails starts (server, console... any time 'start_engine' is called).
188
220
  Any edits you make will NOT persist across the next server restart; instead you
189
- should edit the files within the <engine_name>/public directory itself.
221
+ should edit the files within the <engine_name>/public/ directory itself.
190
222
  EOS
191
223
  end
192
224
  end
225
+ end
226
+
227
+ # Returns the Engine object for the specified engine, e.g.:
228
+ # Engines.get(:login)
229
+ def get(name)
230
+ active.find { |e| e.name == name.to_s || e.name == "#{name}_engine" }
231
+ end
232
+ alias_method :[], :get
193
233
 
194
- source = File.join(engine.root, "public") #engine_dir, "public")
195
- RAILS_DEFAULT_LOGGER.debug "Attempting to copy public engine files from '#{source}'"
234
+ # Returns the Engine object for the current engine, i.e. the engine
235
+ # in which the currently executing code lies.
236
+ def current
237
+ current_file = caller[0]
238
+ active.find do |engine|
239
+ File.expand_path(current_file).index(File.expand_path(engine.root)) == 0
240
+ end
241
+ end
196
242
 
243
+ # Returns an array of active engines
244
+ def active
245
+ ActiveEngines
246
+ end
247
+ end
248
+ end
249
+
250
+ # A simple class for holding information about loaded engines
251
+ class Engine
252
+
253
+ # Returns the base path of this engine
254
+ attr_accessor :root
255
+
256
+ # Returns the name of this engine
257
+ attr_reader :name
258
+
259
+ # An attribute for holding the current version of this engine. There are three
260
+ # ways of providing an engine version. The simplest is using a string:
261
+ #
262
+ # Engines.current.version = "1.0.7"
263
+ #
264
+ # Alternatively you can set it to a module which contains Major, Minor and Release
265
+ # constants:
266
+ #
267
+ # module LoginEngine::Version
268
+ # Major = 1; Minor = 0; Release = 6;
269
+ # end
270
+ # Engines.current.version = LoginEngine::Version
271
+ #
272
+ # Finally, you can set it to your own Proc, if you need something really fancy:
273
+ #
274
+ # Engines.current.version = Proc.new { File.open('VERSION', 'r').readlines[0] }
275
+ #
276
+ attr_writer :version
277
+
278
+ # Engine developers can store any information they like in here.
279
+ attr_writer :info
280
+
281
+ # Creates a new object holding information about an Engine.
282
+ def initialize(name)
283
+
284
+ @root = ''
285
+ suffixes = ['', '_engine', '_bundle']
286
+ while !File.exist?(@root) && !suffixes.empty?
287
+ suffix = suffixes.shift
288
+ @root = File.join(Engines.config(:root), name.to_s + suffix)
289
+ end
290
+
291
+ if !File.exist?(@root)
292
+ raise "Cannot find the engine '#{name}' in either /vendor/plugins/#{name}, " +
293
+ "/vendor/plugins/#{name}_engine or /vendor/plugins/#{name}_bundle."
294
+ end
295
+
296
+ @name = File.basename(@root)
297
+ end
298
+
299
+ # Returns the version string of this engine
300
+ def version
301
+ case @version
302
+ when Module
303
+ "#{@version::Major}.#{@version::Minor}.#{@version::Release}"
304
+ when Proc # not sure about this
305
+ @version.call
306
+ when NilClass
307
+ 'unknown'
308
+ else
309
+ @version
310
+ end
311
+ end
312
+
313
+ # Returns a string describing this engine
314
+ def info
315
+ @info || '(none)'
316
+ end
317
+
318
+ # Returns a string representation of this engine
319
+ def to_s
320
+ "Engine<'#{@name}' [#{version}]:#{root.gsub(RAILS_ROOT, '')}>"
321
+ end
322
+
323
+ # return the path to this Engine's public files (with a leading '/' for use in URIs)
324
+ def public_dir
325
+ File.join("/", Engines.config(:public_dir), name)
326
+ end
327
+
328
+ # Replicates the subdirectories under the engine's /public directory into
329
+ # the corresponding public directory.
330
+ def mirror_engine_files
331
+
332
+ begin
333
+ Engines.create_base_public_directory
334
+
335
+ source = File.join(root, "public")
336
+ Engines.log.debug "Attempting to copy public engine files from '#{source}'"
337
+
197
338
  # if there is no public directory, just return after this file
198
339
  return if !File.exist?(source)
199
340
 
200
341
  source_files = Dir[source + "/**/*"]
201
342
  source_dirs = source_files.select { |d| File.directory?(d) }
202
343
  source_files -= source_dirs
203
-
204
- RAILS_DEFAULT_LOGGER.debug "source dirs: #{source_dirs.inspect}"
205
-
206
- # ensure that we are copying to <something>_engine, whatever the user gives us
207
- full_engine_name = engine.name
208
- full_engine_name += "_engine" if !(full_engine_name =~ /\_engine$/)
344
+
345
+ Engines.log.debug "source dirs: #{source_dirs.inspect}"
209
346
 
347
+ # Create the engine_files/<something>_engine dir if it doesn't exist
348
+ new_engine_dir = File.join(RAILS_ROOT, "public", public_dir)
349
+ if !File.exists?(new_engine_dir)
350
+ # Create <something>_engine dir with a message
351
+ Engines.log.debug "Creating #{public_dir} public dir"
352
+ FileUtils.mkdir_p(new_engine_dir)
353
+ end
210
354
 
211
355
  # create all the directories, transforming the old path into the new path
212
356
  source_dirs.uniq.each { |dir|
213
357
  begin
214
-
215
- # strip out the base path and add the result to the public path
216
- relative_dir = dir.gsub(File.join(engine.root, "public"), full_engine_name)
217
- target_dir = File.join(public_engine_dir, relative_dir)
358
+ # strip out the base path and add the result to the public path, i.e. replace
359
+ # ../script/../vendor/plugins/engine_name/public/javascript
360
+ # with
361
+ # engine_name/javascript
362
+ #
363
+ relative_dir = dir.gsub(File.join(root, "public"), name)
364
+ target_dir = File.join(Engines.public_engine_dir, relative_dir)
218
365
  unless File.exist?(target_dir)
219
- RAILS_DEFAULT_LOGGER.debug "creating directory '#{target_dir}'"
220
- FileUtils.mkdir_p(File.join(public_engine_dir, relative_dir))
366
+ Engines.log.debug "creating directory '#{target_dir}'"
367
+ FileUtils.mkdir_p(target_dir)
221
368
  end
222
369
  rescue Exception => e
223
370
  raise "Could not create directory #{target_dir}: \n" + e
224
371
  end
225
372
  }
226
373
 
227
-
228
-
229
374
  # copy all the files, transforming the old path into the new path
230
375
  source_files.uniq.each { |file|
231
376
  begin
232
377
  # change the path from the ENGINE ROOT to the public directory root for this engine
233
- target = file.gsub(File.join(engine.root, "public"),
234
- File.join(public_engine_dir, full_engine_name))
378
+ target = file.gsub(File.join(root, "public"),
379
+ File.join(Engines.public_engine_dir, name))
235
380
  unless File.exist?(target) && FileUtils.identical?(file, target)
236
- RAILS_DEFAULT_LOGGER.debug "copying file '#{file}' to '#{target}'"
381
+ Engines.log.debug "copying file '#{file}' to '#{target}'"
237
382
  FileUtils.cp(file, target)
238
383
  end
239
384
  rescue Exception => e
240
385
  raise "Could not copy #{file} to #{target}: \n" + e
241
386
  end
242
387
  }
388
+ rescue Exception => e
389
+ Engines.log.warn "WARNING: Couldn't create the engine public file structure for engine '#{name}'; Error follows:"
390
+ Engines.log.warn e
243
391
  end
244
-
245
-
246
- #private
247
- # Return the directory in which this engine is present
248
- def get_engine_dir(engine_name)
249
- engine_dir=File.join(Engines.config(:root), engine_name.to_s)
250
-
251
- if !File.exist?(engine_dir)
252
- # try adding "_engine" to the end of the path.
253
- engine_dir += "_engine"
254
- if !File.exist?(engine_dir)
255
- raise "Cannot find the engine '#{engine_name}' in either /vendor/plugins/#{engine} or /vendor/plugins/#{engine}_engine..."
256
- end
257
- end
258
-
259
- engine_dir
260
- end
261
-
262
- # Returns the Engine object for the specified engine, e.g.:
263
- # Engines.get(:login)
264
- def get(name)
265
- ActiveEngines.find { |e| e.name == name.to_s || e.name == "#{name}_engine" }
266
- end
267
-
268
- # Returns the Engine object for the current engine, i.e. the engine
269
- # in which the currently executing code lies.
270
- def current()
271
- #puts caller.inspect
272
- #puts ">>> " + caller[0]
273
- current_file = caller[0]
274
- ActiveEngines.find do |engine|
275
- File.expand_path(current_file).index(File.expand_path(engine.root)) == 0
276
- end
277
- end
278
- end
392
+ end
279
393
  end
280
394
 
281
- # A simple class for holding information about loaded engines
282
- class Engine
283
-
284
- # Returns the base path of this engine
285
- attr_accessor :root
286
-
287
- # Returns the name of this engine
288
- attr_reader :name
289
-
290
- def name=(val) @name = val.to_s end
291
- def to_s() "Engine<#{@name}>" end
292
- end
395
+
396
+ # These files must be required after the Engines module has been defined.
397
+ require 'engines/dependencies_extensions'
398
+ require 'engines/action_view_extensions'
399
+ require 'engines/action_mailer_extensions'
400
+ require 'engines/testing_extensions'
401
+ require 'engines/migration_extensions'
402
+ require 'engines/active_record_extensions'
@@ -0,0 +1,161 @@
1
+ module Engines
2
+ module RakeTasks
3
+ def self.all_engines
4
+ # An engine is informally defined as any subdirectory in vendor/plugins
5
+ # which ends in '_engine', '_bundle', or contains an 'init_engine.rb' file.
6
+ engine_base_dirs = ['vendor/plugins']
7
+ # The engine root may be different; if possible try to include
8
+ # those directories too
9
+ if Engines.const_defined?(:CONFIG)
10
+ engine_base_dirs << Engines::CONFIG[:root]
11
+ end
12
+ engine_base_dirs.map! {|d| [d + '/*_engine/*',
13
+ d + '/*_bundle/*',
14
+ d + '/*/init_engine.rb']}.flatten!
15
+ engine_dirs = FileList.new(*engine_base_dirs)
16
+ engine_dirs.map do |engine|
17
+ File.basename(File.dirname(engine))
18
+ end.uniq
19
+ end
20
+ end
21
+ end
22
+
23
+
24
+ namespace :engines do
25
+ desc "Display version information about active engines"
26
+ task :info => :environment do
27
+ if ENV["ENGINE"]
28
+ e = Engines.get(ENV["ENGINE"])
29
+ header = "Details for engine '#{e.name}':"
30
+ puts header
31
+ puts "-" * header.length
32
+ puts "Version: #{e.version}"
33
+ puts "Details: #{e.info}"
34
+ else
35
+ puts "Engines plugin: #{Engines.version}"
36
+ Engines.active.each do |e|
37
+ puts "#{e.name}: #{e.version}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ namespace :db do
44
+ namespace :fixtures do
45
+ namespace :engines do
46
+
47
+ desc "Load plugin/engine fixtures into the current environment's database."
48
+ task :load => :environment do
49
+ require 'active_record/fixtures'
50
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
51
+ plugin = ENV['ENGINE'] || '*'
52
+ Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', plugin, 'test', 'fixtures', '*.yml')).each do |fixture_file|
53
+ Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+
61
+ namespace :migrate do
62
+
63
+ desc "Migrate all engines. Target specific version with VERSION=x, specific engine with ENGINE=x"
64
+ task :engines => :environment do
65
+ engines_to_migrate = ENV["ENGINE"] ? [Engines.get(ENV["ENGINE"])].compact : Engines.active
66
+ if engines_to_migrate.empty?
67
+ puts "Couldn't find an engine called '#{ENV["ENGINE"]}'"
68
+ else
69
+ if ENV["VERSION"] && !ENV["ENGINE"]
70
+ # ignore the VERSION, since it makes no sense in this context; we wouldn't
71
+ # want to revert ALL engines to the same version because of a misttype
72
+ puts "Ignoring the given version (#{ENV["VERSION"]})."
73
+ puts "To control individual engine versions, use the ENGINE=<engine> argument"
74
+ else
75
+ engines_to_migrate.each do |engine|
76
+ Engines::EngineMigrator.current_engine = engine
77
+ migration_directory = File.join(engine.root, 'db', 'migrate')
78
+ if File.exist?(migration_directory)
79
+ puts "Migrating engine '#{engine.name}'"
80
+ Engines::EngineMigrator.migrate(migration_directory, ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
81
+ else
82
+ puts "The db/migrate directory for engine '#{engine.name}' appears to be missing."
83
+ puts "Should be: #{migration_directory}"
84
+ end
85
+ end
86
+ if ActiveRecord::Base.schema_format == :ruby && !engines_to_migrate.empty?
87
+ Rake::Task[:db_schema_dump].invoke
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ namespace :engines do
94
+ Engines::RakeTasks.all_engines.each do |engine_name|
95
+ desc "Migrate the '#{engine_name}' engine. Target specific version with VERSION=x"
96
+ task engine_name => :environment do
97
+ ENV['ENGINE'] = engine_name; Rake::Task['db:migrate:engines'].invoke
98
+ end
99
+ end
100
+ end
101
+
102
+ end
103
+ end
104
+
105
+
106
+ # this is just a rip-off from the plugin stuff in railties/lib/tasks/documentation.rake,
107
+ # because the default plugindoc stuff doesn't support subdirectories like <engine>/app or
108
+ # <engine>/component.
109
+ namespace :doc do
110
+
111
+ desc "Generate documation for all installed engines"
112
+ task :engines => Engines::RakeTasks.all_engines.map {|engine| "doc:engines:#{engine}"}
113
+
114
+ namespace :engines do
115
+ # Define doc tasks for each engine
116
+ Engines::RakeTasks.all_engines.each do |engine_name|
117
+ desc "Generation documentation for the '#{engine_name}' engine"
118
+ task engine_name => :environment do
119
+ engine_base = "vendor/plugins/#{engine_name}"
120
+ options = []
121
+ files = Rake::FileList.new
122
+ options << "-o doc/plugins/#{engine_name}"
123
+ options << "--title '#{engine_name.titlecase} Documentation'"
124
+ options << '--line-numbers --inline-source'
125
+ options << '--all' # include protected methods
126
+ options << '-T html'
127
+
128
+ files.include("#{engine_base}/lib/**/*.rb")
129
+ files.include("#{engine_base}/app/**/*.rb") # include the app directory
130
+ files.include("#{engine_base}/components/**/*.rb") # include the components directory
131
+ if File.exists?("#{engine_base}/README")
132
+ files.include("#{engine_base}/README")
133
+ options << "--main '#{engine_base}/README'"
134
+ end
135
+ files.include("#{engine_base}/CHANGELOG") if File.exists?("#{engine_base}/CHANGELOG")
136
+
137
+ options << files.to_s
138
+
139
+ sh %(rdoc #{options * ' '})
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ namespace :test do
146
+ desc "Run the engine tests in vendor/plugins/**/test (or specify with ENGINE=name)"
147
+ # NOTE: we're using the Rails 1.0 non-namespaced task here, just to maintain
148
+ # compatibility with Rails 1.0
149
+ # TODO: make this work with Engines.config(:root)
150
+ Rake::TestTask.new(:engines => :prepare_test_database) do |t|
151
+ t.libs << "test"
152
+
153
+ if ENV['ENGINE']
154
+ t.pattern = "vendor/plugins/#{ENV['ENGINE']}/test/**/*_test.rb"
155
+ else
156
+ t.pattern = 'vendor/plugins/**/test/**/*_test.rb'
157
+ end
158
+
159
+ t.verbose = true
160
+ end
161
+ end