Skip to content

Instantly share code, notes, and snippets.

@simonbaird
Created November 17, 2010 10:52
Show Gist options
  • Save simonbaird/703255 to your computer and use it in GitHub Desktop.
Save simonbaird/703255 to your computer and use it in GitHub Desktop.
write ruby with python style whitespace (a haml hack)
require 'rubygems'
require 'haml'
# Put a - char on each line in just the right place.
# (Need to remove blank lines too, they cause problems)
haml_source = File.read($0).gsub(/\n+/,"\n").gsub(/^\s*/,'\&-')
begin
# Run the file with haml
Haml::Engine.new(haml_source).render
rescue Exception => e
# Spit out the haml source to make it easier to find your error
puts "FAILED!\n#{haml_source}"
raise e
end
exit
# Here's a one line version :)
# Haml::Engine.new(File.read($0).gsub(/\n+/,"\n").gsub(/^\s*/,'\&-')).render; exit
#!/usr/bin/ruby -r hamrbl
# Just a test of hamlrb.rb
module Singing
def sing(count=1)
count.times do |i|
if %w[tweety bigbird].include? @name.downcase
puts "#{@name}: 'tweet tweet #{i+1}'"
else
puts "#{@name}: 'la la la #{i+1}'"
class Singer
include Singing
def initialize(name)
@name = name
# comments are okay :)
Singer.new('Thom').sing(2)
Singer.new('Tweety').sing
$ ls -l
total 24
-rw-r--r-- 1 simon staff 232 17 Nov 21:13 hamrbl.rb
-rwxr-xr-x 1 simon staff 433 17 Nov 21:56 test.rb
$ ./test.rb
Thom: 'la la la 1'
Thom: 'la la la 2'
Tweety: 'tweet tweet 1'
$
@simonbaird
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment