orange 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/README.markdown +7 -6
  2. data/lib/{orange → orange-core}/application.rb +0 -0
  3. data/lib/{orange → orange-core}/assets/css/exceptions.css +0 -0
  4. data/lib/{orange → orange-core}/assets/js/exceptions.js +0 -0
  5. data/lib/{orange → orange-core}/carton.rb +0 -0
  6. data/lib/{orange → orange-core}/core.rb +15 -1
  7. data/lib/{orange → orange-core}/magick.rb +75 -14
  8. data/lib/{orange → orange-core}/middleware/base.rb +1 -1
  9. data/lib/{orange → orange-core}/middleware/database.rb +1 -1
  10. data/lib/{orange → orange-core}/middleware/four_oh_four.rb +1 -1
  11. data/lib/{orange → orange-core}/middleware/globals.rb +1 -1
  12. data/lib/{orange → orange-core}/middleware/loader.rb +1 -1
  13. data/lib/orange-core/middleware/rerouter.rb +53 -0
  14. data/lib/{orange → orange-core}/middleware/restful_router.rb +1 -1
  15. data/lib/{orange → orange-core}/middleware/route_context.rb +1 -1
  16. data/lib/{orange → orange-core}/middleware/route_site.rb +1 -1
  17. data/lib/{orange → orange-core}/middleware/show_exceptions.rb +1 -1
  18. data/lib/{orange → orange-core}/middleware/static.rb +9 -21
  19. data/lib/{orange → orange-core}/middleware/static_file.rb +0 -0
  20. data/lib/{orange → orange-core}/middleware/template.rb +3 -10
  21. data/lib/{orange → orange-core}/packet.rb +0 -0
  22. data/lib/orange-core/plugin.rb +172 -0
  23. data/lib/{orange → orange-core}/resource.rb +2 -2
  24. data/lib/{orange → orange-core}/resources/mapper.rb +1 -26
  25. data/lib/{orange → orange-core}/resources/model_resource.rb +2 -2
  26. data/lib/{orange → orange-core}/resources/not_found.rb +1 -0
  27. data/lib/{orange → orange-core}/resources/page_parts.rb +1 -0
  28. data/lib/{orange → orange-core}/resources/parser.rb +16 -8
  29. data/lib/{orange → orange-core}/resources/routable_resource.rb +1 -1
  30. data/lib/{orange → orange-core}/stack.rb +30 -16
  31. data/lib/{orange → orange-core}/templates/exceptions.haml +0 -0
  32. data/lib/{orange → orange-core}/views/default_resource/create.haml +0 -0
  33. data/lib/{orange → orange-core}/views/default_resource/edit.haml +0 -0
  34. data/lib/{orange → orange-core}/views/default_resource/list.haml +0 -0
  35. data/lib/{orange → orange-core}/views/default_resource/show.haml +0 -0
  36. data/lib/{orange → orange-core}/views/default_resource/table_row.haml +0 -0
  37. data/lib/{orange → orange-core}/views/not_found/404.haml +0 -0
  38. data/lib/orange-core.rb +8 -0
  39. data/lib/{orange → orange-more/administration}/assets/css/admin.css +6 -6
  40. data/lib/{orange → orange-more/administration}/assets/css/blueprint-ie.css +0 -0
  41. data/lib/{orange → orange-more/administration}/assets/css/blueprint-print.css +0 -0
  42. data/lib/{orange → orange-more/administration}/assets/css/blueprint.css +0 -0
  43. data/lib/{orange → orange-more/administration}/assets/js/jquery.js +0 -0
  44. data/lib/orange-more/administration/cartons/site.rb +9 -0
  45. data/lib/{orange → orange-more/administration}/cartons/site_carton.rb +1 -1
  46. data/lib/{orange/cartons/user_carton.rb → orange-more/administration/cartons/user.rb} +2 -0
  47. data/lib/{orange → orange-more/administration}/middleware/access_control.rb +1 -1
  48. data/lib/{orange → orange-more/administration}/middleware/site_load.rb +2 -23
  49. data/lib/orange-more/administration/plugin.rb +22 -0
  50. data/lib/{orange → orange-more/administration}/resources/admin_resource.rb +0 -0
  51. data/lib/orange-more/administration/resources/site_resource.rb +10 -0
  52. data/lib/{orange → orange-more/administration}/resources/user_resource.rb +1 -1
  53. data/lib/{orange → orange-more/administration}/templates/admin.haml +0 -0
  54. data/lib/{orange → orange-more/administration}/views/openid_login.haml +0 -0
  55. data/lib/orange-more/administration.rb +1 -0
  56. data/lib/{orange → orange-more/assets}/cartons/asset_carton.rb +0 -0
  57. data/lib/orange-more/assets/plugin.rb +13 -0
  58. data/lib/{orange → orange-more/assets}/resources/asset_resource.rb +0 -0
  59. data/lib/{orange → orange-more/assets}/views/assets/create.haml +0 -0
  60. data/lib/orange-more/assets.rb +1 -0
  61. data/lib/{orange → orange-more/pages}/cartons/page_carton.rb +1 -1
  62. data/lib/{orange → orange-more/pages}/cartons/page_version_carton.rb +1 -1
  63. data/lib/orange-more/pages/plugin.rb +13 -0
  64. data/lib/{orange → orange-more/pages}/resources/page_resource.rb +0 -0
  65. data/lib/{orange → orange-more/pages}/views/pages/edit.haml +0 -0
  66. data/lib/orange-more/pages.rb +1 -0
  67. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_down.png +0 -0
  68. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_down_d.png +0 -0
  69. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_indent.png +0 -0
  70. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_indent_d.png +0 -0
  71. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_outdent.png +0 -0
  72. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_outdent_d.png +0 -0
  73. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_up.png +0 -0
  74. data/lib/{orange → orange-more/sitemap}/assets/img/sitemap_up_d.png +0 -0
  75. data/lib/{orange → orange-more/sitemap}/assets/js/sitemap.js +0 -0
  76. data/lib/orange-more/sitemap/cartons/route.rb +43 -0
  77. data/lib/{orange → orange-more/sitemap}/middleware/flex_router.rb +2 -7
  78. data/lib/orange-more/sitemap/plugin.rb +17 -0
  79. data/lib/{orange → orange-more/sitemap}/resources/sitemap_resource.rb +3 -43
  80. data/lib/{orange → orange-more/sitemap}/views/sitemap/list.haml +0 -0
  81. data/lib/{orange → orange-more/sitemap}/views/sitemap/sitemap_links.haml +0 -0
  82. data/lib/{orange → orange-more/sitemap}/views/sitemap/table_row.haml +0 -0
  83. data/lib/{orange → orange-more/sitemap}/views/sitemap/two_level.haml +0 -0
  84. data/lib/orange-more/sitemap.rb +1 -0
  85. data/lib/{orange → orange-more/slices}/middleware/radius_parser.rb +1 -1
  86. data/lib/orange-more/slices/plugin.rb +15 -0
  87. data/lib/{orange → orange-more/slices}/resources/radius.rb +0 -0
  88. data/lib/{orange → orange-more/slices}/resources/slices.rb +0 -0
  89. data/lib/orange-more/slices.rb +1 -0
  90. data/lib/orange-more.rb +10 -0
  91. data/lib/orange.rb +2 -6
  92. data/spec/{orange → orange-core}/application_spec.rb +0 -0
  93. data/spec/{orange → orange-core}/carton_spec.rb +0 -0
  94. data/spec/{orange → orange-core}/core_spec.rb +2 -2
  95. data/spec/{orange → orange-core}/magick_spec.rb +0 -0
  96. data/spec/{orange → orange-core}/middleware/base_spec.rb +0 -0
  97. data/spec/{orange → orange-core}/middleware/globals_spec.rb +0 -0
  98. data/spec/{orange → orange-core}/middleware/rerouter_spec.rb +0 -0
  99. data/spec/{orange → orange-core}/middleware/restful_router_spec.rb +0 -0
  100. data/spec/{orange → orange-core}/middleware/route_context_spec.rb +0 -0
  101. data/spec/{orange → orange-core}/middleware/route_site_spec.rb +0 -0
  102. data/spec/{orange → orange-core}/middleware/show_exceptions_spec.rb +0 -0
  103. data/spec/{orange → orange-core}/middleware/static_file_spec.rb +0 -0
  104. data/spec/{orange → orange-core}/middleware/static_spec.rb +0 -0
  105. data/spec/{orange → orange-core}/mock/mock_app.rb +0 -0
  106. data/spec/{orange → orange-core}/mock/mock_carton.rb +0 -0
  107. data/spec/{orange → orange-core}/mock/mock_core.rb +0 -0
  108. data/spec/{orange → orange-core}/mock/mock_middleware.rb +0 -0
  109. data/spec/{orange → orange-core}/mock/mock_mixins.rb +0 -0
  110. data/spec/{orange → orange-core}/mock/mock_model_resource.rb +0 -0
  111. data/spec/{orange → orange-core}/mock/mock_pulp.rb +0 -0
  112. data/spec/{orange → orange-core}/mock/mock_resource.rb +0 -0
  113. data/spec/{orange → orange-core}/mock/mock_router.rb +0 -0
  114. data/spec/{orange → orange-core}/orange_spec.rb +0 -0
  115. data/spec/{orange → orange-core}/packet_spec.rb +0 -0
  116. data/spec/{orange → orange-core}/resource_spec.rb +0 -0
  117. data/spec/{orange → orange-core}/resources/mapper_spec.rb +0 -0
  118. data/spec/{orange → orange-core}/resources/model_resource_spec.rb +0 -0
  119. data/spec/{orange → orange-core}/resources/parser_spec.rb +0 -0
  120. data/spec/{orange → orange-core}/resources/routable_resource_spec.rb +0 -0
  121. data/spec/{orange → orange-core}/spec_helper.rb +1 -1
  122. data/spec/{orange → orange-core}/stack_spec.rb +20 -20
  123. metadata +122 -184
  124. data/lib/orange/middleware/rerouter.rb +0 -13
  125. data/lib/orange/resources/singleton_model_resource.rb +0 -7
  126. data/spec/orange/middleware/access_control_spec.rb +0 -3
  127. data/spec/orange/middleware/database_spec.rb +0 -3
  128. data/spec/orange/middleware/site_load_spec.rb +0 -26
  129. data/spec/orange/middleware/template_spec.rb +0 -3
  130. data/spec/orange/resources/admin_resource_spec.rb +0 -16
  131. data/spec/orange/resources/singleton_model_resource_spec.rb +0 -4
  132. data/spec/orange/resources/sitemap_resource_spec.rb +0 -5
data/README.markdown CHANGED
@@ -93,21 +93,22 @@ is a bit overkill. We designed this to replace ModX in our web builds for client
93
93
  Required Gems
94
94
  -------------
95
95
 
96
- Make sure github gems can be downloaded:
97
-
98
- $ gem sources -a http://gems.github.com
99
-
100
96
  * dm-core (+ do_[sqlite3|mysql|...] )
101
97
  * dm-more
102
98
  * dm-is-awesome_set
103
99
  * rack
104
100
  * haml
105
- * mynyml-rack-abstract-format (github)
101
+ * rack-abstract-format (github)
106
102
  * ruby-openid
107
103
  * rack-openid
108
- * meekish-openid_dm_store
104
+ * openid_dm_store
109
105
  * radius
110
106
 
107
+ All dependencies should be loaded if you install the gem except for the datamapper
108
+ adapter relevant to your set up. If, for example, you want to use a mysql database,
109
+ you'll need to install do_mysql, and for an sqlite3 database, you'll need do_sqlite3
110
+
111
+
111
112
  Also, you'll need a web server of some kind and need to set it up for rack.
112
113
 
113
114
  **Testing**
File without changes
File without changes
File without changes
@@ -6,6 +6,19 @@ module Orange
6
6
  # Declare submodules for later use
7
7
  module Pulp; end
8
8
  module Mixins; end
9
+ module Plugins; end
10
+
11
+ attr_accessor :plugins
12
+
13
+ # Support for plugins
14
+ def self.plugins
15
+ @plugins ||= []
16
+ end
17
+
18
+ # Allows adding plugins
19
+ def self.plugin(plugin)
20
+ self.plugins << plugin if plugin.kind_of?(Orange::Plugins::Base)
21
+ end
9
22
 
10
23
  # Allow mixins directly from Orange
11
24
  def self.mixin(inc)
@@ -57,7 +70,8 @@ module Orange
57
70
  load(Orange::Parser.new, :parser)
58
71
  load(Orange::Mapper.new, :mapper)
59
72
  load(Orange::PageParts.new, :page_parts)
60
- load(Orange::AdminResource.new, :admin)
73
+ Orange.plugins.each{|p| p.resources.each{|args| load(*args)} if p.has_resources?}
74
+ # load(Orange::AdminResource.new, :admin)
61
75
  afterLoad
62
76
  self
63
77
  end
@@ -37,25 +37,86 @@ module Enumerable #:nodoc:
37
37
  end
38
38
  end
39
39
 
40
+ # Borrowed from Roman2k:
41
+ # http://github.com/Roman2K/class-inheritable-attributes/
40
42
  # @private
41
- module ClassInheritableAttributes #:nodoc:
42
- def cattr_inheritable(*args)
43
- @cattr_inheritable_attrs ||= [:cattr_inheritable_attrs]
44
- @cattr_inheritable_attrs += args
45
- args.each do |arg|
46
- class_eval %(
47
- class << self; attr_accessor :#{arg} end
48
- )
43
+ module ClassInheritableAttributes
44
+ class << self
45
+ def eval_in_accessor_module(klass, code)
46
+ mod = klass.instance_eval { @_inheritable_attribute_accessors ||= Module.new }
47
+ klass.extend(mod)
48
+ mod.module_eval(code)
49
+ end
50
+
51
+ def fetch_value(klass, attribute)
52
+ each_parent(klass) do |parent|
53
+ if values = registry[parent] and values.key?(attribute)
54
+ return values[attribute]
55
+ elsif parent.instance_variable_defined?("@#{attribute}")
56
+ return parent.instance_variable_get("@#{attribute}")
57
+ end
58
+ end
59
+ return nil
60
+ end
61
+
62
+ def store_value(klass, attribute, value)
63
+ if Thread.current == Thread.main
64
+ if value.nil?
65
+ klass.instance_eval do
66
+ remove_instance_variable("@#{attribute}") if instance_variable_defined?("@#{attribute}")
67
+ end
68
+ else
69
+ klass.instance_variable_set("@#{attribute}", value)
70
+ end
71
+ else
72
+ registry[klass] ||= {}
73
+ if value.nil?
74
+ registry[klass].delete(attribute)
75
+ registry.delete(klass) if registry[klass].empty?
76
+ else
77
+ registry[klass][attribute] = value
78
+ end
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def each_parent(klass)
85
+ while klass < Object
86
+ yield klass
87
+ klass = klass.superclass
88
+ end
89
+ end
90
+
91
+ def registry
92
+ Thread.current[ClassInheritableAttributes.name] ||= {}
49
93
  end
50
- @cattr_inheritable_attrs
51
94
  end
52
-
53
- def inherited(subclass)
54
- @cattr_inheritable_attrs.each do |inheritable_attribute|
55
- instance_var = "@#{inheritable_attribute}"
56
- subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
95
+
96
+ def cattr_reader(*attributes)
97
+ attributes.each do |attribute|
98
+ ClassInheritableAttributes.eval_in_accessor_module(self, <<-EOS)
99
+ def #{attribute}
100
+ #{ClassInheritableAttributes}.fetch_value(self, :#{attribute})
101
+ end
102
+ EOS
57
103
  end
58
104
  end
105
+
106
+ def cattr_writer(*attributes)
107
+ attributes.each do |attribute|
108
+ ClassInheritableAttributes.eval_in_accessor_module(self, <<-EOS)
109
+ def #{attribute}=(value)
110
+ #{ClassInheritableAttributes}.store_value(self, :#{attribute}, value)
111
+ end
112
+ EOS
113
+ end
114
+ end
115
+
116
+ def cattr_accessor(*attributes)
117
+ cattr_reader(*attributes)
118
+ cattr_writer(*attributes)
119
+ end
59
120
  end
60
121
 
61
122
  module Orange
@@ -1,4 +1,4 @@
1
- require 'orange/packet'
1
+ require 'orange-core/packet'
2
2
 
3
3
  # Orange Middleware is a bit more complex than Rack middleware.
4
4
  # Initializing it requires both a link to the downstream app and
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
  module Orange::Middleware
3
3
 
4
4
  class Database < Base
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
 
3
3
  module Orange::Middleware
4
4
  # The FlexRouter middleware takes a resource that can route paths and
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
  module Orange::Middleware
3
3
 
4
4
  class Globals < Base
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
  module Orange::Middleware
3
3
  class Loader < Base
4
4
  def init(*args)
@@ -0,0 +1,53 @@
1
+ require 'orange-core/middleware/base'
2
+ module Orange::Middleware
3
+
4
+ class Rerouter < Base
5
+ def init(*args)
6
+ orange.add_pulp Orange::Pulp::Packet_Reroute
7
+ end
8
+
9
+ def packet_call(packet)
10
+ begin
11
+ pass packet
12
+ rescue Orange::Reroute
13
+ packet.finish
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module Orange
20
+
21
+ module Pulp::Packet_Reroute
22
+ def reroute(url, type = :real, *args)
23
+ packet['reroute.to'] = url
24
+ packet['reroute.type'] = type
25
+ packet['reroute.args'] = *args if args
26
+ raise Reroute.new(self), 'Unhandled reroute'
27
+ end
28
+ end
29
+
30
+ class Reroute < Exception
31
+ def initialize(packet)
32
+ @packet = packet
33
+ @packet[:headers] = {"Content-Type" => 'text/html', "Location" => self.url}
34
+ @packet[:status] = 302
35
+ end
36
+
37
+ def url
38
+ case packet['reroute.type']
39
+ when :real
40
+ packet['reroute.to']
41
+ # Parsing for orange urls or something
42
+ when :orange
43
+ packet.route_to(packet['reroute.to'], packet['reroute.args', []])
44
+ else
45
+ packet['reroute.to']
46
+ end
47
+ end
48
+
49
+ def packet
50
+ @packet
51
+ end
52
+ end
53
+ end
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
 
3
3
  module Orange::Middleware
4
4
  class RestfulRouter < Base
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
 
3
3
  module Orange::Middleware
4
4
  # This middleware handles setting orange.env['route.context']
@@ -1,4 +1,4 @@
1
- require 'orange/middleware/base'
1
+ require 'orange-core/middleware/base'
2
2
 
3
3
  module Orange::Middleware
4
4
  # This middleware handles setting orange.env['route.site_url']
@@ -1,7 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'rack/request'
3
3
  require 'rack/utils'
4
- require 'orange/middleware/base'
4
+ require 'orange-core/middleware/base'
5
5
 
6
6
  module Orange::Middleware
7
7
  # Rack::ShowExceptions catches all exceptions raised from the app it
@@ -1,5 +1,5 @@
1
- require 'orange/middleware/base'
2
- require 'orange/middleware/static_file'
1
+ require 'orange-core/middleware/base'
2
+ require 'orange-core/middleware/static_file'
3
3
 
4
4
  module Orange::Middleware
5
5
  # The Orange::Middleware::Static middleware intercepts requests for static files
@@ -34,21 +34,21 @@ module Orange::Middleware
34
34
  class Static < Base
35
35
 
36
36
  def initialize(app, core, options={})
37
- core.mixin Orange::Mixins::Static
38
- core.add_static('_orange_', File.join(core.core_dir, 'assets'))
39
- @app = app
40
- @core = core
41
- @libs = options[:libs] || [Orange::Core]
37
+ @lib_urls = {'_orange_' => File.join(core.core_dir, 'assets') }
38
+ Orange.plugins.each{|p| @lib_urls[p.assets_name] = p.assets if p.has_assets?}
42
39
 
40
+ @app = app
41
+ @core = core
43
42
  @urls = options[:urls] || ["/favicon.ico", "/assets/public", "/assets/uploaded"]
44
43
  @root = options[:root] || File.join(orange.app_dir, 'assets')
45
- @lib_urls = core.statics
46
44
  @file_server = Orange::Middleware::StaticFile.new(@root)
47
45
  end
48
46
 
49
47
  def packet_call(packet)
50
48
  path = packet.env["PATH_INFO"]
51
- can_serve_lib = @lib_urls.select{ |url, server| path.index(url) == 0 }.first
49
+ can_serve_lib = @lib_urls.select { |url, server|
50
+ path.index(File.join('', 'assets', url)) == 0
51
+ }.first
52
52
  can_serve = @urls.any?{|url| path.index(url) == 0 }
53
53
  if can_serve_lib
54
54
  lib_url = can_serve_lib.first
@@ -64,16 +64,4 @@ module Orange::Middleware
64
64
  end
65
65
 
66
66
  end
67
- end
68
-
69
- module Orange::Mixins::Static
70
- def add_static(lib_name, path)
71
- @statics ||= {}
72
- key = File.join('', 'assets', lib_name)
73
- @statics.merge!(key => path)
74
- end
75
-
76
- def statics
77
- @statics ||= {}
78
- end
79
67
  end
@@ -1,5 +1,5 @@
1
- require 'orange/core'
2
- require 'orange/middleware/base'
1
+ require 'orange-core/core'
2
+ require 'orange-core/middleware/base'
3
3
 
4
4
  module Orange::Middleware
5
5
 
@@ -10,14 +10,7 @@ module Orange::Middleware
10
10
 
11
11
  # Establish a default template chooser
12
12
  @core.template_chooser do |packet|
13
- if packet['route.context'] == :admin
14
- packet.add_css('admin.css', :module => '_orange_')
15
- packet.add_js('jquery.js', :module => '_orange_')
16
- packet.add_js('admin.js', :module => '_orange_')
17
- 'admin.haml'
18
- else
19
- false
20
- end
13
+ false
21
14
  end
22
15
  end
23
16
 
File without changes
@@ -0,0 +1,172 @@
1
+ require 'orange-core/magick'
2
+ require 'orange-core/core'
3
+ module Orange::Plugins
4
+ # This class defines a basic Orange plugin. A plugin simply defines
5
+ # a bunch of possible classes/files that can be called up by the main
6
+ # orange system.
7
+ #
8
+ # The plugins are used in several places. When the core is initialized,
9
+ # it will ask all plugins if they have any resources that should be added,
10
+ # and load those resources if they exist.
11
+ #
12
+ # The stack will call the list of plugins several times in building a stack
13
+ # once for each possible middleware location.
14
+ class Base
15
+ extend ClassInheritableAttributes
16
+ cattr_accessor :prerouting_middleware, :routing_middleware,
17
+ :responder_middleware, :postrouting_middleware, :has_middleware
18
+ cattr_accessor :assets, :assets_name
19
+ cattr_accessor :resources
20
+ cattr_accessor :views
21
+ cattr_accessor :templates
22
+
23
+ # Adds a single prerouting middleware class to list of prerouting middleware
24
+ def self.prerouter(r)
25
+ prerouters(r)
26
+ end
27
+
28
+ # Adds several prerouting middleware classes to list of prerouting middleware
29
+ def self.prerouters(*routers)
30
+ self.has_middleware = true
31
+ routers.each do |prerouter|
32
+ self.prerouting_middleware << prerouter
33
+ end
34
+ end
35
+
36
+ # Adds a single postrouting middleware class to list of postrouting middleware
37
+ def self.postrouter(r)
38
+ postrouters(r)
39
+ end
40
+
41
+ # Adds several postrouting middleware classes to list of postrouting middleware
42
+ def self.postrouters(*routers)
43
+ self.has_middleware = true
44
+ routers.each do |postrouter|
45
+ self.postrouting_middleware << postrouter
46
+ end
47
+ end
48
+
49
+ # Adds a router middleware class to the list of routing middleware
50
+ def self.router(r)
51
+ routers(r)
52
+ end
53
+ # Adds several router middleware classes
54
+ def self.routers(*routers)
55
+ self.has_middleware = true
56
+ routers.each do |router|
57
+ self.routing_middleware << router
58
+ end
59
+ end
60
+ # Adds a responder middleware class
61
+ def self.responder(r)
62
+ responders(r)
63
+ end
64
+ # Adds several responder middleware classes
65
+ def self.responders(*respones)
66
+ self.has_middleware = true
67
+ respones.each do |response|
68
+ self.responder_middleware << response
69
+ end
70
+ end
71
+
72
+ # Returns the list of prerouting_middleware defined or
73
+ # an empty array if none defined
74
+ def self.prerouting_middleware
75
+ super || self.prerouting_middleware = []
76
+ end
77
+
78
+ # Returns the list of prerouting_middleware defined or
79
+ # an empty array if none defined
80
+ def self.postrouting_middleware
81
+ super || self.postrouting_middleware = []
82
+ end
83
+
84
+ # Returns the list of routing_middleware defined or
85
+ # an empty array if none defined
86
+ def self.routing_middleware
87
+ super || self.routing_middleware = []
88
+ end
89
+
90
+ # Returns the list of responder_middleware defined or
91
+ # an empty array if none defined
92
+ def self.responder_middleware
93
+ super || self.responder_middleware = []
94
+ end
95
+
96
+ def self.templates_dir(arg)
97
+ self.templates = arg
98
+ end
99
+
100
+ def self.views_dir(arg)
101
+ self.views = arg
102
+ end
103
+
104
+ def self.assets_dir(arg)
105
+ self.assets = arg
106
+ end
107
+
108
+ def self.resource(instance, name = false)
109
+ self.resources << [instance, name]
110
+ end
111
+
112
+ def self.resources
113
+ super || self.resources = []
114
+ end
115
+
116
+ # Returns the assigned asset dir name,
117
+ # or Plugin class name formatted like this: PluginClass -> _pluginclass_
118
+ def assets_name
119
+ self.class.assets_name || '_'+self.class.to_s.gsub(/Orange::Plugins::/, '').gsub(/::/, '_').downcase+'_'
120
+ end
121
+
122
+ # Returns the assets directory for this plugin
123
+ def assets
124
+ self.class.assets
125
+ end
126
+
127
+ # Whether this plugin has assets for the static middleware to worry
128
+ # about
129
+ def has_assets?
130
+ !assets.blank?
131
+ end
132
+
133
+ def resources
134
+ self.class.resources
135
+ end
136
+
137
+ def has_resources?
138
+ !resources.blank?
139
+ end
140
+
141
+ def views
142
+ self.class.views
143
+ end
144
+
145
+ def has_views?
146
+ !views.blank?
147
+ end
148
+
149
+ def templates
150
+ self.class.templates
151
+ end
152
+
153
+ def has_templates?
154
+ !templates.blank?
155
+ end
156
+
157
+ def middleware(type = :has)
158
+ case type
159
+ when :responders then self.class.responder_middleware
160
+ when :routing then self.class.routing_middleware
161
+ when :prerouting then self.class.prerouting_middleware
162
+ when :postrouting then self.class.postrouting_middleware
163
+ when :has then self.class.has_middleware
164
+ else nil
165
+ end
166
+ end
167
+
168
+ def has_middleware?
169
+ !middleware.blank?
170
+ end
171
+ end
172
+ end
@@ -1,4 +1,4 @@
1
- require 'orange/core'
1
+ require 'orange-core/core'
2
2
 
3
3
  module Orange
4
4
  # Orange Resource for being subclassed
@@ -6,7 +6,7 @@ module Orange
6
6
  extend ClassInheritableAttributes
7
7
  # Defines a model class as an inheritable class attribute and also an instance
8
8
  # attribute
9
- cattr_inheritable :called
9
+ cattr_accessor :called
10
10
 
11
11
  def initialize(*args, &block)
12
12
  @options = DefaultHash.new.merge!(Options.new(*args, &block).hash)
@@ -1,4 +1,4 @@
1
- require 'orange/core'
1
+ require 'orange-core/core'
2
2
 
3
3
  module Orange
4
4
  class Mapper < Resource
@@ -30,31 +30,6 @@ module Orange
30
30
  packet['reroute.args'] = *args if args
31
31
  raise Reroute.new(self), 'Unhandled reroute'
32
32
  end
33
-
34
- end
35
-
36
- class Reroute < Exception
37
- def initialize(packet)
38
- @packet = packet
39
- @packet[:headers] = {"Content-Type" => 'text/html', "Location" => self.url}
40
- @packet[:status] = 302
41
- end
42
-
43
- def url
44
- case packet['reroute.type']
45
- when :real
46
- packet['reroute.to']
47
- # Parsing for orange urls or something
48
- when :orange
49
- packet.route_to(packet['reroute.to'], packet['reroute.args', []])
50
- else
51
- packet['reroute.to']
52
- end
53
- end
54
-
55
- def packet
56
- @packet
57
- end
58
33
  end
59
34
 
60
35
  end
@@ -1,10 +1,10 @@
1
- require 'orange/resources/routable_resource'
1
+ require 'orange-core/resources/routable_resource'
2
2
 
3
3
  module Orange
4
4
  class ModelResource < RoutableResource
5
5
  # Defines a model class as an inheritable class attribute and also an instance
6
6
  # attribute
7
- cattr_inheritable :model_class
7
+ cattr_accessor :model_class
8
8
  attr_accessor :model_class
9
9
 
10
10
  # Tells the Model resource which Carton class to scaffold
@@ -1,3 +1,4 @@
1
+ require 'orange-core/resource'
1
2
  module Orange
2
3
  class NotFound < Orange::Resource
3
4
  call_me :not_found
@@ -1,3 +1,4 @@
1
+ require 'orange-core/resource'
1
2
  module Orange
2
3
  class PageParts < Resource
3
4
  def afterLoad
@@ -1,4 +1,4 @@
1
- require 'orange/core'
1
+ require 'orange-core/core'
2
2
  require 'haml'
3
3
  require 'yaml'
4
4
 
@@ -6,6 +6,10 @@ module Orange
6
6
  class Parser < Resource
7
7
  def afterLoad
8
8
  orange.add_pulp Orange::Pulp::ParserPulp
9
+ @template_dirs = [File.join(orange.core_dir, 'templates')]
10
+ @view_dirs = [File.join(orange.core_dir, 'views')]
11
+ Orange.plugins.each{|p| @template_dirs << p.templates if p.has_templates? }
12
+ Orange.plugins.each{|p| @view_dirs << p.views if p.has_views? }
9
13
  end
10
14
 
11
15
  def yaml(file)
@@ -22,16 +26,20 @@ module Orange
22
26
  resource = (opts[:resource_name] || '').downcase
23
27
  opts.merge :orange => orange
24
28
 
25
- templates_dir = File.join(orange.core_dir, 'templates')
26
- views_dir = File.join(orange.core_dir, 'views')
27
29
  string = false
28
- string ||= read_if_exists('templates', file) if temp
29
- string ||= read_if_exists(templates_dir, file) if temp
30
+ if temp
31
+ string ||= read_if_exists('templates', file)
32
+ @template_dirs.each do |templates_dir|
33
+ string ||= read_if_exists(templates_dir, file)
34
+ end
35
+ end
30
36
  string ||= read_if_exists('views', resource, file) if resource
31
37
  string ||= read_if_exists('views', file)
32
- string ||= read_if_exists(views_dir, resource, file) if resource
33
- string ||= read_if_exists(views_dir, 'default_resource', file)
34
- string ||= read_if_exists(views_dir, file)
38
+ @view_dirs.each do |views_dir|
39
+ string ||= read_if_exists(views_dir, resource, file) if resource
40
+ string ||= read_if_exists(views_dir, file)
41
+ end
42
+ string ||= read_if_exists(@view_dirs.first, 'default_resource', file)
35
43
  raise LoadError, "Couldn't find haml file '#{file}'" unless string
36
44
 
37
45
  haml_engine = Haml::Engine.new(string)
@@ -1,4 +1,4 @@
1
- require 'orange/resource'
1
+ require 'orange-core/resource'
2
2
 
3
3
  module Orange
4
4
  class RoutableResource < Resource