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.

Files changed (205) hide show
  1. data/CHANGELOG +1 -0
  2. data/CONTRIBUTORS +12 -0
  3. data/LICENSE +9 -0
  4. data/README +91 -0
  5. data/Rakefile +10 -0
  6. data/app/behaviors/archive_behavior.rb +42 -0
  7. data/app/behaviors/archive_day_index_behavior.rb +30 -0
  8. data/app/behaviors/archive_month_index_behavior.rb +30 -0
  9. data/app/behaviors/archive_year_index_behavior.rb +30 -0
  10. data/app/behaviors/env_behavior.rb +18 -0
  11. data/app/behaviors/page_missing_behavior.rb +31 -0
  12. data/app/controllers/admin/export_controller.rb +8 -0
  13. data/app/controllers/admin/layout_controller.rb +23 -0
  14. data/app/controllers/admin/model_controller.rb +119 -0
  15. data/app/controllers/admin/page_controller.rb +119 -0
  16. data/app/controllers/admin/snippet_controller.rb +6 -0
  17. data/app/controllers/admin/user_controller.rb +45 -0
  18. data/app/controllers/admin/welcome_controller.rb +39 -0
  19. data/app/controllers/application.rb +32 -0
  20. data/app/controllers/site_controller.rb +54 -0
  21. data/app/filters/markdown_filter.rb +9 -0
  22. data/app/filters/textile_filter.rb +9 -0
  23. data/app/helpers/admin/export_helper.rb +2 -0
  24. data/app/helpers/admin/layout_helper.rb +2 -0
  25. data/app/helpers/admin/page_helper.rb +10 -0
  26. data/app/helpers/admin/snippet_helper.rb +2 -0
  27. data/app/helpers/admin/user_helper.rb +2 -0
  28. data/app/helpers/admin/welcome_helper.rb +2 -0
  29. data/app/helpers/application_helper.rb +141 -0
  30. data/app/helpers/site_helper.rb +2 -0
  31. data/app/models/archive_finder.rb +66 -0
  32. data/app/models/behavior.rb +194 -0
  33. data/app/models/layout.rb +13 -0
  34. data/app/models/page.rb +91 -0
  35. data/app/models/page_context.rb +526 -0
  36. data/app/models/page_part.rb +13 -0
  37. data/app/models/radiant/config.rb +53 -0
  38. data/app/models/radiant/exporter.rb +11 -0
  39. data/app/models/response_cache.rb +112 -0
  40. data/app/models/snippet.rb +16 -0
  41. data/app/models/status.rb +31 -0
  42. data/app/models/text_filter.rb +11 -0
  43. data/app/models/user.rb +70 -0
  44. data/app/models/user_action_observer.rb +13 -0
  45. data/app/views/admin/layout/index.rhtml +38 -0
  46. data/app/views/admin/layout/new.rhtml +37 -0
  47. data/app/views/admin/layout/remove.rhtml +17 -0
  48. data/app/views/admin/page/_node.rhtml +51 -0
  49. data/app/views/admin/page/_part.rhtml +17 -0
  50. data/app/views/admin/page/children.rhtml +4 -0
  51. data/app/views/admin/page/index.rhtml +172 -0
  52. data/app/views/admin/page/new.rhtml +164 -0
  53. data/app/views/admin/page/remove.rhtml +14 -0
  54. data/app/views/admin/snippet/index.rhtml +36 -0
  55. data/app/views/admin/snippet/new.rhtml +28 -0
  56. data/app/views/admin/snippet/remove.rhtml +16 -0
  57. data/app/views/admin/user/index.rhtml +43 -0
  58. data/app/views/admin/user/new.rhtml +48 -0
  59. data/app/views/admin/user/preferences.rhtml +29 -0
  60. data/app/views/admin/user/remove.rhtml +16 -0
  61. data/app/views/admin/welcome/login.rhtml +51 -0
  62. data/app/views/layouts/application.rhtml +75 -0
  63. data/app/views/site/not_found.rhtml +3 -0
  64. data/bin/radiant +305 -0
  65. data/config/boot.rb +80 -0
  66. data/config/database.mysql.yml +20 -0
  67. data/config/database.postgresql.yml +20 -0
  68. data/config/database.sqlite.yml +20 -0
  69. data/config/environment.rb +76 -0
  70. data/config/environments/development.rb +20 -0
  71. data/config/environments/production.rb +22 -0
  72. data/config/environments/test.rb +20 -0
  73. data/config/locomotive.yml +6 -0
  74. data/config/routes.rb +64 -0
  75. data/db/development_structure.sql +80 -0
  76. data/db/migrate/001_create_radiant_tables.rb +73 -0
  77. data/db/migrate/002_insert_initial_data.rb +45 -0
  78. data/db/migrate/003_rename_behavior_column.rb +9 -0
  79. data/db/migrate/004_rename_filter_column.rb +11 -0
  80. data/db/migrate/005_add_virtual_column_to_page.rb +9 -0
  81. data/db/migrate/006_integer_columns_to_boolean.rb +11 -0
  82. data/db/migrate/007_remove_virtual_column_from_page.rb +9 -0
  83. data/db/migrate/008_add_virtual_column_to_page_again.rb +9 -0
  84. data/db/migrate/009_add_content_type_field_to_layout.rb +9 -0
  85. data/db/schema.rb +74 -0
  86. data/db/templates/empty.yml +2 -0
  87. data/db/templates/simple-blog.yml +197 -0
  88. data/db/templates/styled-blog.yml +472 -0
  89. data/lib/advanced_delegation.rb +21 -0
  90. data/lib/archive_index_behavior_tags_and_methods.rb +48 -0
  91. data/lib/generators/behavior/USAGE +16 -0
  92. data/lib/generators/behavior/behavior_generator.rb +22 -0
  93. data/lib/generators/behavior/templates/model.rb.template +9 -0
  94. data/lib/generators/behavior/templates/unit_test.rb.template +16 -0
  95. data/lib/generators/filter/USAGE +16 -0
  96. data/lib/generators/filter/filter_generator.rb +22 -0
  97. data/lib/generators/filter/templates/model.rb.template +8 -0
  98. data/lib/generators/filter/templates/unit_test.rb.template +7 -0
  99. data/lib/inheritable_class_attributes.rb +65 -0
  100. data/lib/login_system.rb +80 -0
  101. data/lib/plugins/index_quoting_fix/init.rb +32 -0
  102. data/lib/plugins/string_io/init.rb +2 -0
  103. data/lib/radiant.rb +5 -0
  104. data/lib/registerable.rb +70 -0
  105. data/lib/tasks/release.rake +84 -0
  106. data/public/404.html +8 -0
  107. data/public/500.html +8 -0
  108. data/public/dispatch.cgi +10 -0
  109. data/public/dispatch.fcgi +24 -0
  110. data/public/dispatch.rb +10 -0
  111. data/public/favicon.ico +0 -0
  112. data/public/images/add-child.png +0 -0
  113. data/public/images/brown-bottom-line.gif +0 -0
  114. data/public/images/clear-page-cache.png +0 -0
  115. data/public/images/collapse.png +0 -0
  116. data/public/images/expand.png +0 -0
  117. data/public/images/minus.png +0 -0
  118. data/public/images/new-homepage.png +0 -0
  119. data/public/images/new-layout.png +0 -0
  120. data/public/images/new-snippet.png +0 -0
  121. data/public/images/new-user.png +0 -0
  122. data/public/images/page.png +0 -0
  123. data/public/images/plus.png +0 -0
  124. data/public/images/remove-disabled.png +0 -0
  125. data/public/images/remove.png +0 -0
  126. data/public/images/snippet.png +0 -0
  127. data/public/images/spinner.gif +0 -0
  128. data/public/images/view-site.gif +0 -0
  129. data/public/images/virtual-page.png +0 -0
  130. data/public/javascripts/application.js +2 -0
  131. data/public/javascripts/controls.js +815 -0
  132. data/public/javascripts/dragdrop.js +913 -0
  133. data/public/javascripts/effects.js +958 -0
  134. data/public/javascripts/pngfix.js +78 -0
  135. data/public/javascripts/prototype.js +2006 -0
  136. data/public/javascripts/ruledtable.js +28 -0
  137. data/public/javascripts/string.js +23 -0
  138. data/public/javascripts/tabcontrol.js +140 -0
  139. data/public/robots.txt +1 -0
  140. data/public/stylesheets/admin.css +464 -0
  141. data/script/about +3 -0
  142. data/script/breakpointer +3 -0
  143. data/script/console +3 -0
  144. data/script/destroy +3 -0
  145. data/script/generate +3 -0
  146. data/script/performance/benchmarker +3 -0
  147. data/script/performance/profiler +3 -0
  148. data/script/plugin +3 -0
  149. data/script/process/reaper +3 -0
  150. data/script/process/spawner +3 -0
  151. data/script/process/spinner +3 -0
  152. data/script/runner +3 -0
  153. data/script/server +3 -0
  154. data/script/setup_database +297 -0
  155. data/test/fixtures/layouts.yml +26 -0
  156. data/test/fixtures/page_parts.yml +99 -0
  157. data/test/fixtures/pages.yml +359 -0
  158. data/test/fixtures/pages.yml.rej +28 -0
  159. data/test/fixtures/snippets.yml +18 -0
  160. data/test/fixtures/users.yml +30 -0
  161. data/test/functional/admin/export_controller_test.rb +22 -0
  162. data/test/functional/admin/layout_controller_test.rb +40 -0
  163. data/test/functional/admin/model_controller_test.rb +152 -0
  164. data/test/functional/admin/page_controller_test.rb +179 -0
  165. data/test/functional/admin/snippet_controller_test.rb +11 -0
  166. data/test/functional/admin/user_controller_test.rb +71 -0
  167. data/test/functional/admin/welcome_controller_test.rb +48 -0
  168. data/test/functional/application_controller_test.rb +44 -0
  169. data/test/functional/login_system_test.rb +155 -0
  170. data/test/functional/site_controller_test.rb +172 -0
  171. data/test/helpers/archive_index_test_helper.rb +35 -0
  172. data/test/helpers/behavior_render_test_helper.rb +34 -0
  173. data/test/helpers/behavior_test_helper.rb +47 -0
  174. data/test/helpers/caching_test_helper.rb +41 -0
  175. data/test/helpers/layout_test_helper.rb +35 -0
  176. data/test/helpers/page_part_test_helper.rb +49 -0
  177. data/test/helpers/page_test_helper.rb +36 -0
  178. data/test/helpers/snippet_test_helper.rb +32 -0
  179. data/test/helpers/user_test_helper.rb +34 -0
  180. data/test/helpers/validation_test_helper.rb +42 -0
  181. data/test/test_helper.rb +54 -0
  182. data/test/unit/behavior_test.rb +196 -0
  183. data/test/unit/behaviors/archive_behavior_test.rb +33 -0
  184. data/test/unit/behaviors/archive_day_index_behavior_test.rb +21 -0
  185. data/test/unit/behaviors/archive_month_index_behavior_test.rb +21 -0
  186. data/test/unit/behaviors/archive_year_index_behavior_test.rb +21 -0
  187. data/test/unit/behaviors/page_missing_behavior_test.rb +27 -0
  188. data/test/unit/filters/markdown_filter_test.rb +14 -0
  189. data/test/unit/filters/textile_filter_test.rb +14 -0
  190. data/test/unit/inheritable_class_attributes_test.rb +47 -0
  191. data/test/unit/layout_test.rb +29 -0
  192. data/test/unit/page_context_test.rb +375 -0
  193. data/test/unit/page_context_test.rb.rej +26 -0
  194. data/test/unit/page_part_test.rb +44 -0
  195. data/test/unit/page_test.rb +224 -0
  196. data/test/unit/radiant/config_test.rb +46 -0
  197. data/test/unit/radiant/exporter_test.rb +26 -0
  198. data/test/unit/registerable_test.rb +68 -0
  199. data/test/unit/response_cache_test.rb +133 -0
  200. data/test/unit/snippet_test.rb +47 -0
  201. data/test/unit/status_test.rb +43 -0
  202. data/test/unit/text_filter_test.rb +14 -0
  203. data/test/unit/user_action_observer_test.rb +40 -0
  204. data/test/unit/user_test.rb +138 -0
  205. 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,9 @@
1
+ class <%= class_name %>Behavior < Behavior::Base
2
+
3
+ register "<%= behavior_name %>"
4
+
5
+ description %{
6
+ Describe <%= behavior_name %> behavior here.
7
+ }
8
+
9
+ 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,8 @@
1
+ class <%= class_name %>Filter < TextFilter::Base
2
+ register "<%= filter_name %>"
3
+
4
+ def filter(text)
5
+ # filter text here
6
+ text
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+
3
+ class <%= class_name %>BehaviorTest < Test::Unit::TestCase
4
+ def test_registered_id
5
+ assert_equal '<%= filter_name %>', <%= class_name %>Filter.registered_id
6
+ end
7
+ 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
@@ -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
@@ -0,0 +1,2 @@
1
+ # For some reason 1.1 forgot to require "stringio". This causes problems for schema.rb
2
+ require 'stringio'
@@ -0,0 +1,5 @@
1
+ RADIANT_ROOT = File.join(File.dirname(__FILE__), "..") unless defined? RADIANT_ROOT
2
+
3
+ module Radiant
4
+ Version = '0.5.0'
5
+ end
@@ -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