radiant 0.5.0
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.
- data/CHANGELOG +1 -0
- data/CONTRIBUTORS +12 -0
- data/LICENSE +9 -0
- data/README +91 -0
- data/Rakefile +10 -0
- data/app/behaviors/archive_behavior.rb +42 -0
- data/app/behaviors/archive_day_index_behavior.rb +30 -0
- data/app/behaviors/archive_month_index_behavior.rb +30 -0
- data/app/behaviors/archive_year_index_behavior.rb +30 -0
- data/app/behaviors/env_behavior.rb +18 -0
- data/app/behaviors/page_missing_behavior.rb +31 -0
- data/app/controllers/admin/export_controller.rb +8 -0
- data/app/controllers/admin/layout_controller.rb +23 -0
- data/app/controllers/admin/model_controller.rb +119 -0
- data/app/controllers/admin/page_controller.rb +119 -0
- data/app/controllers/admin/snippet_controller.rb +6 -0
- data/app/controllers/admin/user_controller.rb +45 -0
- data/app/controllers/admin/welcome_controller.rb +39 -0
- data/app/controllers/application.rb +32 -0
- data/app/controllers/site_controller.rb +54 -0
- data/app/filters/markdown_filter.rb +9 -0
- data/app/filters/textile_filter.rb +9 -0
- data/app/helpers/admin/export_helper.rb +2 -0
- data/app/helpers/admin/layout_helper.rb +2 -0
- data/app/helpers/admin/page_helper.rb +10 -0
- data/app/helpers/admin/snippet_helper.rb +2 -0
- data/app/helpers/admin/user_helper.rb +2 -0
- data/app/helpers/admin/welcome_helper.rb +2 -0
- data/app/helpers/application_helper.rb +141 -0
- data/app/helpers/site_helper.rb +2 -0
- data/app/models/archive_finder.rb +66 -0
- data/app/models/behavior.rb +194 -0
- data/app/models/layout.rb +13 -0
- data/app/models/page.rb +91 -0
- data/app/models/page_context.rb +526 -0
- data/app/models/page_part.rb +13 -0
- data/app/models/radiant/config.rb +53 -0
- data/app/models/radiant/exporter.rb +11 -0
- data/app/models/response_cache.rb +112 -0
- data/app/models/snippet.rb +16 -0
- data/app/models/status.rb +31 -0
- data/app/models/text_filter.rb +11 -0
- data/app/models/user.rb +70 -0
- data/app/models/user_action_observer.rb +13 -0
- data/app/views/admin/layout/index.rhtml +38 -0
- data/app/views/admin/layout/new.rhtml +37 -0
- data/app/views/admin/layout/remove.rhtml +17 -0
- data/app/views/admin/page/_node.rhtml +51 -0
- data/app/views/admin/page/_part.rhtml +17 -0
- data/app/views/admin/page/children.rhtml +4 -0
- data/app/views/admin/page/index.rhtml +172 -0
- data/app/views/admin/page/new.rhtml +164 -0
- data/app/views/admin/page/remove.rhtml +14 -0
- data/app/views/admin/snippet/index.rhtml +36 -0
- data/app/views/admin/snippet/new.rhtml +28 -0
- data/app/views/admin/snippet/remove.rhtml +16 -0
- data/app/views/admin/user/index.rhtml +43 -0
- data/app/views/admin/user/new.rhtml +48 -0
- data/app/views/admin/user/preferences.rhtml +29 -0
- data/app/views/admin/user/remove.rhtml +16 -0
- data/app/views/admin/welcome/login.rhtml +51 -0
- data/app/views/layouts/application.rhtml +75 -0
- data/app/views/site/not_found.rhtml +3 -0
- data/bin/radiant +305 -0
- data/config/boot.rb +80 -0
- data/config/database.mysql.yml +20 -0
- data/config/database.postgresql.yml +20 -0
- data/config/database.sqlite.yml +20 -0
- data/config/environment.rb +76 -0
- data/config/environments/development.rb +20 -0
- data/config/environments/production.rb +22 -0
- data/config/environments/test.rb +20 -0
- data/config/locomotive.yml +6 -0
- data/config/routes.rb +64 -0
- data/db/development_structure.sql +80 -0
- data/db/migrate/001_create_radiant_tables.rb +73 -0
- data/db/migrate/002_insert_initial_data.rb +45 -0
- data/db/migrate/003_rename_behavior_column.rb +9 -0
- data/db/migrate/004_rename_filter_column.rb +11 -0
- data/db/migrate/005_add_virtual_column_to_page.rb +9 -0
- data/db/migrate/006_integer_columns_to_boolean.rb +11 -0
- data/db/migrate/007_remove_virtual_column_from_page.rb +9 -0
- data/db/migrate/008_add_virtual_column_to_page_again.rb +9 -0
- data/db/migrate/009_add_content_type_field_to_layout.rb +9 -0
- data/db/schema.rb +74 -0
- data/db/templates/empty.yml +2 -0
- data/db/templates/simple-blog.yml +197 -0
- data/db/templates/styled-blog.yml +472 -0
- data/lib/advanced_delegation.rb +21 -0
- data/lib/archive_index_behavior_tags_and_methods.rb +48 -0
- data/lib/generators/behavior/USAGE +16 -0
- data/lib/generators/behavior/behavior_generator.rb +22 -0
- data/lib/generators/behavior/templates/model.rb.template +9 -0
- data/lib/generators/behavior/templates/unit_test.rb.template +16 -0
- data/lib/generators/filter/USAGE +16 -0
- data/lib/generators/filter/filter_generator.rb +22 -0
- data/lib/generators/filter/templates/model.rb.template +8 -0
- data/lib/generators/filter/templates/unit_test.rb.template +7 -0
- data/lib/inheritable_class_attributes.rb +65 -0
- data/lib/login_system.rb +80 -0
- data/lib/plugins/index_quoting_fix/init.rb +32 -0
- data/lib/plugins/string_io/init.rb +2 -0
- data/lib/radiant.rb +5 -0
- data/lib/registerable.rb +70 -0
- data/lib/tasks/release.rake +84 -0
- data/public/404.html +8 -0
- data/public/500.html +8 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/favicon.ico +0 -0
- data/public/images/add-child.png +0 -0
- data/public/images/brown-bottom-line.gif +0 -0
- data/public/images/clear-page-cache.png +0 -0
- data/public/images/collapse.png +0 -0
- data/public/images/expand.png +0 -0
- data/public/images/minus.png +0 -0
- data/public/images/new-homepage.png +0 -0
- data/public/images/new-layout.png +0 -0
- data/public/images/new-snippet.png +0 -0
- data/public/images/new-user.png +0 -0
- data/public/images/page.png +0 -0
- data/public/images/plus.png +0 -0
- data/public/images/remove-disabled.png +0 -0
- data/public/images/remove.png +0 -0
- data/public/images/snippet.png +0 -0
- data/public/images/spinner.gif +0 -0
- data/public/images/view-site.gif +0 -0
- data/public/images/virtual-page.png +0 -0
- data/public/javascripts/application.js +2 -0
- data/public/javascripts/controls.js +815 -0
- data/public/javascripts/dragdrop.js +913 -0
- data/public/javascripts/effects.js +958 -0
- data/public/javascripts/pngfix.js +78 -0
- data/public/javascripts/prototype.js +2006 -0
- data/public/javascripts/ruledtable.js +28 -0
- data/public/javascripts/string.js +23 -0
- data/public/javascripts/tabcontrol.js +140 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/admin.css +464 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/process/spinner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/script/setup_database +297 -0
- data/test/fixtures/layouts.yml +26 -0
- data/test/fixtures/page_parts.yml +99 -0
- data/test/fixtures/pages.yml +359 -0
- data/test/fixtures/pages.yml.rej +28 -0
- data/test/fixtures/snippets.yml +18 -0
- data/test/fixtures/users.yml +30 -0
- data/test/functional/admin/export_controller_test.rb +22 -0
- data/test/functional/admin/layout_controller_test.rb +40 -0
- data/test/functional/admin/model_controller_test.rb +152 -0
- data/test/functional/admin/page_controller_test.rb +179 -0
- data/test/functional/admin/snippet_controller_test.rb +11 -0
- data/test/functional/admin/user_controller_test.rb +71 -0
- data/test/functional/admin/welcome_controller_test.rb +48 -0
- data/test/functional/application_controller_test.rb +44 -0
- data/test/functional/login_system_test.rb +155 -0
- data/test/functional/site_controller_test.rb +172 -0
- data/test/helpers/archive_index_test_helper.rb +35 -0
- data/test/helpers/behavior_render_test_helper.rb +34 -0
- data/test/helpers/behavior_test_helper.rb +47 -0
- data/test/helpers/caching_test_helper.rb +41 -0
- data/test/helpers/layout_test_helper.rb +35 -0
- data/test/helpers/page_part_test_helper.rb +49 -0
- data/test/helpers/page_test_helper.rb +36 -0
- data/test/helpers/snippet_test_helper.rb +32 -0
- data/test/helpers/user_test_helper.rb +34 -0
- data/test/helpers/validation_test_helper.rb +42 -0
- data/test/test_helper.rb +54 -0
- data/test/unit/behavior_test.rb +196 -0
- data/test/unit/behaviors/archive_behavior_test.rb +33 -0
- data/test/unit/behaviors/archive_day_index_behavior_test.rb +21 -0
- data/test/unit/behaviors/archive_month_index_behavior_test.rb +21 -0
- data/test/unit/behaviors/archive_year_index_behavior_test.rb +21 -0
- data/test/unit/behaviors/page_missing_behavior_test.rb +27 -0
- data/test/unit/filters/markdown_filter_test.rb +14 -0
- data/test/unit/filters/textile_filter_test.rb +14 -0
- data/test/unit/inheritable_class_attributes_test.rb +47 -0
- data/test/unit/layout_test.rb +29 -0
- data/test/unit/page_context_test.rb +375 -0
- data/test/unit/page_context_test.rb.rej +26 -0
- data/test/unit/page_part_test.rb +44 -0
- data/test/unit/page_test.rb +224 -0
- data/test/unit/radiant/config_test.rb +46 -0
- data/test/unit/radiant/exporter_test.rb +26 -0
- data/test/unit/registerable_test.rb +68 -0
- data/test/unit/response_cache_test.rb +133 -0
- data/test/unit/snippet_test.rb +47 -0
- data/test/unit/status_test.rb +43 -0
- data/test/unit/text_filter_test.rb +14 -0
- data/test/unit/user_action_observer_test.rb +40 -0
- data/test/unit/user_test.rb +138 -0
- metadata +355 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
class Module
|
2
|
+
def delegate_to(object, *collection)
|
3
|
+
collection = [*collection]
|
4
|
+
is_hash = ((collection.size == 1) and collection.first.kind_of?(Hash))
|
5
|
+
hash = is_hash ? collection.first : nil
|
6
|
+
|
7
|
+
delegate_to_method = lambda do |as, method|
|
8
|
+
module_eval() do
|
9
|
+
define_method(as) do |*args|
|
10
|
+
send(object).send(method, *args)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if hash
|
16
|
+
hash.each { |as, method| delegate_to_method.call(as, method) }
|
17
|
+
else
|
18
|
+
collection.each { |method| delegate_to_method.call(method, method) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ArchiveIndexBehaviorTagsAndMethods
|
2
|
+
def self.included(base)
|
3
|
+
base.module_eval do
|
4
|
+
define_tags do
|
5
|
+
url = request.request_uri unless request.nil?
|
6
|
+
|
7
|
+
tag "archive" do |tag|
|
8
|
+
tag.expand
|
9
|
+
end
|
10
|
+
|
11
|
+
year, month, day = $1, $2, $3 if url =~ %r{/(\d{4})(?:/(\d{2})(?:/(\d{2}))?)?/?$}
|
12
|
+
|
13
|
+
tag "title" do |tag|
|
14
|
+
page = tag.locals.page
|
15
|
+
if year
|
16
|
+
Date.new((year || 1).to_i, (month || 1).to_i, (day || 1).to_i).strftime(page.title)
|
17
|
+
else
|
18
|
+
page.title
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
tag "archive:year" do |tag|
|
23
|
+
year unless year.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
tag "archive:month" do |tag|
|
27
|
+
Date.new(year.to_i, month.to_i, 1).strftime('%B') rescue ''
|
28
|
+
end
|
29
|
+
|
30
|
+
tag "archive:day" do |tag|
|
31
|
+
day.to_i unless day.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
tag "archive:day_of_week" do |tag|
|
35
|
+
Date.new(year.to_i, month.to_i, day.to_i).strftime('%A') rescue ''
|
36
|
+
end
|
37
|
+
|
38
|
+
tag("archive:children:first") { "unimplemented" }
|
39
|
+
tag("archive:children:last" ) { "unimplemented" }
|
40
|
+
tag("archive:children:count") { "unimplemented" }
|
41
|
+
end
|
42
|
+
|
43
|
+
def page_virtual?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
The behavior generator creates stubs for a new behavior.
|
3
|
+
|
4
|
+
The generator takes a model name as its argument. The model name may be
|
5
|
+
given in CamelCase or under_score and should not be suffixed with 'Behavior'.
|
6
|
+
|
7
|
+
The generator creates a model class in app/behaviors and a test suite in
|
8
|
+
test/unit/behaviors.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
./script/generate behavior BookArchive
|
12
|
+
|
13
|
+
This will create a BookArchive behavior:
|
14
|
+
Behavior: app/behaviors/book_archive_behavior.rb
|
15
|
+
Test: test/unit/behaviors/book_archive_behavior_test.rb
|
16
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BehaviorGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
# Check for class naming collisions.
|
6
|
+
m.class_collisions class_path, "#{class_name}Behavior", "#{class_name}BehaviorTest"
|
7
|
+
|
8
|
+
# Model, test, and fixture directories.
|
9
|
+
m.directory File.join('app/behaviors', class_path)
|
10
|
+
m.directory File.join('test/unit/behaviors', class_path)
|
11
|
+
|
12
|
+
# Model class, unit test, and fixtures.
|
13
|
+
m.template 'model.rb.template', File.join('app/behaviors', class_path, "#{file_name}_behavior.rb")
|
14
|
+
m.template 'unit_test.rb.template', File.join('test/unit/behaviors', class_path, "#{file_name}_behavior_test.rb")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def behavior_name
|
19
|
+
class_name.gsub(/([A-Z][a-z])/, ' \1').strip
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../test_helper'
|
2
|
+
|
3
|
+
class <%= class_name %>BehaviorTest < Test::Unit::TestCase
|
4
|
+
test_helper :behavior_render
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@page = Page.new(:title => 'Test Page', :slug => "\\")
|
8
|
+
@page.behavior_id = '<%= behavior_name %>'
|
9
|
+
@behavior = @page.behavior
|
10
|
+
end
|
11
|
+
|
12
|
+
# Replace this with your real tests.
|
13
|
+
def test_title_tag
|
14
|
+
assert_renders 'Test Page', '<r:title />'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
The filter generator creates stubs for a new filter.
|
3
|
+
|
4
|
+
The generator takes a model name as its argument. The model name may be
|
5
|
+
given in CamelCase or under_score and should not be suffixed with 'Filter'.
|
6
|
+
|
7
|
+
The generator creates a model class in app/filters and a test suite in
|
8
|
+
test/unit/filters.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
./script/generate filter RDoc
|
12
|
+
|
13
|
+
This will create a RDoc filter:
|
14
|
+
Behavior: app/filters/r_doc_filter.rb
|
15
|
+
Test: test/unit/filters/r_doc_filter_test.rb
|
16
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class FilterGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
# Check for class naming collisions.
|
6
|
+
m.class_collisions class_path, "#{class_name}Filter", "#{class_name}FilterTest"
|
7
|
+
|
8
|
+
# Model, test, and fixture directories.
|
9
|
+
m.directory File.join('app/filters', class_path)
|
10
|
+
m.directory File.join('test/unit/filters', class_path)
|
11
|
+
|
12
|
+
# Model class, unit test, and fixtures.
|
13
|
+
m.template 'model.rb.template', File.join('app/filters', class_path, "#{file_name}_filter.rb")
|
14
|
+
m.template 'unit_test.rb.template', File.join('test/unit/filters', class_path, "#{file_name}_filter_test.rb")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def filter_name
|
19
|
+
class_name.gsub(/([A-Z][a-z])/, ' \1').strip
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module InheritableClassAttributes
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
base.module_eval do
|
5
|
+
class << self
|
6
|
+
alias inherited_without_inheritable_class_attributes inherited
|
7
|
+
alias inherited inherited_with_inheritable_class_attributes
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def inheritable_cattr_readers
|
14
|
+
@inheritable_class_readers ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def inheritable_cattr_writers
|
18
|
+
@inheritable_class_writers ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
def cattr_inheritable_reader(*symbols)
|
22
|
+
symbols.each do |symbol|
|
23
|
+
self.inheritable_cattr_readers << symbol
|
24
|
+
self.module_eval %{
|
25
|
+
def self.#{symbol}
|
26
|
+
@#{symbol}
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
self.inheritable_cattr_readers.uniq!
|
31
|
+
end
|
32
|
+
|
33
|
+
def cattr_inheritable_writer(*symbols)
|
34
|
+
symbols.each do |symbol|
|
35
|
+
self.inheritable_cattr_writers << symbol
|
36
|
+
self.module_eval %{
|
37
|
+
def self.#{symbol}=(value)
|
38
|
+
@#{symbol} = value
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
self.inheritable_cattr_writers.uniq!
|
43
|
+
end
|
44
|
+
|
45
|
+
def cattr_inheritable_accessor(*symbols)
|
46
|
+
cattr_inheritable_writer(*symbols)
|
47
|
+
cattr_inheritable_reader(*symbols)
|
48
|
+
end
|
49
|
+
|
50
|
+
def inherited_with_inheritable_class_attributes(klass)
|
51
|
+
inherited_without_inheritable_class_attributes(child) if respond_to?(:inherited_without_inheritable_class_attributes)
|
52
|
+
|
53
|
+
readers = inheritable_cattr_readers.dup
|
54
|
+
writers = inheritable_cattr_writers.dup
|
55
|
+
inheritables = [:inheritable_cattr_readers, :inheritable_cattr_writers]
|
56
|
+
|
57
|
+
(readers + writers + inheritables).uniq.each do |attr|
|
58
|
+
var = "@#{attr}"
|
59
|
+
old_value = self.module_eval(var)
|
60
|
+
new_value = (old_value.dup rescue old_value)
|
61
|
+
klass.module_eval("#{var} = new_value")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/login_system.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module LoginSystem
|
2
|
+
def self.append_features(base)
|
3
|
+
base.class_eval %{
|
4
|
+
before_filter :authenticate
|
5
|
+
|
6
|
+
@@controllers_where_no_login_required = []
|
7
|
+
@@controller_permissions = Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = Hash.new } }
|
8
|
+
}
|
9
|
+
base.extend ClassMethods
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def authenticate
|
16
|
+
action = params['action'].to_s.intern
|
17
|
+
user = session[:user]
|
18
|
+
if no_login_required? or (user and user_has_access_to_action?(action))
|
19
|
+
true
|
20
|
+
else
|
21
|
+
if user
|
22
|
+
permissions = self.class.controller_permissions[self.class][action]
|
23
|
+
flash[:error] = permissions[:denied_message] || 'Access denied.'
|
24
|
+
redirect_to permissions[:denied_url] || { :action => :index }
|
25
|
+
else
|
26
|
+
redirect_to login_url
|
27
|
+
end
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def no_login_required?
|
33
|
+
controllers = self.class.controllers_where_no_login_required
|
34
|
+
controllers.include?(self.class)
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_has_role?(role)
|
38
|
+
session[:user].send("#{role}?")
|
39
|
+
end
|
40
|
+
|
41
|
+
def user_has_access_to_action?(action)
|
42
|
+
permissions = self.class.controller_permissions[self.class][action]
|
43
|
+
case
|
44
|
+
when allowed_roles = permissions[:when]
|
45
|
+
allowed_roles = [allowed_roles].flatten
|
46
|
+
allowed_roles.each do |role|
|
47
|
+
return true if user_has_role?(role)
|
48
|
+
end
|
49
|
+
false
|
50
|
+
when condition_method = permissions[:if]
|
51
|
+
send(condition_method)
|
52
|
+
else
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module ClassMethods
|
58
|
+
def no_login_required
|
59
|
+
controllers_where_no_login_required << self
|
60
|
+
end
|
61
|
+
|
62
|
+
def only_allow_access_to(*args)
|
63
|
+
options = {}
|
64
|
+
options = args.pop.dup if args.last.kind_of?(Hash)
|
65
|
+
options.symbolize_keys!
|
66
|
+
actions = args.map { |a| a.to_s.intern }
|
67
|
+
actions.each do |action|
|
68
|
+
controller_permissions[self][action] = options
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def controller_permissions
|
73
|
+
self.class_eval %{ @@controller_permissions }
|
74
|
+
end
|
75
|
+
|
76
|
+
def controllers_where_no_login_required
|
77
|
+
self.class_eval %{ @@controllers_where_no_login_required }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
# Repairs a quoting problem with Active Record, repaired on Edge Rails
|
3
|
+
#
|
4
|
+
module ActiveRecord::ConnectionAdapters::SchemaStatements
|
5
|
+
def add_column(table_name, column_name, type, options = {})
|
6
|
+
add_column_sql = "ALTER TABLE #{table_name} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit])}"
|
7
|
+
add_column_options!(add_column_sql, options)
|
8
|
+
execute(add_column_sql)
|
9
|
+
end
|
10
|
+
|
11
|
+
def remove_column(table_name, column_name)
|
12
|
+
execute "ALTER TABLE #{table_name} DROP #{quote_column_name(column_name)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_index(table_name, column_name, options = {})
|
16
|
+
column_names = Array(column_name)
|
17
|
+
index_name = index_name(table_name, :column => column_names.first)
|
18
|
+
|
19
|
+
if Hash === options # legacy support, since this param was a string
|
20
|
+
index_type = options[:unique] ? "UNIQUE" : ""
|
21
|
+
index_name = options[:name] || index_name
|
22
|
+
else
|
23
|
+
index_type = options
|
24
|
+
end
|
25
|
+
quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
|
26
|
+
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{table_name} (#{quoted_column_names})"
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_index(table_name, options = {})
|
30
|
+
execute "DROP INDEX #{quote_column_name(index_name(table_name, options))} ON #{table_name}"
|
31
|
+
end
|
32
|
+
end
|
data/lib/radiant.rb
ADDED
data/lib/registerable.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Registerable
|
2
|
+
def self.append_features(base)
|
3
|
+
base.class_eval %{
|
4
|
+
@@registered = {}
|
5
|
+
|
6
|
+
def self.registered
|
7
|
+
# protect access to hash
|
8
|
+
@@registered.dup
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.register(id, klass)
|
12
|
+
id = id.to_s.strip
|
13
|
+
unless @@registered[id]
|
14
|
+
@@registered[id] = klass
|
15
|
+
klass.class_eval "def self.registered_id; '\#{id}'; end"
|
16
|
+
else
|
17
|
+
raise "ID `\#{id}' already registered. Choose another ID."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_all
|
22
|
+
self.registered.inject([]) { |a, (k, v)| a << v }.sort_by { |f| f.registered_id }
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.[](id)
|
26
|
+
id = id.to_s.strip
|
27
|
+
if @@registered.has_key?(id)
|
28
|
+
@@registered[id]
|
29
|
+
else
|
30
|
+
Base
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.create(id)
|
35
|
+
self[id].new
|
36
|
+
end
|
37
|
+
|
38
|
+
class Base
|
39
|
+
def self.register(id)
|
40
|
+
#{base.name}.register(id, self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.registered_id
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def registered_id
|
48
|
+
self.class.registered_id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
}
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
require 'active_record'
|
57
|
+
class ActiveRecord::Base
|
58
|
+
def self.registered_attr(symbol, registerable_module)
|
59
|
+
module_eval %{
|
60
|
+
def #{symbol}
|
61
|
+
if @#{symbol}.nil? or (@old_#{symbol}_id != #{symbol}_id)
|
62
|
+
@old_#{symbol}_id = #{symbol}_id
|
63
|
+
@#{symbol} = #{registerable_module}[#{symbol}_id].new
|
64
|
+
else
|
65
|
+
@#{symbol}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|