Class: FatFreeCRM::ViewFactory
- Inherits:
-
Object
- Object
- FatFreeCRM::ViewFactory
- Includes:
- Comparable
- Defined in:
- lib/fat_free_crm/view_factory.rb
Overview
A view factory keeps track of views and the contexts in which they are available.
The context that a view is available for is defined by ‘controllers’ and ‘actions’
controllers => ['contacts'] means that the view is available when the contacts controller is used
actions => [:index, show] means that the view is available for search listings AND individual records
template => 'contacts/index_full' is the partial that is rendered for this view
Icon is optional. If specified, it will be passed to asset_path.
Constant Summary collapse
- @@views =
[]
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#controllers ⇒ Object
Returns the value of attribute controllers.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#template ⇒ Object
Returns the value of attribute template.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
-
.register(view) ⇒ Object
Register with the view factory —————————————————————————-.
-
.template_for_current_view(options = {}) ⇒ Object
Return template name of the current view pass in options to specify view name —————————————————————————-.
-
.views_for(options = {}) ⇒ Object
Return views that are available based on context —————————————————————————-.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Define view equivalence.
-
#initialize(options = {}) ⇒ ViewFactory
constructor
Instance methods —————————————————————————-.
Constructor Details
#initialize(options = {}) ⇒ ViewFactory
Instance methods
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fat_free_crm/view_factory.rb', line 54 def initialize( = {}) self.name = [:name] self.title = [:title] self.icon = [:icon] # optional self.controllers = [:controllers] || [] self.actions = [:actions] || [] self.template = [:template] self.id = generate_id self.class.register(self) end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def actions @actions end |
#controllers ⇒ Object
Returns the value of attribute controllers.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def controllers @controllers end |
#icon ⇒ Object
Returns the value of attribute icon.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def icon @icon end |
#id ⇒ Object
Returns the value of attribute id.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def name @name end |
#template ⇒ Object
Returns the value of attribute template.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def template @template end |
#title ⇒ Object
Returns the value of attribute title.
21 22 23 |
# File 'lib/fat_free_crm/view_factory.rb', line 21 def title @title end |
Class Method Details
.register(view) ⇒ Object
Register with the view factory
28 29 30 |
# File 'lib/fat_free_crm/view_factory.rb', line 28 def register(view) @@views << view unless @@views.map(&:id).include?(view.id) end |
.template_for_current_view(options = {}) ⇒ Object
Return template name of the current view pass in options to specify view name
46 47 48 49 |
# File 'lib/fat_free_crm/view_factory.rb', line 46 def template_for_current_view( = {}) view = views_for().first view && view.template end |
.views_for(options = {}) ⇒ Object
Return views that are available based on context
34 35 36 37 38 39 40 41 |
# File 'lib/fat_free_crm/view_factory.rb', line 34 def views_for( = {}) controller = [:controller] action = [:action] name = [:name] # optional @@views.select do |view| view.controllers.include?(controller) && view.actions.include?(action) && (name.present? ? view.name == name : true) end end |
Instance Method Details
#<=>(other) ⇒ Object
Define view equivalence. They are the same if they have the same id.
67 68 69 |
# File 'lib/fat_free_crm/view_factory.rb', line 67 def <=>(other) id <=> other.id end |