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 CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 7
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -2,7 +2,7 @@
2
2
  * Jelly. a sweet unobtrusive javascript framework
3
3
  * for jQuery and Rails
4
4
  *
5
- * version 0.7.0
5
+ * version 0.7.2
6
6
  *
7
7
  * Copyright (c) 2009 Pivotal Labs
8
8
  * Licensed under the MIT license.
data/jelly.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jelly}
8
- s.version = "0.7.1"
8
+ s.version = "0.7.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pivotal Labs, Inc"]
@@ -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, #{jelly_attached_components_on_ready.to_json});
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
- argument = jelly_attach_arguments(output)
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
- pre_document_ready_part = html.split("\n")[0..3].join("\n")
75
- pre_document_ready_part.split("\n")[0].should_not include("$(document).ready(function() {")
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
- document_ready_part = html.split("\n")[4..-1].join("\n")
90
- document_ready_part.split("\n")[0].should include("$(document).ready(function() {")
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
@@ -21,6 +21,7 @@ end
21
21
  require 'spec'
22
22
  require 'spec/rails'
23
23
  require 'spec/autorun'
24
+ require 'nokogiri'
24
25
 
25
26
  $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
26
27
  require "jelly"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honkster-jelly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal Labs, Inc