ryonakae
3/11/2012 - 3:41 PM

HAML with YAML

HAML with YAML

airports:
- 
  name: 'La Crosse, WI'
  code: LSE
  directions: http://g.co/maps/62ufz
  image: 'lacrosse-image.jpg'
  website: http://www.cityoflacrosse.org/index.aspx?NID=851
  rental_cars: http://www.cityoflacrosse.org/index.aspx?NID=882
  description: La Crosse is the closest flight destination. It is right 
    on the Mississippi and about an hour away. It is a small airport so we 
    <strong>definitely recommend</strong> making a rental car reservation ahead of time.
-
  name: 'Madison, WI'
  code: MSN
  directions: http://g.co/maps/sghms 
  image: madison-image.jpg
  website: http://www.msnairport.com/
  rental_cars: http://msnairport.com/guide/car_rental.aspx
  description: You also can fly into Madison and drive through the gorgeous 
    countryside. Flying into Madison often saves you $50 (over La Crosse), however,
    you now have a two-and-half hour drive.
-
  name: 'Minneapolis, WI'
  code: MSP
  directions: http://g.co/maps/tk827
  image: minneapolis-image.jpg
  website: http://msairport.com/
  rental_cars: http://mspairport.com/GroundTransportation/car-rentals.aspx 
  description: Another option is to drive three hours from the Minneapolis airport. 
    Flying into here will often save you $50 (over La Crosse).
 

- require 'YAML'
- data = YAML.load(File.read("#{File.basename(__FILE__,'.haml')}.yaml"))
!!!
%html
  %head
    %title
      = data['title']
  %body
    .container
      - data['airports'].each_with_index do |airport,index|
        %div.span-20.details
          %img.span-2(src="#{airport['image']}")
          .span-16.instructions
            .span-16.title 
              = "#{airport['name']} (#{airport['code']})"
            = airport['description']
            .prepend-5.links
              [
              %a(href="#{airport['website']}" target="_blank") Website
              |
              %a(href="#{airport['rental_cars']}" target="_blank") Rental Cars
              |
              %a(href="#{airport['directions']}" target="_blank") Directions 
              ]
        - if index < data['airports'].count - 1
          .border-line.span-18
$ haml index.haml > index.html
guard 'shell' do
  watch(/(.*).(?:haml|ya?ml)/) do |file|
    haml_file = file.first.gsub(/ya?ml/,'haml')
    html_file = file.first.gsub(/[yh]a?ml/,'html')
  
    puts "Converting #{haml_file} to #{html_file}"
    `haml #{haml_file} > #{html_file} --trace`
  end
end