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
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fat_free_crm/view_factory.rb', line 56 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.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def actions @actions end |
#controllers ⇒ Object
Returns the value of attribute controllers.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def controllers @controllers end |
#icon ⇒ Object
Returns the value of attribute icon.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def icon @icon end |
#id ⇒ Object
Returns the value of attribute id.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def name @name end |
#template ⇒ Object
Returns the value of attribute template.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def template @template end |
#title ⇒ Object
Returns the value of attribute title.
23 24 25 |
# File 'lib/fat_free_crm/view_factory.rb', line 23 def title @title end |
Class Method Details
.register(view) ⇒ Object
Register with the view factory
30 31 32 |
# 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 = {}) ⇒ Object
Return template name of the current view pass in options to specify view name
48 49 50 51 |
# File 'lib/fat_free_crm/view_factory.rb', line 48 def template_for_current_view( = {}) view = views_for().first view&.template end |
.views_for(options = {}) ⇒ Object
Return views that are available based on context
36 37 38 39 40 41 42 43 |
# File 'lib/fat_free_crm/view_factory.rb', line 36 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.
69 70 71 |
# File 'lib/fat_free_crm/view_factory.rb', line 69 def <=>(other) id <=> other.id end |