parlement 0.14 → 0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +41 -1
- data/MEMORY +66 -5
- data/README +10 -5
- data/Rakefile +15 -23
- data/app/controllers/account_controller.rb +48 -43
- data/app/controllers/{application.rb → application_controller.rb} +15 -12
- data/app/controllers/elt_controller.rb +77 -32
- data/app/controllers/subscriber_controller.rb +11 -10
- data/app/helpers/application_helper.rb +14 -1
- data/app/helpers/elt_helper.rb +9 -7
- data/app/models/elt.rb +25 -24
- data/app/models/mail.rb +44 -47
- data/app/models/person_notify.rb +2 -2
- data/app/models/user.rb +128 -2
- data/app/models/user_notify.rb +15 -15
- data/app/views/account/_login.rhtml +39 -39
- data/app/views/account/_show.rhtml +22 -30
- data/app/views/account/signup.rhtml +2 -2
- data/app/views/elt/_choice.rhtml +6 -6
- data/app/views/elt/_elt.rhtml +27 -32
- data/app/views/elt/choices.rhtml +16 -18
- data/app/views/elt/list/_byDate.rhtml +14 -14
- data/app/views/elt/list/_byVote.rhtml +15 -15
- data/app/views/elt/list/_children.rhtml +48 -40
- data/app/views/elt/list/_subscribers.rhtml +1 -1
- data/app/views/elt/new.rhtml +22 -21
- data/app/views/elt/rss.rxml +4 -11
- data/app/views/elt/show.rhtml +65 -61
- data/app/views/elt/vote_rss.rxml +4 -11
- data/app/views/layouts/top.rhtml +39 -50
- data/app/views/person/_listElts.rhtml +1 -1
- data/app/views/person/show.rhtml +1 -1
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/change_password.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/delete.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/forgot_password.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/pending_delete.rhtml +0 -0
- data/{vendor/plugins/login_engine/app → app}/views/user_notify/signup.rhtml +0 -0
- data/config/boot.rb +97 -32
- data/config/environment.rb +37 -35
- data/config/environments/development.rb +2 -3
- data/config/environments/production.rb +3 -0
- data/config/initializers/string_ruby_1.8.rb +10 -0
- data/config/routes.rb +17 -22
- data/db/schema.rb +102 -74
- data/lib/tasks/rspec.rake +167 -0
- data/public/404.html +25 -7
- data/public/500.html +26 -7
- data/public/dispatch.cgi +0 -0
- data/public/dispatch.fcgi +0 -0
- data/public/dispatch.rb +0 -0
- data/public/images/live_tree_branch_collapsed_icon.gif +0 -0
- data/public/images/live_tree_branch_expanded_icon.gif +0 -0
- data/public/images/live_tree_leaf_icon.gif +0 -0
- data/public/javascripts/application.js +258 -0
- data/public/javascripts/controls.js +544 -414
- data/public/javascripts/dragdrop.js +229 -198
- data/public/javascripts/effects.js +499 -459
- data/public/javascripts/prototype.js +2926 -1121
- data/public/javascripts/shadedborder.js +68 -50
- data/public/stylesheets/default.css +34 -34
- data/public/stylesheets/live_tree.css +0 -0
- data/public/stylesheets/scaffold.css +6 -6
- data/script/about +0 -0
- data/script/autospec +6 -0
- data/script/benchmarker +0 -0
- data/script/breakpointer +0 -0
- data/script/console +0 -0
- data/script/dbconsole +3 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/plugin +0 -0
- data/script/profiler +0 -0
- data/script/runner +0 -0
- data/script/server +0 -0
- data/script/spec +10 -0
- data/script/spec_server +9 -0
- data/test/unit/attachment_test.rb +4 -4
- data/test/unit/choice_test.rb +1 -1
- data/test/unit/elt_test.rb +9 -9
- data/test/unit/mail_notify_test.rb +2 -2
- data/test/unit/mail_test.rb +18 -11
- data/test/unit/person_notify_test.rb +1 -1
- data/test/unit/person_test.rb +1 -1
- data/test/unit/subscriber_test.rb +1 -1
- data/test/unit/user_test.rb +81 -0
- data/test/unit/visit_test.rb +6 -6
- data/vendor/plugins/activerecord_foreign_key_extensions/init.rb +2 -0
- data/vendor/plugins/activerecord_foreign_key_extensions/lib/active_record_extensions.rb +182 -0
- data/vendor/plugins/activerecord_text_id_extensions/init.rb +2 -0
- data/vendor/plugins/activerecord_text_id_extensions/lib/active_record_extensions.rb +24 -0
- data/vendor/plugins/acts_as_nested_set/README +15 -0
- data/vendor/plugins/acts_as_nested_set/init.rb +1 -0
- data/vendor/plugins/acts_as_nested_set/lib/active_record/acts/nested_set.rb +210 -0
- data/vendor/plugins/acts_as_nested_set/test/nested_set_test.rb +269 -0
- data/vendor/plugins/acts_as_tree/README +26 -0
- data/vendor/plugins/acts_as_tree/Rakefile +22 -0
- data/vendor/plugins/acts_as_tree/init.rb +1 -0
- data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +96 -0
- data/vendor/plugins/{output_compression/CHANGELOG → acts_as_tree/test/abstract_unit.rb} +0 -0
- data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +219 -0
- data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
- data/vendor/plugins/classic_pagination/CHANGELOG +152 -0
- data/vendor/plugins/classic_pagination/README +18 -0
- data/vendor/plugins/{output_compression/rakefile → classic_pagination/Rakefile} +22 -22
- data/vendor/plugins/classic_pagination/init.rb +33 -0
- data/vendor/plugins/classic_pagination/install.rb +1 -0
- data/vendor/plugins/classic_pagination/lib/pagination.rb +405 -0
- data/vendor/plugins/classic_pagination/lib/pagination_helper.rb +135 -0
- data/vendor/plugins/classic_pagination/test/fixtures/companies.yml +24 -0
- data/vendor/plugins/classic_pagination/test/fixtures/company.rb +9 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developer.rb +7 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developers.yml +21 -0
- data/vendor/plugins/classic_pagination/test/fixtures/developers_projects.yml +13 -0
- data/vendor/plugins/classic_pagination/test/fixtures/project.rb +3 -0
- data/vendor/plugins/classic_pagination/test/fixtures/projects.yml +7 -0
- data/vendor/plugins/classic_pagination/test/fixtures/replies.yml +13 -0
- data/vendor/plugins/classic_pagination/test/fixtures/reply.rb +5 -0
- data/vendor/plugins/classic_pagination/test/fixtures/schema.sql +42 -0
- data/vendor/plugins/classic_pagination/test/fixtures/topic.rb +3 -0
- data/vendor/plugins/classic_pagination/test/fixtures/topics.yml +22 -0
- data/vendor/plugins/classic_pagination/test/helper.rb +117 -0
- data/vendor/plugins/classic_pagination/test/pagination_helper_test.rb +38 -0
- data/vendor/plugins/classic_pagination/test/pagination_test.rb +177 -0
- data/vendor/plugins/file_column/lib/file_column.rb +1 -1
- data/vendor/plugins/file_column/test/file_column_test.rb +0 -0
- metadata +151 -197
- data/app/helpers/live_tree.rb +0 -238
- data/app/views/elt/_form.rhtml +0 -31
- data/app/views/elt/show_tree.rhtml +0 -8
- data/config/environments/user_environment.rb +0 -1
- data/db/ROOT/Titemagli.txt +0 -3
- data/db/ROOT/titemagli.txt +0 -9
- data/public/javascripts/behaviour.js +0 -254
- data/public/javascripts/ie7-load.htc +0 -1
- data/public/javascripts/ie7.js +0 -6
- data/public/javascripts/live_tree.js +0 -749
- data/public/javascripts/mybehaviour.js +0 -225
- data/public/javascripts/scriptaculous.js +0 -47
- data/public/javascripts/slider.js +0 -283
- data/public/stylesheets/blue.css +0 -471
- data/vendor/plugins/engines/CHANGELOG +0 -241
- data/vendor/plugins/engines/MIT-LICENSE +0 -21
- data/vendor/plugins/engines/README +0 -64
- data/vendor/plugins/engines/Rakefile +0 -32
- data/vendor/plugins/engines/UPGRADING +0 -93
- data/vendor/plugins/engines/about.yml +0 -7
- data/vendor/plugins/engines/generators/plugin_migration/USAGE +0 -45
- data/vendor/plugins/engines/generators/plugin_migration/plugin_migration_generator.rb +0 -79
- data/vendor/plugins/engines/generators/plugin_migration/templates/plugin_migration.erb +0 -13
- data/vendor/plugins/engines/init.rb +0 -40
- data/vendor/plugins/engines/install.rb +0 -32
- data/vendor/plugins/engines/lib/engines.rb +0 -323
- data/vendor/plugins/engines/lib/engines/deprecated_config_support.rb +0 -135
- data/vendor/plugins/engines/lib/engines/plugin.rb +0 -214
- data/vendor/plugins/engines/lib/engines/plugin_list.rb +0 -31
- data/vendor/plugins/engines/lib/engines/plugin_migrator.rb +0 -60
- data/vendor/plugins/engines/lib/engines/rails_extensions.rb +0 -6
- data/vendor/plugins/engines/lib/engines/rails_extensions/active_record.rb +0 -19
- data/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb +0 -143
- data/vendor/plugins/engines/lib/engines/rails_extensions/migrations.rb +0 -155
- data/vendor/plugins/engines/lib/engines/rails_extensions/public_asset_helpers.rb +0 -116
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails.rb +0 -20
- data/vendor/plugins/engines/lib/engines/rails_extensions/rails_initializer.rb +0 -86
- data/vendor/plugins/engines/lib/engines/rails_extensions/routing.rb +0 -77
- data/vendor/plugins/engines/lib/engines/rails_extensions/templates.rb +0 -140
- data/vendor/plugins/engines/lib/engines/testing.rb +0 -87
- data/vendor/plugins/engines/tasks/engines.rake +0 -149
- data/vendor/plugins/login_engine/CHANGELOG +0 -22
- data/vendor/plugins/login_engine/README +0 -344
- data/vendor/plugins/login_engine/app/controllers/user_controller.rb +0 -262
- data/vendor/plugins/login_engine/app/helpers/user_helper.rb +0 -88
- data/vendor/plugins/login_engine/app/models/user.rb +0 -7
- data/vendor/plugins/login_engine/app/models/user_notify.rb +0 -75
- data/vendor/plugins/login_engine/app/views/user/_edit.rhtml +0 -11
- data/vendor/plugins/login_engine/app/views/user/_password.rhtml +0 -9
- data/vendor/plugins/login_engine/app/views/user/change_password.rhtml +0 -17
- data/vendor/plugins/login_engine/app/views/user/edit.rhtml +0 -23
- data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +0 -18
- data/vendor/plugins/login_engine/app/views/user/home.rhtml +0 -7
- data/vendor/plugins/login_engine/app/views/user/login.rhtml +0 -17
- data/vendor/plugins/login_engine/app/views/user/logout.rhtml +0 -8
- data/vendor/plugins/login_engine/app/views/user/signup.rhtml +0 -17
- data/vendor/plugins/login_engine/db/migrate/001_initial_schema.rb +0 -25
- data/vendor/plugins/login_engine/init_engine.rb +0 -11
- data/vendor/plugins/login_engine/install.rb +0 -4
- data/vendor/plugins/login_engine/lib/login_engine.rb +0 -62
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +0 -113
- data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +0 -155
- data/vendor/plugins/login_engine/public/stylesheets/login_engine.css +0 -81
- data/vendor/plugins/login_engine/test/fixtures/users.yml +0 -41
- data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +0 -536
- data/vendor/plugins/login_engine/test/mocks/mail.rb +0 -14
- data/vendor/plugins/login_engine/test/mocks/time.rb +0 -19
- data/vendor/plugins/login_engine/test/test_helper.rb +0 -11
- data/vendor/plugins/login_engine/test/unit/user_test.rb +0 -114
- data/vendor/plugins/output_compression/MIT-LICENSE +0 -20
- data/vendor/plugins/output_compression/README +0 -4
- data/vendor/plugins/output_compression/init.rb +0 -1
- data/vendor/plugins/output_compression/lib/output_compression.rb +0 -84
- data/vendor/plugins/output_compression/test/output_test.rb +0 -11
- data/vendor/plugins/output_compression/test/test_controller.rb +0 -3
- data/vendor/plugins/output_compression/test/test_helper.rb +0 -14
@@ -1,19 +0,0 @@
|
|
1
|
-
# Here we add a single helpful method to ActiveRecord::Base. This method may be deprecated
|
2
|
-
# in the future, since support for the Module#config mechanism which required it has
|
3
|
-
# also been dropped.
|
4
|
-
module Engines::RailsExtensions::ActiveRecord
|
5
|
-
# NOTE: Currently the Migrations system will ALWAYS wrap given table names
|
6
|
-
# in the prefix/suffix, so any table name set via ActiveRecord::Base#set_table_name,
|
7
|
-
# for instance will always get wrapped in the process of migration. For this
|
8
|
-
# reason, whatever value you give to the config will be wrapped when set_table_name
|
9
|
-
# is used in the model.
|
10
|
-
#
|
11
|
-
# This method is useful for determining the actual name (including prefix and
|
12
|
-
# suffix) that Rails will use for a model, given a particular set_table_name
|
13
|
-
# parameter.
|
14
|
-
def wrapped_table_name(name)
|
15
|
-
table_name_prefix + name + table_name_suffix
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
::ActiveRecord::Base.extend(Engines::RailsExtensions::ActiveRecord)
|
@@ -1,143 +0,0 @@
|
|
1
|
-
# One of the magic features that that engines plugin provides is the ability to
|
2
|
-
# override selected methods in controllers and helpers from your application.
|
3
|
-
# This is achieved by trapping requests to load those files, and then mixing in
|
4
|
-
# code from plugins (in the order the plugins were loaded) before finally loading
|
5
|
-
# any versions from the main +app+ directory.
|
6
|
-
#
|
7
|
-
# The behaviour of this extension is output to the log file for help when
|
8
|
-
# debugging.
|
9
|
-
#
|
10
|
-
# == Example
|
11
|
-
#
|
12
|
-
# A plugin contains the following controller in <tt>plugin/app/controllers/my_controller.rb</tt>:
|
13
|
-
#
|
14
|
-
# class MyController < ApplicationController
|
15
|
-
# def index
|
16
|
-
# @name = "HAL 9000"
|
17
|
-
# end
|
18
|
-
# def list
|
19
|
-
# @robots = Robot.find(:all)
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# In one application that uses this plugin, we decide that the name used in the
|
24
|
-
# index action should be "Robbie", not "HAL 9000". To override this single method,
|
25
|
-
# we create the corresponding controller in our application
|
26
|
-
# (<tt>RAILS_ROOT/app/controllers/my_controller.rb</tt>), and redefine the method:
|
27
|
-
#
|
28
|
-
# class MyController < ApplicationController
|
29
|
-
# def index
|
30
|
-
# @name = "Robbie"
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# The list method remains as it was defined in the plugin controller.
|
35
|
-
#
|
36
|
-
# The same basic principle applies to helpers, and also views and partials (although
|
37
|
-
# view overriding is performed in Engines::RailsExtensions::Templates; see that
|
38
|
-
# module for more information).
|
39
|
-
#
|
40
|
-
# === What about models?
|
41
|
-
#
|
42
|
-
# Unfortunately, it's not possible to provide this kind of magic for models.
|
43
|
-
# The only reason why it's possible for controllers and helpers is because
|
44
|
-
# they can be recognised by their filenames ("whatever_controller", "jazz_helper"),
|
45
|
-
# whereas models appear the same as any other typical Ruby library ("node",
|
46
|
-
# "user", "image", etc.).
|
47
|
-
#
|
48
|
-
# If mixing were allowed in models, it would mean code mixing for *every*
|
49
|
-
# file that was loaded via +require_or_load+, and this could result in
|
50
|
-
# problems where, for example, a Node model might start to include
|
51
|
-
# functionality from another file called "node" somewhere else in the
|
52
|
-
# <tt>$LOAD_PATH</tt>.
|
53
|
-
#
|
54
|
-
# One way to overcome this is to provide model functionality as a module in
|
55
|
-
# a plugin, which developers can then include into their own model
|
56
|
-
# implementations.
|
57
|
-
#
|
58
|
-
# Another option is to provide an abstract model (see the ActiveRecord::Base
|
59
|
-
# documentation) and have developers subclass this model in their own
|
60
|
-
# application if they must.
|
61
|
-
#
|
62
|
-
# ---
|
63
|
-
#
|
64
|
-
# The Engines::RailsExtensions::Dependencies module includes a method to
|
65
|
-
# override Dependencies.require_or_load, which is called to load code needed
|
66
|
-
# by Rails as it encounters constants that aren't defined.
|
67
|
-
#
|
68
|
-
# This method is enhanced with the code-mixing features described above.
|
69
|
-
#
|
70
|
-
module Engines::RailsExtensions::Dependencies
|
71
|
-
def self.included(base) #:nodoc:
|
72
|
-
base.class_eval { alias_method_chain :require_or_load, :engine_additions }
|
73
|
-
end
|
74
|
-
|
75
|
-
# Attempt to load the given file from any plugins, as well as the application.
|
76
|
-
# This performs the 'code mixing' magic, allowing application controllers and
|
77
|
-
# helpers to override single methods from those in plugins.
|
78
|
-
# If the file can be found in any plugins, it will be loaded first from those
|
79
|
-
# locations. Finally, the application version is loaded, using Ruby's behaviour
|
80
|
-
# to replace existing methods with their new definitions.
|
81
|
-
#
|
82
|
-
# If <tt>Engines.disable_code_mixing == true</tt>, the first controller/helper on the
|
83
|
-
# <tt>$LOAD_PATH</tt> will be used (plugins' +app+ directories are always lower on the
|
84
|
-
# <tt>$LOAD_PATH</tt> than the main +app+ directory).
|
85
|
-
#
|
86
|
-
# If <tt>Engines.disable_application_code_loading == true</tt>, controllers will
|
87
|
-
# not be loaded from the main +app+ directory *if* they are present in any
|
88
|
-
# plugins.
|
89
|
-
#
|
90
|
-
# Returns true if the file could be loaded (from anywhere); false otherwise -
|
91
|
-
# mirroring the behaviour of +require_or_load+ from Rails (which mirrors
|
92
|
-
# that of Ruby's own +require+, I believe).
|
93
|
-
def require_or_load_with_engine_additions(file_name, const_path=nil)
|
94
|
-
return require_or_load_without_engine_additions(file_name, const_path) if Engines.disable_code_mixing
|
95
|
-
|
96
|
-
file_loaded = false
|
97
|
-
|
98
|
-
# try and load the plugin code first
|
99
|
-
# can't use model, as there's nothing in the name to indicate that the file is a 'model' file
|
100
|
-
# rather than a library or anything else.
|
101
|
-
['controller', 'helper'].each do |file_type|
|
102
|
-
# if we recognise this type
|
103
|
-
# (this regexp splits out the module/filename from any instances of app/#{type}, so that
|
104
|
-
# modules are still respected.)
|
105
|
-
if file_name =~ /^(.*app\/#{file_type}s\/)?(.*_#{file_type})(\.rb)?$/
|
106
|
-
base_name = $2
|
107
|
-
# ... go through the plugins from first started to last, so that
|
108
|
-
# code with a high precedence (started later) will override lower precedence
|
109
|
-
# implementations
|
110
|
-
Rails.plugins.each do |plugin|
|
111
|
-
plugin_file_name = File.expand_path(File.join(plugin.root, 'app', "#{file_type}s", base_name))
|
112
|
-
logger.debug("checking plugin '#{plugin.name}' for '#{base_name}'")
|
113
|
-
if File.file?("#{plugin_file_name}.rb")
|
114
|
-
logger.debug("==> loading from plugin '#{plugin.name}'")
|
115
|
-
file_loaded = true if require_or_load_without_engine_additions(plugin_file_name, const_path)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# finally, load any application-specific controller classes using the 'proper'
|
120
|
-
# rails load mechanism, EXCEPT when we're testing engines and could load this file
|
121
|
-
# from an engine
|
122
|
-
if Engines.disable_application_code_loading
|
123
|
-
logger.debug("loading from application disabled.")
|
124
|
-
else
|
125
|
-
# Ensure we are only loading from the /app directory at this point
|
126
|
-
app_file_name = File.join(RAILS_ROOT, 'app', "#{file_type}s", "#{base_name}")
|
127
|
-
if File.file?("#{app_file_name}.rb")
|
128
|
-
logger.debug("loading from application: #{base_name}")
|
129
|
-
file_loaded = true if require_or_load_without_engine_additions(app_file_name, const_path)
|
130
|
-
else
|
131
|
-
logger.debug("(file not found in application)")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# if we managed to load a file, return true. If not, default to the original method.
|
138
|
-
# Note that this relies on the RHS of a boolean || not to be evaluated if the LHS is true.
|
139
|
-
file_loaded || require_or_load_without_engine_additions(file_name, const_path)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
::Dependencies.send(:include, Engines::RailsExtensions::Dependencies)
|
@@ -1,155 +0,0 @@
|
|
1
|
-
# Contains the enhancements to Rails' migrations system to support the
|
2
|
-
# Engines::PluginMigrator. See Engines::RailsExtensions::Migrations for more
|
3
|
-
# information.
|
4
|
-
|
5
|
-
require "engines/plugin_migrator"
|
6
|
-
|
7
|
-
# = Plugins and Migrations: Background
|
8
|
-
#
|
9
|
-
# Rails uses migrations to describe changes to the databases as your application
|
10
|
-
# evolves. Each change to your application - adding and removing models, most
|
11
|
-
# commonly - might require tweaks to your schema in the form of new tables, or new
|
12
|
-
# columns on existing tables, or possibly the removal of tables or columns. Migrations
|
13
|
-
# can even include arbitrary code to *transform* data as the underlying schema
|
14
|
-
# changes.
|
15
|
-
#
|
16
|
-
# The point is that at any particular stage in your application's development,
|
17
|
-
# migrations serve to transform the database into a state where it is compatible
|
18
|
-
# and appropriate at that time.
|
19
|
-
#
|
20
|
-
# == What about plugins?
|
21
|
-
#
|
22
|
-
# If you want to share models using plugins, chances are that you might also
|
23
|
-
# want to include the corresponding migrations to create tables for those models.
|
24
|
-
# With the engines plugin installed, plugins can carry migration data easily:
|
25
|
-
#
|
26
|
-
# vendor/
|
27
|
-
# |
|
28
|
-
# plugins/
|
29
|
-
# |
|
30
|
-
# my_plugin/
|
31
|
-
# |- init.rb
|
32
|
-
# |- lib/
|
33
|
-
# |- db/
|
34
|
-
# |-migrate/
|
35
|
-
# |- 001_do_something.rb
|
36
|
-
# |- 002_and_something_else.rb
|
37
|
-
# |- ...
|
38
|
-
#
|
39
|
-
# When you install a plugin which contains migrations, you are undertaking a
|
40
|
-
# further step in the development of your application, the same as the addition
|
41
|
-
# of any other code. With this in mind, you may want to 'roll back' the
|
42
|
-
# installation of this plugin at some point, and the database should be able
|
43
|
-
# to migrate back to the point without this plugin in it too.
|
44
|
-
#
|
45
|
-
# == An example
|
46
|
-
#
|
47
|
-
# For example, our current application is at version 14 (according to the
|
48
|
-
# +schema_info+ table), when we decide that we want to add a tagging plugin. The
|
49
|
-
# tagging plugin chosen includes migrations to create the tables it requires
|
50
|
-
# (say, _tags_ and _taggings_, for instance), along with the models and helpers
|
51
|
-
# one might expect.
|
52
|
-
#
|
53
|
-
# After installing this plugin, these tables should be created in our database.
|
54
|
-
# Rather than running the migrations directly from the plugin, they should be
|
55
|
-
# integrated into our main migration stream in order to accurately reflect the
|
56
|
-
# state of our application's database *at this moment in time*.
|
57
|
-
#
|
58
|
-
# $ script/generate plugin_migration
|
59
|
-
# exists db/migrate
|
60
|
-
# create db/migrate/015_migrate_tagging_plugin_to_version_3.rb
|
61
|
-
#
|
62
|
-
# This migration will take our application to version 15, and contains the following,
|
63
|
-
# typical migration code:
|
64
|
-
#
|
65
|
-
# class MigrateTaggingPluginToVersion3 < ActiveRecord::Migration
|
66
|
-
# def self.up
|
67
|
-
# Rails.plugins[:tagging].migrate(3)
|
68
|
-
# end
|
69
|
-
# def self.down
|
70
|
-
# Rails.plugins[:tagging].migrate(0)
|
71
|
-
# end
|
72
|
-
# end
|
73
|
-
#
|
74
|
-
# When we migrate our application up, using <tt>rake db:migrate</tt> as normal,
|
75
|
-
# the plugin will be migrated up to its latest version (3 in this example). If we
|
76
|
-
# ever decide to migrate the application back to the state it was in at version 14,
|
77
|
-
# the plugin migrations will be taken back down to version 0 (which, typically,
|
78
|
-
# would remove all tables the plugin migrations define).
|
79
|
-
#
|
80
|
-
# == Upgrading plugins
|
81
|
-
#
|
82
|
-
# It might happen that later in an application's life, we update to a new version of
|
83
|
-
# the tagging plugin which requires some changes to our database. The tagging plugin
|
84
|
-
# provides these changes in the form of its own migrations.
|
85
|
-
#
|
86
|
-
# In this case, we just need to re-run the plugin_migration generator to create a
|
87
|
-
# new migration from the current revision to the newest one:
|
88
|
-
#
|
89
|
-
# $ script/generate plugin_migration
|
90
|
-
# exists db/migrate
|
91
|
-
# create db/migrate/023_migrate_tagging_plugin_to_version_5.rb
|
92
|
-
#
|
93
|
-
# The contents of this migration are:
|
94
|
-
#
|
95
|
-
# class MigrateTaggingPluginToVersion3 < ActiveRecord::Migration
|
96
|
-
# def self.up
|
97
|
-
# Rails.plugins[:tagging].migrate(5)
|
98
|
-
# end
|
99
|
-
# def self.down
|
100
|
-
# Rails.plugins[:tagging].migrate(3)
|
101
|
-
# end
|
102
|
-
# end
|
103
|
-
#
|
104
|
-
# Notice that if we were to migrate down to revision 22 or lower, the tagging plugin
|
105
|
-
# will be migrated back down to version 3 - the version we were previously at.
|
106
|
-
#
|
107
|
-
#
|
108
|
-
# = Creating migrations in plugins
|
109
|
-
#
|
110
|
-
# In order to use the plugin migration functionality that engines provides, a plugin
|
111
|
-
# only needs to provide regular migrations in a <tt>db/migrate</tt> folder within it.
|
112
|
-
#
|
113
|
-
# = Explicitly migrating plugins
|
114
|
-
#
|
115
|
-
# It's possible to migrate plugins within your own migrations, or any other code.
|
116
|
-
# Simply get the Plugin instance, and its Plugin#migrate method with the version
|
117
|
-
# you wish to end up at:
|
118
|
-
#
|
119
|
-
# Rails.plugins[:whatever].migrate(version)
|
120
|
-
#
|
121
|
-
# ---
|
122
|
-
#
|
123
|
-
# The Engines::RailsExtensions::Migrations module defines extensions for Rails'
|
124
|
-
# migration systems. Specifically:
|
125
|
-
#
|
126
|
-
# * Adding a hook to initialize_schema_information to create the plugin schema
|
127
|
-
# info table.
|
128
|
-
#
|
129
|
-
module Engines::RailsExtensions::Migrations
|
130
|
-
def self.included(base) # :nodoc:
|
131
|
-
base.class_eval { alias_method_chain :initialize_schema_information, :engine_additions }
|
132
|
-
end
|
133
|
-
|
134
|
-
# Create the schema tables, and ensure that the plugin schema table
|
135
|
-
# is also initialized. The plugin schema info table is defined by
|
136
|
-
# Engines::PluginMigrator.schema_info_table_name.
|
137
|
-
def initialize_schema_information_with_engine_additions
|
138
|
-
initialize_schema_information_without_engine_additions
|
139
|
-
|
140
|
-
# create the plugin schema stuff.
|
141
|
-
begin
|
142
|
-
execute <<-ESQL
|
143
|
-
CREATE TABLE #{Engines::PluginMigrator.schema_info_table_name}
|
144
|
-
(plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})
|
145
|
-
ESQL
|
146
|
-
rescue ActiveRecord::StatementInvalid
|
147
|
-
# Schema has been initialized
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
::ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, Engines::RailsExtensions::Migrations)
|
153
|
-
|
154
|
-
# Set ActiveRecord to ignore the plugin schema table by default
|
155
|
-
::ActiveRecord::SchemaDumper.ignore_tables << Engines.schema_info_table
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# The engines plugin makes it trivial to share public assets using plugins.
|
2
|
-
# To do this, include an <tt>assets</tt> directory within your plugin, and put
|
3
|
-
# your javascripts, stylesheets and images in subdirectories of that folder:
|
4
|
-
#
|
5
|
-
# my_plugin
|
6
|
-
# |- init.rb
|
7
|
-
# |- lib/
|
8
|
-
# |- assets/
|
9
|
-
# |- javascripts/
|
10
|
-
# | |- my_functions.js
|
11
|
-
# |
|
12
|
-
# |- stylesheets/
|
13
|
-
# | |- my_styles.css
|
14
|
-
# |
|
15
|
-
# |- images/
|
16
|
-
# |- my_face.jpg
|
17
|
-
#
|
18
|
-
# Files within the <tt>asset</tt> structure are automatically mirrored into
|
19
|
-
# a publicly-accessible folder each time your application starts (see
|
20
|
-
# Plugin#mirror_public_assets).
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# == Using plugin assets in views
|
24
|
-
#
|
25
|
-
# It's also simple to use Rails' helpers in your views to use plugin assets.
|
26
|
-
# The default helper methods have been enhanced by the engines plugin to accept
|
27
|
-
# a <tt>:plugin</tt> option, indicating the plugin containing the desired asset.
|
28
|
-
#
|
29
|
-
# For example, it's easy to use plugin assets in your layouts:
|
30
|
-
#
|
31
|
-
# <%= stylesheet_link_tag "my_styles", :plugin => "my_plugin", :media => "screen" %>
|
32
|
-
# <%= javascript_include_tag "my_functions", :plugin => "my_plugin" %>
|
33
|
-
#
|
34
|
-
# ... and similarly in views and partials, it's easy to use plugin images:
|
35
|
-
#
|
36
|
-
# <%= image_tag "my_face", :plugin => "my_plugin" %>
|
37
|
-
# <!-- or -->
|
38
|
-
# <%= image_path "my_face", :plugin => "my_plugin" %>
|
39
|
-
#
|
40
|
-
# Where the default helpers allow the specification of more than one file (i.e. the
|
41
|
-
# javascript and stylesheet helpers), you can do similarly for multiple assets from
|
42
|
-
# within a single plugin.
|
43
|
-
#
|
44
|
-
# ---
|
45
|
-
#
|
46
|
-
# This module enhances four of the methods from ActionView::Helpers::AssetTagHelper:
|
47
|
-
#
|
48
|
-
# * stylesheet_link_tag
|
49
|
-
# * javascript_include_tag
|
50
|
-
# * image_path
|
51
|
-
# * image_tag
|
52
|
-
#
|
53
|
-
# Each one of these methods now accepts the key/value pair <tt>:plugin => "plugin_name"</tt>,
|
54
|
-
# which can be used to specify the originating plugin for any assets.
|
55
|
-
#
|
56
|
-
module Engines::RailsExtensions::PublicAssetHelpers
|
57
|
-
def self.included(base) #:nodoc:
|
58
|
-
base.class_eval do
|
59
|
-
[:stylesheet_link_tag, :javascript_include_tag, :image_path, :image_tag].each do |m|
|
60
|
-
alias_method_chain m, :engine_additions
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Adds plugin functionality to Rails' default stylesheet_link_tag method.
|
66
|
-
def stylesheet_link_tag_with_engine_additions(*sources)
|
67
|
-
stylesheet_link_tag_without_engine_additions(*Engines::RailsExtensions::PublicAssetHelpers.pluginify_sources("stylesheets", *sources))
|
68
|
-
end
|
69
|
-
|
70
|
-
# Adds plugin functionality to Rails' default javascript_include_tag method.
|
71
|
-
def javascript_include_tag_with_engine_additions(*sources)
|
72
|
-
javascript_include_tag_without_engine_additions(*Engines::RailsExtensions::PublicAssetHelpers.pluginify_sources("javascripts", *sources))
|
73
|
-
end
|
74
|
-
|
75
|
-
#--
|
76
|
-
# Our modified image_path now takes a 'plugin' option, though it doesn't require it
|
77
|
-
#++
|
78
|
-
|
79
|
-
# Adds plugin functionality to Rails' default image_path method.
|
80
|
-
def image_path_with_engine_additions(source, options={})
|
81
|
-
options.stringify_keys!
|
82
|
-
source = Engines::RailsExtensions::PublicAssetHelpers.plugin_asset_path(options["plugin"], "images", source) if options["plugin"]
|
83
|
-
image_path_without_engine_additions(source)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Adds plugin functionality to Rails' default image_tag method.
|
87
|
-
def image_tag_with_engine_additions(source, options={})
|
88
|
-
options.stringify_keys!
|
89
|
-
if options["plugin"]
|
90
|
-
source = Engines::RailsExtensions::PublicAssetHelpers.plugin_asset_path(options["plugin"], "images", source)
|
91
|
-
options.delete("plugin")
|
92
|
-
end
|
93
|
-
image_tag_without_engine_additions(source, options)
|
94
|
-
end
|
95
|
-
|
96
|
-
#--
|
97
|
-
# The following are methods on this module directly because of the weird-freaky way
|
98
|
-
# Rails creates the helper instance that views actually get
|
99
|
-
#++
|
100
|
-
|
101
|
-
# Convert sources to the paths for the given plugin, if any plugin option is given
|
102
|
-
def self.pluginify_sources(type, *sources)
|
103
|
-
options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
|
104
|
-
sources.map! { |s| plugin_asset_path(options["plugin"], type, s) } if options["plugin"]
|
105
|
-
options.delete("plugin") # we don't want it appearing in the HTML
|
106
|
-
sources << options # re-add options
|
107
|
-
end
|
108
|
-
|
109
|
-
# Returns the publicly-addressable relative URI for the given asset, type and plugin
|
110
|
-
def self.plugin_asset_path(plugin_name, type, asset)
|
111
|
-
raise "No plugin called '#{plugin_name}' - please use the full name of a loaded plugin." if Rails.plugins[plugin_name].nil?
|
112
|
-
"/#{Rails.plugins[plugin_name].public_asset_directory}/#{type}/#{asset}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
::ActionView::Helpers::AssetTagHelper.send(:include, Engines::RailsExtensions::PublicAssetHelpers)
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# In order to give a richer infrastructure for dealing with plugins, the engines
|
2
|
-
# plugin adds two new attributes to the Rails module:
|
3
|
-
#
|
4
|
-
# [+plugins+] A PluginList instance which holds the currently loaded plugins
|
5
|
-
# [+configuration+] The current Rails::Configuration instance, so that we can
|
6
|
-
# query any parameters that might be set *after* Rails has
|
7
|
-
# loaded, as well as during plugin initialization
|
8
|
-
#
|
9
|
-
#--
|
10
|
-
# Here we just re-open the Rails module and add our custom accessors; it
|
11
|
-
# may be cleaner to seperate them into a module, but in this case that seems
|
12
|
-
# like overkill.
|
13
|
-
#++
|
14
|
-
module Rails
|
15
|
-
# The set of all loaded plugins
|
16
|
-
mattr_accessor :plugins
|
17
|
-
|
18
|
-
# The Rails::Initializer::Configuration object
|
19
|
-
mattr_accessor :configuration
|
20
|
-
end
|