Class: Card::Layout
- Inherits:
-
Object
show all
- Defined in:
- mod/layout/lib/card/layout.rb,
mod/layout/lib/card/layout/card_layout.rb,
mod/layout/lib/card/layout/code_layout.rb,
mod/layout/lib/card/layout/proc_layout.rb,
mod/layout/lib/card/layout/unknown_layout.rb more...
Defined Under Namespace
Classes: CardLayout, CodeLayout, ProcLayout, UnknownLayout
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(layout, format) ⇒ Layout
Returns a new instance of Layout.
[View source]
81
82
83
84
|
# File 'mod/layout/lib/card/layout.rb', line 81
def initialize layout, format
@layout = layout
@format = format
end
|
Class Method Details
.built_in_layouts ⇒ Object
[View source]
56
57
58
|
# File 'mod/layout/lib/card/layout.rb', line 56
def built_in_layouts
built_in_layouts_hash.keys
end
|
.built_in_layouts_hash ⇒ Object
[View source]
52
53
54
|
# File 'mod/layout/lib/card/layout.rb', line 52
def built_in_layouts_hash
@built_in_layouts ||= {}
end
|
.clear_cache ⇒ Object
[View source]
64
65
66
|
# File 'mod/layout/lib/card/layout.rb', line 64
def clear_cache
@built_in_layouts = @layouts = nil
end
|
.code_layout?(name) ⇒ Boolean
[View source]
26
27
28
|
# File 'mod/layout/lib/card/layout.rb', line 26
def code_layout? name
built_in_layouts_hash.key? name.to_sym
end
|
.deregister_layout(layout_name) ⇒ Object
[View source]
37
38
39
|
# File 'mod/layout/lib/card/layout.rb', line 37
def deregister_layout layout_name
layouts.delete layout_key(layout_name)
end
|
.layout_key(name) ⇒ Object
[View source]
41
42
43
44
45
|
# File 'mod/layout/lib/card/layout.rb', line 41
def layout_key name
return name if name.is_a? Symbol
name.to_name.key.to_sym
end
|
[View source]
60
61
62
|
# File 'mod/layout/lib/card/layout.rb', line 60
def layouts
@layouts ||= {}
end
|
.main_nest_opts(layout_name, format) ⇒ Object
[View source]
68
69
70
71
72
|
# File 'mod/layout/lib/card/layout.rb', line 68
def main_nest_opts layout_name, format
key = layout_key layout_name
opts = layouts[key] || register_layout_with_nest(layout_name, format)
opts.clone
end
|
.register_built_in_layout(new_layout, opts) ⇒ Object
[View source]
47
48
49
50
|
# File 'mod/layout/lib/card/layout.rb', line 47
def register_built_in_layout new_layout, opts
register_layout(new_layout) { opts.present? ? opts : nil }
built_in_layouts_hash[new_layout] = true
end
|
.register_layout(new_layout) ⇒ Object
[View source]
30
31
32
33
34
35
|
# File 'mod/layout/lib/card/layout.rb', line 30
def register_layout new_layout
key = layout_key new_layout
return if layouts[key]
layouts[key] = block_given? ? yield : {}
end
|
.register_layout_with_nest(layout_name, format) ⇒ Object
[View source]
74
75
76
77
78
|
# File 'mod/layout/lib/card/layout.rb', line 74
def register_layout_with_nest layout_name, format
register_layout(layout_name) do
layout_class(layout_name).new(layout_name, format).fetch_main_nest_opts
end
end
|
.render(layout, format) ⇒ Object
[View source]
4
5
6
|
# File 'mod/layout/lib/card/layout.rb', line 4
def render layout, format
layout_class(layout).new(layout, format).render
end
|
Instance Method Details
#fetch_main_nest_opts ⇒ Object
[View source]
86
87
88
|
# File 'mod/layout/lib/card/layout.rb', line 86
def fetch_main_nest_opts
{}
end
|
#main_nest_opts ⇒ Object
[View source]
90
91
92
|
# File 'mod/layout/lib/card/layout.rb', line 90
def main_nest_opts
self.class.main_nest_opts @layout, @format
end
|