Class: Orange::Resource
Overview
Orange Resource for being subclassed
Class Method Summary
collapse
Instance Method Summary
collapse
-
#afterLoad ⇒ Object
-
#do_view(packet, mode, *args) ⇒ String
Renders a view, with all options set for haml to access.
-
#find_extras(packet, mode) ⇒ Hash
Returns a hash of extra options to be set and made available by the haml parser.
-
#init ⇒ Object
-
#initialize(*args, &block) ⇒ Resource
constructor
A new instance of Resource.
-
#nests ⇒ Object
-
#options ⇒ Object
-
#orange ⇒ Object
-
#orange_name ⇒ Object
-
#routable ⇒ Object
-
#set_orange(orange, name) ⇒ Object
-
#view(packet = false, *args) ⇒ Object
-
#view_opts(packet, mode, *args) ⇒ Hash
Returns the options for including in template rendering.
-
#viewable(packet, mode, opts = {}) ⇒ Object
cattr_accessor, cattr_reader, cattr_writer, eval_in_accessor_module, fetch_value, store_value
Constructor Details
#initialize(*args, &block) ⇒ Resource
Returns a new instance of Resource.
21
22
23
24
|
# File 'lib/orange-core/resource.rb', line 21
def initialize(*args, &block)
@options = DefaultHash.new.merge!(Options.new(*args, &block).hash)
self.class.viewable_actions ||= []
end
|
Class Method Details
.call_me(name) ⇒ Object
45
46
47
|
# File 'lib/orange-core/resource.rb', line 45
def self.call_me(name)
self.called = name
end
|
.set_orange(*args) ⇒ Object
34
35
36
|
# File 'lib/orange-core/resource.rb', line 34
def self.set_orange(*args)
raise 'instantiate the resource before calling set orange'
end
|
.viewable(*args) ⇒ Object
16
17
18
19
|
# File 'lib/orange-core/resource.rb', line 16
def self.viewable(*args)
self.viewable_actions ||= []
args.each{|arg| self.viewable_actions << arg}
end
|
Instance Method Details
#afterLoad ⇒ Object
42
43
|
# File 'lib/orange-core/resource.rb', line 42
def afterLoad
end
|
#do_view(packet, mode, *args) ⇒ String
Renders a view, with all options set for haml to access. Calls #view_opts to generate the haml options.
89
90
91
92
|
# File 'lib/orange-core/resource.rb', line 89
def do_view(packet, mode, *args)
haml_opts = view_opts(packet, mode, *args)
orange[:parser].haml("#{mode.to_s}.haml", packet, haml_opts)
end
|
Returns a hash of extra options to be set and made available by the haml parser. Overriding this method is useful for passing extra bits of info to rendering for certain view modes without rewriting all of the other scaffolding
117
118
119
|
# File 'lib/orange-core/resource.rb', line 117
def (packet, mode)
{}
end
|
38
39
40
|
# File 'lib/orange-core/resource.rb', line 38
def init
afterLoad
end
|
12
13
14
|
# File 'lib/orange-core/resource.rb', line 12
def nests
{}
end
|
79
80
81
|
# File 'lib/orange-core/resource.rb', line 79
def options
@options
end
|
49
50
51
|
# File 'lib/orange-core/resource.rb', line 49
def orange
@orange
end
|
#orange_name ⇒ Object
75
76
77
|
# File 'lib/orange-core/resource.rb', line 75
def orange_name
@my_orange_name || self.class.called || false
end
|
53
54
55
|
# File 'lib/orange-core/resource.rb', line 53
def routable
false
end
|
#set_orange(orange, name) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/orange-core/resource.rb', line 26
def set_orange(orange, name)
@orange = orange
@my_orange_name = name
init
orange.register(:stack_loaded) { |s| stack_init } if self.respond_to? :stack_init
self
end
|
#view(packet = false, *args) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/orange-core/resource.rb', line 57
def view(packet = false, *args)
opts = args.
my_action = packet['route.resource_action'] if packet
action = opts[:mode] || opts[:resource_action] || my_action || :index
viewable(packet, action, opts)
end
|
#view_opts(packet, mode, *args) ⇒ Hash
Returns the options for including in template rendering. All keys passed in the args array will automatically be local variables in the haml template. In addition, the props, resource, and model_name variables will be available.
104
105
106
107
108
109
|
# File 'lib/orange-core/resource.rb', line 104
def view_opts(packet, mode, *args)
opts = args..with_defaults({:path => ''})
all_opts = {:resource => self, :model_name => @my_orange_name}.merge!(opts)
all_opts.with_defaults! (packet, mode)
all_opts
end
|
#viewable(packet, mode, opts = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/orange-core/resource.rb', line 64
def viewable(packet, mode, opts={})
self.class.viewable_actions ||= []
if(self.respond_to?(mode))
self.__send__(mode, packet, opts)
elsif(self.class.viewable_actions.include?(mode))
do_view(packet, mode, opts)
else
''
end
end
|