rbjs 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbjs.rb CHANGED
@@ -36,7 +36,7 @@ module Rbjs
36
36
 
37
37
  def evaluate function_parameters = nil
38
38
  instance_exec *function_parameters, &@_block
39
- @_called_expressions.map(&:last_of_chain).reject(&:is_argument).map(&:to_s).join(";\n")
39
+ @_called_expressions.map(&:last_childs).flatten.reject(&:is_argument).map(&:to_s).join(";\n")
40
40
  end
41
41
 
42
42
  def method_missing name, *args, &block
@@ -57,10 +57,11 @@ module Rbjs
57
57
 
58
58
  class Expression
59
59
  attr_accessor :parent_expression
60
- attr_accessor :child_expression
60
+ attr_accessor :child_expressions
61
61
  attr_accessor :is_argument
62
62
 
63
63
  def initialize name, view_context = nil, *args, &block
64
+ @child_expressions = []
64
65
  @name = name.to_s.gsub '!', '()'
65
66
  @_view_context = view_context
66
67
  args << block if block_given?
@@ -70,7 +71,7 @@ module Rbjs
70
71
  def method_missing name, *args, &block
71
72
  expression = Expression.new name, @_view_context, *args, &block
72
73
  expression.parent_expression = self
73
- self.child_expression = expression
74
+ @child_expressions << expression
74
75
  expression
75
76
  end
76
77
 
@@ -89,17 +90,21 @@ module Rbjs
89
90
  @name + argument_list
90
91
  end
91
92
  end
93
+
94
+ def to_ary
95
+ nil
96
+ end
92
97
 
93
98
  def argument_list
94
99
  return '' if @arguments.empty?
95
100
  '(' + @arguments.join(', ') + ')'
96
101
  end
97
102
 
98
- def last_of_chain
99
- if @child_expression
100
- @child_expression.last_of_chain
103
+ def last_childs
104
+ if @child_expressions.length > 0
105
+ @child_expressions.map(&:last_childs).flatten
101
106
  else
102
- self
107
+ [self]
103
108
  end
104
109
  end
105
110
 
data/lib/rbjs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rbjs
2
- VERSION = "0.10.2"
2
+ VERSION = "0.10.3"
3
3
  end
data/spec/rbjs_spec.rb CHANGED
@@ -133,4 +133,24 @@ describe Rbjs::Root, '#evaluate' do
133
133
  js.strip.should == "docs.map(function(doc) {\nw.match(/^_/);\nemit(doc)})"
134
134
  end
135
135
 
136
+ it "should render multiple calls to locally assigned expressions" do
137
+ js = build do
138
+ selector = jQuery('#content').find('.note')
139
+ selector.hide!
140
+ selector.html 'some text'
141
+ end
142
+ js.strip.should == "jQuery(\"#content\").find(\".note\").hide();\njQuery(\"#content\").find(\".note\").html(\"some text\")"
143
+ end
144
+
145
+ it "should support multiple nested functions" do
146
+ js = build do
147
+ jQuery('.note').fadeIn do
148
+ delay 1000 do
149
+ jQuery('.note').hide!
150
+ end
151
+ end
152
+ end
153
+ js.strip.should == ''
154
+ end
155
+
136
156
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 0.10.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-20 00:00:00.000000000 Z
12
+ date: 2012-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70329092185820 !ruby/object:Gem::Requirement
16
+ requirement: &70186833414720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70329092185820
24
+ version_requirements: *70186833414720
25
25
  description: Remote Javascript Builder for Ruby on Rails
26
26
  email:
27
27
  - buhrmi@gmail.com