moovweb / tritium

Tritium is a magical document modifying language. It's JavaScript-like and simple to learn. Think XSLT without the nightmare. It was designed by Hampton Catlin (@hcatlin), and has been heavily influenced by Aaron Leung (@akhleung).
http://tritium.io
Mozilla Public License 2.0
33 stars 7 forks source link

read() function breaks! #4

Closed jeffpatzer closed 13 years ago

jeffpatzer commented 13 years ago

Hampton

There appears to be a bug in the read() function. Specifically, I want to import a JS file that lives in a the /scripts/pages/foo_folder/foo.js from a path of scripts/bar_folder/_bar.ts. The lines would read something like this

inject(read("templateStore.js"))

but that spits back an error of:

/usr/local/rvm/gems/ruby-1.9.2-p180@1800flowers/gems/tritium-0.4.151/lib/tritium/parser/parser.rb:265:in `read': No such file or directory - /Users/jefeman/workspace/1800flowers/scripts/template/templateStore.js

Where the important thing is

/Users/jefeman/workspace/1800flowers/scripts/template/templateStore.js

Okay. So its looking in the local folder structure. It just didn't work when it was relative. So let's trying giving it a path that would fix it.

inject(read("../pages/templatized/templateStore.js"))

but that spits back an error of:

/usr/local/rvm/gems/ruby-1.9.2-p180@1800flowers/gems/tritium-0.4.151/lib/tritium/parser/parser.rb:265:in `read': No such file or directory - /Users/jefeman/workspace/1800flowers/scripts/pages/templatized/pages/templatized/templateStore.js

Alrighty, so its doubling the path. That's odd. Let's try another. (Although I don't expect this one to work)

inject(read("../templateStore.js"))

but that spits back an error of

/usr/local/rvm/gems/ruby-1.9.2-p180@1800flowers/gems/tritium-0.4.151/lib/tritium/parser/parser.rb:265:in `read': No such file or directory - /Users/jefeman/workspace/1800flowers/scripts/template/../templateStore.js (Errno::ENOENT)

with the important part being

/Users/jefeman/workspace/1800flowers/scripts/template/../templateStore.js

Okay! Another go (still don't expect this one to work)

inject(read("../templatized/templateStore.js")) 

but alas

/usr/local/rvm/gems/ruby-1.9.2-p180@1800flowers/gems/tritium-0.4.151/lib/tritium/parser/parser.rb:265:in `read': No such file or directory - /Users/jefeman/workspace/1800flowers/scripts/template/../templatized/templateStore.js (Errno::ENOENT)

we get this.

/Users/jefeman/workspace/1800flowers/scripts/template/../templatized/templateStore.js

Okay. Last one

inject(read("../../scripts/pages/templatized/templateStore.js"))

and behind door number 3 is....

/usr/local/rvm/gems/ruby-1.9.2-p180@1800flowers/gems/tritium-0.4.151/lib/tritium/parser/parser.rb:265:in `read': No such file or directory - /Users/jefeman/workspace/1800flowers/scripts/pages/templatized/pages/templatized/templateStore.js (Errno::ENOENT)

where we now have

/Users/jefeman/workspace/1800flowers/scripts/pages/templatized/pages/templatized/templateStore.js

Alright, so I think we found the issue. Its when you provide the exact path that the relative path dude takes over and messes things. That's why we could have ../ in some paths, see them in the path, but when you provide the correct path, it barfs. PUKE!

akhleung commented 13 years ago

Crap, I think I neglected to make 'read' do the same path-chopping that the parser does. I'll look into it.

HamptonMakes commented 13 years ago

Hrrrm... I can't replicate this. Weird.