Rails, Bootstrap, Icons, and Classes

Written by Tim Bielawa on May 1, 2013 Categories: /dev/null, Documentation, Programming Tags: , , , ,

Scope

You’re using Ruby on Rails and the Twitter Bootstrap framework. You are using the link_to ActionView helper method. The generated anchor will be visually represented in a navbar as a Bootstrap button component (via the ‘btn’ and ‘btn-small’ class attributes). Finally, you want to use one of those sweet Boostrap icons instead of text. It should look something like this:

RNOC Action Bar

RNOC Action Bar

The Problem

I had difficulty understanding the correct way to call the link_to method to get the results I desired. Part of my failure to grok is because I’m a complete newbie to RoR, and the other part of it is because the link_to method has 4 distinct signatures that you can call it by.

After some searching around I found a couple of resources on Stack Overflow which looked promising:

However, none of those results were quite exactly what I was looking for. They did provide some useful insight into solving the problem though.

Solution

Here’s the code:

Explanation

If my understanding is correct, then this approach implements the third link_to method signature: link_to(options = {}, html_options = {}) do 

The options parameter we give here is a hash which is passed to the url_for method, and finally to the Route Module. It ends up returning a URL string in the form of http://yoursite/pages/new

The html_options parameter describes the attributes (other than href) which we desire present in the generated anchor. In this example we are describing an anchor with two classes: btn and btn-small. You could add additional symbols to the hash just as easily: {:class => ‘btn btn-small’, :id => ‘new-page-button’, :title => ‘Create A New Page’}

Finally, the way we’re calling link_to requires that we pass it a block to use as the generated link body (or in our case, icon). So we escape from the ERB sequence for a moment, enter the HTML which Boostrap turns into an icon, and then close the block.

No Comments

Scholarship Announcement Recap

Written by Tim Bielawa on April 24, 2013 Categories: GNU/Linux, Life Tags: ,

Gave the Open Source Scholarship talk today with @akbutcher. It was a smash hit. We were lucky to get a lot of great promotion around the internet for this event:

I also want to give Michael Dehaan a huge thank you for his cameo today. The students loved it!

The presentation is available online: Open Source: A Guide. I was referring to it as our self documenting presentation, in that virtually everything Andrew and I touched on during the talk was linked from within the preso slides.

Thanks to all the students who came out (especially the folks who asked questions). We’re doing this for you!

Michael Dehaan on Google Hangout

Michael Dehaan on Google Hangout

No Comments

A new scholarship for open source

Written by Tim Bielawa on April 13, 2013 Categories: /dev/null, GNU/Linux, Life Tags: , ,
Education, Design, Community, Coding, Technical Writing

Open Source Scholars

I’m super proud to be able to say this today:

Some of my friends and I have started a scholarship at West Virginia University. We’re calling it the “Open Source Scholarship“. Here’s our pitch:

The Problem: Paying for school is hard, when you’re finished you haven’t learned enough skills to set you apart from your peers, and your resume is unimpressive.

This is a scholarship to motivate young adults to become involved in open source communities.

Committee members working professionally in the open source market will use their collective 30 years experience to recommend students based on the impact of their contributions.

We’ll show you what open source is all about: how to negotiate the open source ecosystem, show you were to get started, and walk you through your first contributions.

On April 23rd of this month @akbutcher and I will taking a few days off from work to fly back to Morgantown, WV where we’ll make the official announcement to the students. Immediately following the announcement we’ll give the what open source is about and how to become involved in it prezo. We’re hoping that if we pull it off right the students will feel comfortable enough to go out and start looking for ways to become involved.

We know what we’re asking the students to do isn’t trivial, so we’re not going to leave them all on their own! After the announcement has been made we’ll be maintaining an IRC channel on freenode.net and handing out our contact information.

The students will have from the day of the official announcement through the Friday before Thanksgiving this year to make contributions. We’ve put together a simple submission portal where they can enter and track their contributions.

I am so excited to see this take off! Check out the official scholarship website for all the details:

http://OpenSourceScholars.org

No Comments

Using TTF fonts with DocBook and dblatex

Written by Tim Bielawa on April 4, 2013 Categories: DocBook, Documentation, GNU/Linux, Publishing, Tutorials, XML Tags: , , , , , , , , ,

The Problem:

You’re writing a book in DocBook XML, publishing it with dblatex, and you dislike (or want to customize) the fonts it uses in the rendered PDF.

You hunt around the internet and find a nice family of fonts you want to use in your final product. Best of all, they’re free and released under the Open Font License!(Thanks, Adobe!)

The dblatex documentation shows you how to set your fonts, but you can’t seem to get it to work.

  • What do you put in for the names anyway?
  • Do spaces matter, or do you enter file names?
  • Where do you install the fonts?
  • OTF, TTF? What type of font must they be?
  • Does the TeX engine even support this?

The Solution:

1. Find The Family Names

Caveat: I can verify that this solution works for TTF type fonts, I can not comment on how well it works for other font types.

First, you will need to identify the actual family name of the fonts you want to use. If your font is not installed on your system there is a command called otfinfo that can tell you the family of the font file (despite sounding specific to OTF fonts, this works on TTFs as well). The otfinfo command is provided by the lcdf-typetools package:

If your desired font is already installed on your system you can use the fc-list command instead to find the same information (fc-list is provided by the fontconfig package):

2. Install New Font Files

If this is a new font on your system then you’ll need to install it. There are (at least) two locations that work:

  • $HOME/.fonts
  • /usr/share/fonts/truetype/

The Font Manager application (package: font-manager) also provides a graphical way to install font collections.

(Optional) Rebuild Font Cache

Rebuild your font caches with the fc-cache -f -v command. If I recall correctly, you need to have super user permissions to run this. I may be wrong though.

3. Configure dblatex

The necessary changes to consume your custom fonts isn’t difficult. Assume that up until now you’ve been rendering your PDFs from XML source like this:

  • dblatex -o output/Virtual-Disk-Operations.pdf Virtual-Disk-Operations.xml

We need to use XSLT stylesheets to define what our chosen font families are going to be. In this example I’m using Source Sans Pro for the body font and Source Code Pro for monospaced sequences.

First, make a directory called xsl and put a file like this in it:

Next, slightly modify the command you run to build your PDFs (new parts are in bold text):

  •  dblatex -p xsl/dblatex-pdf.xsl -b xetex -o output/Virtual-Disk-Operations.pdf Virtual-Disk-Operations.xml

-p xsl/dblatex-pdf.xsl: This tells dblatex that we’re providing a “user stylesheet” to use when transforming the XML. This stylesheet only has our font customizations in it, but you can put much more in them than just that.

-b xetex: This tells dblatex that instead of rendering our PDF with pdftex we want to use a different backend driver (or “TeX engine”). Specifically we want to use the xetex driver. We choose the xetex driver because of it’s superior font handling abilities via the fontspec LaTeX package. When we use the xetex engine dblatex will insert some special macros into the intermediate LaTeX document it generates, this process is transparent to the end user:

After this, dblatex runs any custom post-compilation scripts, and then hands the intermediate file off to xetex where it is finally transformed into PDF format.

4. The Aftermath

In my case there were some unexpected side-effects from switching backends. Here’s what I’ve noticed so far:

  • remark elements no longer appear in PDF output
  • The DRAFT watermark no longer appears
  • screen elements no longer show a ‘wrapping character’ in long lines
Compare new formatting with old

On the left is the book rendered with xetex and the new fonts.On the right is the book rendered with pdftex and no special font customizations.

The only thing that really bothers me is the broken word-wrapping character. I can deal with the others breaking. I had intended to remove them from the final product anyway.

No Comments

PROTIP: Shell Functions – cdmkdir

Written by Tim Bielawa on March 29, 2013 Categories: /dev/null

Here’s a shell function which unifies the act of creating a directory and then subsequently changing into it:

Example usage:

No Comments