Module: Card::Set::Format::AbstractFormat
Overview
All Format modules are extended with this module in order to support
the basic format API (ok, view definitions. It's just view
definitions.)
No longer just view definitions. Also basket definitions now.
Instance Method Summary
collapse
Methods included from HamlViews
#haml_template_path, #haml_template_render_block, #haml_template_render_block_with_locals, #haml_to_html, #haml_view_block, #try_haml_template_path
Methods included from Basket
#abstract_basket, #add_to_basket, #basket
Instance Method Details
100
101
102
103
104
|
# File 'lib/card/set/format.rb', line 100
def view, cache_rule
return unless cache_rule
methodname = Card::Format.view_cache_setting_method view
define_method(methodname) { cache_rule }
end
|
#haml_view?(args) ⇒ Boolean
111
112
113
|
# File 'lib/card/set/format.rb', line 111
def haml_view? args
args.first.is_a?(Hash) && args.first[:template] == :haml
end
|
#interpret_view_opts(view, opts) ⇒ Object
94
95
96
97
98
|
# File 'lib/card/set/format.rb', line 94
def interpret_view_opts view, opts
return unless opts.present?
Card::Format.interpret_view_opts view, opts
view, opts.delete(:cache)
end
|
#lookup_alias_block(view, args) ⇒ Object
115
116
117
118
119
120
121
122
123
|
# File 'lib/card/set/format.rb', line 115
def lookup_alias_block view, args
opts = args[0].is_a?(Hash) ? args.shift : { view: args.shift }
opts[:mod] ||= self
opts[:view] ||= view
views[opts[:mod]][opts[:view]] || begin
raise "cannot find #{opts[:view]} view in #{opts[:mod]}; " \
"failed to alias #{view} in #{self}"
end
end
|
#set_module ⇒ Object
remove the format part of the module name
130
131
132
|
# File 'lib/card/set/format.rb', line 130
def set_module
Card.const_get name.split("::")[0..-2].join("::")
end
|
#source_location ⇒ Object
125
126
127
|
# File 'lib/card/set/format.rb', line 125
def source_location
set_module.source_location
end
|
#view(view, *args, &block) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/card/set/format.rb', line 86
def view view, *args, &block
view = view.to_viewname.key.to_sym
views[self] ||= {}
interpret_view_opts view, args[0] if block_given?
view_block = views[self][view] = view_block view, args, &block
define_method "_view_#{view}", view_block
end
|
#view_block(view, args, &block) ⇒ Object
106
107
108
109
|
# File 'lib/card/set/format.rb', line 106
def view_block view, args, &block
return haml_view_block(view, &block) if haml_view?(args)
block_given? ? block : lookup_alias_block(view, args)
end
|