Tuesday, February 28, 2006

Who Stole December -- and, uh, January (and February)?

Wow, I haven't posted in quite a while! Sorry about that. Things have just been kinda crazy.

Well then, lemme catch you up on a few things... I finished up a stint with Site5. I was helping them out on their new offering: Flashback -- Be sure and check 'em out, they're a good bunch of guys 'n gals that really care about web-hosting. [/plug]

There are a couple of patches to the theme_engine that I need to integrate and publish -- look for that in the near future.

In the next few weeks I'm planning on releasing version 0.6 of TaskTHIS. It will fix some issues with Rails 1.0 (probably 1.1 at that point) and have better database support. Also, it'll have some examples of AJAX failure handling (which I'll talk more about in the next few days).

Activity on the Zoo Dot Com front! I'm writing several storylines now so that I can keep well ahead of schedule. And there's something else, very exciting, in the works for ZDC -- I can't tell you about it now, though. Hopefully soon. Very soon.

I guess that's pretty much it -- Oh yeah, I moved too. Heh, a little time consuming that is. Anyway, I will now return to my more regular posting self -- Stay tuned. Same M@ channel, same M@ time. (Did I just say that? Oh jeez...)

Tuesday, November 29, 2005

Now for something completely different...

For a change of pace, here's a picture riddle for you:

The first one to post with the right answer gets -- Well, nothing actually. Respect maybe? Uh, sure, why not.

Monday, November 14, 2005

Rails Theme Support Plugin

Update: I changed the svn URL to point to it's new home!

Currently, to add support for themes into your rails application, you have to install the theme_generator. The generator will then create the folder structure for themes, and it also creates the plugin files for theme support in rails.

The more I've thought about it, the less I like this approach. I'd rather have a fully encapsulated plugin that would add support for themes into rails and define a simple generator that would merely create the boilerplate theme structure.

To that end, I present the Rail Theme Support plugin. To install the plugin execute the following in the root of your application (requires rails 0.14.3+):

./script/plugin install http://mattmccray.com/svn/rails/plugins/theme_support

In the next couple of days I'll have a trac installation up and running for it too.

You can, of course, still get the theme_generator from RubyForge. But I think the plugin will be the approach I will recommend moving forward.

Try it out and let me know what you think!

Saturday, November 12, 2005

Theme Generator Shapes Up

I've released theme_generator version 1.3.0. It's shaping up rather nicely, if I say so myself.

The theme support is now completely encapsulated in a plugin -- it was split across a plugin and a component.

Like Typo, it fully supports custom application views, of course. (It is based on the Typo theme system, after all.)

It also supports using liquid templates (if you have the liquid plugin installed). You can also lock down the themes to only allow the rendering of liquid templates.

And it's dead simple to use. Once you have the theme_generator installed, here are the steps to make your application support themes...

Step One: Generate a theme named 'default'

In your command terminal, cd into your Rails (0.14.3+) application folder and execute:

./script/generate theme default

It spits out the folder structure for a theme named 'default' (it doesn't actually have to be called 'default', call it what you like).

Since it's the first time we've used it for this application, it'll also create the theme_support plugin files for us.

Step Two: Update your ApplicationController

Now we update the ApplicationController (application.rb) to tell Rails to use our new theme.

classApplicationController< ActionController::Base
  layout 'default'# You may need to modify this, the generator will
# create a layout named 'default' by, uh, default
  theme 'default'# Tell Rails to use the theme named default
end

Step Three: There is no step three

Your app is now ready to support themes! You can create whatever theme-specific stylesheets, images, javascripts, layouts, and application views you'd like and Rails will pick them up.

Note: To reference theme-specific content you'll want to use the theme_* helper tags. See the docs for more.

Credit where credit is due...

Of course, this generator and plugin wouldn't be as remotely robust if it wasn't for the excellent work of Tobias, Scott, and the rest of the Typo guys.

Installation

Want it? Just gem it:

sudo gem install theme_generator

Or, if you already have it:

sudo gem update theme_generator

If you are on Windows, you can leave out the sudo part.

In the near future I'll be posting a tutorial explaining how to implement user and/or application level themes... In the meantime, if you have any suggestions or questions, feel free to send 'em my way.

Wednesday, October 26, 2005

Full Theme Support in Rails, Revisited

OK, so after a short discussion and some experiments, I've realized that the Typo approach to themes has a lot more merit than I initially thought... For general use it still has some trouble areas, but that's nothing that can't be fixed.

I've created a new theme_generator that takes their general approach and makes it easy to leverage in any application. Even an existing one.

How to use it...

Usage is extremely easy. First, use the generator to create a default theme.

  ./script/generate theme default

(It doesn't have to be called 'default', it can be whatever you'd like)

This will create the main themes folder structure, the initial theme files for the theme ('default' in this case), and it creates the plugins/components needed to support themes.

Now you can use themes as easily as you do layouts. The following will use a layout named 'main' in the 'default' theme.

class ApplicationController < ActionController::Base
  layout 'main'
  theme 'default'
end

Here's an example of per-user themes:

class ApplicationController < ActionController::Base
  layout 'default'
  theme :get_user_theme

  def get_user_theme
    # This assumes, of course, your User has a 'theme' field
    return @session[:user].nil? ? 'default' : @session[:user].theme
  end
end

Differences from Typo themes...

I did take the liberty of tweaking of couple of things (beyond setting the theme in your controller). The main difference is that I changed the cached theme structure.

Before:

/public
  /images
    /theme
  /stylesheets
    /theme
  /javascript
    /theme

After:

/public
  /themes
    /[THEME_NAME]
      /images
      /stylesheets
      /javascript

What does this mean? For one thing, it's a lot easier to remove cached theme files... Just delete the public/themes folder.

Also, you should be using relative paths to images in your CSS. For example:

BODY {
  background: #FFF url(../images/page-bg.jpg) top left;
}

Requirements...

Update: theme_generator is now hosted on RubyForge.

The theme_generator requires Rails >= 0.14. The easiest way to install the theme_generator is by running:

  sudo gem install theme_generator

It's that simple. Feel free to install it and let me know what you think.