$ rake -T my_plugin rake my_plugin:cleanup # Clear out the temporary files in Java

Generation QR in Java $ rake -T my_plugin rake my_plugin:cleanup # Clear out the temporary files
$ rake -T my_plugin rake my_plugin:cleanup # Clear out the temporary files
Quick Response Code Generator In Java
Using Barcode generator for Java Control to generate, create QR Code 2d barcode image in Java applications.
1927 The Plugin s Rakefile
Creating Barcode In Java
Using Barcode creation for Java Control to generate, create barcode image in Java applications.
Generated plugins get their own little Rakefile, which can be used from within the plugin s directory to run its tests and generate its RDoc documentation (see Listing 196)
Recognizing Barcode In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
Listing 196 A generated plugin rakefile require 'rake/testtask' desc 'Default: run unit tests' task :default => :test desc 'Test the my_plugin plugin' Rake::TestTasknew(:test) do |t| tlibs << 'test' tpattern = 'test/**/*_testrb' end
Make QR Code In Visual C#
Using Barcode generator for .NET framework Control to generate, create Quick Response Code image in VS .NET applications.
While we re on the subject, I ll also mention that Rails has its own default rake tasks related to plugins, and they re fairly self-explanatory:
Create Quick Response Code In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
$ rake -T plugin rake doc:clobber_plugins # Remove plugin documentation rake doc:plugins # Generate docs for installed plugins rake test:plugins # Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)
Quick Response Code Generation In VS .NET
Using Barcode drawer for .NET framework Control to generate, create Denso QR Bar Code image in .NET framework applications.
Before closing this section, let s make the distinction between a plugin s Rakefile and any rake files in the tasks folder clear:
Create QR-Code In VB.NET
Using Barcode encoder for VS .NET Control to generate, create QR Code image in .NET applications.
Use Rakefile for tasks that operate on the plugin s source files, such as special testing
EAN 13 Generation In Java
Using Barcode drawer for Java Control to generate, create UPC - 13 image in Java applications.
or documentation These must be run from the plugin s directory
USS Code 39 Printer In Java
Using Barcode generation for Java Control to generate, create Code 39 Full ASCII image in Java applications.
Use tasks/*rake for tasks that are part of the development or deployment of the
USS-128 Creation In Java
Using Barcode creator for Java Control to generate, create GTIN - 128 image in Java applications.
application in which the plugin is installed These will be shown in the output of
Draw Data Matrix In Java
Using Barcode creator for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
rake T, the list of all Rake tasks for this application
Barcode Creation In Java
Using Barcode generator for Java Control to generate, create bar code image in Java applications.
192 Writing Your Own Plugins
Bookland EAN Printer In Java
Using Barcode generator for Java Control to generate, create Bookland EAN image in Java applications.
1928 Including Assets with Your Plugin
Create Barcode In .NET Framework
Using Barcode creator for .NET Control to generate, create bar code image in .NET applications.
Sometimes when writing a plugin you will want to have additional resources available to the application, such as javascript or css, but you do not want installation to copy files all over the place This can be handled in your plugin initializer via a few hooks provided by Action View For javascript, you will simply need to register a javascript expansion using ActionView::Helpers::AssetTagHelper In the following example we add two javascript files from our plugin under the namespace my_plugin Note that the source files in the plugin must also reside in public/javascripts
Code 39 Generation In VB.NET
Using Barcode generator for .NET framework Control to generate, create Code 3/9 image in .NET applications.
ActionView::Helpers::AssetTagHelper register_javascript_expansion :my_plugin => ["core", "ext"]
Painting Code128 In VS .NET
Using Barcode printer for ASP.NET Control to generate, create ANSI/AIM Code 128 image in ASP.NET applications.
This javascript can then be loaded into the application through the standard javascript include tag, and passing the name defined by the plugin
Create UPCA In .NET
Using Barcode drawer for ASP.NET Control to generate, create Universal Product Code version A image in ASP.NET applications.
javascript_include_tag :my_plugin
Paint Bar Code In .NET
Using Barcode encoder for ASP.NET Control to generate, create bar code image in ASP.NET applications.
Stylesheets are handled in a similar manner, with stylesheets needing to reside in your plugin s public/stylesheets directory
Generate USS Code 128 In Visual C#.NET
Using Barcode encoder for Visual Studio .NET Control to generate, create Code128 image in VS .NET applications.
ActionView::Helpers::AssetTagHelper register_stylesheet_expansion :my_plugin => ["layouts", "forms"]
Barcode Printer In Visual C#.NET
Using Barcode drawer for .NET framework Control to generate, create bar code image in .NET framework applications.
Once initialized the stylesheets can then be loaded using the stylesheet link tag in the application
stylesheet_link_tag :my_plugin
Plugins
1929 Testing Plugins
Last but not least, the development of your plugin should be Test-Driven Writing tests for plugins is for the most part identical to any testing in Rails or Ruby and for the most part the methods used to test both are the same However, because plugins cannot often predict the exact environment in which they are run, they require extra precautions to ensure that the test behavior of your plugin code is isolated from the rest of the application There is a subtle distinction between running plugin tests using the global test:plugins rake task and via the plugin s own Rakefile Although the former can test all installed plugins at the same time, the internal Rakefile can and should be exploited to add any specific tasks your plugin requires to be tested properly Techniques used in testing plugins properly include bootstrapping a separate database for testing plugins in complete isolation This is particularly useful when a
19: Extending Rails with Plugins
plugin augments ActiveRecord with additional functionality, because you need to test the new methods in a controlled environment, minimizing the interaction with other plugins and the application s own test data As you can imagine, testing of plugins is a lengthy topic that is primarily of interest to plugin authors Unfortunately, I must leave further analysis of the subject out of this book for reasons of practicality and overall length
19210 Railties
Railties are classes that extend from Rails::Railtie and provide hooks into Rails initialization for add-on libraries This is extremely useful for gems which want to seemlessly integrate with Rails Railties provide hooks for libraries to add the following functionality:
Creating initializers Providing Rake tasks Adding generators Registering event subscribers (for logging)
To create a Railtie, create a class called Railtie in your project s namespace that inherits from Rails::Railtie Make sure you require rails and your own gem in the file as well
require 'my_gem' require 'rails' module MyGem class Railtie < Rails::Railtie end end
At this point you are ready to hook in Methods defined on Rails::Railtie that can be used for configuration are: