orange 0.2.4 → 0.2.5
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-core/application.rb +7 -4
- data/lib/orange-core/core.rb +7 -2
- data/lib/orange-core/middleware/template.rb +6 -6
- data/lib/orange-core/stack.rb +6 -2
- data/lib/orange-more/news/resources/news_resource.rb +1 -1
- data/lib/orange-more/slices/middleware/radius_parser.rb +1 -1
- data/lib/orange-more/slices/resources/radius.rb +5 -0
- data/lib/orange-more/testimonials/resources/testimonials_resource.rb +5 -3
- metadata +3 -3
@@ -19,7 +19,7 @@ module Orange
|
|
19
19
|
@core = core || self.class.core
|
20
20
|
@options ||= {}
|
21
21
|
@options = Orange::Options.new(*opts, &block).hash.with_defaults(self.class.opts)
|
22
|
-
core.application(self) # Register self into core
|
22
|
+
@core.application(self) # Register self into core
|
23
23
|
init
|
24
24
|
end
|
25
25
|
|
@@ -106,9 +106,12 @@ module Orange
|
|
106
106
|
# Returns an instance of Orange::Stack to be run by Rack
|
107
107
|
#
|
108
108
|
# Usually, you'll call this in the rackup file: `run MyApplication.app`
|
109
|
-
def self.app(
|
110
|
-
|
111
|
-
|
109
|
+
def self.app(c = false)
|
110
|
+
if c
|
111
|
+
self.core = c
|
112
|
+
else
|
113
|
+
self.core ||= Orange::Core.new
|
114
|
+
end
|
112
115
|
return self.core.stack unless self.core.stack.blank?
|
113
116
|
if self.stack_block.instance_of?(Proc)
|
114
117
|
Orange::Stack.new self, self.core, &self.stack_block # turn saved proc into a block arg
|
data/lib/orange-core/core.rb
CHANGED
@@ -156,11 +156,16 @@ module Orange
|
|
156
156
|
end
|
157
157
|
|
158
158
|
# Takes an instance of Orange::Stack and saves it.
|
159
|
-
def stack(
|
160
|
-
@stack =
|
159
|
+
def stack(new_stack = false)
|
160
|
+
@stack = new_stack if new_stack
|
161
161
|
@stack
|
162
162
|
end
|
163
163
|
|
164
|
+
# Takes an instance of Orange::Stack and saves it.
|
165
|
+
def stack=(new_stack)
|
166
|
+
@stack = new_stack
|
167
|
+
end
|
168
|
+
|
164
169
|
# Convenience self for consistent naming across middleware
|
165
170
|
# @return [Orange::Core] self
|
166
171
|
def orange; self; end
|
@@ -8,10 +8,6 @@ module Orange::Middleware
|
|
8
8
|
@core.add_pulp(Orange::Pulp::Template)
|
9
9
|
@core.mixin(Orange::Mixins::Template)
|
10
10
|
|
11
|
-
# Establish a default template chooser
|
12
|
-
@core.template_chooser do |packet|
|
13
|
-
false
|
14
|
-
end
|
15
11
|
end
|
16
12
|
|
17
13
|
def packet_call(packet)
|
@@ -51,9 +47,13 @@ end
|
|
51
47
|
|
52
48
|
module Orange::Mixins::Template
|
53
49
|
def template_for(packet)
|
54
|
-
|
50
|
+
template_chooser.call(packet)
|
55
51
|
end
|
56
52
|
def template_chooser(&block)
|
57
|
-
|
53
|
+
if block_given?
|
54
|
+
@template_chooser = Proc.new
|
55
|
+
else
|
56
|
+
@template_chooser ||= Proc.new {|packet| false}
|
57
|
+
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/orange-core/stack.rb
CHANGED
@@ -29,6 +29,7 @@ module Orange
|
|
29
29
|
def initialize(app_class = nil, core = false, prebuilt = :none, &block)
|
30
30
|
@build = Rack::Builder.new
|
31
31
|
@core = core || Orange::Core.new
|
32
|
+
@core.stack = self # Set a back reference in the core.
|
32
33
|
@auto_reload = false
|
33
34
|
@app = false
|
34
35
|
@middleware = []
|
@@ -200,13 +201,16 @@ module Orange
|
|
200
201
|
@app = false # Rebuild no matter what if autoload
|
201
202
|
end
|
202
203
|
unless @app
|
203
|
-
@app =
|
204
|
-
orange.stack self
|
204
|
+
@app = do_build # Build if necessary
|
205
205
|
orange.fire(:stack_loaded, @app)
|
206
206
|
end
|
207
207
|
@app
|
208
208
|
end
|
209
209
|
|
210
|
+
def do_build
|
211
|
+
@build.to_app
|
212
|
+
end
|
213
|
+
|
210
214
|
# Sets the core and then passes on to the stack, according to standard
|
211
215
|
# rack procedure
|
212
216
|
def call(env)
|
@@ -4,7 +4,7 @@ module Orange
|
|
4
4
|
call_me :news
|
5
5
|
def stack_init
|
6
6
|
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'News')
|
7
|
-
orange[:radius, true].
|
7
|
+
orange[:radius, true].define_tag "latest_news" do |tag|
|
8
8
|
orange[:news].latest(tag.locals.packet)
|
9
9
|
end
|
10
10
|
end
|
@@ -4,6 +4,7 @@ module Orange
|
|
4
4
|
# Radius resource is for exposing the Radius context
|
5
5
|
# and allowing parsing.
|
6
6
|
class Radius < Resource
|
7
|
+
call_me :radius
|
7
8
|
def afterLoad
|
8
9
|
@context = ::Radius::Context.new
|
9
10
|
orange.fire(:radius_loaded, self)
|
@@ -13,6 +14,10 @@ module Orange
|
|
13
14
|
@context
|
14
15
|
end
|
15
16
|
|
17
|
+
def define_tag(*args, &block)
|
18
|
+
@context.define_tag(*args, &block)
|
19
|
+
end
|
20
|
+
|
16
21
|
def parse(packet)
|
17
22
|
content = packet[:content, false]
|
18
23
|
unless content.blank?
|
@@ -4,14 +4,15 @@ module Orange
|
|
4
4
|
call_me :testimonials
|
5
5
|
def stack_init
|
6
6
|
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
|
7
|
-
orange[:radius].
|
7
|
+
orange[:radius].define_tag "testimonials" do |tag|
|
8
8
|
if tag.attr["tag"] && model_class.all.count >0
|
9
9
|
m = model_class.with_tag(tag.attr["tag"]).first(:offset => rand(model_class.with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag
|
10
10
|
elsif model_class.all.count > 0
|
11
11
|
m = model_class.first(:offset => rand(model_class.all.count)) #selects a random testimonial
|
12
12
|
end
|
13
13
|
unless m.nil?
|
14
|
-
|
14
|
+
template = tag.attr["template"] || "testimonials"
|
15
|
+
orange[:testimonials].testimonial(tag.locals.packet, {:model => m, :template => template})
|
15
16
|
else
|
16
17
|
""
|
17
18
|
end
|
@@ -19,7 +20,8 @@ module Orange
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def testimonial(packet, opts = {})
|
22
|
-
|
23
|
+
template = opts[:template].to_sym || :testimonials
|
24
|
+
do_view(packet, template, opts)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Haslem
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-07 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|