views:

14

answers:

2

I have a two line script that works nicely in ruby. I moved it to haml and getting the error

NameError at / uninitialized constant Tilt::CompileSite::Nokogiri

the haml code:

      %td
        - @doc = Nokogiri::XML(File.open(file))
        = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }

any idea how I can make it work?

using below on Win XP SP3

  • ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
  • nokogiri (1.4.3.1 x86-mingw32)
  • sinatra (1.0)
  • thin (1.2.7 x86-mswin32)
A: 

still do not know why the error happens but I solved it by have a function defined in sinatra file and calling it in haml file = get_testsuite(file)

def get_testsuite (file)

  @doc = Nokogiri::XML(File.open(file))
  output = Array.new
  @doc.xpath("//testsuite").each_with_index {|node,index|
    output << "#{index+1}. #{node.attributes["name"].value}<BR>"
  }
  return output
end
Radek
+1  A: 

Try this:

%td
  - @doc = ::Nokogiri::XML(File.open(file))
  = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"].value}<BR>" }
Konstantin Haase