Potluck PHP Framework

In my free time I've been playing around with some different tools for development and I've sort of come up with a Potluck PHP Framework of sorts. It's actually not bad and stays pretty lightweight while giving some decent functionality. Keep in mind, I've not spent extensive time with this setup, but I am liking what I'm encountering so far. Here's what I've pieced together:

Slim: PHP5 Micro Framework

It's pretty lightweight and you're not going to find tons of functionality built into it. But don't let it fool you. It is pretty easy to extend or build upon and has some important pieces of functionality that a framework should have already built in.

My only "beef" with Slim is probably that it doesn't give a great Controller structure if you're going to take an MVC approach to things. But I'm still just starting to play with the framework so I might find a way to build in something more like what I'm expecting. I typically like the CodeIgniter approach on controllers/routes. I'd like to see if I can figure out a way to minimally recreate that functionality so I can make a new route just by dropping a file/class/method into the appropriate place(s). For a small site this would be a non-issue anyhow.

Twig: Template Engine

This is rather easily integrated into Slim and gives you a nice template engine for your views. I'm typically not a fan of mustache templating systems but Twig is a pretty robust engine. In my playing around with it, I am finding myself willing to deal with the mustaches in order to gain the advantages Twig is providing.

phpDataMapper

phpDataMapper is more or less a port of the Ruby DataMapper project. This is the one I've had the least time spent with of the 3 items on this list. But I definitely enjoy not having to worry about escaping things for the database, etc., and being able to quickly establish a database back end for the app I'm using this setup with. I went from no database connection to pulling data out and displaying it on my page in about 5 minutes with phpDataMapper.


Could I have done all of this with something like CodeIgniter? Sure. I'm a big fan of CodeIgniter so I'm not making this list as an argument against CI or other PHP frameworks. I will say that I was able to integrate Slim, Twig, and phpDataMapper in about 15 minutes of Googling and typing.

One advantage I could see to using a setup like this is that you get to very explicitly choose where you want to put weight into the framework you're piecing together for your application. I'm not sure how light-weight Twig and phpDataMapper would be considered, but Slim is definitely light-weight. Database interactions and rendering are areas that I was ok with adding weight to the application for because of what they provide me.

Vagrant and Puppet are pretty fun

I had some good times with Vagrant and Puppet this week. I would easily recommend checking it out if you typically develop for *nix based systems as it can make setting up a local dev environment pretty nice and easy to manage. Not only that, but you can then share the dev environment with other developers on your team which is great news for folks that play well with others.

You will probably find it to be a bit of a "slow down in order to speed up" routine. I had previously played with it a little so I was able to dive in pretty fast this time around and found it pretty straight forward after having wrapped my head around it the first time several weeks back.

I originally found out about it by reading the article "Facilitating Development Environment Consistency" over on the PHP advent site. So that might be a good place for you to start if you're interested in the approach.

If you're not already subscribed to PHP Advent or following them on Twitter, I'd highly recommend it. New articles only come in December of each year but some of them can be pretty stellar.

Hosted on github

One of the side benefits of markd is that I can now just host my site on github since it's just static HTML. So I've moved my site over.

Speaking of markd, I've added some more features:

  • Post formats

    An example would be my link posts which you can see are formatted slightly differently than normal posts. Post formats are defined on the fly based on what you specify in the header section of your markdown files. If you specify a format then the template engine looks for a corresponding content file in the formats directory inside of your theme.

  • Google Code Prettify support
  • Subpages are now in subdirectories on the published site

    This makes things a little prettier in the published site.

  • Category support

    Categories are created while the site is being published from what you specify in the header section of your markdown files. Listing (e.g. archive) pages are created for each category. You can see an example by looking at my Development category.

  • Template files are now PHP

    Using basic string replaces with .tpl files for the theme was going to become painful fast so I switched things up to let template files be PHP which means you can dynamically process things when the site is generated. This also makes the hook system more straight forward to take advantage of.

  • Now, future dated posts are not published until the date specified in their source markdown file.

Coming up:

  • Tag support

    It's possible I may just rename categories to tags and go with the one taxonomy.

  • WordPress importer

    Maybe my previous content will make an appearance here :)

  • Child theme system
  • FTP Deployments of your site

    This is still a maybe. I'm not sure how useful it will be for the system.

Until next time … take care.

Updates to markd

After releasing the first version of markd over the weekend, I'm following it up with a reasonable amount of changes and new features.

There is now support for Pages. They're created from a file/directory hierarchy in your content/pages directory. Along with this a menu with support to up to 2 levels deep can be generated. This might be easier to explain by example. Let's assume you have a directory structure that looks like this:

  • /content
    • /pages
      • /about.md
      • /Projects
        • /markd.md
      • /contact.md

This would generate code that looks like this:

<ul class="nav">
    <li><a href="about.html">About</a></li>
    <li class="dropdown" data-dropdown="dropdown">
        <a class="dropdown-toggle" href="#">Projects</a>
        <ul class="dropdown-menu">
            <li><a href="markd.html">markd</a></li>
        </ul>
    </li>
    <li><a href="contact">Contact</a></li>
</ul>

The link names are pulled from the directory name (e.g. "Projects") or from the Title in the markdown file (e.g. "About"). Essentially all you need to do is create a structure and markd will take care of making a menu system for it and linking things up properly.

Also with the support of pages comes support for page templates. If you need a page to look different, then create a corresponding template file with the same file name inside your theme. For example, if you wanted your "about.md" page to use a special template, then you can create an "about.tpl" inside the theme and alter the HTML for that page only. If there's not a specific page template in the theme directory, then it will default to using a generic "page.tpl" from the theme directory.

There's also a simple (for the time being) hook system that was introduced which allows themes/plugins to do some manipulation of the generated site. Along with markd comes a plugin called Twitter Timeline Widget to show how this can be used to add something to the sidebar of posts/pages. There is another example in the default theme which depending on whether a JotForm ID is provided, it will either add the Contact Me button (that you see on the right hand side of this page) or not. This is a little crude at the moment, but I hope to flush it out and make things a little smoother as time goes on.

A lot of other tweaks were made along the way with these features, but you can read commits over on github if you really need to know about that boring stuff :)

Up next:

  • Support for categories
  • Restructuring of pages in the published site (need to build a directory structure rather than cramming it all into the site root)
  • Child theme system (mainly for me to be able to apply customizations to the default theme)
  • Post formats (make things like Links or Tweets look different)
  • Future dated posts won't be published until the proper time even if their published status is set to true

Welcome To My New Site

Complete

So here it is. I've been working on a static site generator for the past couple of weeks and I finally have things put together enough to start running my site off of it. The project is called markd and it's hosted on github.

The overview of how the system works is you create files (posts) that are written in Markdown syntax. markd will then generate a static HTML version of your blog from those files. It makes everything you see here.

I would say it's still very alpha at the moment, and even when it is stable it will still be something of more interest to developers rather than the average blogger. The installation and setup instructions basically don't exist, but will be coming in the future.

Here are the basic reasons why I wrote it:

  • I needed a new hobby project :)
  • Having a static HTML site just seemed to make sense for various reasons
  • It was a bit of an exercise in some development areas that I wanted to work out
  • Creating Markdown files is so easy and the way I have this all set up, makes writing a new post both simple and something I can easily enjoy in my favorite text editor
  • Really, it's just something that I had a strong interest in and decided to run with it. I'm happy with how it's turned out.

If you're curious how it works, here is how I have things set up:

  • I write blog posts in a text editor, with the Markdown syntax. They're saved on Dropbox so I can access them from any computer.
  • I run markd which is a PHP-CLI set of scripts that generates the HTML for my home page, single post pages, archives, etc.
  • Those files are then automatically published to my web server using a set of not-included shell scripting.

I'm enjoying working on it and have plans for things to do in the future like enhancing the theme engine, adding hooks for a plugin system and support for some different post formats. At this point you might be thinking this is starting to sound a lot like WordPress, or many of the other blogging engines, including the others that create static sites. Well, you'd be correct.

I wanted this project to do things the way I wanted them done. It's definitely taking hints from WordPress, and I also intend to take some hints from the Carrington Theme Framework for the theme engine.

I'm looking forward to where this might go. Who knows, maybe working on markd might get me blogging frequently again since I'll be developing it and want to try things out.

Connect

Matt Walters on about.me Matt Walters on twitter Matt Walters on Linked In Matt Walters on github RSS Feed for MattWalters.net

Latest Tweets