class FatFreeCRM::ViewFactory
A view factory keeps track of views and the contexts in which they are available.
Attributes
actions[RW]
controllers[RW]
icon[RW]
id[RW]
name[RW]
template[RW]
title[RW]
Public Class Methods
new(options = {})
click to toggle source
Instance methods
# File lib/fat_free_crm/view_factory.rb, line 56 def initialize(options = {}) self.name = options[:name] self.title = options[:title] self.icon = options[:icon] # optional self.controllers = options[:controllers] || [] self.actions = options[:actions] || [] self.template = options[:template] self.id = generate_id self.class.register(self) end
register(view)
click to toggle source
Register with the view factory
# File lib/fat_free_crm/view_factory.rb, line 30 def register(view) @@views << view unless @@views.map(&:id).include?(view.id) end
template_for_current_view(options = {})
click to toggle source
Return template name of the current view pass in options to specify view name
# File lib/fat_free_crm/view_factory.rb, line 48 def template_for_current_view(options = {}) view = views_for(options).first view&.template end
views_for(options = {})
click to toggle source
Return views that are available based on context
# File lib/fat_free_crm/view_factory.rb, line 36 def views_for(options = {}) controller = options[:controller] action = options[:action] name = options[:name] # optional @@views.select do |view| view.controllers.include?(controller) && view.actions.include?(action) && (name.present? ? view.name == name : true) end end
Public Instance Methods
<=>(other)
click to toggle source
Define view equivalence. They are the same if they have the same id.
# File lib/fat_free_crm/view_factory.rb, line 69 def <=>(other) id <=> other.id end
Private Instance Methods
generate_id()
click to toggle source
This defines what it means for one view to be different to another
# File lib/fat_free_crm/view_factory.rb, line 77 def generate_id [name, controllers.sort, actions.sort].flatten.map(&:to_s).map(&:underscore).join('_') end