Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Allow passing of File objects to #13

wants to merge 1 commit into from

2 participants


This patch allows for the passing of File objects, which means that html files can be processed in-place, so references to relative files will be in-tact, rather than Harmony trying to find them in the temporary directories.


Why did I build this? While I was playing with RightJS in Harmony I noticed that doing harmony_page.load('right.js') threw errors — this was because RightJS expects itself to feature in the list of <script> tags — it appears that #load doesn't inject the javascript in that way so it was having a rough time.

With this patch I can now create an HTML loader file and do'loader.html')), but I'd really like Harmony/Johnson to look for references in the current ruby working directory too, if anyone knows how that could be achieved? Here's an example:

require 'harmony'
# => true 
# => true
page = <<-eHTML
<html><head><script src="right.js"></script></head><body></body></html>
# WARNIING: [Wed Sep 08 2010 12:32:57 GMT+0100 (BST)] {ENVJS} could not load script /var/folders/0g/0gCwWYT-HeGprEfdSvQmDU+++TI/-Tmp-/right.js: No such file or directory - /var/folders/0g/0gCwWYT-HeGprEfdSvQmDU+++TI/-Tmp-/right.js
# => #<Harmony::Page:0x101847f40 @window=[object Window 1]> 

I see, so you did try a fix for this yourself, good call :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 8, 2010
  1. @jphastings
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +6 −1 lib/harmony/page.rb
7 lib/harmony/page.rb
@@ -26,7 +26,12 @@ def from_uri(uri)
def from_document(document)
-'harmony') {|f| f << document; @path = f.path }
+ # Allow passing of File objects:'index.html'))
+ if document.is_a? File
+ @path = File.expand_path document.path
+ else
+'harmony') {|f| f << document; @path = f.path }
+ end
Something went wrong with that request. Please try again.