Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Tuesday, March 17, 2009

Drupal 6 JavaScript and jQuery is out

I got my copies of Drupal 6 JavaScript and jQuery today.

Honestly, writing this book was a struggle. I think I spent longer debugging JavaScript on a multitude of platforms than I did actually writing the book. That makes the entire experience less enjoyable.

Another frustration with the book was trying to use the appropriate tone. My intent at the outset was to attract a different crowd. Rather than write to computer scientists and software engineers, I wanted to write to new web developers -- perhaps those who haven't done much programming at all. I don't think I met my own expectations in that regard. It is a rare gift to be able to explain something you know well to someone who has little base knowledge.

On the reverse side, I did have a chance to write some of the flashiest book code that I have ever written. Instead of writing generic code, I had the opportunity to start from what Drupal already has and build out. A few of my favorite examples were:
  • The real-time comment notification system (like Growl for a website). I might even have a project coming up that would allow me to use this on a production site.
  • A simple but configurable HTML editor called "better editor" (because it is an extension of an earlier example in the book). I could actually imagine creating a real module version of that.
  • A sorta cool client-side theming engine. It was fun. It has some practical application. Who knows... perhaps someone else will be able to make something useful of it.
So, yes, there were parts of this book that I really enjoyed working on.

Biographically speaking, it was rather strange to write a JavaScript book. I think the first server-side web apps that I wrote (that is, beyond simple CGIs) were written in Netscape's "Server-Side" JavaScript sometime around 1996 or 1997. And my first major consulting position was as a Lawson JavaScript developer. Looking back, Lawson was an unsung pioneer in the field. They were attempting to approximate AJAX with frames (not iframes -- no, this was before iframes were widely adopted). When I jumped ship from JavaScript to Java, I didn't think I'd turn back. But as the technologies have matured, I've found reason to want to script stuff on the client again.

Finally, I think the most interesting thing to come out of the book (and out of a discussion I had with Larry Garfield while writing the book) was QueryPath. Okay, to be completely honest, QueryPath was the result of three things:
  • Wes Munsil's teaching me how to write recursive descent parsers in June. Once I knew how to do it, I really wanted to write one. And who writes CSS parsers for PHP?
  • Learning jQuery. As soon as I started working with it I became enamoured. And the JavaScript book gave me more of a chance to think about its structure.
  • Expressing my frustrations with XML technologies to Crell, who flippantly suggested I write "jQuery for PHP". Really, that was the moment when the entire thing meshed. That happened somewhere around Chapter 4 of this book.
Will I write more books? Probably. I love the process. But maybe I'll take a breather for a few.

Wait... I just came up with a good idea for a book.

Saturday, January 24, 2009

QueryPath: It's like jQuery PHP.

I have just posted "my winter project." Its name is QueryPath, and it's something like jQuery PHP (or is that PHP jQuery?).

While writing the Drupal 6, JavaScript, and jQuery book, I started looking for something like jQuery in the PHP world. I found several projects that implemented small subsets of the jQuery API, but nothing approaching the complexity I had in mind.

So I went back a step, and started looking for a good CSS 3 Selector implementation. I didn't find one of those, either. At best, I found some simple regex-style tools that supported a small portion of the CSS 3 Selector standard.

There was nothing else to do but start coding.

First I wrote a recursive descent parser for CSS 3, including support for XML namespaces and other ill-defined yuckiness.

Then I wrote an event-based API similar to SAX2 -- only for CSS 3 Selectors. And I wrote an implementation of the API.

From there, I began constructing a PHP equivalent of jQuery. Not all of the jQuery API is relevant in PHP. After all, an event model glue layer is not of general interest in a single-threaded PHP app. But HTML/XML traversing and manipulating certainly are. So I borrowed as much of the jQuery API as seemed appropriate.

While I used the same function names (except for empty, which is a PHP reserved word), and tried to follow as closely as possible in parameters and return values, the internals are almost completely different. Why not? After all, JavaScript and PHP are very different languages.

The coding process was interesting. I'm too busy to write something like this in one go. So I spread it out... in 15-30 minute increments. In fact, I developed most of QueryPath while riding Chicagoland trains to and from work. Even with this bizarre and disjointed development path, I eventually finished. QueryPath's main library has 58 public methods, almost all of which are from jQuery's API (though I added some, like an XPath query and tools to use PHP delta and callback functions).

But I wasn't happy. I wanted some cool extensions (plugins), too. It didn't take me long to figure out the obvious: QueryPath needed a database layer. Using PHP's PDO library, I constructed a simple database library, QPDB, that allowed various ways of merging SQL results into XML/HTML. Take a query and turn it into a table or a list. Or get get more detailed -- you can put database results (in whole or in part) wherever you want! There's even a simple template language (I like to call it HTML) that you can use to format results in sophisticated ways.

I am so happy with the library that I have released it under LGPL or MIT License (your choice). You can head over to QueryPath.org (or skip straight to the downloads and docs at http://fedorahosted.org/querypath) to try it out for yourself.)

N.B. A huge thanks to the Fedora Hosted folks for (a) inviting me to host there, (b) providing an unbelievable array of VCS and bug tracking tools, and (c) being more than congenial all along.

Thursday, September 11, 2008

Slashdot review of Learning Drupal 6

I just found out that Slashdot posted a review of Learning Drupal 6 Module Development. The reviewer gave it a 9/10 -- with his detracting points being a few typos in the text, and some stylistic differences with the Packt writing guidelines. Needless to say, I'm thrilled to get such a positive review on a site like Slashdot.

Friday, July 25, 2008

DrupalCamp Colorado


Tomorrow, DrupalCamp Colorado begins.

I am planning on doing a session there on JavaScript and Drupal (heavy on the jQuery).

There are a surprising number of session proposals, and it looks like many of them will be very interesting. I'm excited to be going.

In the meantime, I have been working on J.D. Trout's new web page (moving here). It's using Drupal 6 with a whole host of newly-minted Drupal 6 modules -- like Views 2, CCK, and Image. Which brings to mind something I'd really like to rant about: What in the world is going on with Drupal image support? ImageField is gone... now FileField Image is here.... but wait... it's gone now. And maybe ImageField is coming back. Maybe. Poor lonely Image is the only image module that looks stable on Drupal 6.... and it's awfully hard to use with Views and CCK.

Thursday, June 19, 2008

In the Works: A Book on Drupal and JavaScript

I've started on a new book on Drupal. This time, instead of covering the PHP aspect, I am focusing on JavaScript. Drupal 6 has made some major headway in this arena, and it seems to be about time to focus on that.

As usual, Packt is the publisher. They're a great company to work with.

Friday, February 22, 2008

Learning Drupal 6 Module Development

Packt has now set up the official information page for my Drupal book.

This book has a very hands-on practical feeling to it. Each chapter walks through the creation of a module, theme, or installation profile. The goal is to produce modules that actually do something.

The modules cover a range of development tasks, from the fun (jQuery, AJAX/JSON, and XML feeds) to the practical (providing administrators with a special email notification system). More attention has been devoted to some of the new or updated Drupal 6 subsystems, like the Menu API, Forms API, mail subsystem, triggers and actions, sub-themes, and new Javascript.

One chapter covers theming, and one chapter covers building a custom installation profile (that is, an installer for a highly customized version of Drupal).

I'm actually done writing the book (ahead of schedule, I might add). Now, it will go through reviewing and printing before hitting the shelves. My editor tells me that it will probably ship in June. But apparently they are optimistic -- they but the book up for pre-order already.

This has been by far the most fun book I've written, and I think I will stick to this sort of format for future books (at least the development ones).

And if you are coming to DrupalCon Boston, look me up.

Friday, February 1, 2008

JS Library of PHP Functions

Sometimes the most painful thing about Javascript programming is the lack of utility functions. I end up writing an awful lot of boilerplate.

jQuery -- my favorite Javascript library of all time -- goes a long way toward simplifying DOM-related tasks.
But why can't Javascript be more like PHP? Why can't it have a decent set of string and array manipulation functions?

It does now.... in the form of the php.js library. I haven't gotten to do any real testing of this library, but I read through the source code and am happy to see the beginnings of a library that might just encroach upon jQuery's top spot.