rbjs 0.9.8 → 0.9.10
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/lib/rbjs/version.rb +1 -1
- data/lib/rbjs.rb +4 -2
- data/readme.md +27 -14
- metadata +1 -1
data/lib/rbjs/version.rb
CHANGED
data/lib/rbjs.rb
CHANGED
@@ -75,8 +75,11 @@ module Rbjs
|
|
75
75
|
@parent_statement.to_s + '[' + @arguments.first + ']= ' + @arguments.last
|
76
76
|
elsif @name == '[]'
|
77
77
|
@parent_statement.to_s + '[' + @arguments.first + ']'
|
78
|
+
'var ' + @arguments.join(', ')
|
78
79
|
elsif @parent_statement
|
79
|
-
@parent_statement.to_s
|
80
|
+
parent_str = @parent_statement.to_s
|
81
|
+
parent_str += parent_str == 'var' ? ' ' : '.'
|
82
|
+
parent_str + @name + argument_list
|
80
83
|
else
|
81
84
|
@name + argument_list
|
82
85
|
end
|
@@ -84,7 +87,6 @@ module Rbjs
|
|
84
87
|
|
85
88
|
def argument_list
|
86
89
|
return '' if @arguments.empty?
|
87
|
-
|
88
90
|
'(' + @arguments.join(', ') + ')'
|
89
91
|
end
|
90
92
|
|
data/readme.md
CHANGED
@@ -1,10 +1,22 @@
|
|
1
|
-
|
1
|
+
## RJS IS BACK
|
2
2
|
|
3
|
-
|
3
|
+
### And it's better than ever before.
|
4
4
|
|
5
|
-
Rbjs is a modern RJS extension for Rails 3 and up. It stands for **r**u**b**y**j**ava**s**cript. In contrast to prototype-rails, this library is designed to work with all javascript frameworks.
|
5
|
+
Rbjs is a modern RJS (remote javascript) extension for Rails 3 and up. It stands for **r**u**b**y**j**ava**s**cript. In contrast to prototype-rails, this library is designed to work with all javascript frameworks.
|
6
6
|
|
7
|
-
However, it is *not* a drop-in replacement for _.rjs_
|
7
|
+
However, it is *not* a drop-in replacement for _.rjs_ -- it does things quite differently.
|
8
|
+
|
9
|
+
This is a very fresh gem. Feel free to test it while the documentation and tests are still being written. I've added some examples to this readme file. These should help you get a general idea of what this is about.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add the following line to your Gemfile
|
14
|
+
|
15
|
+
> gem 'rbjs'
|
16
|
+
|
17
|
+
and run _bundle install_ to install the gem and it's dependencies.
|
18
|
+
|
19
|
+
## Examples
|
8
20
|
|
9
21
|
### Take a look at a simple example:
|
10
22
|
|
@@ -16,7 +28,7 @@ However, it is *not* a drop-in replacement for _.rjs_. It does things quite diff
|
|
16
28
|
end
|
17
29
|
|
18
30
|
# views/greeter/index.html.erb
|
19
|
-
link_to "Hi there!", "greeter
|
31
|
+
link_to "Hi there!", "/greeter/greet_me", :remote => true
|
20
32
|
|
21
33
|
### And a more complex example:
|
22
34
|
|
@@ -37,7 +49,7 @@ However, it is *not* a drop-in replacement for _.rjs_. It does things quite diff
|
|
37
49
|
|
38
50
|
# controllers/posts_controller.rb
|
39
51
|
def refresh_all
|
40
|
-
@posts = Post.
|
52
|
+
@posts = Post.limit(10)
|
41
53
|
end
|
42
54
|
|
43
55
|
# views/posts/refresh_all.js.rbjs
|
@@ -68,20 +80,21 @@ However, it is *not* a drop-in replacement for _.rjs_. It does things quite diff
|
|
68
80
|
)
|
69
81
|
|
70
82
|
|
71
|
-
# Here is the same example,
|
83
|
+
# Here is the same example, this time declaring the variables in javascript
|
84
|
+
# by prefixing them with var.
|
72
85
|
# views/posts/increase_counter.js.rbjs
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
86
|
+
var.allCounters = jQuery('.post.counter')
|
87
|
+
allCounters.each do |index, element|
|
88
|
+
var.element = jQuery(element)
|
89
|
+
var.currentValue = element.html!.to_i!
|
77
90
|
element.html(currentValue + @increment)
|
78
91
|
end
|
79
92
|
|
80
93
|
# And the rendered result:
|
81
|
-
allCounters=(jQuery(".post.counter"));
|
94
|
+
var allCounters=(jQuery(".post.counter"));
|
82
95
|
allCounters.each(function(index, element) {
|
83
|
-
element=(jQuery(element));
|
84
|
-
currentValue=(element.html().to_i());
|
96
|
+
var element=(jQuery(element));
|
97
|
+
var currentValue=(element.html().to_i());
|
85
98
|
element.html(currentValue+4)
|
86
99
|
})
|
87
100
|
|