apotomo 1.1.0.rc1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.textile CHANGED
@@ -8,6 +8,7 @@ h3. Changes
8
8
  * You can now @#render_widget@ in your widget views to render children.
9
9
  * @#widget@ now accepts one arg only (the widget prefix). @widget(:comments)@ sets id to @:comments@. We also removed the start state argument.
10
10
  * Start states are no longer accepted, you have to explicitely pass the state to #render_widget. That's why #invoke now requires an explicit state as well.
11
+ * #replace/#update now append a @;@ to the JavaScript expression. You may pass an arbitrary selector string as first argument (optional).
11
12
  * The event is no longer added to #options at triggering time.
12
13
  * Options passed in #render_widget are no longer merged with #options. They are passed as state-args to reduce complexity.
13
14
  * We no longer have @opts and @params but #options and #params from Cell::Base.
@@ -33,8 +33,8 @@ module Apotomo
33
33
  module Prototype
34
34
  def prototype; end
35
35
  def element(id); "$(\"#{id}\")"; end
36
- def update(id, markup); element(id) + '.update("'+escape(markup)+'")'; end
37
- def replace(id, markup); element(id) + '.replace("'+escape(markup)+'")'; end
36
+ def update(id, markup); element(id) + '.update("'+escape(markup)+'");'; end
37
+ def replace(id, markup); element(id) + '.replace("'+escape(markup)+'");'; end
38
38
  def update_id(id, markup); update(id, markup); end
39
39
  def replace_id(id, markup); replace(id, markup); end
40
40
  end
@@ -42,8 +42,8 @@ module Apotomo
42
42
  module Right
43
43
  def right; end
44
44
  def element(id); "$(\"#{id}\")"; end
45
- def update(id, markup); element(id) + '.update("'+escape(markup)+'")'; end
46
- def replace(id, markup); element(id) + '.replace("'+escape(markup)+'")'; end
45
+ def update(id, markup); element(id) + '.update("'+escape(markup)+'");'; end
46
+ def replace(id, markup); element(id) + '.replace("'+escape(markup)+'");'; end
47
47
  def update_id(id, markup); update(id, markup); end
48
48
  def replace_id(id, markup); replace(id, markup); end
49
49
  end
@@ -51,8 +51,8 @@ module Apotomo
51
51
  module Jquery
52
52
  def jquery; end
53
53
  def element(id); "$(\"#{id}\")"; end
54
- def update(id, markup); element(id) + '.html("'+escape(markup)+'")'; end
55
- def replace(id, markup); element(id) + '.replaceWith("'+escape(markup)+'")'; end
54
+ def update(id, markup); element(id) + '.html("'+escape(markup)+'");'; end
55
+ def replace(id, markup); element(id) + '.replaceWith("'+escape(markup)+'");'; end
56
56
  def update_id(id, markup); update("##{id}", markup); end
57
57
  def replace_id(id, markup); replace("##{id}", markup); end
58
58
  end
@@ -1,3 +1,3 @@
1
1
  module Apotomo
2
- VERSION = '1.1.0.rc1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -1,5 +1,10 @@
1
1
  module Apotomo
2
2
  module JavascriptMethods
3
+ # Returns the escaped script.
4
+ def escape_js(script)
5
+ Apotomo.js_generator.escape(script)
6
+ end
7
+
3
8
  # Wraps the rendered content in a replace statement targeted at your +Apotomo.js_framework+ setting.
4
9
  # Use +:selector+ to change the selector.
5
10
  #
@@ -28,12 +33,12 @@ module Apotomo
28
33
 
29
34
  private
30
35
  def wrap_in_javascript_for(mode, *args)
31
- content = render(*args)
32
- options = args.first.is_a?(::Hash) ? args.shift : {}
36
+ selector = args.first.is_a?(String) ? args.shift : false
37
+ content = render(*args)
33
38
 
34
- options[:selector] ?
35
- Apotomo.js_generator.send(mode, options[:selector], content) : # replace(:twitter)
36
- Apotomo.js_generator.send("#{mode}_id", name, content) # replace_id(:twitter)
39
+ selector ?
40
+ Apotomo.js_generator.send(mode, selector, content) : # replace(:twitter)
41
+ Apotomo.js_generator.send("#{mode}_id", name, content) # replace_id(:twitter)
37
42
  end
38
43
  end
39
44
  end
@@ -18,19 +18,19 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
18
18
  end
19
19
 
20
20
  should "respond to replace" do
21
- assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace(:drinks, 'EMPTY!')
21
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace(:drinks, 'EMPTY!')
22
22
  end
23
23
 
24
24
  should "respond to replace_id" do
25
- assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
25
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
26
26
  end
27
27
 
28
28
  should "respond to update" do
29
- assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update(:drinks, '<li id="beer"></li>')
29
+ assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update(:drinks, '<li id="beer"></li>')
30
30
  end
31
31
 
32
32
  should "respond to update_id" do
33
- assert_equal "$(\"drinks\").update(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
33
+ assert_equal "$(\"drinks\").update(\"EMPTY!\");", @gen.update_id("drinks", 'EMPTY!')
34
34
  end
35
35
  end
36
36
 
@@ -44,19 +44,19 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
44
44
  end
45
45
 
46
46
  should "respond to replace" do
47
- assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace(:drinks, 'EMPTY!')
47
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace(:drinks, 'EMPTY!')
48
48
  end
49
49
 
50
50
  should "respond to replace_id" do
51
- assert_equal "$(\"drinks\").replace(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
51
+ assert_equal "$(\"drinks\").replace(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
52
52
  end
53
53
 
54
54
  should "respond to update" do
55
- assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update(:drinks, '<li id="beer"></li>')
55
+ assert_equal "$(\"drinks\").update(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update(:drinks, '<li id="beer"></li>')
56
56
  end
57
57
 
58
58
  should "respond to update_id" do
59
- assert_equal "$(\"drinks\").update(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
59
+ assert_equal "$(\"drinks\").update(\"EMPTY!\");", @gen.update_id("drinks", 'EMPTY!')
60
60
  end
61
61
  end
62
62
 
@@ -70,19 +70,19 @@ class JavascriptGeneratorTest < Test::Unit::TestCase
70
70
  end
71
71
 
72
72
  should "respond to replace" do
73
- assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\")", @gen.replace("#drinks", 'EMPTY!')
73
+ assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\");", @gen.replace("#drinks", 'EMPTY!')
74
74
  end
75
75
 
76
76
  should "respond to replace_id" do
77
- assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\")", @gen.replace_id("drinks", 'EMPTY!')
77
+ assert_equal "$(\"#drinks\").replaceWith(\"EMPTY!\");", @gen.replace_id("drinks", 'EMPTY!')
78
78
  end
79
79
 
80
80
  should "respond to update" do
81
- assert_equal "$(\"#drinks\").html(\"<li id=\\\"beer\\\"><\\/li>\")", @gen.update("#drinks", '<li id="beer"></li>')
81
+ assert_equal "$(\"#drinks\").html(\"<li id=\\\"beer\\\"><\\/li>\");", @gen.update("#drinks", '<li id="beer"></li>')
82
82
  end
83
83
 
84
84
  should "respond to update_id" do
85
- assert_equal "$(\"#drinks\").html(\"EMPTY!\")", @gen.update_id("drinks", 'EMPTY!')
85
+ assert_equal "$(\"#drinks\").html(\"EMPTY!\");", @gen.update_id("drinks", 'EMPTY!')
86
86
  end
87
87
  end
88
88
  end
@@ -85,43 +85,49 @@ class RenderTest < ActionView::TestCase
85
85
  end
86
86
  end
87
87
 
88
- context "with #update" do
88
+ context "#update" do
89
89
  should "wrap the :text in an update statement" do
90
90
  @mum.instance_eval do
91
91
  def squeak
92
92
  update :text => "squeak!"
93
93
  end
94
94
  end
95
- assert_equal "$(\"#mum\").html(\"squeak!\")", @mum.invoke(:squeak)
95
+ assert_equal "$(\"#mum\").html(\"squeak!\");", @mum.invoke(:squeak)
96
96
  end
97
97
 
98
- should "accept :selector" do
98
+ should "accept a selector" do
99
99
  @mum.instance_eval do
100
100
  def squeak
101
- update :text => '<div id="mum">squeak!</div>', :selector => "div#mouse"
101
+ update "div#mouse", :text => '<div id="mum">squeak!</div>'
102
102
  end
103
103
  end
104
- assert_equal "$(\"div#mouse\").html(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
104
+ assert_equal "$(\"div#mouse\").html(\"<div id=\\\"mum\\\">squeak!<\\/div>\");", @mum.invoke(:squeak)
105
105
  end
106
106
  end
107
107
 
108
- context "with #replace" do
108
+ context "#replace" do
109
109
  should "wrap the :text in a replace statement" do
110
110
  @mum.instance_eval do
111
111
  def squeak
112
112
  replace :text => '<div id="mum">squeak!</div>'
113
113
  end
114
114
  end
115
- assert_equal "$(\"#mum\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
115
+ assert_equal "$(\"#mum\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\");", @mum.invoke(:squeak)
116
116
  end
117
117
 
118
- should "accept :selector" do
118
+ should "accept a selector" do
119
119
  @mum.instance_eval do
120
120
  def squeak
121
- replace :text => '<div id="mum">squeak!</div>', :selector => "div#mouse"
121
+ replace "div#mouse", :text => '<div id="mum">squeak!</div>'
122
122
  end
123
123
  end
124
- assert_equal "$(\"div#mouse\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\")", @mum.invoke(:squeak)
124
+ assert_equal "$(\"div#mouse\").replaceWith(\"<div id=\\\"mum\\\">squeak!<\\/div>\");", @mum.invoke(:squeak)
125
+ end
126
+ end
127
+
128
+ context "#escape_js" do
129
+ should "escape the string" do
130
+ assert_equal "<div id=\\\"mum\\\">squeak!<\\/div>", @mum.escape_js('<div id="mum">squeak!</div>')
125
131
  end
126
132
  end
127
133
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apotomo
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
8
  - 0
9
- - rc1
10
- version: 1.1.0.rc1
9
+ version: 1.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Nick Sutterer
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-02-24 00:00:00 +01:00
17
+ date: 2011-03-01 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -205,13 +204,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
204
  required_rubygems_version: !ruby/object:Gem::Requirement
206
205
  none: false
207
206
  requirements:
208
- - - ">"
207
+ - - ">="
209
208
  - !ruby/object:Gem::Version
210
209
  segments:
211
- - 1
212
- - 3
213
- - 1
214
- version: 1.3.1
210
+ - 0
211
+ version: "0"
215
212
  requirements: []
216
213
 
217
214
  rubyforge_project: