The First Month

It dawned on me today as I released 0.4.1 that’s it has been one month since the first release, 0.0.4. What a month it’s been! When 0.0.4 got released I hadn’t been working on Mack for more than a few weeks. So really, Mack has been going for about six weeks now. It’s funny to think how far the code has progressed, how many features have been developed, and most importantly, how much attention it’s received.

Firsts:

  • First Bug: Matt Todd found the first bug with a Mack. It was a simple bug with convert_security_of_methods the second parameter wasn’t being used. Matt has since become a good friend of Mack, and has a couple of other firsts on this list.
  • First Blog Comment: Mr. Eel questioning the validatey of some rough DataMapper vs. ActiveRecord numbers I posted.
  • First Link to Mack: Matt Todd gets his second ‘first’ of this list.
  • First ‘Demo’ Request: Gregg Pollack from RailsEnvy.com requested a demo app so he could feature Mack on the RailsEnvy.com podcast.
  • First Podcast: I think this one is fairly obvious, but it goes to the RailsEnvy.com guys. Thanks for the press!
  • First Speaking Request: Tom Dyer/Boston Ruby Users Group. I’ll be speaking May 13th on the joys of Mack.
  • First Request to Contribute: Arun Agrawal.
  • First Tech Support Request: Brian Dunbar. He had some trouble running the demo app. Turns out it was a bad require in the cachetastic gem, that I subsequently fixed.
  • First ‘Watcher’ on GitHub.com: Once again, Mr. Matt Todd! Gotta love the Matt.
  • First Fork on GitHub.com: Kabari Hendrick. Based out of Chicago, http://www.threedozen.com/, I’m excited to see what he does with his fork.

Wow! That’s a lot of firsts for a first month. Here’s a list of some of the features that have been released in that time:

  • Distributed Routes!
  • Better testing support
  • Built-in encryption/decryption
  • XML support
  • A Generator framework
  • ‘Scaffold’ generator
  • Plugin support
  • Server-side redirects
  • Inflection
  • Render url
  • Extensible rendering system
  • ‘Format’ driven content

That’s just a few things that have gone in there. That’s not to mention refactoring, documentation, demo apps, etc…

I’d like to this time to say thank you to everyone on the ‘firsts’ lists. I would like to thank everyone else who’s shown interest, commented, wrote about, or even just thought of Mack. Every comment on the site, every email I get, every blog link I see fills me with great happiness and makes me think that I’m on to something here.

I truly feel that there is a void for a Ruby web framework that deals with distributed, portal-like applications, and that’s where Mack is headed. That’s what makes Mack different from Rails or Merb or Ramaze or Sinatra or any other framework out there.

What’s on the horizon for Mack? A lot. I’m going to be speaking at the Boston Ruby Users Group on May 13th. Of course, I’ll be showing off Mack, so if you’re in town, I would recommend coming on down. Details on that as we get closer to the event. You can expect more app to app communication, more generators, more ORM support, more testing support, page caching, ‘portlets’, and much much more!

Once again, thanks to everyone for their support. I’m looking forward to see what the future holds.

Release 0.3.0

I’ve been holding back this release so I could get distributed routing into it, but it appears that there’s still a little more work that needs to be done before it’s ready to go. I’m hoping to get it out by the beginning of next week, but don’t quote me on that.

Instead of focusing on what didn’t make it in, let’s talk about what did make it in! There’s some cool stuff in this release.

Format Driven Content

Mack now allows you to drive different content based on the format requested. For example:

/posts - will render app/views/posts/index.html.erb
/posts.html - will also render app/views/posts/index.html.erb
/posts.xml - will render app/views/posts/index.xml.erb - A special note *.xml.erb files, despite their name, do NOT get run through ERB, instead they use the XML Builder library
/posts.js - will render app/views/posts/index.js.erb
etc…

Alternatively, in your action you can now define ‘want’ blocks, to run specific code based on the format. Example:

class PostsController
  def index
    # find all the posts in the system
     @posts = Post.find(:all)
    wants(:html) do
      # this will only be run if html is requested.
      # we need a username for a 'welcome message in the view'
      @username = @user.username
    end
    wants(:xml) do
      # this will only be run if html is requested.
      # find the last published date
      @last_pub_date = Rss.find_last_by_date_by_object(:posts)
    end
  end
end

XML Builder Support

I’m not going to go into this, there is another nice post coming shortly that will explain how to use this library to add RSS to our blog demo. Here’s the post.

Built-in Encryption

In every app I’ve ever built I found the need to use encryption. Whether it’s for encrypting something into a cookie, a password in the database, or a file on disk, we all need encryption, so I’ve baked the crypt gem into Mack.

At the very simple level you can easily do this in your code:

@my_encrypted_value = _encrypt("hello world")

and you’ll be returned a nice pieced of garbled data using the Crypt/Rijndael library. Decrypting is just as easy:

_decrypt(@my_encrypted_value) # => "hello world"

See, I told you it couldn’t be easier. It gets even better you can even define your own ‘worker’ to implement other encryption schemes. It’s as simple as this:

class Mack::Utils::Crypt::HorribleWorker
  def encrypt(value)
    value.reverse
  end
  def decrypt(value)
    value.reverse
  end
end

_encrypt("hello", :horrible) # => "olleh"
_decrypt("decrypt", :horrible) # => "hello"

See how easy that was? You can also do:

@my_encrypted_value = "Hello".encrypt
@my_encrypted_value.decrypt #=> "Hello"

Either way it’s now easy to handle encryption in your funky cool Mack app.

Changelog:

  • Ticket: #8 Xml Builder Support
  • Ticket: #7 Ability to drive certain content based on ‘format’
  • Ticket: #9 Added a global encryption system to make encrypting/decrypting of strings easy to use
  • gem: builder 2.1.2
  • gem: crypt 1.1.4

0.3.0: Adding RSS/xml feeds to our Blog demo

Ok, as you remember a while back we created a simple blog using mack, http://www.mackframework.com/2008/03/04/the-obligatory-blog-demo/. Well now it’s time to add the all important RSS/xml feed to it.

Mack 0.3.0 introduces xml rendering support natively, so this shouldn’t be so hard. First things first, let’s fire up the app, shall we:

$ rake server

Now let’s head over to http://localhost:3000/posts. We should see our beautiful posts index page. Now let’s try to go to http://localhost:3000/posts.xml you should see something that looks like this:

XML blog demo 1

Clearly, that’s not what we want, is it? I didn’t think so. The error is telling us that it’s looking for a file called index.xml.erb in the app/views/posts directory of our blog project. Obviously that file doesn’t exist.

Let’s take a second and talk about why Mack was looking for index.xml.erb. We haven’t changed anything in our controller. Our index method still looks something like this:

def index
  @posts = Post.find(:all)
end

No where in there does it mention xml. The only place xml is mentioned is on the the url itself, remember? We looked for /posts.xml. By adding .xml you’re telling Mack that you want to render, well… xml. So it goes looking for that. That’s also new in 0.3.0. The default is html, but if you append a format (.js, .xml, etc…), it will go looking for app/views/<controller_name>/<action_name>.<format>.erb and render it.

Ok, now that we understand why we’re looking for an xml file, let’s fire up our trusty text editor and create a new file called: app/views/posts/index.xml.erb. Let’s edit the file to look like this:

xml.instruct! :xml, :version=>"1.0"
xml.rss(:version => "2.0") do
  xml.channel do
    xml.title("My Mack Blog")
    xml.link(posts_index_full_url)
    xml.description("Find out about all the cool stuff happening on my blog!")
    xml.language("en-us")
    xml.copyright("Copyright Me")
    xml.pubDate(CGI.rfc1123_date(Time.now))
    xml.lastBuildDate(CGI.rfc1123_date(Time.now))
    @posts.each do |post|
      xml.entry do
        xml.title(post.title)
        xml.link(posts_show_full_url(:id => post.id))
        xml.description(post.body)
        xml.pubDate(post.created_at.strftime("%a, %d %b %Y %H:%M:%S"))
      end
    end
  end
end

Mack uses the standard builder gem library. I’m not going to go into explaining how that works, there are plenty of other tutorials and documentation that will show you that. I’m also not going to explain all the necessary pieces of an RSS feed. Instead I’ll point out in that code you’ll see we’re using the @posts instance variable that we set in the index action of our PostsController. Just like regular *.html.erb files we have access to all the instance variables from the controller, as well, helpers, etc…

So now if we go to http://localhost:3000/posts.xml we should see our RSS feed. If we did a view source we should see something that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
 <channel>
  <title>My Mack Blog</title>
  <link>http://localhost:3000/posts</link>
  <description>Find out about all the cool stuff happening on my blog!</description>
  <language>en-us</language>
  <copyright>Copyright Me</copyright>
  <pubDate>Tue, 18 Mar 2008 17:18:05 GMT</pubDate>
  <lastBuildDate>Tue, 18 Mar 2008 17:18:05 GMT</lastBuildDate>
  <entry>
   <title>My New Post</title>
   <link>http://localhost:3000/posts/1</link>
   <description>This is my first post in my cool Mack blog!</description>
   <pubDate>Tue, 18 Mar 2008 11:58:30</pubDate>
  </entry>
 </channel>
</rss>

Awesome! All that’s really left is create one of those fancy RSS tags in the location field of our browsers that people can click and go straight to the RSS feed. Let’s do that now.

At the top of your app/views/posts/index.html.erb file add the following:

<%= rss_tag(posts_index_url(:format => :xml)) %>

Now, refresh the page in your browser, and there you go, you should now see the little RSS button in the location bar of your browser. If you click that you should be taken to your feed.

That’s all there is to adding not only xml, but an RSS feed to your new blog.

The code for this demo can be found here.