What we're listening to:
Jared

The Hold Steady:
Heaven Is Whenever
Jeff

Paper Route:
Absence

For adding a blog to your refinery site, there’s pretty much only one option: the refinerycms-blog plugin. Fortunately like most refinery things, it’s pretty easy to customize.

I wanted to use DISQUS to moderate the comments on this particular blog, and here’s how I did it (You obviously need a DISQUS account to do this).  If a file referred to doesn’t exist, copy it from vendor/plugins/app/views/blogs to your theme directory.

  1. Remove the old comment form:
    themes/mysite/views/blogs/show.html.erb

    remove the render “_form” line since we don’t need a comment form anymore
  2. Add the Disqus embed code
    themes/mytheme/views/blogs/_comments.html.erb

    Replace everything in this file with the disqus embed code, replace mysite below with your disqus shortname.

    <div id='comments'>
     <div id="disqus_thread"></div>
     <script type="text/javascript">
     var disqus_identifier = "<%= @blog.permalink %>";
     <%= "var disqus_developer = 1;" if local_request? %>
    
     (function() {
     var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
     dsq.src = 'http://mysite.disqus.com/embed.js';
     (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
     })();
     </script>
     <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript=mysite">comments powered by Disqus.</a></noscript>
    </div>
  3. Add the disqus comment counter code
    /themes/mysite/views/blogs/index.html.erb

    Change line 16 to:

      <%= link_to 'Read more', blog_post_url(blog.permalink)+"#disqus_thread" -%>
    

    Put this somewhere near the bottom:

    <% content_for :footer do -%>
     <script type="text/javascript">
     //<![CDATA[
     (function() {
     var links = document.getElementsByTagName('a');
     var query = '?';
     for(var i = 0; i < links.length; i++) {
     if(links[i].href.indexOf('#disqus_thread') >= 0) {
     query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
     }
     }
     document.write('<script charset="utf-8" type="text/javascript" src="http://disqus.com/forums/poetrybooths/get_num_replies.js' + query + '"></' + 'script>');
     })();
     //]]>
     </script>
    <% end -%>

    /themes/mysite/views/shared/_footer.html.erb
    add <%= yield :footer %> to your footer file so our comment counter javascript gets placed there.

Pretty easy.

Recently I’ve been evaluating refinerycms for a few client projects that it seemed suited for, and I really like that while it’s not always 100% what I want, it’s very easy to modify to get it to where I need it.

Here’s an example: My site needs a main nav to link offsite in a new window by adding target=”_blank” to the link, which is not handled out of the box by refinery.  So I copied vendor/refinery/app/views/shared/_menu_branch.html.erb into my theme directory to override the functionality and modified line 11 to the following:

<%= link_to menu_branch.title, menu_branch.url, \
:target => menu_branch.url.include?("http://") ? "_blank" : "" %>

Now any link containing http:// is automatically given a blank target. Presto.

Had issue today with autospec never stopping, and found this article, but I did have the autotest-rails gem installed.  Thanks to Mario Aquino’s article here, I learned that you can pass -v to autospec/autotest and it will print out what triggered it to run.  My culprit was rerun.txt, and then I found buried in the Cucumber documentation:

If you find that autotest runs your features continuously, your features may be changing a file which autotest is monitoring as they run. Use a setting like this to ignore such files. You’ll likely need to set autotest to ignore “rerun.txt” as well.

So, to your project’s .autotest or at ~/.autotest, add something like this:

Autotest.add_hook :initialize do |at|
%w{.svn .hg .git vendor rerun.txt}.each {|exception| at.add_exception(exception)}
end

At least, that’s what my ~/.autotest has, and after adding rerun.txt in there, everything is good.

Hopefully this will help someone else googling for the same thing I was with no luck.

all day events in event calendar

December 10th, 2009

Some events don’t start and stop at specific times, but instead last all day. We’ve had this option when creating events in our application(s), but until now it wasn’t visually apparent when shown in EventCalendar, a rails plugin.

Now we have a new use_all_day option!

When set to true, the plugin checks if the event is all day and/or multiple days. If it is, then it will display with the usual background color bar. Otherwise it just shows the event text using its color. (Similar to many popular calendar programs.)

For more info check out: the screenshot, homepage, and github (commit).

The Event Calendar rails plugin (see: post & github) we created a few months back has been working great and, thanks to all the feedback, the bugs have pretty much been worked out. There was one annoying limitation, however:

The width couldn’t be set arbitrarily.

Well, no longer. I completely re-wrote the HTML and CSS styling that the helper generates. Events are now table columns which span the calendar days. The calendar grid is also a table, not a background image which needed to be created whenever setting a non-default width.

This means you can give the calendar any width, or don’t set it at all and let it resize to it’s containing element. Awesome!

I also took the opportunity to remove some old code, comments, and options that were hanging around from the plugin’s previous lives. In some ways there is now more flexibility to customize, in a few ways less. One consequence is that some of the options from before the rewrite no longer exist, so update with care.

Overall I’m very happy with how it turned out. Enjoy!

wordpress now playing plugin

October 20th, 2009

We love music around here, which is why we’re always showing off what were listening too over on the left. Some time ago I automated the process of looking up album artwork using the Amazon API and posting it on or blog.

This approach has a couple advantages over things like last.fm, like being able to select exactly what you want shown, and automatic linking to amazon for affiliate commissions.

I’ve packaged everything up into a wordpress plugin and put it on my github page here:  http://github.com/jaredmoody/wp_now_playing

It also comes with a nice applescript so you can submit what’s currently playing to your blog with a single click:

I’d love some feedback on it, and patches are also more than welcome.

Please report any issues on the github page, thanks!

I hadn’t done this before and everywhere I googled suggested using a custom interpolation to replace :basename in the default :path and :url params to has_attached_file

The problem with this is 1. the actual image_file_name column in the database doesn’t get replaced 2 whatever you put in your interpolation function gets run every time the image url gets generated.

The answer is just rename the image_file_name before the model gets saved.

I couldn’t find this anywhere, but pieced it out from the article on riding rails:

sudo env ARCHFLAGS="-arch x86_64" gem install id3lib-ruby

Event Calendar Rails Plugin

July 23rd, 2009

For a recent project we needed to show events on a calendar. The existing Rails plugins we tried didn’t allow us to satisfactorily show multiple, overlapping events across calendar days and rows.

I found the same complaint here and began to adapt it to our needs.

I’ve extracted the result and put it on github in the hopes that others might find it useful and/or add improvements.

http://github.com/elevation/event_calendar

The above link has more details, as well as how to install and use the plugin.

Here’s the 1000 word screenshot:

Event Calendar Screenshot

Using the use_all_day option:

Event Calendar using all day option

PLEASE:

Thanks and enjoy!

amend git commit

February 4th, 2009

Thanks to the beauty of local git repositories, I no longer worry about committing. So what if things aren’t pretty, its just a snapshot of my work in progress.

When I push to remote, however, its a good idea to clean up these commits. Up till now I’ve been using git rebase -i which, while very handy, can be a bit of overkill for my normal workflow.

Instead I can use

git commit --amend

to squash my new changes into the latest commit. This is what I’ve usually been doing with rebase -i anyways.

And making a new git alias removes the extra typing.

Git ‘R done