radiant 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of radiant might be problematic. Click here for more details.

Files changed (65) hide show
  1. data/CHANGELOG +37 -0
  2. data/CONTRIBUTORS +9 -0
  3. data/app/controllers/admin/page_controller.rb +3 -2
  4. data/app/controllers/admin/user_controller.rb +2 -2
  5. data/app/controllers/admin/welcome_controller.rb +3 -3
  6. data/app/controllers/application.rb +9 -1
  7. data/app/helpers/admin/abstract_model_helper.rb +2 -0
  8. data/app/helpers/admin/page_helper.rb +4 -0
  9. data/app/helpers/application_helper.rb +4 -6
  10. data/app/models/page.rb +4 -1
  11. data/app/models/response_cache.rb +10 -7
  12. data/app/models/standard_tags.rb +7 -5
  13. data/app/views/admin/layout/index.rhtml +1 -1
  14. data/app/views/admin/layout/remove.rhtml +1 -1
  15. data/app/views/admin/page/_node.rhtml +4 -4
  16. data/app/views/admin/snippet/index.rhtml +1 -1
  17. data/app/views/admin/user/index.rhtml +1 -1
  18. data/app/views/layouts/application.rhtml +4 -4
  19. data/config/environment.rb +77 -70
  20. data/config/environments/test.rb +9 -2
  21. data/db/migrate/016_add_sessions.rb +16 -0
  22. data/db/schema.rb +10 -1
  23. data/lib/generators/extension/templates/tasks.rake +13 -2
  24. data/lib/generators/extension/templates/test_helper.rb +3 -2
  25. data/lib/login_system.rb +19 -4
  26. data/lib/plugins/extension_patches/init.rb +1 -1
  27. data/lib/plugins/extension_patches/lib/fixture_loading_extension.rb +32 -33
  28. data/lib/radiant.rb +1 -1
  29. data/lib/radiant/extension.rb +14 -0
  30. data/lib/radiant/extension_loader.rb +135 -106
  31. data/lib/radiant/initializer.rb +2 -0
  32. data/lib/tasks/extensions.rake +16 -1
  33. data/public/javascripts/prototype.js +305 -175
  34. data/public/javascripts/sitemap.js +1 -1
  35. data/public/stylesheets/admin/main.css +5 -2
  36. data/test/fixtures/extensions/01_basic/vendor/plugins/multiple/init.rb +1 -0
  37. data/test/fixtures/extensions/01_basic/vendor/plugins/multiple/lib/multiple.rb +2 -0
  38. data/test/fixtures/extensions/01_basic/vendor/plugins/plugin_normal/init.rb +1 -0
  39. data/test/fixtures/extensions/01_basic/vendor/plugins/plugin_normal/lib/normal_plugin.rb +2 -0
  40. data/test/fixtures/extensions/02_overriding/overriding_extension.rb +1 -1
  41. data/test/fixtures/extensions/02_overriding/vendor/plugins/multiple/init.rb +1 -0
  42. data/test/fixtures/extensions/02_overriding/vendor/plugins/multiple/lib/multiple.rb +2 -0
  43. data/test/fixtures/extensions/load_order_blue/load_order_blue_extension.rb +11 -0
  44. data/test/fixtures/extensions/load_order_green/load_order_green_extension.rb +11 -0
  45. data/test/fixtures/extensions/load_order_red/load_order_red_extension.rb +11 -0
  46. data/test/fixtures/pages.yml +16 -1
  47. data/test/functional/admin/abstract_model_controller_test.rb +2 -2
  48. data/test/functional/admin/export_controller_test.rb +2 -1
  49. data/test/functional/admin/extension_controller_test.rb +2 -1
  50. data/test/functional/admin/layout_controller_test.rb +6 -4
  51. data/test/functional/admin/page_controller_test.rb +48 -22
  52. data/test/functional/admin/user_controller_test.rb +12 -9
  53. data/test/functional/admin/welcome_controller_test.rb +4 -4
  54. data/test/functional/application_controller_test.rb +3 -2
  55. data/test/functional/extension_initialization_test.rb +31 -5
  56. data/test/functional/extension_load_order_test.rb +49 -0
  57. data/test/functional/login_system_test.rb +21 -11
  58. data/test/helpers/difference_test_helper.rb +13 -0
  59. data/test/helpers/extension_tag_test_helper.rb +3 -3
  60. data/test/helpers/login_test_helper.rb +12 -0
  61. data/test/helpers/page_test_helper.rb +4 -1
  62. data/test/unit/page_test.rb +5 -0
  63. data/test/unit/response_cache_test.rb +27 -6
  64. data/test/unit/standard_tags_test.rb +6 -3
  65. metadata +1789 -1767
@@ -5,8 +5,15 @@
5
5
  # your test database is "scratch space" for the test suite and is wiped
6
6
  # and recreated between test runs. Don't rely on the data there!
7
7
  config.cache_classes = true
8
- config.extension_paths << File.join(File.expand_path(RADIANT_ROOT), 'test', 'fixtures', 'extensions')
8
+
9
+ # ensure test extensions are loaded
10
+ test_extension_dir = File.join(File.expand_path(RADIANT_ROOT), 'test', 'fixtures', 'extensions')
11
+ config.extension_paths << test_extension_dir
9
12
  config.extension_paths.uniq!
13
+ if config.extensions && !config.extensions.include?(:all)
14
+ config.extensions.concat(Dir["#{test_extension_dir}/*"].sort.map {|x| File.basename(x).sub(/^\d+_/,'')})
15
+ config.extensions.uniq!
16
+ end
10
17
 
11
18
  # Log error messages when you accidentally call methods on nil.
12
19
  config.whiny_nils = true
@@ -19,4 +26,4 @@ ResponseCache.defaults[:perform_caching] = false
19
26
  # Tell ActionMailer not to deliver emails to the real world.
20
27
  # The :test delivery method accumulates sent emails in the
21
28
  # ActionMailer::Base.deliveries array.
22
- config.action_mailer.delivery_method = :test
29
+ config.action_mailer.delivery_method = :test
@@ -0,0 +1,16 @@
1
+ class AddSessions < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :sessions do |t|
4
+ t.column :session_id, :string
5
+ t.column :data, :text
6
+ t.column :updated_at, :datetime
7
+ end
8
+
9
+ add_index :sessions, :session_id
10
+ add_index :sessions, :updated_at
11
+ end
12
+
13
+ def self.down
14
+ drop_table :sessions
15
+ end
16
+ end
@@ -2,7 +2,7 @@
2
2
  # migrations feature of ActiveRecord to incrementally modify your database, and
3
3
  # then regenerate this schema definition.
4
4
 
5
- ActiveRecord::Schema.define(:version => 15) do
5
+ ActiveRecord::Schema.define(:version => 16) do
6
6
 
7
7
  create_table "config", :force => true do |t|
8
8
  t.column "key", :string, :limit => 40, :default => "", :null => false
@@ -52,6 +52,15 @@ ActiveRecord::Schema.define(:version => 15) do
52
52
  t.column "lock_version", :integer, :default => 0
53
53
  end
54
54
 
55
+ create_table "sessions", :force => true do |t|
56
+ t.column "session_id", :string
57
+ t.column "data", :text
58
+ t.column "updated_at", :datetime
59
+ end
60
+
61
+ add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
62
+ add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
63
+
55
64
  create_table "snippets", :force => true do |t|
56
65
  t.column "name", :string, :limit => 100, :default => "", :null => false
57
66
  t.column "filter_id", :string, :limit => 25
@@ -11,7 +11,18 @@ namespace :radiant do
11
11
  <%= class_name %>.migrator.migrate
12
12
  end
13
13
  end
14
-
14
+
15
+ desc "Copies public assets of the <%= extension_name %> to the instance public/ directory."
16
+ task :update => :environment do
17
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
18
+ Dir[<%= class_name %>.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
19
+ path = file.sub(<%= class_name %>.root, '')
20
+ directory = File.dirname(path)
21
+ puts "Copying #{path}..."
22
+ mkdir_p RAILS_ROOT + directory
23
+ cp file, RAILS_ROOT + path
24
+ end
25
+ end
15
26
  end
16
27
  end
17
- end
28
+ end
@@ -1,7 +1,8 @@
1
- # Load the the environment
1
+ require 'test/unit'
2
+ # # Load the environment
2
3
  unless defined? RADIANT_ROOT
3
4
  ENV["RAILS_ENV"] = "test"
4
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/boot"
5
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
5
6
  end
6
7
  require "#{RADIANT_ROOT}/test/test_helper"
7
8
 
@@ -5,6 +5,7 @@ module LoginSystem
5
5
 
6
6
  @@controllers_where_no_login_required = []
7
7
  @@controller_permissions = Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = Hash.new } }
8
+ helper_method :current_user
8
9
  }
9
10
  base.extend ClassMethods
10
11
  super
@@ -12,13 +13,27 @@ module LoginSystem
12
13
 
13
14
  protected
14
15
 
16
+ def current_user
17
+ @current_user ||= User.find(session['user_id']) rescue nil
18
+ end
19
+
20
+ def current_user=(value=nil)
21
+ if value && value.is_a?(User)
22
+ @current_user = value
23
+ session['user_id'] = value.id
24
+ else
25
+ @current_user = nil
26
+ session['user_id'] = nil
27
+ end
28
+ @current_user
29
+ end
30
+
15
31
  def authenticate
16
32
  action = params['action'].to_s.intern
17
- user = session['user']
18
- if no_login_required? or (user and user_has_access_to_action?(action))
33
+ if no_login_required? or (current_user and user_has_access_to_action?(action))
19
34
  true
20
35
  else
21
- if user
36
+ if current_user
22
37
  permissions = self.class.controller_permissions[self.class][action]
23
38
  flash[:error] = permissions[:denied_message] || 'Access denied.'
24
39
  redirect_to permissions[:denied_url] || { :action => :index }
@@ -35,7 +50,7 @@ module LoginSystem
35
50
  end
36
51
 
37
52
  def user_has_role?(role)
38
- session['user'].send("#{role}?")
53
+ current_user.send("#{role}?")
39
54
  end
40
55
 
41
56
  def user_has_access_to_action?(action)
@@ -1,4 +1,4 @@
1
1
  require 'routing_extension'
2
2
  require 'view_paths_extension'
3
3
  require 'mailer_view_paths_extension'
4
- require 'fixture_loading_extension'
4
+ require 'fixture_loading_extension' if RAILS_ENV == 'test'
@@ -5,42 +5,41 @@ module Radiant
5
5
  include ClassMethods
6
6
  alias_method_chain :create_fixtures, :multiple_paths
7
7
  end
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def create_fixtures_with_multiple_paths(fixtures_directory, table_names, class_names = {})
13
- table_names = [table_names].flatten.map { |n| n.to_s }
14
- connection = block_given? ? yield : ActiveRecord::Base.connection
15
- ActiveRecord::Base.silence do
16
- fixtures_map = {}
17
- fixtures = table_names.map do |table_name|
18
- paths = fixtures_directory.dup
19
- begin
20
- directory = paths.pop
21
- fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, class_names[table_name.to_sym], File.join(directory, table_name))
22
- rescue Exception => e
23
- retry unless paths.empty?
24
- raise e
25
- end
26
- end
27
- all_loaded_fixtures.merge! fixtures_map
28
-
29
- connection.transaction(Thread.current['open_transactions'] == 0) do
30
- fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
31
- fixtures.each { |fixture| fixture.insert_fixtures }
32
-
33
- # Cap primary key sequences to max(pk).
34
- if connection.respond_to?(:reset_pk_sequence!)
35
- table_names.each do |table_name|
36
- connection.reset_pk_sequence!(table_name)
8
+ end
37
9
 
10
+ module ClassMethods
11
+ def create_fixtures_with_multiple_paths(fixtures_directory, table_names, class_names = {})
12
+ table_names = [table_names].flatten.map { |n| n.to_s }
13
+ connection = block_given? ? yield : ActiveRecord::Base.connection
14
+ ActiveRecord::Base.silence do
15
+ fixtures_map = {}
16
+ fixtures = table_names.map do |table_name|
17
+ paths = fixtures_directory.dup
18
+ begin
19
+ directory = paths.pop
20
+ fixtures_map[table_name] = Fixtures.new(connection, File.split(table_name.to_s).last, class_names[table_name.to_sym], File.join(directory, table_name))
21
+ rescue Exception => e
22
+ retry unless paths.empty?
23
+ raise e
24
+ end
25
+ end
26
+ all_loaded_fixtures.merge! fixtures_map
27
+
28
+ connection.transaction(Thread.current['open_transactions'] == 0) do
29
+ fixtures.reverse.each { |fixture| fixture.delete_existing_fixtures }
30
+ fixtures.each { |fixture| fixture.insert_fixtures }
31
+
32
+ # Cap primary key sequences to max(pk).
33
+ if connection.respond_to?(:reset_pk_sequence!)
34
+ table_names.each do |table_name|
35
+ connection.reset_pk_sequence!(table_name)
36
+ end
38
37
  end
39
38
  end
39
+
40
+ return fixtures.size > 1 ? fixtures : fixtures.first
40
41
  end
41
-
42
- return fixtures.size > 1 ? fixtures : fixtures.first
43
- end
44
- end
42
+ end
43
+ end
45
44
  end
46
45
  end
47
46
 
@@ -5,7 +5,7 @@ unless defined? Radiant::Version
5
5
  module Version
6
6
  Major = '0'
7
7
  Minor = '6'
8
- Tiny = '2'
8
+ Tiny = '3'
9
9
 
10
10
  class << self
11
11
  def to_s
@@ -35,6 +35,7 @@ module Radiant
35
35
 
36
36
  def activate_extension
37
37
  return if instance.active?
38
+ load_plugins
38
39
  instance.activate if instance.respond_to? :activate
39
40
  ActionController::Routing::Routes.reload
40
41
  instance.active = true
@@ -72,6 +73,19 @@ module Radiant
72
73
  @route_definitions ||= []
73
74
  end
74
75
 
76
+ def load_plugins
77
+ plugins = Dir[self.root + "/vendor/plugins/*"].select{|path| File.directory?(path)}
78
+ plugins.each do |plugin|
79
+ const_name = "PLUGIN_#{File.basename(plugin).upcase}"
80
+ begin
81
+ Radiant::Extension.const_get(const_name)
82
+ rescue
83
+ $LOAD_PATH << "#{plugin}/lib"
84
+ require "#{plugin}/init.rb"
85
+ Radiant::Extension.const_set const_name, plugin
86
+ end
87
+ end
88
+ end
75
89
  end
76
90
  end
77
91
  end
@@ -1,107 +1,136 @@
1
- require 'radiant/extension'
2
-
3
- module Radiant
4
- class ExtensionLoader
5
-
6
- class DependenciesObserver < MethodObserver
7
- attr_accessor :config
8
-
9
- def initialize(rails_config)
10
- @config = rails_config
11
- end
12
-
13
- def before_clear(*args)
14
- ExtensionLoader.deactivate_extensions
15
- end
16
-
17
- def after_clear(*args)
18
- ExtensionLoader.activate_extensions
19
- end
20
- end
21
-
22
- include Simpleton
23
-
24
- attr_accessor :initializer
25
-
26
- def initialize
27
- @extension_roots = []
28
- end
29
-
30
- def configuration
31
- initializer.configuration
32
- end
33
-
34
- def initializer=(initializer)
35
- @initializer = initializer
36
- end
37
-
38
- def run
39
- DependenciesObserver.new(configuration).observe(Dependencies)
40
-
41
- discover_extensions
42
- activate_extensions
43
- end
44
-
45
- def discover_extensions
46
- extension_roots = configuration.extension_paths.collect do |path|
47
- Dir.glob("#{path}/*").sort.select { |f| File.directory?(f) }.collect do |ext_path|
48
- ext_path = File.expand_path(ext_path)
49
- load_paths = %w(lib app/models app/controllers app/helpers test/helpers).collect { |p| "#{ext_path}/#{p}" }
50
- load_paths << ext_path
51
- load_paths.each { |p| configuration.load_paths << p }
52
- configuration.controller_paths << "#{ext_path}/app/controllers"
53
- configuration.view_paths << "#{ext_path}/app/views"
54
- @extension_roots << ext_path
55
- end
56
- end.flatten
57
- initializer.set_autoload_paths
58
- initializer.initialize_view_paths
59
- extension_roots
60
- end
61
-
62
- def deactivate_extensions
63
- Extension.descendants.each { |extension| deactivate(extension) }
64
- end
65
-
66
- def activate_extensions(enabled_extensions = nil)
67
- initializer.initialize_default_admin_tabs
68
- activated_extensions = @extension_roots.select do |root|
69
- extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"
70
- extension = extension_file.camelize.constantize
71
- extension.root = root
72
- extension.unloadable
73
- if enabled_extensions
74
- enabled = enabled_extensions.include?(extension.extension_name) || enabled_extensions.include?(extension)
75
- enable(extension, enabled)
76
- else
77
- activate(extension)
78
- end
79
- end
80
- initializer.initialize_routing
81
- activated_extensions
82
- end
83
- alias :reactivate :activate_extensions
84
-
85
- private
86
-
87
- def activate(extension)
88
- if extension.enabled?
89
- extension.activate
90
- extension
91
- end
92
- end
93
-
94
- def deactivate(extension)
95
- if extension.active?
96
- extension.deactivate
97
- extension
98
- end
99
- end
100
-
101
- def enable(extension, enabled)
102
- extension.enable(enabled)
103
- extension if enabled
104
- end
105
-
106
- end
1
+ require 'radiant/extension'
2
+
3
+ module Radiant
4
+ class ExtensionLoader
5
+
6
+ class DependenciesObserver < MethodObserver
7
+ attr_accessor :config
8
+
9
+ def initialize(rails_config)
10
+ @config = rails_config
11
+ end
12
+
13
+ def before_clear(*args)
14
+ ExtensionLoader.deactivate_extensions
15
+ end
16
+
17
+ def after_clear(*args)
18
+ ExtensionLoader.activate_extensions
19
+ end
20
+ end
21
+
22
+ include Simpleton
23
+
24
+ attr_accessor :initializer
25
+
26
+ def initialize
27
+ @extension_roots = []
28
+ end
29
+
30
+ def configuration
31
+ initializer.configuration
32
+ end
33
+
34
+ def initializer=(initializer)
35
+ @initializer = initializer
36
+ end
37
+
38
+ def run
39
+ DependenciesObserver.new(configuration).observe(Dependencies)
40
+
41
+ discover_extensions
42
+ activate_extensions
43
+ end
44
+
45
+ def discover_extensions
46
+ all_extension_roots = configuration.extension_paths.collect do |path|
47
+ Dir.glob("#{path}/*").sort.select { |f| File.directory?(f) }.collect do |ext_path|
48
+ ext_path = File.expand_path(ext_path)
49
+ end
50
+ end.flatten
51
+ if configuration.extensions
52
+ #put in the paths for extensions into the array
53
+ extension_roots = configuration.extensions.map do |ext_name|
54
+ if :all === ext_name
55
+ :all
56
+ else
57
+ ext_name = ext_name.to_s
58
+ ext_path = all_extension_roots.detect do |maybe_path|
59
+ File.basename(maybe_path).sub(/^\d+_/,'') == ext_name
60
+ end
61
+ raise(LoadError, "Cannot find the extension '#{ext_name}'!") if ext_path.nil?
62
+ all_extension_roots.delete(ext_path)
63
+ ext_path
64
+ end
65
+ end
66
+ #replace the :all symbol with any remaining paths
67
+ extension_roots.map! do |ext_path|
68
+ if :all === ext_path
69
+ all_extension_roots
70
+ else
71
+ ext_path
72
+ end
73
+ end
74
+ extension_roots.flatten!
75
+ else
76
+ extension_roots = all_extension_roots
77
+ end
78
+ extension_roots.each do |ext_path|
79
+ load_paths = %w(lib app/models app/controllers app/helpers test/helpers).collect { |p| "#{ext_path}/#{p}" }
80
+ load_paths << ext_path
81
+ load_paths.each { |p| configuration.load_paths << p }
82
+ configuration.controller_paths << "#{ext_path}/app/controllers"
83
+ configuration.view_paths << "#{ext_path}/app/views"
84
+ @extension_roots << ext_path
85
+ end
86
+ initializer.set_autoload_paths
87
+ initializer.initialize_view_paths
88
+ extension_roots
89
+ end
90
+
91
+ def deactivate_extensions
92
+ Extension.descendants.each { |extension| deactivate(extension) }
93
+ end
94
+
95
+ def activate_extensions(enabled_extensions = nil)
96
+ initializer.initialize_default_admin_tabs
97
+ activated_extensions = @extension_roots.select do |root|
98
+ extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"
99
+ extension = extension_file.camelize.constantize
100
+ extension.root = root
101
+ extension.unloadable
102
+ if enabled_extensions
103
+ enabled = enabled_extensions.include?(extension.extension_name) || enabled_extensions.include?(extension)
104
+ enable(extension, enabled)
105
+ else
106
+ activate(extension)
107
+ end
108
+ end
109
+ initializer.initialize_routing
110
+ activated_extensions
111
+ end
112
+ alias :reactivate :activate_extensions
113
+
114
+ private
115
+
116
+ def activate(extension)
117
+ if extension.enabled?
118
+ extension.activate
119
+ extension
120
+ end
121
+ end
122
+
123
+ def deactivate(extension)
124
+ if extension.active?
125
+ extension.deactivate
126
+ extension
127
+ end
128
+ end
129
+
130
+ def enable(extension, enabled)
131
+ extension.enable(enabled)
132
+ extension if enabled
133
+ end
134
+
135
+ end
107
136
  end