jump to navigation

Use Custom Fonts in Ruby on Rails 3.1 with the asset pipeline February 24, 2012

Posted by hoitomt in Programming.
add a comment

Just a quick post on something I just learned.  If you want to use a custom font in a ROR 3.1 project start with this post: http://spin.atomicobject.com/2011/09/26/serving-fonts-in-rails-3-1/

Sidebar: FontSquirrel is awesome, the kit is really helpful. It’s another one of those really fantastic web projects that somebody put out there for free.

Anyway, after you get the font kit downloaded and have it unzipped into app/assets/fonts look in the stylesheet.css file in the kit.  There is some CSS that you can use to get started. Update the css to support the asset pipeline. You have to structure your URLs as follows:

@font-face {

font-family: ‘DroidSerifRegular’;
src: url(/assets/DroidSerif-Regular-webfont.eot);
src: url(/assets/DroidSerif-Regular-webfont.eot?#iefix) format(‘embedded-opentype’),
url(/assets/DroidSerif-Regular-webfont.woff) format(‘woff’),
url(/assets/DroidSerif-Regular-webfont.ttf) format(‘truetype’),
url(/assets/DroidSerif-Regular-webfont.svg#DroidSerifRegular) format(‘svg’);
font-weight: normal;
font-style: normal;

}

Finally, if you are using Chrome for development it will throw an error like “Resource interpreted as Font but transferred with MIME type application/octet-stream”.  To fix this update config/initializers/mime_types with this line:

Mime::Type.register “font/opentype”, :font

That will fix the Chrome error.  Cheers and thanks to the Intertubes for the help:

http://spin.atomicobject.com/

http://www.fontsquirrel.com/

http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts

Java and Ruby, Rails and Spring February 15, 2012

Posted by hoitomt in Programming.
add a comment

I’m in the middle of studying for the Core Spring Essentials Certification exam and wanted to put a couple of thoughts out there with regards to Spring and Java for the Web. Spring has a nice web framework know as Spring MVC. It doesn’t need a JEE container to run so it runs on Tomcat and other non-enterprise servers. I think a person could get it set up on a PAAS like Heroku, now that they have Java support.  So it makes a very viable option for developing web applications for personal and freelance projects.

However I don’t know why anybody would use it for that.  If you are a Java developer and don’t know Ruby on Rails, or one of the other newer web language/framework combos, I suppose Spring MVC would be a good option.  But compared to ROR, Spring MVC seems like a much more complex way to solve the exact same problem: serve dynamic web pages with data pulled from a database mixed with static content.

I know that Spring will integrate into a Java environment that supports messaging, transactions, and any other enterprise bits that you need. But ROR can do some of those things as well and, really, how many sites really need a full enterprise backend? I’m a J2EE dev in my day job so I’m tempted to use a Java framework for my side projects as well, as a way of improving my skills. But using Spring MVC seems like overkill.

I really don’t mean to bash Spring or to criticize Spring MVC. Spring is a great framework and it makes Java Enterprise Programming much easier. I understand that if you are a Java programmer and want to start web programming on the side, then Spring MVC (and probably Spring ROO) are a perfect starting point for you. But my advice would be to learn one of the new “scripting” languages (ROR) or Javascript/Node.js/Backbone.js.

Follow

Get every new post delivered to your Inbox.