red 4.1.5 → 4.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/red CHANGED
@@ -6,7 +6,6 @@
6
6
  require 'rubygems' rescue nil
7
7
  require 'red'
8
8
  require 'red/executable'
9
- require 'red/version'
10
9
  require 'optparse'
11
10
  require 'ftools'
12
11
 
data/lib/red.rb CHANGED
@@ -3,6 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'parse_tree'
5
5
  require 'red/errors'
6
+ require 'red/executable'
6
7
  require 'red/plugin'
7
8
  require 'red/nodes/assignment_nodes'
8
9
  require 'red/nodes/call_nodes'
@@ -15,7 +16,7 @@ require 'red/nodes/logic_nodes'
15
16
  require 'red/nodes/variable_nodes'
16
17
 
17
18
  module Red # :nodoc:
18
- VERSION = '4.1.5'
19
+ VERSION = '4.1.6'
19
20
 
20
21
  ARRAY_NODES = {
21
22
  :and => LogicNode::Conjunction::And,
@@ -9,18 +9,6 @@ module Red # :nodoc:
9
9
  puts @files && exit
10
10
  end
11
11
 
12
- # def add_unobtrusive(library)
13
- # @files ||= ''
14
- # self.build_red_plugin_for_rails(false)
15
- # self.create_plugin_file(:copy, 'public/javascripts/dom_ready.js', File.join(File.dirname(__FILE__), "../javascripts/#{(library || '').downcase}_dom_ready.js"))
16
- # self.create_plugin_file(:copy, 'public/javascripts/red/unobtrusive.red', File.join(File.dirname(__FILE__), "../javascripts/red/unobtrusive.red"))
17
- #
18
- # rescue Errno::ENOENT
19
- # puts "There is no Unobtrusive Red support for #{library}"
20
- # ensure
21
- # puts @files && exit
22
- # end
23
-
24
12
  def make_plugin_directory(dir, only_this_directory = false)
25
13
  parent_dir = File.dirname(dir)
26
14
  self.make_plugin_directory(parent_dir) unless File.exists?(parent_dir) || only_this_directory
data/lib/red/plugin.rb CHANGED
@@ -1,43 +1,49 @@
1
1
  module Red
2
- class << self
3
- def already_updated?
4
- @@red_updated ||= false
5
- end
6
-
7
- def update_javascripts
8
- @@red_updated = true
9
- Red.init
10
- red_dir = 'public/javascripts/red/'
11
- Dir.glob("#{red_dir}**/*.red").each do |filepath|
12
- if self.update?(filename = filepath.gsub(red_dir,'').gsub(/.[rb|red]+$/,'')) || true
13
- js_output = (File.read(filepath).translate_to_sexp_array.red! || '')
14
-
15
- filename.split('/')[0...-1].inject('public/javascripts') do |string,dir|
16
- new_dir = string << '/' << dir
17
- Dir.mkdir(new_dir) unless File.exists?(new_dir)
18
- string
19
- end
20
-
21
- File.open("public/javascripts/#{filename}.js", 'w') { |f| f.write(js_output) }
22
- end
23
- end
24
- end
25
-
26
- def update?(filename)
27
- if File.exists?("public/javascripts/#{filename}.js")
28
- (File.mtime("public/javascripts/red/#{filename}.red") rescue File.mtime("public/javascripts/red/#{filename}.rb")) > File.mtime("public/javascripts/#{filename}.js")
29
- else
30
- return true
2
+ def self.update_javascripts
3
+ red_dir = 'public/javascripts/red/'
4
+ (Dir.glob("%s/*.red" % red_dir) + Dir.glob("%s/*.rb" % red_dir)).each do |filepath|
5
+ basename = File.basename(filepath).gsub(/\.(rb|red)/,'')
6
+ if self.update?(basename)
7
+ Red.init(filepath)
8
+ js_output = File.read(filepath).translate_to_sexp_array.red!
9
+ ruby_js = compile_ruby_js_source
10
+ pre = Red.debug ? "try{" : ""
11
+ post = Red.debug ? "}catch(e){if(e.__class__){m$raise(e);};$ee=e;var m=e.message.match(/([^\\$]+)\\.m\\$(\\w+)\\sis\\snot\\sa\\sfunction/);if(m){m$raise(c$NoMethodError,$q('undefined method \"'+m[2]+'\" for '+m[1]));};var c=e.message.match(/([\\s\\S]+)\\sis\\sundefined/);if(c){c=c[1].replace(/\\./g,'::').replace(/c\\$/g,'');m$raise(c$NameError,$q('uninitialized constant '+c));};}" : ""
12
+ File.open("public/javascripts/%s.js" % basename, 'w') {|f| f.write(pre + ruby_js + js_output + post)}
31
13
  end
32
14
  end
33
15
  end
34
16
 
17
+ def self.update?(basename)
18
+ return true unless File.exists?('public/javascripts/%s.js' % basename)
19
+ return (File.mtime('public/javascripts/red/%s.red' % basename) rescue File.mtime('public/javascripts/red/%s.rb' % basename)) > File.mtime('public/javascripts/%s.js' % basename)
20
+ end
21
+
22
+ # def self.update_javascripts
23
+ # @@red_updated = true
24
+ # Red.init
25
+ # red_dir = 'public/javascripts/red/'
26
+ # Dir.glob("#{red_dir}**/*.red").each do |filepath|
27
+ # if self.update?(filename = filepath.gsub(red_dir,'').gsub(/.[rb|red]+$/,'')) || true
28
+ # js_output = (File.read(filepath).translate_to_sexp_array.red! || '')
29
+ #
30
+ # filename.split('/')[0...-1].inject('public/javascripts') do |string,dir|
31
+ # new_dir = string << '/' << dir
32
+ # Dir.mkdir(new_dir) unless File.exists?(new_dir)
33
+ # string
34
+ # end
35
+ #
36
+ # File.open("public/javascripts/#{filename}.js", 'w') { |f| f.write(js_output) }
37
+ # end
38
+ # end
39
+ # end
40
+
35
41
  module RailsBase # :nodoc:
36
42
  def self.included(base)
37
43
  base.send('alias_method', :red_old_process, :process)
38
44
  base.class_eval do
39
45
  def process(*args)
40
- Red.update_javascripts #unless Red.already_updated?
46
+ Red.update_javascripts
41
47
  red_old_process(*args)
42
48
  end
43
49
  end
@@ -71,7 +71,11 @@ module CodeEvents
71
71
  def fire(sym, delay, *args)
72
72
  name = sym.to_sym
73
73
  return self unless @code_events && events_group = @code_events[name]
74
- events_group.each {|proc| proc.process_event(self, delay, args) }
74
+ events_group.each do |proc|
75
+ `var f=function(){return proc.__block__.apply(null,args);}`
76
+ `if(delay){return setTimeout(f,delay);}`
77
+ `f()`
78
+ end
75
79
  return self
76
80
  end
77
81
 
@@ -193,12 +197,4 @@ module CodeEvents
193
197
  return self
194
198
  end
195
199
  end
196
-
197
- class ::Proc # :nodoc:
198
- def process_event(context, delay, args_array) # :nodoc:
199
- `var f=this.__block__.__unbound__,event_function=function(){return f.apply(context,args_array);}`
200
- `if(delay){return setTimeout(event_function,delay);}`
201
- `event_function()`
202
- end
203
- end
204
200
  end
@@ -1,3 +1,5 @@
1
+ require 'document'
2
+
1
3
  # Class +Cookie+ governs the writing and accessing of cookies in the browser.
2
4
  #
3
5
  # A cookie is a key-value pair stored by your browser as text data. If you
@@ -91,7 +93,7 @@ class Cookie
91
93
  end
92
94
  `str += '; secure'` if cookie.secure
93
95
 
94
- `#{cookie.document.native}.cookie = str`
96
+ `#{cookie.document}.__native__.cookie = str`
95
97
  return cookie
96
98
  end
97
99
 
@@ -25,6 +25,15 @@ class Request
25
25
  }
26
26
  }
27
27
 
28
+ class Response
29
+ attr :text, :xml
30
+
31
+ def initialize(text,xml)
32
+ @text = text
33
+ @xml = xml
34
+ end
35
+ end
36
+
28
37
  # call-seq:
29
38
  # Request.new(options = {}) -> request
30
39
  #
@@ -34,9 +43,9 @@ class Request
34
43
  `this.__xhr__ = typeof(ActiveXObject)=='undefined' ? new XMLHttpRequest : new ActiveXObject('MSXML2.XMLHTTP')`
35
44
  @options = OPTIONS.merge(options)
36
45
  `#{@options[:headers]}.__xhr__=this.__xhr__` # MooTools sets the ResponseHeaders in the xhr
37
- # def (@options[:headers]).[](name) # only during execution, but allows you to get
38
- # `this.__xhr__.getResponseHeader(name)` # at them at any time. I'm not sure whether it
39
- # end # is necessary for us to emulate this exactly.
46
+ # def (@options[:headers]).[](name) # only during execution, but allows you to get
47
+ # `this.__xhr__.getResponseHeader(name)` # at them at any time. I'm not sure whether it
48
+ # end # is necessary for us to emulate this exactly.
40
49
  end
41
50
 
42
51
  # call-seq:
@@ -127,15 +136,6 @@ class Request
127
136
  return self
128
137
  end
129
138
 
130
- # call-seq:
131
- # req.failure! -> req
132
- #
133
- # Fires _req_'s "response" and "failure" callbacks, then returns _req_.
134
- #
135
- def failure!
136
- self.fire(:response).fire(:failure, @xhr);
137
- end
138
-
139
139
  # call-seq:
140
140
  # req.headers -> hash
141
141
  #
@@ -161,11 +161,11 @@ class Request
161
161
  `try{#{@status}=xhr.status}catch(e){;}`
162
162
 
163
163
  if self.success?
164
- @response = {:text => `$q(xhr.responseText)`, :xml => `xhr.responseXML`}
165
- self.success!(self.process_scripts(@response[:text]), @response[:xml])
164
+ @response = Response.new(self.process_scripts(`$q(xhr.responseText)`), `xhr.responseXML`)
165
+ self.fire(:response, 0, @response).fire(:success, 0, @response).call_chain
166
166
  else
167
- @response = {:text => nil, :xml => nil};
168
- self.failure!
167
+ @response = Response.new(nil,nil)
168
+ self.fire(:response, 0, @response).fire(:failure, 0, @xhr)
169
169
  end
170
170
 
171
171
  `xhr.onreadystatechange=function(){;}`
@@ -190,15 +190,6 @@ class Request
190
190
  return str.strip_scripts(@options[:eval_scripts])
191
191
  end
192
192
 
193
- # call-seq:
194
- # req.success!(text, xml) -> req
195
- #
196
- # Fires _req_'s "response" and "success" callbacks, then returns _req_.
197
- #
198
- def success!(text, xml)
199
- self.fire(:response, [text, xml]).fire(:success, [text, xml]).call_chain
200
- end
201
-
202
193
  # call-seq:
203
194
  # req.success? -> true or false
204
195
  #
@@ -230,7 +221,7 @@ class Request
230
221
  #
231
222
  def strip_scripts(evaluate = false)
232
223
  scripts = ''
233
- result = `this.__value__.replace(/<script[^>]*>([\\s\\S]*?)<\\/script>/gi,function(){scripts.__value__+=arguments[1]+'\\n';return '';})`
224
+ result = `$q(this.__value__.replace(/<script[^>]*>([\\s\\S]*?)<\\/script>/gi,function(){scripts.__value__+=arguments[1]+'\\n';return '';}))`
234
225
  Document.execute_js(scripts) if evaluate
235
226
  return result
236
227
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.5
4
+ version: 4.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Sielaff
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-06 00:00:00 -05:00
12
+ date: 2008-11-07 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency