red 3.3.0 → 3.4.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 +11 -0
- data/lib/red/assignment_nodes.rb +31 -5
- data/lib/red/call_nodes.rb +8 -3
- data/lib/red/conditional_nodes.rb +1 -1
- data/lib/red/control_nodes.rb +4 -2
- data/lib/red/data_nodes.rb +3 -2
- data/lib/red/definition_nodes.rb +6 -0
- data/lib/red/executable.rb +44 -20
- data/lib/red/version.rb +1 -1
- data/lib/red.rb +1 -1
- data/tasks/deployment.rake +1 -6
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
== 3.4.0 2008-08-09
|
2
|
+
|
3
|
+
* 2 major enhancements:
|
4
|
+
* Added functionality to "obj" of "class << obj" construct.
|
5
|
+
* Souped up -r and -u options for the Red executable.
|
6
|
+
|
7
|
+
* 3 bug fixes:
|
8
|
+
* Added <= and >= to the list of sugared Ruby operators.
|
9
|
+
* Fixed nested ternary operators.
|
10
|
+
* Fixed camelcasing of all_CAPS sections in identifiers.
|
11
|
+
|
1
12
|
== 3.3.0 2008-08-08
|
2
13
|
|
3
14
|
* 1 major enhancement:
|
data/lib/red/assignment_nodes.rb
CHANGED
@@ -9,6 +9,14 @@ module Red
|
|
9
9
|
return [@variable_name, @expression].compile_nodes(:as_argument => true)
|
10
10
|
end
|
11
11
|
|
12
|
+
def compile_increment(options = {})
|
13
|
+
return "%s%s" % [options[:receiver] || @variable_name.compile_node, @expression.increment_operator * 2]
|
14
|
+
end
|
15
|
+
|
16
|
+
def call_to_increment?
|
17
|
+
return @expression.increment_operator rescue false
|
18
|
+
end
|
19
|
+
|
12
20
|
class ClassVariableNode < AssignmentNode # :nodoc:
|
13
21
|
def compile_node(options = {})
|
14
22
|
expression = @expression.compile_node(:as_argument => true)
|
@@ -17,6 +25,7 @@ module Red
|
|
17
25
|
"%s: %s"
|
18
26
|
else
|
19
27
|
receiver = "%s.%s" % [@@red_class, @variable_name.compile_node]
|
28
|
+
return self.compile_increment(:receiver => receiver) if self.call_to_increment?
|
20
29
|
"%s = %s"
|
21
30
|
end % [receiver, expression]
|
22
31
|
end
|
@@ -24,19 +33,23 @@ module Red
|
|
24
33
|
|
25
34
|
class GlobalVariableNode < AssignmentNode # :nodoc:
|
26
35
|
def compile_node(options = {})
|
36
|
+
return self.compile_increment if self.call_to_increment?
|
27
37
|
return "%s = %s" % self.compile_internals
|
28
38
|
end
|
29
39
|
end
|
30
40
|
|
31
41
|
class InstanceVariableNode < AssignmentNode # :nodoc:
|
32
42
|
def compile_node(options = {})
|
33
|
-
|
43
|
+
receiver = "this.%s" % @variable_name.compile_node
|
44
|
+
return self.compile_increment(:receiver => receiver) if self.call_to_increment?
|
45
|
+
return "this.%s = %s" % [receiver, @expression.compile_node(:as_argument => true)]
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
37
49
|
class LocalVariableNode < AssignmentNode # :nodoc:
|
38
50
|
def compile_node(options = {})
|
39
|
-
return
|
51
|
+
return self.compile_increment if self.call_to_increment?
|
52
|
+
return (@variable_name.is_a?(LiteralNode::NamespaceNode) || options[:skip_var] ? "%s = %s" : "var %s = %s") % self.compile_internals
|
40
53
|
end
|
41
54
|
end
|
42
55
|
|
@@ -51,7 +64,8 @@ module Red
|
|
51
64
|
end
|
52
65
|
|
53
66
|
def compile_internals(options = {})
|
54
|
-
variable_name, slot
|
67
|
+
variable_name, slot = [@variable_name, @slot].compile_nodes(:quotes => '')
|
68
|
+
expression = @expression.compile_node(:as_argument => true)
|
55
69
|
receiver = self.compile_receiver(variable_name, slot)
|
56
70
|
return [receiver, expression]
|
57
71
|
end
|
@@ -63,9 +77,17 @@ module Red
|
|
63
77
|
|
64
78
|
class OperatorNode # :nodoc:
|
65
79
|
def compile_node(options = {})
|
80
|
+
return self.compile_increment if self.call_to_increment?
|
66
81
|
return "%s%s = %s %s %s" % self.compile_internals
|
67
82
|
end
|
68
83
|
|
84
|
+
def compile_increment(options = {})
|
85
|
+
receiver, operation = [@receiver, @operation].compile_nodes
|
86
|
+
slot = @slot.compile_node(:quotes => '')
|
87
|
+
original = self.compile_receiver(receiver, slot)
|
88
|
+
return "%s%s" % [original, operation * 2]
|
89
|
+
end
|
90
|
+
|
69
91
|
def compile_internals(options = {})
|
70
92
|
receiver, operation = [@receiver, @operation].compile_nodes
|
71
93
|
expression = @expression.compile_node(:as_argument => true)
|
@@ -75,6 +97,10 @@ module Red
|
|
75
97
|
return [var, original, original, operation, expression]
|
76
98
|
end
|
77
99
|
|
100
|
+
def call_to_increment?
|
101
|
+
return ['+', '-'].include?(@operation.compile_node) && @expression.compile_node == '1'
|
102
|
+
end
|
103
|
+
|
78
104
|
class BracketNode < OperatorNode # :nodoc:
|
79
105
|
def initialize(receiver, bracket_contents, operation, expression)
|
80
106
|
@receiver, @slot, @operation, @expression = [receiver, bracket_contents.last, operation, expression].build_nodes
|
@@ -105,7 +131,7 @@ module Red
|
|
105
131
|
end
|
106
132
|
|
107
133
|
def var?
|
108
|
-
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode].include?(@receiver.class)
|
134
|
+
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode, VariableNode::ClassVariableNode].include?(@receiver.class)
|
109
135
|
end
|
110
136
|
end
|
111
137
|
|
@@ -119,7 +145,7 @@ module Red
|
|
119
145
|
end
|
120
146
|
|
121
147
|
def var?
|
122
|
-
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode].include?(@receiver.class)
|
148
|
+
return "var " unless [VariableNode::GlobalVariableNode, VariableNode::InstanceVariableNode, VariableNode::ClassVariableNode].include?(@receiver.class)
|
123
149
|
end
|
124
150
|
end
|
125
151
|
end
|
data/lib/red/call_nodes.rb
CHANGED
@@ -40,17 +40,18 @@ module Red
|
|
40
40
|
class MethodNode # :nodoc:
|
41
41
|
def compile_node(options = {})
|
42
42
|
call_to_returned_function = [DefinitionNode::InstanceMethodNode, CallNode::BlockNode].include?(@receiver.class) ? :call : false
|
43
|
-
receiver = @receiver.
|
44
|
-
function = @function.compile_node
|
43
|
+
receiver, function = [@receiver, @function].compile_nodes
|
45
44
|
arguments = @arguments.compile_nodes(:as_argument => true, :quotes => "'")
|
46
45
|
return ("$%s(%s)" % [receiver = ((receiver == '$-') || (receiver == 'id' && @@red_library == :Prototype) ? nil : receiver), arguments.first]).gsub('$$','$').gsub('$class','$$') if @receiver.is_a?(VariableNode::GlobalVariableNode) && function == '-'
|
47
46
|
case function.to_sym
|
48
|
-
when :-, :+, :<, :>, :%, :*, :/, :^, :==, :===, :instanceof
|
47
|
+
when :-, :+, :<, :>, :>=, :<=, :%, :*, :/, :^, :==, :===, :instanceof
|
49
48
|
"%s %s %s" % [receiver, function, arguments.first]
|
50
49
|
when :raise
|
51
50
|
"throw(%s)" % [arguments.first]
|
52
51
|
when :new
|
53
52
|
"new %s(%s)" % [receiver, arguments.join(', ')]
|
53
|
+
when :var
|
54
|
+
"var %s" % [arguments.join(', ')]
|
54
55
|
when :[]
|
55
56
|
if ([:symbol, :string].include?(@arguments.first.data_type) rescue false)
|
56
57
|
arguments = @arguments.compile_nodes(:quotes => "", :as_argument => true)
|
@@ -66,6 +67,10 @@ module Red
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
def increment_operator
|
71
|
+
return @function.compile_node if ['+', '-'].include?(@function.compile_node) && @arguments.first.compile_node == '1'
|
72
|
+
end
|
73
|
+
|
69
74
|
class ExplicitNode < MethodNode # :nodoc:
|
70
75
|
def initialize(receiver, function, arguments = [nil])
|
71
76
|
@receiver, @function = [receiver, function].build_nodes
|
@@ -15,7 +15,7 @@ module Red
|
|
15
15
|
|
16
16
|
def compile_internals(options = {})
|
17
17
|
true_case, else_case, condition = [@true_case, @else_case, @condition].compile_nodes
|
18
|
-
return [condition, (true_case.empty? ? 'null' : true_case), (else_case.empty? ? 'null' : else_case)] if options[:as_argument]
|
18
|
+
return [condition, (true_case.empty? ? 'null' : @true_case.compile_node(:as_argument => true)), (else_case.empty? ? 'null' : @else_case.compile_node(:as_argument => true))] if options[:as_argument]
|
19
19
|
condition = (true_case.empty? ? "!(%s)" : "%s") % [condition]
|
20
20
|
true_case = "{ %s; }" % [true_case] unless true_case.empty?
|
21
21
|
join = " else " unless true_case.empty? || else_case.empty?
|
data/lib/red/control_nodes.rb
CHANGED
@@ -88,7 +88,8 @@ module Red
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def compile_internals(options = {})
|
91
|
-
condition
|
91
|
+
condition = @condition.compile_node(:skip_var => true)
|
92
|
+
body = @body.compile_node
|
92
93
|
return [condition, body]
|
93
94
|
end
|
94
95
|
end
|
@@ -108,7 +109,8 @@ module Red
|
|
108
109
|
end
|
109
110
|
|
110
111
|
def compile_internals(options = {})
|
111
|
-
condition
|
112
|
+
condition = @condition.compile_node(:skip_var => true)
|
113
|
+
body = @body.compile_node
|
112
114
|
return [condition, body]
|
113
115
|
end
|
114
116
|
end
|
data/lib/red/data_nodes.rb
CHANGED
@@ -75,11 +75,12 @@ module Red
|
|
75
75
|
return @value = @value.to_s unless camelize? && !disabled
|
76
76
|
words = @value.to_s.gsub(/@|\$/,'').split(/_| /)
|
77
77
|
underscore = words.shift if words.first.empty?
|
78
|
-
@value = (underscore ? '_' : '') + words[0] + words[1..-1].map {|word| word.capitalize}.join
|
78
|
+
@value = (underscore ? '_' : '') + words[0] + words[1..-1].map {|word| word == word.upcase ? word : word.capitalize }.join
|
79
79
|
end
|
80
80
|
|
81
81
|
def camelize?
|
82
|
-
|
82
|
+
value = @value.to_s
|
83
|
+
is_not_a_constant_name = value != value.upcase || value =~ (/@|\$/)
|
83
84
|
is_not_a_js_special_attribute = @value.to_s[0..1] != '__'
|
84
85
|
return is_not_a_constant_name && is_not_a_js_special_attribute
|
85
86
|
end
|
data/lib/red/definition_nodes.rb
CHANGED
@@ -127,14 +127,20 @@ module Red
|
|
127
127
|
|
128
128
|
class ObjectLiteralNode # :nodoc:
|
129
129
|
def initialize(receiver, scope)
|
130
|
+
old_class = @@red_class
|
131
|
+
@@red_class = @class = receiver.build_node.compile_node
|
130
132
|
block_node = scope.assoc(:block) || scope
|
131
133
|
properties = block_node.select {|node| (node.first == :cvdecl) rescue false }
|
132
134
|
functions = block_node.select {|node| ![:block, :scope].include?(node) }
|
133
135
|
@slots = (properties | functions).build_nodes
|
136
|
+
@@red_class = old_class
|
134
137
|
end
|
135
138
|
|
136
139
|
def compile_node(options = {})
|
140
|
+
old_class = @@red_class
|
141
|
+
@@red_class = @class
|
137
142
|
slots = @slots.compile_nodes(:as_prototype => true).compact.join(', ')
|
143
|
+
@@red_class = old_class
|
138
144
|
return "{ %s }" % [slots]
|
139
145
|
end
|
140
146
|
end
|
data/lib/red/executable.rb
CHANGED
@@ -1,26 +1,49 @@
|
|
1
1
|
module Red # :nodoc:
|
2
|
-
def build_red_plugin_for_rails
|
3
|
-
|
2
|
+
def build_red_plugin_for_rails(display_message = true)
|
3
|
+
@files ||= ''
|
4
|
+
self.make_rails_directory('vendor/plugins/red', true)
|
4
5
|
|
5
|
-
|
6
|
+
self.create_plugin_file(:open, 'vendor/plugins/red/init.rb', "require 'rubygems'\nrequire 'red'\n\nRed.rails\n")
|
6
7
|
|
7
|
-
|
8
|
+
self.make_rails_directory('public/javascripts/red')
|
9
|
+
|
10
|
+
return unless display_message
|
11
|
+
puts RED_MESSAGES[:rails] % @files
|
8
12
|
exit
|
9
13
|
end
|
10
14
|
|
11
15
|
def add_unobtrusive(library)
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
@files ||= ''
|
17
|
+
self.build_red_plugin_for_rails(false)
|
18
|
+
|
19
|
+
self.create_plugin_file(:copy, 'public/javascripts/dom_ready.js', File.join(File.dirname(__FILE__), "../javascripts/#{(library || '').downcase}_dom_ready.js"))
|
20
|
+
self.create_plugin_file(:copy, 'public/javascripts/red/unobtrusive.red', File.join(File.dirname(__FILE__), "../javascripts/red/unobtrusive.red"))
|
15
21
|
|
16
|
-
puts RED_MESSAGES[:unobtrusive]
|
17
|
-
exit
|
18
22
|
rescue Errno::ENOENT
|
19
23
|
puts "There is no Unobtrusive Red support for #{library}"
|
20
|
-
|
24
|
+
ensure
|
25
|
+
puts RED_MESSAGES[:unobtrusive] % @files
|
21
26
|
exit
|
22
27
|
end
|
23
28
|
|
29
|
+
def create_plugin_file(operation, filename, contents)
|
30
|
+
file_status = self.check_if_plugin_file_exists(filename)
|
31
|
+
case operation
|
32
|
+
when :open : File.open(filename, 'w') { |f| f.write(contents) } if file_status == 'created'
|
33
|
+
when :copy : File.copy(contents, filename)
|
34
|
+
end
|
35
|
+
@files << "\n%s %s" % [file_status, filename]
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_if_plugin_file_exists(filename)
|
39
|
+
if File.exists?(filename)
|
40
|
+
print "File #{filename} exists. Overwrite [yN]? "
|
41
|
+
return (gets =~ /y/i ? 'created' : 'exists ')
|
42
|
+
else
|
43
|
+
return 'created'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
24
47
|
def direct_translate(string)
|
25
48
|
js_output = hush_warnings { string.string_to_node }.compile_node
|
26
49
|
print_js(js_output, 'test')
|
@@ -41,13 +64,10 @@ module Red # :nodoc:
|
|
41
64
|
puts RED_MESSAGES[:output] % [("- #{filename}.js" unless filename == 'test'), js_output, @@red_errors ||= '']
|
42
65
|
end
|
43
66
|
|
44
|
-
def make_rails_directory(dir)
|
67
|
+
def make_rails_directory(dir, only_this_directory = false)
|
45
68
|
parent_dir = File.dirname(dir)
|
46
|
-
unless File.exists?(parent_dir)
|
47
|
-
|
48
|
-
exit
|
49
|
-
end
|
50
|
-
Dir.mkdir(dir) unless File.exists?(dir)
|
69
|
+
self.make_rails_directory(parent_dir) unless File.exists?(parent_dir) || only_this_directory
|
70
|
+
@files << (File.exists?(dir) ? "\nexists %s" : Dir.mkdir(dir) && "\ncreated %s") % dir
|
51
71
|
rescue SystemCallError
|
52
72
|
puts "Unable to create directory in #{parent_dir}"
|
53
73
|
exit
|
@@ -116,12 +136,16 @@ Use red -h for help.
|
|
116
136
|
MESSAGE
|
117
137
|
|
118
138
|
RED_MESSAGES[:unobtrusive] = <<-MESSAGE
|
119
|
-
|
120
|
-
public/javascripts/dom_ready.js
|
121
|
-
public/javascripts/red
|
122
|
-
public/javascripts/red/unobtrusive.red
|
139
|
+
%s
|
123
140
|
|
124
141
|
Unobtrusive Red added to project.
|
125
142
|
|
126
143
|
MESSAGE
|
144
|
+
|
145
|
+
RED_MESSAGES[:rails] = <<-MESSAGE
|
146
|
+
%s
|
147
|
+
|
148
|
+
Red plugin added to project.
|
149
|
+
|
150
|
+
MESSAGE
|
127
151
|
end
|
data/lib/red/version.rb
CHANGED
data/lib/red.rb
CHANGED
data/tasks/deployment.rake
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
desc 'Release the website and new gem version'
|
2
|
-
task :deploy => [:check_version, :release] do
|
3
|
-
puts "Remember to create SVN tag:"
|
4
|
-
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
-
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
-
puts "Suggested comment:"
|
7
|
-
puts "Tagging release #{CHANGES}"
|
2
|
+
task :deploy => [:check_version, :publish_docs, :release] do
|
8
3
|
end
|
9
4
|
|
10
5
|
task :check_version do
|
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.
|
4
|
+
version: 3.4.0
|
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-08-
|
12
|
+
date: 2008-08-10 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|