Prototype Class Generator plugin

Plugin details

A Ruby on Rails generator for Prototype JavaScript classes and tests, Plugin Edition.

This tool creates a Prototype-style JavaScript class, a unit test - using the JS Test::Unit class from script.aculo.us - and all of the necessary testing prerequisite files, so its super easy to start building tests for your JavaScript classes, just like you do for your models, views, and controllers.

Repositoryhttp://sbecker.net/shared/plugins/prototype_class_generator Author Scott Becker Tags Prototype, Javascript, generator LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://sbecker.net/shared/plugins/prototype_class_generator

Create your first Prototype Class:

script/generate prototype_class FormValidator



You should see some output like this:

create  public/javascripts/form_validator.js
create  public/javascripts/test/lib
create  public/javascripts/test/unit
create  public/javascripts/test/lib/test.css
create  public/javascripts/test/lib/unittest.js
create  public/javascripts/test/run_unit_tests.html
create  public/javascripts/test/unit/form_validator_test.html
create  public/javascripts/test/unit/index.html
create  entry for FormValidator class in JS unit test suite



Congratulations, you've got a valid Prototype class called FormValidator. Not only that, you've got a full JavaScript test harness to run within the browser to test your new class. Lets run it now.

Open this file in your browser:
"public/javascripts/test/run_unit_tests.html"

If you've already got the rails app running on your machine, you should be able to get to it here:

http://localhost:3000/javascripts/test/run_unit_tests.html

This is a nice pre-built testing harness for all of your JS unit tests.


Create additional classes and tests.

You've already got a FormValidator class, but now you also need an Accordion class. Great, lets generate the shell:

script/generate prototype_class Accordion



This time you'll see some output like this:

create  public/javascripts/accordion.js
exists  public/javascripts/test/lib
exists  public/javascripts/test/unit
identical  public/javascripts/test/lib/test.css
identical  public/javascripts/test/lib/unittest.js
identical  public/javascripts/test/run_unit_tests.html
create  public/javascripts/test/unit/accordion_test.html
skip  public/javascripts/test/unit/index.html
create  entry for Accordion class in JS unit test suite



Some of the prerequisite files we need already exist, so we didn't overwrite them. What we did do is:

- create the Accordion class
- create the Accordion unit test
- add a link to the Accordion unit test to the existing unit test index page.

Now if you view the unit test page in your browser, you'll notice its got a new link to run the Accordion unit test. And the FormValidator unit test is still there. Sweet!

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 6 months ago