red 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 3.3.0 2008-08-08
2
+
3
+ * 1 major enhancement:
4
+ * Added -u option, which installs unobtrusive JavaScript scaffolding.
5
+
1
6
  == 3.2.1 2008-08-08
2
7
 
3
8
  * 1 bug fix:
data/Manifest.txt CHANGED
@@ -7,6 +7,9 @@ Rakefile
7
7
  bin/red
8
8
  config/hoe.rb
9
9
  config/requirements.rb
10
+ lib/javascripts/_dom_ready.js
11
+ lib/javascripts/prototype_dom_ready.js
12
+ lib/javascripts/red/unobtrusive.red
10
13
  lib/red.rb
11
14
  lib/red/assignment_nodes.rb
12
15
  lib/red/call_nodes.rb
data/bin/red CHANGED
@@ -13,6 +13,7 @@ require 'red'
13
13
  require 'red/executable'
14
14
  require 'red/version'
15
15
  require 'optparse'
16
+ require 'ftools'
16
17
 
17
18
  include Red
18
19
 
@@ -22,7 +23,7 @@ parser = OptionParser.new do |opts|
22
23
  opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
23
24
  opts.on("-r", "--rails", "Add Red plugin to ./vendor/plugins.") { build_red_plugin_for_rails }
24
25
  opts.on("-s", "--string=RUBY_STRING", "Translate a single string to JavaScript.") { |string| direct_translate(string) }
25
- opts.on("-u", "--unobtrusive=LIBRARY", "Add an unobtrusive ")
26
+ opts.on("-u", "--unobtrusive [LIBRARY]", "Add support for unobtrusive JavaScript to your Rails project.") { |library| add_unobtrusive(library) }
26
27
  opts.on("-v", "--version", "Print version number.") { puts Red::VERSION::STRING; exit }
27
28
  begin
28
29
  opts.parse!(ARGV)
@@ -0,0 +1,249 @@
1
+ // http://tanny.ica.com/ICA/TKO/test.nsf/js/addevent.js
2
+ // Accessed 8/08/08 for Red
3
+
4
+ // written by Dean Edwards, 2005
5
+ // with input from Tino Zijdel, Matthias Miller, Diego Perini
6
+ // http://dean.edwards.name/weblog/2005/10/add-event/
7
+ // 2007-07-10 TKO - Removed check for body in schedule because of problems with Firefox 2.0
8
+
9
+ /*global domReady */
10
+
11
+ function addEvent(element, type, handler) {
12
+ // Modification by Tanny O'Haley, http://tanny.ica.com to add the
13
+ // DOMContentLoaded for all browsers.
14
+ if ((type === "DOMContentLoaded" || type === "domload")) {
15
+ if(typeof domReady === "function") {
16
+ domReady(handler);
17
+ return;
18
+ } else {
19
+ type = "load";
20
+ }
21
+ }
22
+
23
+ if (element.addEventListener) {
24
+ element.addEventListener(type, handler, false);
25
+ } else {
26
+ // assign each event handler a unique ID
27
+ if (!handler.$$guid) {
28
+ handler.$$guid = addEvent.guid++;
29
+ }
30
+ // create a hash table of event types for the element
31
+ if (!element.events) {
32
+ element.events = {};
33
+ }
34
+ // create a hash table of event handlers for each element/event pair
35
+ var handlers = element.events[type];
36
+ if (!handlers) {
37
+ handlers = element.events[type] = {};
38
+ // store the existing event handler (if there is one)
39
+ if (element["on" + type]) {
40
+ handlers[0] = element["on" + type];
41
+ }
42
+ }
43
+ // store the event handler in the hash table
44
+ handlers[handler.$$guid] = handler;
45
+ // assign a global event handler to do all the work
46
+ element["on" + type] = handleEvent;
47
+ }
48
+ }
49
+ // a counter used to create unique IDs
50
+ addEvent.guid = 1;
51
+
52
+ function removeEvent(element, type, handler) {
53
+ if (element.removeEventListener) {
54
+ element.removeEventListener(type, handler, false);
55
+ } else {
56
+ // delete the event handler from the hash table
57
+ if (element.events && element.events[type]) {
58
+ delete element.events[type][handler.$$guid];
59
+ }
60
+ }
61
+ }
62
+
63
+ function handleEvent(event) {
64
+ var returnValue = true;
65
+ // grab the event object (IE uses a global event object)
66
+ event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
67
+ // get a reference to the hash table of event handlers
68
+ var handlers = this.events[event.type];
69
+ // execute each event handler
70
+ for (var i in handlers) {
71
+ this.$$handleEvent = handlers[i];
72
+ if (this.$$handleEvent(event) === false) {
73
+ returnValue = false;
74
+ }
75
+ }
76
+ return returnValue;
77
+ }
78
+
79
+ function fixEvent(event) {
80
+ // add W3C standard event methods
81
+ event.preventDefault = fixEvent.preventDefault;
82
+ event.stopPropagation = fixEvent.stopPropagation;
83
+ return event;
84
+ }
85
+ fixEvent.preventDefault = function() {
86
+ this.returnValue = false;
87
+ };
88
+ fixEvent.stopPropagation = function() {
89
+ this.cancelBubble = true;
90
+ };
91
+
92
+ // End Dean Edwards addEvent.
93
+
94
+ // Tino Zijdel - crisp@xs4all.nl This little snippet fixes the problem that the onload attribute on
95
+ // the body-element will overwrite previous attached events on the window object for the onload event.
96
+ if (!window.addEventListener) {
97
+ document.onreadystatechange = function(){
98
+ if (window.onload && window.onload !== handleEvent) {
99
+ addEvent(window, 'load', window.onload);
100
+ window.onload = handleEvent;
101
+ }
102
+ };
103
+ }
104
+
105
+ // -----------------------------------------------------
106
+ // -----------------------------------------------------
107
+
108
+ // http://tanny.ica.com/ICA/TKO/test.nsf/js/domready.js
109
+ // Accessed 8/08/08 for Red
110
+
111
+ // DOMContentLoaded event handler. Works for browsers that don't support the DOMContentLoaded event.
112
+ //
113
+ // Modification Log:
114
+ // Date Initial Description
115
+ // 26 May 2008 TKO Created by Tanny O'Haley
116
+
117
+ /*global addEvent, escape, unescape */
118
+
119
+ var domReadyEvent = {
120
+ name: "domReadyEvent",
121
+ // Array of DOMContentLoaded event handlers.
122
+ events: {},
123
+ domReadyID: 1,
124
+ bDone: false,
125
+ DOMContentLoadedCustom: null,
126
+
127
+ // Function that adds DOMContentLoaded listeners to the array.
128
+ add: function(handler) {
129
+ // Assign each event handler a unique ID. If the handler has an ID, it
130
+ // has already been added to the events object or been run.
131
+ if (!handler.$$domReadyID) {
132
+ handler.$$domReadyID = this.domReadyID++;
133
+
134
+ // If the DOMContentLoaded event has happened, run the function.
135
+ if(this.bDone){
136
+ handler();
137
+ }
138
+
139
+ // store the event handler in the hash table
140
+ this.events[handler.$$domReadyID] = handler;
141
+ }
142
+ },
143
+
144
+ remove: function(handler) {
145
+ // Delete the event handler from the hash table
146
+ if (handler.$$domReadyID) {
147
+ delete this.events[handler.$$domReadyID];
148
+ }
149
+ },
150
+
151
+ // Function to process the DOMContentLoaded events array.
152
+ run: function() {
153
+ // quit if this function has already been called
154
+ if (this.bDone) {
155
+ return;
156
+ }
157
+
158
+ // Flag this function so we don't do the same thing twice
159
+ this.bDone = true;
160
+
161
+ // iterates through array of registered functions
162
+ for (var i in this.events) {
163
+ this.events[i]();
164
+ }
165
+ },
166
+
167
+ schedule: function() {
168
+ // Quit if the init function has already been called
169
+ if (this.bDone) {
170
+ return;
171
+ }
172
+
173
+ // First, check for Safari or KHTML.
174
+ if(/KHTML|WebKit/i.test(navigator.userAgent)) {
175
+ if(/loaded|complete/.test(document.readyState)) {
176
+ this.run();
177
+ } else {
178
+ // Not ready yet, wait a little more.
179
+ setTimeout(this.name + ".schedule()", 100);
180
+ }
181
+ } else if(document.getElementById("__ie_onload")) {
182
+ // Second, check for IE.
183
+ return true;
184
+ }
185
+
186
+ // Check for custom developer provided function.
187
+ if(typeof this.DOMContentLoadedCustom === "function") {
188
+ //if DOM methods are supported, and the body element exists
189
+ //(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1]
190
+ //in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
191
+ if(typeof document.getElementsByTagName !== 'undefined' && (document.getElementsByTagName('body')[0] !== null || document.body !== null)) {
192
+ // Call custom function.
193
+ if(this.DOMContentLoadedCustom()) {
194
+ this.run();
195
+ } else {
196
+ // Not ready yet, wait a little more.
197
+ setTimeout(this.name + ".schedule()", 250);
198
+ }
199
+ }
200
+ }
201
+
202
+ return true;
203
+ },
204
+
205
+ init: function() {
206
+ // If addEventListener supports the DOMContentLoaded event.
207
+ if(document.addEventListener) {
208
+ document.addEventListener("DOMContentLoaded", function() { domReadyEvent.run(); }, false);
209
+ }
210
+
211
+ // Schedule to run the init function.
212
+ setTimeout("domReadyEvent.schedule()", 100);
213
+
214
+ function run() {
215
+ domReadyEvent.run();
216
+ }
217
+
218
+ // Just in case window.onload happens first, add it to onload using an available method.
219
+ if(typeof addEvent !== "undefined") {
220
+ addEvent(window, "load", run);
221
+ } else if(document.addEventListener) {
222
+ document.addEventListener("load", run, false);
223
+ } else if(typeof window.onload === "function") {
224
+ var oldonload = window.onload;
225
+ window.onload = function() {
226
+ domReadyEvent.run();
227
+ oldonload();
228
+ };
229
+ } else {
230
+ window.onload = run;
231
+ }
232
+
233
+ /* for Internet Explorer */
234
+ /*@cc_on
235
+ @if (@_win32 || @_win64)
236
+ document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
237
+ var script = document.getElementById("__ie_onload");
238
+ script.onreadystatechange = function() {
239
+ if (this.readyState == "complete") {
240
+ domReadyEvent.run(); // call the onload handler
241
+ }
242
+ };
243
+ @end
244
+ @*/
245
+ }
246
+ };
247
+
248
+ var domReady = function(handler) { domReadyEvent.add(handler); };
249
+ domReadyEvent.init();
@@ -0,0 +1 @@
1
+ var domReady = function(handler) { document.observe('dom:loaded', handler); };
@@ -0,0 +1,6 @@
1
+ # To enable DOM-ready functionality, be sure the <head> of your layout contains:
2
+ # <script type="text/javascript" src="/javascripts/dom_ready.js"></script>
3
+ # <script type="text/javascript" src="/javascripts/unobtrusive.js"></script>
4
+ dom_ready do
5
+ # The contents of this block will be executed when the DOM is finished loading.
6
+ end
@@ -1,16 +1,6 @@
1
1
  module Red # :nodoc:
2
2
  def build_red_plugin_for_rails
3
- unless File.exists?('vendor/plugins')
4
- puts "Directory vendor/plugins does not exist."
5
- exit
6
- end
7
-
8
- begin
9
- Dir.mkdir('vendor/plugins/red') unless File.exists?('vendor/plugins/red')
10
- rescue SystemCallError
11
- puts "Unable to create directory in vendor/plugins"
12
- exit
13
- end
3
+ self.make_rails_directory('vendor/plugins/red')
14
4
 
15
5
  File.open('vendor/plugins/red/init.rb', 'w') { |f| f.write("require 'rubygems'\nrequire 'red'\n\nRed.rails\n") }
16
6
 
@@ -18,6 +8,19 @@ module Red # :nodoc:
18
8
  exit
19
9
  end
20
10
 
11
+ def add_unobtrusive(library)
12
+ red_directory_created = self.make_rails_directory('public/javascripts/red')
13
+ File.copy(File.join(File.dirname(__FILE__), "../javascripts/#{(library || '').downcase}_dom_ready.js"), "public/javascripts/dom_ready.js")
14
+ File.copy(File.join(File.dirname(__FILE__), "../javascripts/red/unobtrusive.red"), 'public/javascripts/red/unobtrusive.red')
15
+
16
+ puts RED_MESSAGES[:unobtrusive]
17
+ exit
18
+ rescue Errno::ENOENT
19
+ puts "There is no Unobtrusive Red support for #{library}"
20
+ Dir.rmdir('public/javascripts/red') if red_directory_created
21
+ exit
22
+ end
23
+
21
24
  def direct_translate(string)
22
25
  js_output = hush_warnings { string.string_to_node }.compile_node
23
26
  print_js(js_output, 'test')
@@ -38,6 +41,18 @@ module Red # :nodoc:
38
41
  puts RED_MESSAGES[:output] % [("- #{filename}.js" unless filename == 'test'), js_output, @@red_errors ||= '']
39
42
  end
40
43
 
44
+ def make_rails_directory(dir)
45
+ parent_dir = File.dirname(dir)
46
+ unless File.exists?(parent_dir)
47
+ puts "Directory #{parent_dir} does not exist."
48
+ exit
49
+ end
50
+ Dir.mkdir(dir) unless File.exists?(dir)
51
+ rescue SystemCallError
52
+ puts "Unable to create directory in #{parent_dir}"
53
+ exit
54
+ end
55
+
41
56
  def compile_red_to_js(filename)
42
57
  unless File.exists?(file = "%s.red" % [filename]) || File.exists?(file = "%sred/%s.red" % [(dir = "public/javascripts/"), filename])
43
58
  puts "File #{filename}.red does not exist."
@@ -99,4 +114,14 @@ Use red -h for help.
99
114
  %s
100
115
 
101
116
  MESSAGE
117
+
118
+ RED_MESSAGES[:unobtrusive] = <<-MESSAGE
119
+
120
+ public/javascripts/dom_ready.js
121
+ public/javascripts/red
122
+ public/javascripts/red/unobtrusive.red
123
+
124
+ Unobtrusive Red added to project.
125
+
126
+ MESSAGE
102
127
  end
data/lib/red/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Red
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
- MINOR = 2
5
- TINY = 1
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -1,5 +1,5 @@
1
1
  desc 'Release the website and new gem version'
2
- task :deploy => [:check_version, :website, :release] do
2
+ task :deploy => [:check_version, :release] do
3
3
  puts "Remember to create SVN tag:"
4
4
  puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
5
  "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
@@ -7,9 +7,6 @@ task :deploy => [:check_version, :website, :release] do
7
7
  puts "Tagging release #{CHANGES}"
8
8
  end
9
9
 
10
- desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
- task :local_deploy => [:website_generate, :install_gem]
12
-
13
10
  task :check_version do
14
11
  unless ENV['VERSION']
15
12
  puts 'Must pass a VERSION=x.y.z release version'
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: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Sielaff
@@ -65,6 +65,9 @@ files:
65
65
  - bin/red
66
66
  - config/hoe.rb
67
67
  - config/requirements.rb
68
+ - lib/javascripts/_dom_ready.js
69
+ - lib/javascripts/prototype_dom_ready.js
70
+ - lib/javascripts/red/unobtrusive.red
68
71
  - lib/red.rb
69
72
  - lib/red/assignment_nodes.rb
70
73
  - lib/red/call_nodes.rb