December 31, 2007 at 12:40 am
· Filed under CSSes, Rails, Ruby
I try to follow some good guidelines when developing a website. I separate content from style with CSS, for example, by judiciously using class and id attributes for html elements. Of course, I also usually leave the styling until the content has been mostly completed. The problem with that, though, is I end up with many views and many helpers that reference class and id attributes for elements I haven’t styled yet.
So I made CSSes. It searches helpers and views (you’re not putting style information in your controllers or models are you?) for references to html entities, and creates a bare-bones CSS file.
It has a few shortcomings. It doesn’t yet handle link_to* or image_tag or any of the form building methods, just raw referenced html. It’s only Rails 2.0.x friendly so far. It makes just one file, public/stylesheets/application.css, and you can’t control the name. If you use the < character in html attribute values, it will probably make a little noise. It doesn’t have any unit tests.
But! It was sure nice to run after working on a site for a while and finding this waiting for me:
body {}
div {}
div#author_bio {}
div#author_url {}
div#chapbook_exceprt {}
...
div.chapbook_links {}
div.poem_content {}
div.poem_links {}
...
h1 {}
h1#author_name {}
h1#chapbooks_header {}
...
Get it:
sudo gem install csses
Run it:
script/generate css
Any help at all would be greatly appreciated; it’s pretty raw. But I plan on making it more robust and more fun.
Update!: We’ve got tests, automatic anchor tag pseudo-classes, and basic link_to* and image_tag support (figuring out how to handle class and id attributes in rails helpers is a little trickier than I guessed at first). AND: it’s a gem now.
Permalink
December 24, 2007 at 2:06 pm
· Filed under Ruby
According to Matz, Ruby 1.9.0 will be released today (relatively). The expected time is 3pm JST on 12/25, which is 1am EST on 12/25. I’ll be staying up until 11pm MST today (12/24) (where I am), hoping it gets released on time. All incompatibilities with 1.8.6 will be finalized, but it’s not as stable as hoped. Nonetheless, I’m jazzed. I’ve been playing with the 1.9.0 trunk, enjoying the changes and YARV’s speed.
Here’s the bash script I’ve been using to update my 1.9 install (taken mostly from one I saw somewhere, but can’t find now). I’ll probably be using it to keep tracking trunk.
#!/bin/bash
set -e
RUBY19_DIR=~/dev/ruby19
cd ${RUBY19_DIR}
svn up
VERSION=`grep 'RUBY_VERSION ' version.h | awk '{print $3}' | sed -e's/"//g'`
SUFFIX=`grep RUBY_RELEASE_CODE version.h | awk '{print $3}'`
echo "Building ${VERSION}-${SUFFIX}"
./configure --prefix=/usr/local --program-suffix=19 --with-readline-dir=/usr/local
make
sudo make install
exit 0
Permalink
December 17, 2007 at 12:52 pm
· Filed under Guess Method
It looks like Giles Bowkett’s Utility Belt gem is having the same sort problems with Rails as GuessMethod, i.e. loading .irbrc anywhere that isn’t irb or script/console breaks things. His problem was one of method name conflicts and visibility, but the ultimate solution is the same: leave .irbrc alone when loading script/server! As Giles says, this should be considered a bug in Rails…
…but it appears to have been fixed in Rails 2.0.x, so any temporary hacks can go away as soon as everyone upgrades.
Permalink
December 13, 2007 at 1:04 am
· Filed under Guess Method, Rails, Ruby, irb
I was looking at the code for Giles Bowkett’s utility_belt gem, and came across something I wish I had known about ages ago. There’s a way to execute some code in an .irbrc after everything else when the irb session starts (technically, when the context changes). The problem with GuessMethod and Rails was that GuessMethod can’t load first. Problem solved.
So now my .irbrc has this line to include GuessMethod in a way that works with script/console:
IRB.conf[:IRB_RC] = Proc.new { require 'guessmethod' }
Of course, if you’re using that IRB.conf[:IRB_RC] for something else (like using utility_belt), something’s going to overwrite something.
Anyway, I’ve finally just given up and wrapped my entire .irbrc in a big unless:
unless $0 == 'script/server'
I’m confused as to why script/server loads .irbrc for every request, but at least this mitigates that issue a bit. (As an aside, can someone tell me why it does that?)
Permalink
December 7, 2007 at 12:41 pm
· Filed under Ruby
For those, like me, who missed RubyConf this year, Confreaks have (finally) put up (most) of the videos.
The Reject Conf videos have been up for weeks.
Permalink
December 6, 2007 at 4:39 pm
· Filed under Guess Method, Ruby
I was talking yesterday to Corey (of mini-magick fame) and he suggested something for GuessMethod. I implemented it and sent him an instant message demonstrating such. He said, “Oh yeah! I totally want this. This will enrage so many people! I love it.”
What is it? GuessMethod for Rake.
mvb:~/hot-rails-app cms$ grake db:migrat
(in /Users/cms/hot-rails-app)
attention: invoking task db:migrate instead of db:migrat
...
You can use your new grake command, or add require 'guessmethod/rake' to your rakefiles for this functionality. This is probably ten times more dangerous than plain old GuessMethod. Please, oh please, don’t use this in production.
Otherwise, things are pretty much the same:
001:0> Strin.tos
attention: replacing non-existant constant Strin with String for Object
attention: sending to_s instead of tos to String:Class
“String”
Get it:
sudo gem install guessmethod
Permalink