honkster-jelly 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/generators/jelly/templates/javascripts/jelly.js +1 -1
- data/jelly.gemspec +1 -1
- data/lib/jelly/jelly_helper.rb +20 -8
- data/spec/helpers/jelly_helper_spec.rb +11 -5
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
data/VERSION.yml
CHANGED
data/jelly.gemspec
CHANGED
data/lib/jelly/jelly_helper.rb
CHANGED
@@ -14,19 +14,31 @@ module JellyHelper
|
|
14
14
|
def spread_jelly
|
15
15
|
attach_javascript_component("Jelly.Location")
|
16
16
|
attach_javascript_component("Jelly.Page", controller.controller_path.camelcase, controller.action_name)
|
17
|
+
<<-HTML
|
18
|
+
#{window_token_javascript_tag}
|
19
|
+
#{attach_javascript_component_javascript_tag(jelly_attached_components)}
|
20
|
+
#{attach_javascript_component_on_document_ready_javascript_tag(jelly_attached_components_on_ready)}
|
21
|
+
HTML
|
22
|
+
end
|
23
|
+
|
24
|
+
def window_token_javascript_tag
|
25
|
+
javascript_tag("window._token = '#{form_authenticity_token}';")
|
26
|
+
end
|
27
|
+
|
28
|
+
def attach_javascript_component_javascript_tag(*components)
|
29
|
+
components = [components].flatten
|
30
|
+
javascript_tag("Jelly.attach.apply(Jelly, #{components.to_json});")
|
31
|
+
end
|
32
|
+
|
33
|
+
def attach_javascript_component_on_document_ready_javascript_tag(*components)
|
34
|
+
components = [components].flatten
|
17
35
|
javascript_tag <<-JS
|
18
|
-
#{javascript_set_window_token}
|
19
|
-
Jelly.attach.apply(Jelly, #{jelly_attached_components.to_json});
|
20
36
|
$(document).ready(function() {
|
21
|
-
Jelly.attach.apply(Jelly, #{
|
22
|
-
}
|
37
|
+
Jelly.attach.apply(Jelly, #{components.to_json});
|
38
|
+
}
|
23
39
|
JS
|
24
40
|
end
|
25
41
|
|
26
|
-
def javascript_set_window_token
|
27
|
-
"window._token = '#{form_authenticity_token}';"
|
28
|
-
end
|
29
|
-
|
30
42
|
def clear_jelly_attached
|
31
43
|
jelly_attached_components.clear
|
32
44
|
end
|
@@ -16,7 +16,8 @@ describe JellyHelper do
|
|
16
16
|
it "should create a javascript include tag that attaches the Jelly.Location and Jelly.Page components" do
|
17
17
|
output = helper.spread_jelly
|
18
18
|
output.should include('<script type="text/javascript">')
|
19
|
-
|
19
|
+
doc = Nokogiri::HTML(output)
|
20
|
+
argument = jelly_attach_arguments(doc.css("script")[1].inner_html)
|
20
21
|
argument.should include({'component' => "Jelly.Location", 'arguments' => []})
|
21
22
|
argument.should include({'component' => "Jelly.Page", 'arguments' => ['MyFunController', 'super_good_action']})
|
22
23
|
end
|
@@ -71,8 +72,10 @@ describe JellyHelper do
|
|
71
72
|
]
|
72
73
|
|
73
74
|
html = helper.spread_jelly
|
74
|
-
|
75
|
-
|
75
|
+
doc = Nokogiri::HTML(html)
|
76
|
+
pre_document_ready_tag = doc.css("script")[1]
|
77
|
+
pre_document_ready_tag.inner_html.should_not include("$(document).ready(function() {")
|
78
|
+
pre_document_ready_part = pre_document_ready_tag.inner_html.split("\n")[2]
|
76
79
|
|
77
80
|
arguments = jelly_attach_arguments(pre_document_ready_part)
|
78
81
|
arguments.should include({'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg3']})
|
@@ -86,8 +89,11 @@ describe JellyHelper do
|
|
86
89
|
]
|
87
90
|
|
88
91
|
html = helper.spread_jelly
|
89
|
-
|
90
|
-
|
92
|
+
doc = Nokogiri::HTML(html)
|
93
|
+
document_ready_tag = doc.css("script")[2]
|
94
|
+
document_ready_tag.inner_html.should include("$(document).ready(function() {")
|
95
|
+
|
96
|
+
document_ready_part = document_ready_tag.inner_html.split("\n")[3]
|
91
97
|
arguments = jelly_attach_arguments(document_ready_part)
|
92
98
|
arguments.should include({'component' => "MyComponent", 'arguments' => ['arg1', 'arg2', 'arg3']})
|
93
99
|
end
|
data/spec/spec_helper.rb
CHANGED