Offline Ruby Documentation 1

Posted by Paul
on Thursday, October 09

I can run gem server and get the documentation for all my gems served at http://localhost:8808. Very handy indeed and something I always have to hand when coding. I access the Ruby documentation more than anything else and, although the online docs are fine, it's not too useful when I'm offline! It'd be nice if I could get them served locally huh? Below are instructions for doing just that for my version of Ruby. Read on...

  • At the command line type ruby -v to get the version and patch level of the Ruby version you're running.

  • Go to http://svn.ruby-lang.org/repos/ruby/tags and find the path to the revision of the Ruby source that you're running. For me that'd be http://svn.ruby-lang.org/repos/ruby/tags/v1_8_6_111.

  • Go get Subversion if you don't already have it.

  • Get a local copy of the Ruby source for that version. To do so I ran svn export http://svn.ruby-lang.org/repos/ruby/tags/v1_8_6_111/ at the command line. Note I'm exporting (export) rather than checking out (co) as I'm not going to need to commit changes back again.

  • Jump into the root folder of the newly created directory structure (for me this was v1_8_6_111) and run rdoc -o c:\ruby\lib\ruby\gems\1.8\doc\ruby-1.8.6.111. The -o flag tells rdoc where to put the generated documentation (amend as necessary).

  • Jump into 'c:\ruby\lib\ruby\gems\1.8\specifications' and create a new file named 'ruby-1.8.6.111.gemspec' with the following content:

    # -*- encoding: utf-8 -*-
    
    Gem::Specification.new do |s|
      s.name = 'ruby'
      s.version = '1.8.6.111'
      s.homepage = 'http://www.ruby-lang.org'
      s.summary = 'The Ruby documentation'
    end

    When the gem server initialises it searches this folder for gem specifications. Having this file here causes the code to display a link to our Ruby documentation

This means that by going to http://localhost:8808 when the gem server is running I'm able to view the Ruby documentation along with all my gems.

Nice.

Rails, Haml and gettext 0

Posted by Paul
on Saturday, March 08

The other day I started looking at altering an application I've written to be internationalised. This led me to decide on using gettext as my method of internationalisation. I had a few problems getting gettext up and running on my application and then getting it to play well with Haml. I thought I'd write a few notes about it.

My gettext and Rails Gotcha

Make sure that you have the gettext libraries installed on your machine. It would seem that the gettext gem does not do the work itself but palms it off to your system. This had me for a bit.

My gettext and Haml Gotcha

I found the solution for this through the Google cache, the original link looks dead.

The gettext gem has parsers for different types of files ($GETTEXT_GEM_FOLDER/lib/gettext/parser/), Haml is not included. I have the following in $APP/lib/haml_parser.rb.

# haml_parser.rb
require 'gettext/rgettext'
 
module HamlParser
  module_function
 
  def target?(file)
    File.extname(file) == ".haml"
  end
 
  def parse(file, ary = [])
    haml = Haml::Engine.new(IO.readlines(file).join)
    code = haml.precompiled.split(/$/)
    RubyParser.parse_lines(file, code, ary)
  end
end
 
GetText::RGetText.add_parser(HamlParser)

My updatepo rake task looks like:

desc "Update pot/po files to match new version."
task :updatepo do
  require 'gettext/utils'
  require 'haml_parser'
  GetText.update_pofiles("socialclub", Dir.glob("{app,lib}/**/*.{rb,haml}"), "socialclub 0.1.0")
end

Problems Updating RubyGems 1.0.1 on Ubuntu 0

Posted by Paul
on Thursday, February 28

So, I decided to start using gemsonrails to manage freezing gems in my applications. So I ran:

APPLICATION_ROOT$ sudo gem install gemsonrails
APPLICATION_ROOT$ gemsonrails
Installed gems_to_rails 0.7.2 to ./vendor/plugins/gemsonrails

Fine so far. Now to freeze Haml 1.8.2 into my application.

APPLICATION_ROOT$ rake gems:freeze GEM=Haml VERSION=1.8.2
rake aborted!
uninitialized constant Gem::Installer

Oh dear. After some googling I found that gemsonrails requires rubygems 1.9.5. I was currently running a version before that (gem -v) so I updated to rubygems 1.0.1.

$ sudo gem update --system
.
.
.
$ gem list
/usr/bin/gem:23: uninitialized constant Gem::GemRunner (NameError)

After reading a post on ragged blog it seems gem now lives at /usr/bin/gem1.8 on my Ubuntu system instead of the previous /usr/bin/gem. Better fix it up.

$ which gem
/usr/bin/gem
$ sudo rm /usr/bin/gem
$ sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
$ gem list

*** LOCAL GEMS ***


Where have my gems gone?!

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.0.1 (1.0.1)
  - RUBY VERSION: 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/bin/ruby1.8
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org

My gem installation directory is now /usr/lib/ruby/gems/1.8 when it used to be /var/lib/gems/1.8/gems. So I'll make a cup of tea and install my gems again then remove my old gem installation directory

Let it be known that this is a very good example of why you should freeze your gems into your applications. Now I have gemsonrails up and running this should be a more manageable task!

Self Announcement 0

Posted by Paul
on Tuesday, February 12

Hello and welcome to my little patch on the big wide web. It's all still a bit rough around the edges here as I get to grips with what I want to do with this site. Hopefully, given time, this little patch might evolve into something useful to someone other than just me. Only time will tell I guess. For now I'm happy just to have something up and running and a place to show my forays into Ruby on Rails to myself and maybe a few others as well.

Check back soon, who knows what might be here next week.