Class: Card::Layout
- Inherits:
-
Object
show all
- Defined in:
- lib/card/layout.rb,
lib/card/layout/card_layout.rb,
lib/card/layout/code_layout.rb,
lib/card/layout/proc_layout.rb,
lib/card/layout/unknown_layout.rb
Overview
support class for layout wrappers
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.
82
83
84
85
|
# File 'lib/card/layout.rb', line 82
def initialize layout, format
@layout = layout
@format = format
end
|
Class Method Details
.built_in_layouts ⇒ Object
57
58
59
|
# File 'lib/card/layout.rb', line 57
def built_in_layouts
built_in_layouts_hash.keys
end
|
.built_in_layouts_hash ⇒ Object
53
54
55
|
# File 'lib/card/layout.rb', line 53
def built_in_layouts_hash
@built_in_layouts_hash ||= {}
end
|
.card_layout?(name) ⇒ Boolean
21
22
23
24
25
|
# File 'lib/card/layout.rb', line 21
def card_layout? name
Card.fetch_type_id(name).in? [LayoutTypeID, HtmlID, BasicID]
rescue ArgumentError, Card::Error::CodenameNotFound => _e
false
end
|
.clear_cache ⇒ Object
65
66
67
|
# File 'lib/card/layout.rb', line 65
def clear_cache
@built_in_layouts = @layouts = nil
end
|
.code_layout?(name) ⇒ Boolean
27
28
29
|
# File 'lib/card/layout.rb', line 27
def code_layout? name
built_in_layouts_hash.key? name.to_sym
end
|
.deregister_layout(layout_name) ⇒ Object
38
39
40
|
# File 'lib/card/layout.rb', line 38
def deregister_layout layout_name
layouts.delete layout_key(layout_name)
end
|
.layout_class(layout) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/card/layout.rb', line 9
def layout_class layout
if layout.respond_to? :call
ProcLayout
elsif card_layout? layout
CardLayout
elsif code_layout? layout
CodeLayout
else
UnknownLayout
end
end
|
.layout_key(name) ⇒ Object
42
43
44
45
46
|
# File 'lib/card/layout.rb', line 42
def layout_key name
return name if name.is_a? Symbol
name.to_name.key.to_sym
end
|
.layouts ⇒ Object
61
62
63
|
# File 'lib/card/layout.rb', line 61
def layouts
@layouts ||= {}
end
|
.main_nest_opts(layout_name, format) ⇒ Object
69
70
71
72
73
|
# File 'lib/card/layout.rb', line 69
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
48
49
50
51
|
# File 'lib/card/layout.rb', line 48
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
31
32
33
34
35
36
|
# File 'lib/card/layout.rb', line 31
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
75
76
77
78
79
|
# File 'lib/card/layout.rb', line 75
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
5
6
7
|
# File 'lib/card/layout.rb', line 5
def render layout, format
layout_class(layout).new(layout, format).render
end
|
Instance Method Details
#fetch_main_nest_opts ⇒ Object
87
88
89
|
# File 'lib/card/layout.rb', line 87
def fetch_main_nest_opts
{}
end
|
#main_nest_opts ⇒ Object
91
92
93
|
# File 'lib/card/layout.rb', line 91
def main_nest_opts
self.class.main_nest_opts @layout, @format
end
|