The ysd_core_plugins gem defines a way to extend "any" of your modules or gems.
Following some simple rules, you will have an engine which can be used to extend your applications or gems.
The core plugin brings you a hook system that can be used to extend your gems.
Moreover, you can automatically register sinatra extensions and helpers. This way you application will look cleaner.
The plugin system is made of the following components:
- Plugins::Plugin
- Plugins::Aspect
The Plugins::Plugin class which lets us to define a plugin.
A plugin defines the following properties:
- id
- name
- author
- description
- version
- settings
It also allow to declare the hook classes which can extend other modules. You can do it in the plugin registration.
The method Plugin.register allows registering a new plugin. It receives two parameters, the plugin id and a block which is used to define the plugin.
Plugins::Plugin.register :cms do name= 'cms' author= 'yurak sisa' description= 'CMS integration' version= '0.1' hooker Huasi::CMSExtension # It defines a hook which can extend any module end
The SinatraAppPlugin, is a Plugin subclass which lets us define sinatra extensions and helpers.
Plugins::SinatraAppPlugin.register :cms do name= 'cms' author= 'yurak sisa' description= 'CMS integration' version= '0.1' hooker Huasi::CMSExtension sinatra_extension Sinatra::MyExtension sinatra_helper Sinatra::MyHelper end
To use the plugin system in your sinatra application, you only have to register it extension. All of the registered plugins will be initialized when the extension is registered.
class MySinatraApp < Sinatra::Base register Sinatra::YSD::PluginExtension helper Plugins::HookCall end