Class: Refinery::Plugin
- Inherits:
-
Object
- Object
- Refinery::Plugin
- Defined in:
- lib/refinery/plugin.rb
Instance Attribute Summary collapse
-
#always_allow_access ⇒ Object
Returns the value of attribute always_allow_access.
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#hide_from_menu ⇒ Object
Returns the value of attribute hide_from_menu.
-
#menu_match ⇒ Object
Returns the value of attribute menu_match.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pathname ⇒ Object
Returns the value of attribute pathname.
-
#url ⇒ Object
Returns a hash that can be used to create a url that points to the administration part of the plugin.
Class Method Summary collapse
Instance Method Summary collapse
-
#description ⇒ Object
Returns the internationalized version of the description.
-
#highlighted?(params) ⇒ Boolean
Used to highlight the current tab in the admin interface.
-
#initialize ⇒ Plugin
constructor
A new instance of Plugin.
- #landable? ⇒ Boolean
-
#title ⇒ Object
Returns the internationalized version of the title.
Constructor Details
#initialize ⇒ Plugin
Returns a new instance of Plugin.
59 60 61 62 63 |
# File 'lib/refinery/plugin.rb', line 59 def initialize # provide a default pathname to where this plugin is using its lib directory. depth = 4 self.pathname ||= Pathname.new(caller(depth).first.match("(.*)#{File::SEPARATOR}lib")[1]) end |
Instance Attribute Details
#always_allow_access ⇒ Object
Returns the value of attribute always_allow_access.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def always_allow_access @always_allow_access end |
#class_name ⇒ Object
Returns the value of attribute class_name.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def class_name @class_name end |
#controller ⇒ Object
Returns the value of attribute controller.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def controller @controller end |
#directory ⇒ Object
Returns the value of attribute directory.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def directory @directory end |
#hide_from_menu ⇒ Object
Returns the value of attribute hide_from_menu.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def @hide_from_menu end |
#menu_match ⇒ Object
Returns the value of attribute menu_match.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def @menu_match end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def name @name end |
#pathname ⇒ Object
Returns the value of attribute pathname.
4 5 6 |
# File 'lib/refinery/plugin.rb', line 4 def pathname @pathname end |
#url ⇒ Object
Returns a hash that can be used to create a url that points to the administration part of the plugin.
47 48 49 |
# File 'lib/refinery/plugin.rb', line 47 def url @url end |
Class Method Details
.register {|plugin = new| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/refinery/plugin.rb', line 8 def self.register(&_block) yield(plugin = new) raise ArgumentError, "A plugin MUST have a name!: #{plugin.inspect}" if plugin.name.blank? # Set defaults. plugin. ||= %r{refinery/#{plugin.name}(/.+?)?$} plugin.always_allow_access ||= false plugin.class_name ||= plugin.name.camelize # add the new plugin to the collection of registered plugins ::Refinery::Plugins.registered.unshift(plugin).uniq!(&:name) end |
Instance Method Details
#description ⇒ Object
Returns the internationalized version of the description
28 29 30 |
# File 'lib/refinery/plugin.rb', line 28 def description ::I18n.translate(['refinery', 'plugins', name, 'description'].join('.')) end |
#highlighted?(params) ⇒ Boolean
Used to highlight the current tab in the admin interface
33 34 35 |
# File 'lib/refinery/plugin.rb', line 33 def highlighted?(params) !!(params[:controller].try(:gsub, "admin/", "") =~ ) end |
#landable? ⇒ Boolean
42 43 44 |
# File 'lib/refinery/plugin.rb', line 42 def landable? ! && url.present? end |
#title ⇒ Object
Returns the internationalized version of the title
23 24 25 |
# File 'lib/refinery/plugin.rb', line 23 def title ::I18n.translate(['refinery', 'plugins', name, 'title'].join('.')) end |