Class: Orange::Resource
Overview
Orange Resource for being subclassed
Direct Known Subclasses
AdminResource, AnalyticsResource, CloudResource, DisqusResource, Mapper, NotFound, PageParts, Parser, Radius, RoutableResource, Scaffold, Slices
Class Method Summary
collapse
Instance Method Summary
collapse
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.
11
12
13
|
# File 'lib/orange-core/resource.rb', line 11
def initialize(*args, &block)
@options = DefaultHash.new.merge!(Options.new(*args, &block).hash)
end
|
Class Method Details
.call_me(name) ⇒ Object
34
35
36
|
# File 'lib/orange-core/resource.rb', line 34
def self.call_me(name)
self.called = name
end
|
.set_orange(*args) ⇒ Object
23
24
25
|
# File 'lib/orange-core/resource.rb', line 23
def self.set_orange(*args)
raise 'instantiate the resource before calling set orange'
end
|
Instance Method Details
#afterLoad ⇒ Object
31
32
|
# File 'lib/orange-core/resource.rb', line 31
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.
64
65
66
67
|
# File 'lib/orange-core/resource.rb', line 64
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
92
93
94
|
# File 'lib/orange-core/resource.rb', line 92
def (packet, mode)
{}
end
|
27
28
29
|
# File 'lib/orange-core/resource.rb', line 27
def init
afterLoad
end
|
54
55
56
|
# File 'lib/orange-core/resource.rb', line 54
def options
@options
end
|
38
39
40
|
# File 'lib/orange-core/resource.rb', line 38
def orange
@orange
end
|
#orange_name ⇒ Object
50
51
52
|
# File 'lib/orange-core/resource.rb', line 50
def orange_name
@my_orange_name || self.class.called || false
end
|
42
43
44
|
# File 'lib/orange-core/resource.rb', line 42
def routable
false
end
|
#set_orange(orange, name) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/orange-core/resource.rb', line 15
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
46
47
48
|
# File 'lib/orange-core/resource.rb', line 46
def view(packet = false, *args)
''
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.
79
80
81
82
83
84
|
# File 'lib/orange-core/resource.rb', line 79
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
|