New Command-Line jQuery Tool
Update: I have completely refactored jcheat and added substantial new functionality, including a ton of filters that can be used in any combination. Do a gem update and run jcheat -h for full usage details.
I released a new tool, jquery-cheat, that allows you to get information about the jQuery API directly from the command-line. You can get the description of a function, a list of functions in each module, search the list of all function descriptions for a string, get a list of all functions whose name match a string, and some other cool tricks.
Some examples:
# jcheat desc clearForm -------------------------------------------------------------------------------- Name: clearForm() Description: Clears the form data. Details: Clears the form data. Takes the following actions on the form's input fields: - input text fields will have their 'value' property set to the empty string - select elements will have their 'selectedIndex' property set to -1 - checkbox and radio inputs will have their 'checked' property set to false - inputs of type submit, button, reset, and hidden will *not* be effected - button elements will *not* be effected Returns: jQuery -------------------------------------------------------------------------------- | EXAMPLES | -------------------------------------------------------------------------------- --------------- | Description | --------------- Clears all forms on the page. -------- | Code | -------- $('form').clearForm(); # jcheat namelike $.ajax $.ajaxTimeout(time) in Ajax $.ajaxSetup(settings) in Ajax $.ajax(properties) in Ajax # jcheat like clear field clearForm() in Plugins/Form clearFields() in Plugins/Form
You can grab the tool by doing:
gem install jquery-cheat -y
The -y is so that it automatically includes hpricot, a required dependency.
This looks cool, Yehuda! Unfortunately, you might have to explain in a bit more detail how to “grab the tool.” I’m guessing that RubyGems is required for this to work and that there might be some more prep work involved before we can just type the one-liner on the command line and make things magically happen. Any chance you could an executive summary for those of us who aren’t Ruby/Rails gurus so that we can try this out? That would be really cool.
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find jquery-cheat (> 0) in any repository
Lil’ help?
Hey Bradley, took me a couple tries before I got it installed. Maybe try
sudo gem install jquery-cheat -y
?Nice stuff!
@Karl: Nope, using sudo yields the same result. That was my first instinct as well. Meh.
You can try a “gem list –remote” and see if jquery-cheat is listed. It should be between jqpeg2pdf and jruby-openssl. You might somehow be using a weird repository. You can also download the raw gem and install it manually at http://jquery-cheat.rubyforge.org/.
Got it working. It just “magically” started working this afternoon. I’m thinking my ISP is doing some heavy caching, since weird things like this happen sometimes, but it seems weird to affect rubyforge like that.
Thanks for the suggestions guys. Was just my luck, I guess.
The Before/Result HTML examples appear in encoded form, so instead of seeing the HTML tags, I see stuff like & lt ; p & gt ; — any way to get these to show up unencoded?
Can you give me an example of a specific command that produces the bad results? I’m having trouble reproducing.
Sure, both of the following did not work before, but do now. Like I said, I think it was something between my network and rubyforge, likely my ISP caching some old data.
$> gem install jquery-cheat -y
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find jquery-cheat (> 0) in any repository
$> sudo gem install jquery-cheat -y
Password:
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find jquery-cheat (> 0) in any repository
Now, it works fine. Must have been an intermittent problem.
Maybe you meant Geoff’s comment. I get the same thing:
$> jcheat desc size
--------------------------------------------------------------------------------
Name: size()
Description: Get the number of elements currently matched.
Details: Get the number of elements currently matched. This returns the
same number as the 'length' property of the jQuery object.
Returns: Number
--------------------------------------------------------------------------------
| EXAMPLES |
--------------------------------------------------------------------------------
----------
| Before |
----------
<img src="test1.jpg"/> <img src="test2.jpg"/>
--------
| Code |
--------
$("img").size();
----------
| Result |
----------
2
Haha, okay WordPress, way to translate the entities for me. Gah!
Spacing added to the entities to preserve formatting:
----------
| Before |
----------
& l t ; img src="test1.jpg"/ & g t ; & l t ; img src="test2.jpg"/ & g t ;
D’oh. I thought this was made with JQuery, using FireBug as a command line. Now that would be even cooler IMO.