envjs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/envjsrb CHANGED
@@ -12,7 +12,7 @@ require 'envjs/runtime'
12
12
  RUNTIME = js = Johnson::Runtime.new
13
13
  RUNTIME.extend Envjs::Runtime
14
14
 
15
- RUNTIME.load Envjs::ENVJS
15
+ # RUNTIME.load Envjs::ENVJS
16
16
 
17
17
  EXIT_VERBS = [nil] + %w(exit quit)
18
18
 
@@ -124,24 +124,40 @@ if ARGV.length > 0
124
124
  begin
125
125
  about_blank = true
126
126
  ARGV.each do |file|
127
- if file == "about:blank"
127
+
128
+ uri = URI.parse file
129
+
130
+ if uri.scheme == nil
131
+ uri.scheme = "file"
132
+ begin
133
+ uri.path = Pathname.new(uri.path).realpath.to_s
134
+ rescue Errno::ENOENT; end
135
+ uri = URI.parse uri.to_s
136
+ end
137
+
138
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
139
+
140
+ if uri.scheme == "about" and uri.opaque == "blank"
128
141
  RUNTIME.wait
129
142
  RUNTIME.evaluate("window.location = 'about:blank'", "(comand line)", 1)
130
143
  about_blank = true
131
- elsif file =~ /\.x?html?$/ || file =~ %r(^https?://)
144
+ elsif uri.path =~ /\.x?html?$/ || uri.scheme =~ %r(^https?)
145
+
132
146
  # this might want to go alway; jazrb does it manually now, which I think was the use case
133
147
  # that wanted this
134
148
  if !about_blank
135
149
  RUNTIME.wait
136
150
  RUNTIME.evaluate("window.location = 'about:blank'", "(comand line)", 1)
137
151
  end
152
+
138
153
  RUNTIME.wait
139
- RUNTIME.evaluate("window.location = 'file://#{Pathname.new(file).realpath}'", file, 1)
154
+ # RUNTIME.evaluate("window.location = 'file://#{Pathname.new(file).realpath}'", file, 1)
155
+ RUNTIME.evaluate("window.location = '#{uri_s}'", file, 1)
140
156
  about_blank = false
141
157
  else
142
158
  RUNTIME.become_first_script_window
143
- RUNTIME.top_level_load file
144
- RUNTIME.load file
159
+ RUNTIME.top_level_load uri_s
160
+ RUNTIME.load uri_s
145
161
  end
146
162
  end
147
163
  rescue Johnson::Error => je
data/lib/envjs/env.js CHANGED
@@ -127,9 +127,14 @@ $env.location = function(path, base){
127
127
  base.path = path;
128
128
  base = base + "";
129
129
  } else {
130
+ // debug("bb", base);
131
+ // base = base + Ruby.URI.parse(path);
132
+ b = Ruby.eval("lambda { |a,b| a+b; }");
133
+ base = b(base,path);
134
+ // base.path = base.path.substring(0, base.path.lastIndexOf('/'));
135
+ // base.path = base.path + '/' + path;
130
136
  base = base + "";
131
- base = base.substring(0, base.lastIndexOf('/'));
132
- base = base + '/' + path;
137
+ // debug("bbb", base);
133
138
  }
134
139
  var result = base;
135
140
  // ? This path only used for files?
data/lib/envjs/runtime.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'envjs'
2
2
  require "open-uri"
3
- require 'rubygems'
3
+ require 'pathname'
4
4
  begin
5
5
  require 'fsdb'
6
6
  rescue LoadError; end
@@ -90,7 +90,7 @@ EOJS
90
90
  top_level_js = nil
91
91
 
92
92
  add_dep = nil
93
-
93
+
94
94
  clear_deps = lambda do |w|
95
95
  begin
96
96
  if db.call
@@ -138,7 +138,20 @@ EOJS
138
138
  end
139
139
  end
140
140
  if !loc || loc == "about:blank"
141
- tll = "file://" + Pathname(top_level_js).realpath.to_s
141
+ uri = URI.parse top_level_js
142
+ if uri.scheme == nil
143
+ uri.scheme = "file"
144
+ begin
145
+ uri.path = Pathname.new(uri.path).realpath.to_s
146
+ rescue Errno::ENOENT; end
147
+ uri = URI.parse uri.to_s
148
+ end
149
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
150
+
151
+ # tll = "file://" + Pathname(top_level_js).realpath.to_s
152
+
153
+ tll = uri_s
154
+
142
155
  if ( tll != path )
143
156
  loc = tll
144
157
  end
@@ -168,7 +181,25 @@ EOJS
168
181
  if files.length == 2 && !(String === files[1])
169
182
  f = files[0]
170
183
  w = files[1]
171
- v = open(f).read.gsub(/\A#!.*$/, '')
184
+
185
+ # Hmmm ...
186
+ uri = URI.parse f
187
+
188
+ if uri.scheme == nil
189
+ uri.scheme = "file"
190
+ begin
191
+ uri.path = Pathname.new(uri.path).realpath.to_s
192
+ rescue Errno::ENOENT; end
193
+ uri = URI.parse uri.to_s
194
+ end
195
+
196
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
197
+
198
+ if uri.scheme == "file"
199
+ uri_s = uri.path
200
+ end
201
+
202
+ v = open(uri_s).read.gsub(/\A#!.*$/, '')
172
203
  loc = nil
173
204
  add_dep.call w, f
174
205
  evaluate(v, f, 1, w, w, f)
@@ -177,6 +208,35 @@ EOJS
177
208
  end
178
209
  }
179
210
 
211
+ def load *files
212
+ files.map { |f|
213
+ # Hmmm ...
214
+
215
+ uri = URI.parse f
216
+ if uri.scheme == nil
217
+ uri.scheme = "file"
218
+ begin
219
+ uri.path = Pathname.new(uri.path).realpath.to_s
220
+ rescue Errno::ENOENT; end
221
+ uri = URI.parse uri.to_s
222
+ end
223
+ uri_s = uri.to_s.sub %r(^file:/([^/])), 'file:///\1'
224
+
225
+ if uri.scheme == "file"
226
+ super uri.path
227
+ else
228
+ raise "hell 1"
229
+ end
230
+
231
+ # v = open(uri_s).read.gsub(/\A#!.*$/, '')
232
+ # loc = nil
233
+ # add_dep.call w, f
234
+ # evaluate(v, f, 1, w, w, f)
235
+ # evaluate(File.read(f).gsub(/\A#!.*$/, ''), f, 1)
236
+
237
+ }.last
238
+ end
239
+
180
240
  master.reload = lambda { |*files|
181
241
  if files.length == 2 && !(String === files[1])
182
242
  f = files[0]
@@ -274,6 +334,8 @@ EOJS
274
334
  @envjs[k] = v
275
335
  end
276
336
 
337
+ load Envjs::ENVJS
338
+
277
339
  end
278
340
  end
279
341
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Resig
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-25 00:00:00 -08:00
13
+ date: 2010-02-05 00:00:00 -08:00
14
14
  default_executable: envjsrb
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency