mod/standard/lib/card/layout.rb in card-1.97.0 vs mod/standard/lib/card/layout.rb in card-1.97.0.1
- old
+ new
@@ -4,15 +4,15 @@
def render layout, format
layout_class(layout).new(layout, format).render
end
def layout_class layout
- if layout.respond_to?(:call)
+ if layout.respond_to? :call
Card::Layout::ProcLayout
- elsif card_layout?(layout)
+ elsif card_layout? layout
Card::Layout::CardLayout
- elsif code_layout?(layout)
+ elsif code_layout? layout
Card::Layout::CodeLayout
else
Card::Layout::UnknownLayout
end
end
@@ -26,17 +26,27 @@
def code_layout? name
built_in_layouts_hash.key? name.to_sym
end
def register_layout new_layout
- return if layouts[new_layout]
+ key = layout_key new_layout
+ return if layouts[key]
- layouts[new_layout] = block_given? ? yield : {}
+ layouts[key] = block_given? ? yield : {}
end
- def register_built_in_layout new_layout
- register_layout new_layout
+ def deregister_layout layout_name
+ layouts.delete layout_key(layout_name)
+ end
+
+ def layout_key name
+ return name if name.is_a? Symbol
+ name.to_name.key.to_sym
+ end
+
+ def register_built_in_layout new_layout, opts
+ register_layout(new_layout) { opts.present? ? opts : nil }
built_in_layouts_hash[new_layout] = true
end
def built_in_layouts_hash
@built_in_layouts ||= {}
@@ -53,14 +63,18 @@
def clear_cache
@built_in_layouts = @layouts = nil
end
def main_nest_opts layout_name, format
- opts = layouts[layout_name] ||
- register_layout(layout_name) do
- layout_class(layout_name).new(layout_name, format).fetch_main_nest_opts
- end
+ key = layout_key layout_name
+ opts = layouts[key] || register_layout_with_nest(layout_name, format)
opts.clone
+ end
+
+ 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
end
def initialize layout, format
@layout = layout