Creating your own modules
Creating your own modules is a useful way to expand the functionality of BrowserCMS via gems.
Getting Started
Run the following command to generate a basic BrowserCMS application that is ready to turn into a module.
bcms bcms_[module name] -m module
The module template used to create this application will create the following files:
This file prevents files you almost certainly will not want to be added to git to be added to git.
public/bcms/[module name]/README
Explains what this directory is for. It can safely be deleted.
bcms_[module name].gemspec
Creates a gemspec file in case you want to manage the gemspec by hand.
config/initializers/init_module.rb
Requires the following file.
lib/bcms_[module name].rb
Requires the following file.
lib/bcms_[module name]/routes.rb
Has boilerplate code ready in case you have specific routes the application will need to have available. For example, if your module has content blocks that will be managed by the CMS administrative interface, routes for the controllers handling this management will need to be added here.
Adds the gem root to the rails paths, adds all migration files to the list of files that will be copied into any application using the module when script/generate browser_cms is run, and adds all files in public/bcms/bcms_[module name]/ to the list of files that will be copied into any application using the module when script/generate browser_cms is run.
GNU Lesser General Public License
BrowserMedia’s copyright text.
GNU General Public License
Note: the module template was developed primarily for BrowserMedia in-house use. Therefore the license, copywrite, and gemspec files all reflect our organization. Please edit and/or remove these files to fit your needs.
Conventions When Building Your Module
Build your module as if you were building a rails application that does whatever you want.
That said, there are some conventions that tend to make things easier.
First, place any files that are used as configuration files for public assects (for example, the fckeditor) in the public/bcms_config/[module_name] directory and have the gem only copy them if they are not already there. For example you can add code like the following to the rails/init.rb file.
unless File.exists?("#{RAILS_ROOT}/public/bcms_config/fckeditor/fckstyles.xml")
Cms.add_generator_paths gem_root, "public/bcms_config/fckeditor/fckstyles.xml"
end
This will make the required configuration file available to the fckeditor, but it won’t overwrite it (or even ask you if you want to overwrite it) every time you run script/generate browser_cms for your application.
Testing Your Gem
We strongly encourage the creation of unit, functional, and integration tests as part of your module.
We also suggest that you test your gem against a BrowserCMS application. To do this, first run
bcms module_tester -m demo
wherever (I use /var/tmp ). Edit the config/environment.rb file to include the line
gem.config 'bcms_[module name]'
then run the app locally and make sure your module works as expected.
|