cybo42

Turning caffeine into code...

Making Octopress Groovy

One of the reasons I picked Octopress for my blog was how easy it was to share code snippets and link to code on Github. When I migrated one of my older posts I found that the syntax highlighting was not working for Groovy code samples. After some investigation, I determined it was not going to be to hard to get things working, reaffirming my choice in using it. I created a fork with the changes detailed below.

Latest and Greatest

Octopress uses a gem called pygments.rb to generate the code snippets. This was the root of my issue. Octopress ships with version 0.1.3 of the pygments.rb gem which does not have support for Groovy. I updated the pygments.rb gem to the latest (0.2.4).

That seemed to do the trick.

1
2
3
['Octopress', 'is', 'Groovy', 'Yeah! baby!'].each{
  println it
}

Since I was feeling adventurous I also updated all the other Octopress gems to their latest versions. To keep things organized updated the .rvimrc and created an octopress gemset.

Don’t stop there

I am also a big fan of Gradle, a build tool which uses Groovy as a DSL to define your build files. The file extension on the build files are .gradle which means they do not get highlighted correctly. A mapping was added into plugins/pygments_code.rb to allow Gradle syntax to be treated as Groovy.

1
2
3
4
5
6
7
8
9
10
11
index a5d1b79..1676a3e 100644
--- a/plugins/pygments_code.rb
+++ b/plugins/pygments_code.rb
@@ -7,7 +7,6 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)

 module HighlightCode
   def highlight(str, lang)
+    lang = 'groovy' if lang == 'gradle'
     lang = 'ruby' if lang == 'ru'
     lang = 'objc' if lang == 'm'
     lang = 'perl' if lang == 'pl'

First Post! New Domain New Blog Engine

Well I am a little late on my New Year’s resolution to redo my blog and this year actually try to post on a regular basis.

I decided to do a little rebranding and pick a new blog engine. In the end I picked Octopress.

My original blog used WordPress which worked fine for its time, however it was a little overweight for my needs. I still think that WordPress is a good application. I continue recommend and use it for some of my side work.

Octopress appealed to me for a few reasons.

  1. It was just static HTML in the end. Simple to host and maintain.
  2. Had a nice look and feel out of the box, but allowed for easy customization.
  3. Posts / pages are just text files. (My name is Joe and I am a Vim addict)
  4. Code formatting / sharing is drop dead simple.
  5. Ability to import posts from WordPress

In the end since I only had a handful of old posts, and there wasn’t a lot of substance I didn’t end up importing anything besides a few drafts which needed finishing.

I did run into a couple of gotchas getting up and running, which I will write up in future posts.

My New Favorite Thing: Gradle

I like other Java developers have a love / hate relationship with Maven. While on most days it leans more towards the love side, there are times when the love just isn’t there. Usually those times are when I want to do something not quite standard. It seems that I end up spending the afternoon sacrificing XML in order to appease the Maven gods.

For a current project I decided to take a hard look at Gradle and was pleasantly surprised.

Getting started

If you have a simple java project using the standard convention of putting your source under src/main/java then all you need is one a one line build script.

1
apply plugin: 'java'

Thats it. Ok so that’s not super impressive, your not really doing much more then javac. The little more you are doing is working with the “standard” directory structure, and you can automaticly package up your code into a .jar by running gradle assemble

1
2
3
4
src/main/java
src/main/resources
src/test/java
src/test/resources