orange 0.5.5 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/orange.rb +2 -5
- data/spec/orange_spec.rb +5 -0
- data/spec/{orange-core/spec_helper.rb → spec_helper.rb} +0 -0
- metadata +28 -235
- data/lib/orange-core.rb +0 -8
- data/lib/orange-core/application.rb +0 -132
- data/lib/orange-core/assets/css/exceptions.css +0 -50
- data/lib/orange-core/assets/js/exceptions.js +0 -44
- data/lib/orange-core/carton.rb +0 -178
- data/lib/orange-core/core.rb +0 -266
- data/lib/orange-core/magick.rb +0 -270
- data/lib/orange-core/middleware/base.rb +0 -96
- data/lib/orange-core/middleware/database.rb +0 -45
- data/lib/orange-core/middleware/four_oh_four.rb +0 -45
- data/lib/orange-core/middleware/globals.rb +0 -17
- data/lib/orange-core/middleware/loader.rb +0 -13
- data/lib/orange-core/middleware/rerouter.rb +0 -53
- data/lib/orange-core/middleware/restful_router.rb +0 -99
- data/lib/orange-core/middleware/route_context.rb +0 -39
- data/lib/orange-core/middleware/route_site.rb +0 -51
- data/lib/orange-core/middleware/show_exceptions.rb +0 -80
- data/lib/orange-core/middleware/static.rb +0 -67
- data/lib/orange-core/middleware/static_file.rb +0 -32
- data/lib/orange-core/middleware/template.rb +0 -60
- data/lib/orange-core/packet.rb +0 -232
- data/lib/orange-core/plugin.rb +0 -172
- data/lib/orange-core/resource.rb +0 -96
- data/lib/orange-core/resources/mapper.rb +0 -36
- data/lib/orange-core/resources/model_resource.rb +0 -228
- data/lib/orange-core/resources/not_found.rb +0 -10
- data/lib/orange-core/resources/page_parts.rb +0 -68
- data/lib/orange-core/resources/parser.rb +0 -113
- data/lib/orange-core/resources/routable_resource.rb +0 -16
- data/lib/orange-core/resources/scaffold.rb +0 -106
- data/lib/orange-core/stack.rb +0 -226
- data/lib/orange-core/templates/exceptions.haml +0 -111
- data/lib/orange-core/views/default_resource/create.haml +0 -4
- data/lib/orange-core/views/default_resource/edit.haml +0 -9
- data/lib/orange-core/views/default_resource/list.haml +0 -10
- data/lib/orange-core/views/default_resource/show.haml +0 -4
- data/lib/orange-core/views/default_resource/table_row.haml +0 -7
- data/lib/orange-core/views/not_found/404.haml +0 -2
- data/lib/orange-more.rb +0 -23
- data/lib/orange-more/administration.rb +0 -1
- data/lib/orange-more/administration/assets/css/admin.css +0 -286
- data/lib/orange-more/administration/assets/css/blueprint-ie.css +0 -35
- data/lib/orange-more/administration/assets/css/blueprint-print.css +0 -29
- data/lib/orange-more/administration/assets/css/blueprint.css +0 -257
- data/lib/orange-more/administration/assets/js/jquery.js +0 -152
- data/lib/orange-more/administration/cartons/site.rb +0 -7
- data/lib/orange-more/administration/cartons/site_carton.rb +0 -12
- data/lib/orange-more/administration/cartons/user.rb +0 -27
- data/lib/orange-more/administration/middleware/access_control.rb +0 -156
- data/lib/orange-more/administration/middleware/site_load.rb +0 -25
- data/lib/orange-more/administration/plugin.rb +0 -23
- data/lib/orange-more/administration/resources/admin_resource.rb +0 -27
- data/lib/orange-more/administration/resources/site_resource.rb +0 -10
- data/lib/orange-more/administration/resources/user_resource.rb +0 -40
- data/lib/orange-more/administration/templates/admin.haml +0 -25
- data/lib/orange-more/administration/views/openid_login.haml +0 -14
- data/lib/orange-more/administration/views/users/create.haml +0 -10
- data/lib/orange-more/administration/views/users/edit.haml +0 -15
- data/lib/orange-more/adverts.rb +0 -1
- data/lib/orange-more/adverts/cartons/adverts_carton.rb +0 -14
- data/lib/orange-more/adverts/plugin.rb +0 -13
- data/lib/orange-more/adverts/resources/adverts_resource.rb +0 -27
- data/lib/orange-more/adverts/views/adverts/adverts.haml +0 -2
- data/lib/orange-more/analytics.rb +0 -1
- data/lib/orange-more/analytics/middleware/analytics.rb +0 -30
- data/lib/orange-more/analytics/plugin.rb +0 -11
- data/lib/orange-more/analytics/resources/analytics_resource.rb +0 -42
- data/lib/orange-more/assets.rb +0 -1
- data/lib/orange-more/assets/cartons/asset_carton.rb +0 -27
- data/lib/orange-more/assets/plugin.rb +0 -13
- data/lib/orange-more/assets/resources/asset_resource.rb +0 -115
- data/lib/orange-more/assets/views/assets/change.haml +0 -1
- data/lib/orange-more/assets/views/assets/create.haml +0 -13
- data/lib/orange-more/assets/views/assets/insert.haml +0 -1
- data/lib/orange-more/blog.rb +0 -1
- data/lib/orange-more/blog/cartons/blog.rb +0 -8
- data/lib/orange-more/blog/cartons/blog_post.rb +0 -60
- data/lib/orange-more/blog/plugin.rb +0 -14
- data/lib/orange-more/blog/resources/blog_post_resource.rb +0 -53
- data/lib/orange-more/blog/resources/blog_resource.rb +0 -104
- data/lib/orange-more/blog/views/blog/blog_archive_view.haml +0 -6
- data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +0 -12
- data/lib/orange-more/blog/views/blog/blog_post_view.haml +0 -4
- data/lib/orange-more/blog/views/blog/sitemap_row.haml +0 -14
- data/lib/orange-more/blog/views/blog_posts/edit.haml +0 -8
- data/lib/orange-more/blog/views/blog_posts/show.haml +0 -4
- data/lib/orange-more/cloud.rb +0 -1
- data/lib/orange-more/cloud/plugin.rb +0 -10
- data/lib/orange-more/cloud/resources/cloud_resource.rb +0 -21
- data/lib/orange-more/contactforms.rb +0 -1
- data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +0 -15
- data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +0 -6240
- data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +0 -660
- data/lib/orange-more/contactforms/assets/js/lib/jquery.js +0 -4376
- data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +0 -122
- data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +0 -12
- data/lib/orange-more/contactforms/plugin.rb +0 -13
- data/lib/orange-more/contactforms/resources/contactforms_resource.rb +0 -56
- data/lib/orange-more/contactforms/views/contactforms/contactform.haml +0 -20
- data/lib/orange-more/debugger.rb +0 -1
- data/lib/orange-more/debugger/assets/css/debug_bar.css +0 -46
- data/lib/orange-more/debugger/middleware/debugger.rb +0 -50
- data/lib/orange-more/debugger/plugin.rb +0 -12
- data/lib/orange-more/debugger/views/debug_bar.haml +0 -87
- data/lib/orange-more/disqus.rb +0 -1
- data/lib/orange-more/disqus/plugin.rb +0 -11
- data/lib/orange-more/disqus/resources/disqus_resource.rb +0 -9
- data/lib/orange-more/disqus/views/disqus/comment_thread.haml +0 -7
- data/lib/orange-more/donations.rb +0 -1
- data/lib/orange-more/donations/cartons/donation_carton.rb +0 -9
- data/lib/orange-more/donations/plugin.rb +0 -12
- data/lib/orange-more/donations/resources/donations_resource.rb +0 -51
- data/lib/orange-more/donations/views/donations/donate_form.haml +0 -21
- data/lib/orange-more/donations/views/donations/donate_thanks.haml +0 -2
- data/lib/orange-more/donations/views/donations/paypal_form.haml +0 -13
- data/lib/orange-more/events.rb +0 -1
- data/lib/orange-more/events/assets/js/events.js +0 -55
- data/lib/orange-more/events/cartons/orange_calendar.rb +0 -8
- data/lib/orange-more/events/cartons/orange_event.rb +0 -60
- data/lib/orange-more/events/plugin.rb +0 -14
- data/lib/orange-more/events/resources/calendar_resource.rb +0 -33
- data/lib/orange-more/events/resources/event_resource.rb +0 -147
- data/lib/orange-more/events/views/calendar/calendar.haml +0 -8
- data/lib/orange-more/events/views/events/create.haml +0 -55
- data/lib/orange-more/events/views/events/edit.haml +0 -59
- data/lib/orange-more/events/views/events/list.haml +0 -13
- data/lib/orange-more/events/views/events/show.haml +0 -4
- data/lib/orange-more/events/views/events/table_row.haml +0 -17
- data/lib/orange-more/members.rb +0 -1
- data/lib/orange-more/members/cartons/member_carton.rb +0 -38
- data/lib/orange-more/members/plugin.rb +0 -13
- data/lib/orange-more/members/resources/members_resource.rb +0 -327
- data/lib/orange-more/members/views/members/create.haml +0 -12
- data/lib/orange-more/members/views/members/edit.haml +0 -15
- data/lib/orange-more/members/views/members/live.show.haml +0 -1
- data/lib/orange-more/members/views/members/login.haml +0 -17
- data/lib/orange-more/members/views/members/logout.haml +0 -1
- data/lib/orange-more/members/views/members/profile.haml +0 -50
- data/lib/orange-more/members/views/members/register.haml +0 -37
- data/lib/orange-more/news.rb +0 -1
- data/lib/orange-more/news/cartons/news.rb +0 -12
- data/lib/orange-more/news/plugin.rb +0 -13
- data/lib/orange-more/news/resources/news_resource.rb +0 -82
- data/lib/orange-more/news/views/news/archive.haml +0 -14
- data/lib/orange-more/news/views/news/edit.haml +0 -7
- data/lib/orange-more/news/views/news/latest.haml +0 -8
- data/lib/orange-more/news/views/news/sitemap_row.haml +0 -14
- data/lib/orange-more/pages.rb +0 -1
- data/lib/orange-more/pages/cartons/page_carton.rb +0 -14
- data/lib/orange-more/pages/cartons/page_version_carton.rb +0 -12
- data/lib/orange-more/pages/plugin.rb +0 -13
- data/lib/orange-more/pages/resources/page_resource.rb +0 -179
- data/lib/orange-more/pages/views/pages/edit.haml +0 -34
- data/lib/orange-more/pages/views/pages/show.haml +0 -6
- data/lib/orange-more/sitemap.rb +0 -1
- data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
- data/lib/orange-more/sitemap/assets/js/sitemap.js +0 -11
- data/lib/orange-more/sitemap/cartons/route.rb +0 -43
- data/lib/orange-more/sitemap/middleware/flex_router.rb +0 -25
- data/lib/orange-more/sitemap/plugin.rb +0 -17
- data/lib/orange-more/sitemap/resources/sitemap_resource.rb +0 -295
- data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +0 -30
- data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +0 -12
- data/lib/orange-more/sitemap/views/sitemap/list.haml +0 -4
- data/lib/orange-more/sitemap/views/sitemap/one_level.haml +0 -7
- data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +0 -15
- data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +0 -14
- data/lib/orange-more/sitemap/views/sitemap/table_row.haml +0 -30
- data/lib/orange-more/sitemap/views/sitemap/two_level.haml +0 -13
- data/lib/orange-more/slices.rb +0 -1
- data/lib/orange-more/slices/middleware/radius_parser.rb +0 -24
- data/lib/orange-more/slices/plugin.rb +0 -15
- data/lib/orange-more/slices/resources/radius.rb +0 -117
- data/lib/orange-more/slices/resources/slices.rb +0 -35
- data/lib/orange-more/subsites.rb +0 -1
- data/lib/orange-more/subsites/cartons/subsite.rb +0 -8
- data/lib/orange-more/subsites/middleware/subsite_load.rb +0 -29
- data/lib/orange-more/subsites/plugin.rb +0 -17
- data/lib/orange-more/subsites/resources/subsite_resource.rb +0 -54
- data/lib/orange-more/subsites/views/subsites/index.haml +0 -2
- data/lib/orange-more/testimonials.rb +0 -1
- data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +0 -15
- data/lib/orange-more/testimonials/plugin.rb +0 -13
- data/lib/orange-more/testimonials/resources/testimonials_resource.rb +0 -42
- data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +0 -4
- data/spec/orange-core/application_spec.rb +0 -183
- data/spec/orange-core/carton_spec.rb +0 -136
- data/spec/orange-core/core_spec.rb +0 -248
- data/spec/orange-core/magick_spec.rb +0 -96
- data/spec/orange-core/middleware/base_spec.rb +0 -38
- data/spec/orange-core/middleware/globals_spec.rb +0 -3
- data/spec/orange-core/middleware/rerouter_spec.rb +0 -3
- data/spec/orange-core/middleware/restful_router_spec.rb +0 -3
- data/spec/orange-core/middleware/route_context_spec.rb +0 -3
- data/spec/orange-core/middleware/route_site_spec.rb +0 -3
- data/spec/orange-core/middleware/show_exceptions_spec.rb +0 -3
- data/spec/orange-core/middleware/static_file_spec.rb +0 -3
- data/spec/orange-core/middleware/static_spec.rb +0 -3
- data/spec/orange-core/mock/mock_app.rb +0 -16
- data/spec/orange-core/mock/mock_carton.rb +0 -43
- data/spec/orange-core/mock/mock_core.rb +0 -2
- data/spec/orange-core/mock/mock_middleware.rb +0 -25
- data/spec/orange-core/mock/mock_mixins.rb +0 -19
- data/spec/orange-core/mock/mock_model_resource.rb +0 -47
- data/spec/orange-core/mock/mock_pulp.rb +0 -24
- data/spec/orange-core/mock/mock_resource.rb +0 -26
- data/spec/orange-core/mock/mock_router.rb +0 -10
- data/spec/orange-core/orange_spec.rb +0 -19
- data/spec/orange-core/packet_spec.rb +0 -203
- data/spec/orange-core/resource_spec.rb +0 -96
- data/spec/orange-core/resources/mapper_spec.rb +0 -5
- data/spec/orange-core/resources/model_resource_spec.rb +0 -246
- data/spec/orange-core/resources/parser_spec.rb +0 -5
- data/spec/orange-core/resources/routable_resource_spec.rb +0 -5
- data/spec/orange-core/stack_spec.rb +0 -232
data/lib/orange-core/magick.rb
DELETED
@@ -1,270 +0,0 @@
|
|
1
|
-
# Monkey Patch the extract_options! stolen from ActiveSupport
|
2
|
-
# @private
|
3
|
-
class ::Array #:nodoc:
|
4
|
-
def extract_options!
|
5
|
-
last.is_a?(::Hash) ? pop : {}
|
6
|
-
end
|
7
|
-
def extract_with_defaults(defaults)
|
8
|
-
extract_options!.with_defaults(defaults)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Monkey Patch for merging defaults into a hash
|
13
|
-
# @private
|
14
|
-
class ::Hash #:nodoc:
|
15
|
-
def with_defaults(defaults)
|
16
|
-
self.merge(defaults){ |key, old, new| old.nil? ? new : old }
|
17
|
-
end
|
18
|
-
def with_defaults!(defaults)
|
19
|
-
self.merge!(defaults){ |key, old, new| old.nil? ? new : old }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# Monkey patch for awesome array -> hash conversions
|
26
|
-
# use:
|
27
|
-
#
|
28
|
-
# [:x, :y, :z].inject_hash do |results, letter|
|
29
|
-
# results[letter] = rand(100)
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# # => {:x => 32, :y => 63, :z => 91}
|
33
|
-
# @private
|
34
|
-
module Enumerable #:nodoc:
|
35
|
-
def inject_hash(hash = {})
|
36
|
-
inject(hash) {|(h,item)| yield(h,item); h}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# Borrowed from Roman2k:
|
41
|
-
# http://github.com/Roman2K/class-inheritable-attributes/
|
42
|
-
# @private
|
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] ||= {}
|
93
|
-
end
|
94
|
-
end
|
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
|
103
|
-
end
|
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
|
120
|
-
end
|
121
|
-
|
122
|
-
module Orange
|
123
|
-
|
124
|
-
# Class that extends hash so that [] can have an optional second attribute
|
125
|
-
class DefaultHash < ::Hash
|
126
|
-
def [](key, my_default = nil)
|
127
|
-
my_default = self.default if my_default.nil?
|
128
|
-
self.has_key?(key) ? super(key) : my_default
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
# This class acts as a simple sink for ignoring messages, it will return itself
|
133
|
-
# for any message call. Orange::Core can optionally return this when trying
|
134
|
-
# to access resources so that you can make method calls to a resource that
|
135
|
-
# might not be really there. It will silently swallow any errors that might arrise,
|
136
|
-
# so this should be used with caution.
|
137
|
-
class Ignore
|
138
|
-
def blank?; true; end
|
139
|
-
def method_missing(name, *args, &block)
|
140
|
-
return self
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# Simple class for evaluating options and allowing us to access them.
|
145
|
-
class Options
|
146
|
-
|
147
|
-
def initialize(*options, &block)
|
148
|
-
@options = options.extract_options!
|
149
|
-
@options ||= {}
|
150
|
-
instance_eval(&block) if block_given?
|
151
|
-
end
|
152
|
-
|
153
|
-
def hash
|
154
|
-
@options
|
155
|
-
end
|
156
|
-
|
157
|
-
def method_missing(key, *args)
|
158
|
-
return (@options[key.to_s.gsub(/\?$/, '').to_sym].eql?(true)) if key.to_s.match(/\?$/)
|
159
|
-
if args.empty?
|
160
|
-
@options[key.to_sym]
|
161
|
-
elsif(key.to_s.match(/\=$/))
|
162
|
-
@options[key.to_s.gsub(/\=$/, '').to_sym] = (args.size == 1 ? args.first : args)
|
163
|
-
else
|
164
|
-
@options[key.to_sym] = (args.size == 1 ? args.first : args)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# @private
|
170
|
-
module Inflector
|
171
|
-
extend self
|
172
|
-
# @private
|
173
|
-
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
174
|
-
if first_letter_in_uppercase
|
175
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
176
|
-
else
|
177
|
-
lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
if Module.method(:const_get).arity == 1
|
182
|
-
def constantize(camel_cased_word)
|
183
|
-
names = camel_cased_word.split('::')
|
184
|
-
names.shift if names.empty? || names.first.empty?
|
185
|
-
|
186
|
-
constant = Object
|
187
|
-
names.each do |name|
|
188
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
189
|
-
end
|
190
|
-
constant
|
191
|
-
end
|
192
|
-
else
|
193
|
-
def constantize(camel_cased_word) #:nodoc:
|
194
|
-
names = camel_cased_word.split('::')
|
195
|
-
names.shift if names.empty? || names.first.empty?
|
196
|
-
|
197
|
-
constant = Object
|
198
|
-
names.each do |name|
|
199
|
-
constant = constant.const_get(name, false) || constant.const_missing(name)
|
200
|
-
end
|
201
|
-
constant
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
208
|
-
|
209
|
-
# @private
|
210
|
-
class Object #:nodoc:
|
211
|
-
# An object is blank if it's false, empty, or a whitespace string.
|
212
|
-
# For example, "", " ", +nil+, [], and {} are blank.
|
213
|
-
#
|
214
|
-
# This simplifies
|
215
|
-
#
|
216
|
-
# if !address.nil? && !address.empty?
|
217
|
-
#
|
218
|
-
# to
|
219
|
-
#
|
220
|
-
# if !address.blank?
|
221
|
-
def blank?
|
222
|
-
respond_to?(:empty?) ? empty? : !self
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
# @private
|
227
|
-
class NilClass #:nodoc:
|
228
|
-
def blank?
|
229
|
-
true
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
# @private
|
234
|
-
class FalseClass #:nodoc:
|
235
|
-
def blank?
|
236
|
-
true
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
# @private
|
241
|
-
class TrueClass #:nodoc:
|
242
|
-
def blank?
|
243
|
-
false
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
# @private
|
248
|
-
class Array #:nodoc:
|
249
|
-
alias_method :blank?, :empty?
|
250
|
-
end
|
251
|
-
|
252
|
-
# @private
|
253
|
-
class Hash #:nodoc:
|
254
|
-
alias_method :blank?, :empty?
|
255
|
-
end
|
256
|
-
|
257
|
-
# @private
|
258
|
-
class String #:nodoc:
|
259
|
-
def blank?
|
260
|
-
self !~ /\S/
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
# @private
|
265
|
-
class Numeric #:nodoc:
|
266
|
-
def blank?
|
267
|
-
false
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'orange-core/packet'
|
2
|
-
|
3
|
-
# Orange Middleware is a bit more complex than Rack middleware.
|
4
|
-
# Initializing it requires both a link to the downstream app and
|
5
|
-
# the core, and calling the app often requires an Orange::Packet
|
6
|
-
#
|
7
|
-
# Orange::Middleware::Base takes care of these basic tasks.
|
8
|
-
# Subclasses override the init method for extra initialization
|
9
|
-
# and the packet_call for a call with a packet, rather than
|
10
|
-
# a basic call
|
11
|
-
module Orange::Middleware
|
12
|
-
class Base
|
13
|
-
# Initialize will set the core and downstream app, then call init
|
14
|
-
# subclasses should override init instead of initialize.
|
15
|
-
# If the subclass defines a stack_init, then it will be registered
|
16
|
-
# as a stack_loaded event.
|
17
|
-
# @param [Object] app a downstream app
|
18
|
-
# @param [Orange::Core] core the orange core
|
19
|
-
# @param [optional, Array] args any arguments
|
20
|
-
def initialize(app, core, *args)
|
21
|
-
@app = app
|
22
|
-
@core = core
|
23
|
-
init(*args)
|
24
|
-
core.middleware(self)
|
25
|
-
end
|
26
|
-
|
27
|
-
# A stub method that subclasses can override to handle initialization
|
28
|
-
# For initialization
|
29
|
-
# @return [void]
|
30
|
-
def init(*args)
|
31
|
-
end
|
32
|
-
|
33
|
-
# The standard Rack "call". By default, Orange Middleware wraps the env into
|
34
|
-
# an Orange::Packet and passes it on to #packet_call. Subclasses will typically
|
35
|
-
# override packet_call rather than overriding call directly.
|
36
|
-
#
|
37
|
-
# Orange Middleware
|
38
|
-
# should expect to have this method ignored by upstream Orange-aware apps in
|
39
|
-
# favor of calling packet_call directly.
|
40
|
-
# @param [Hash] env the hash of environment variables given by the rack interface.
|
41
|
-
# @return [Array] the standard Rack striplet of status, headers and content
|
42
|
-
def call(env)
|
43
|
-
packet = Orange::Packet.new(@core, env)
|
44
|
-
packet_call(packet)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Like the standard call, but with the env hash already wrapped into a Packet
|
48
|
-
# This is called automatically as part of #call, so subclasses can have a packet
|
49
|
-
# without having to initialize it. It will be called directly by Orange-aware
|
50
|
-
# upstream middleware, skipping the step of initializing the packet during #call.
|
51
|
-
#
|
52
|
-
# Passing the packet downstream should be done with #pass rather than the Rack
|
53
|
-
# standard @app.call, since #pass will take the packet and do a #packet_call
|
54
|
-
# if possible.
|
55
|
-
# @param [Orange::Packet] packet the packet corresponding to this env
|
56
|
-
# @return [Array] the standard Rack striplet of status, headers and content
|
57
|
-
def packet_call(packet)
|
58
|
-
pass packet
|
59
|
-
end
|
60
|
-
|
61
|
-
# Pass will sent the packet to the downstream app by calling call or packet call.
|
62
|
-
# Calling pass on a packet is the preferred way to call downstream apps, as it
|
63
|
-
# will call packet_call directly if possible (to avoid reinitializing the packet)
|
64
|
-
# @param [Orange::Packet] packet the packet to pass to downstream apps
|
65
|
-
# @return [Array] the standard Rack striplet of status, headers and content
|
66
|
-
def pass(packet)
|
67
|
-
if @app.respond_to?(:packet_call)
|
68
|
-
@app.packet_call(packet)
|
69
|
-
else
|
70
|
-
recapture(@app.call(packet.env), packet)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# After the pass has been completed, we should recapture the contents and make
|
75
|
-
# sure they are placed in the packet, in case the downstream app is not Orange aware.
|
76
|
-
# @param [Array] the standard Rack striplet of status, headers and content
|
77
|
-
# @param [Orange::Packet] packet the packet to pass to downstream apps
|
78
|
-
# @return [Array] the standard Rack striplet of status, headers and content
|
79
|
-
def recapture(response, packet)
|
80
|
-
packet[:status] = response[0]
|
81
|
-
packet[:headers] = response[1]
|
82
|
-
packet[:content] = response[2].first
|
83
|
-
response
|
84
|
-
end
|
85
|
-
|
86
|
-
# Accessor for @core, which is the stack's instance of Orange::Core
|
87
|
-
# @return [Orange::Core] the stack's instance of Orange::Core
|
88
|
-
def orange; @core; end
|
89
|
-
|
90
|
-
# Help stack traces
|
91
|
-
# @return [String] string representing this middleware (#to_s)
|
92
|
-
def inspect
|
93
|
-
self.to_s
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'orange-core/middleware/base'
|
2
|
-
module Orange::Middleware
|
3
|
-
|
4
|
-
class Database < Base
|
5
|
-
def init(opts = {})
|
6
|
-
opts = opts.with_defaults(:migration_url => (orange.options[:development_mode] ? '/__ORANGE_DB__/migrate' : false), :no_auto_upgrade => false)
|
7
|
-
orange.mixin Orange::Mixins::DBLoader
|
8
|
-
@options = opts
|
9
|
-
end
|
10
|
-
|
11
|
-
def stack_init
|
12
|
-
unless orange.options.has_key?('database') && orange.options['database'] == false
|
13
|
-
db = orange.options['database'] || 'sqlite3::memory:'
|
14
|
-
orange.load_db!(db)
|
15
|
-
orange.upgrade_db! unless @options[:no_auto_upgrade] || orange.options['db_no_auto_upgrade']
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def packet_call(packet)
|
20
|
-
path = packet['route.path'] || packet.request.path_info
|
21
|
-
if @options[:migration_url] && @options[:migration_url] == path
|
22
|
-
orange.migrate_db!
|
23
|
-
after = packet.flash('redirect_to') || '/'
|
24
|
-
packet.reroute(after)
|
25
|
-
end
|
26
|
-
pass packet
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
module Orange::Mixins::DBLoader
|
33
|
-
def load_db!(url)
|
34
|
-
DataMapper.setup(:default, url)
|
35
|
-
end
|
36
|
-
|
37
|
-
def migrate_db!
|
38
|
-
DataMapper.auto_migrate!
|
39
|
-
end
|
40
|
-
|
41
|
-
def upgrade_db!
|
42
|
-
DataMapper.auto_upgrade!
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'orange-core/middleware/base'
|
2
|
-
|
3
|
-
module Orange::Middleware
|
4
|
-
# The FlexRouter middleware takes a resource that can route paths and
|
5
|
-
# then intercepts routes for that resource. By default,
|
6
|
-
# it uses the Orange::SitemapResource.
|
7
|
-
#
|
8
|
-
# The resource is automatically loaded into the core as
|
9
|
-
# :sitemap. The resource must respond to "route?(path)"
|
10
|
-
# and "route(packet)".
|
11
|
-
#
|
12
|
-
# Pass a different routing resource using the :resource arg
|
13
|
-
class FourOhFour < Base
|
14
|
-
def init(opts = {})
|
15
|
-
@resource = opts[:resource] || Orange::NotFound
|
16
|
-
orange.load @resource.new, :not_found
|
17
|
-
orange.add_pulp Orange::Pulp::NotFoundHelper
|
18
|
-
end
|
19
|
-
|
20
|
-
# Sets the sitemap resource as the router if the resource can accept
|
21
|
-
# the path.
|
22
|
-
def packet_call(packet)
|
23
|
-
packet['route.router'] = orange[:not_found] unless packet['route.router']
|
24
|
-
begin
|
25
|
-
pass packet
|
26
|
-
rescue Orange::NotFoundException
|
27
|
-
orange[:not_found].route(packet)
|
28
|
-
packet.finish
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module Orange
|
36
|
-
class NotFoundException < Exception
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
module Pulp::NotFoundHelper
|
41
|
-
def not_found
|
42
|
-
raise Orange::NotFoundException.new
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|