jquery-rails-rails4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require 'jquery/rails'
@@ -0,0 +1,99 @@
1
+ module ActionDispatch
2
+ module Assertions
3
+ module SelectorAssertions
4
+ # Selects content from a JQuery response. Patterned loosely on
5
+ # assert_select_rjs.
6
+ #
7
+ # === Narrowing down
8
+ #
9
+ # With no arguments, asserts that one or more method calls are made.
10
+ #
11
+ # Use the +method+ argument to narrow down the assertion to only
12
+ # statements that call that specific method.
13
+ #
14
+ # Use the +opt+ argument to narrow down the assertion to only statements
15
+ # that pass +opt+ as the first argument.
16
+ #
17
+ # Use the +id+ argument to narrow down the assertion to only statements
18
+ # that invoke methods on the result of using that identifier as a
19
+ # selector.
20
+ #
21
+ # === Using blocks
22
+ #
23
+ # Without a block, +assert_select_jquery_ merely asserts that the
24
+ # response contains one or more statements that match the conditions
25
+ # specified above
26
+ #
27
+ # With a block +assert_select_jquery_ also asserts that the method call
28
+ # passes a javascript escaped string containing HTML. All such HTML
29
+ # fragments are selected and passed to the block. Nested assertions are
30
+ # supported.
31
+ #
32
+ # === Examples
33
+ #
34
+ # # asserts that the #notice element is hidden
35
+ # assert_select :hide, '#notice'
36
+ #
37
+ # # asserts that the #cart element is shown with a blind parameter
38
+ # assert_select :show, :blind, '#cart'
39
+ #
40
+ # # asserts that #cart content contains a #current_item
41
+ # assert_select :html, '#cart' do
42
+ # assert_select '#current_item'
43
+ # end
44
+
45
+ PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
46
+ PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
47
+
48
+ def assert_select_jquery(*args, &block)
49
+ jquery_method = args.first.is_a?(Symbol) ? args.shift : nil
50
+ jquery_opt = args.first.is_a?(Symbol) ? args.shift : nil
51
+ id = args.first.is_a?(String) ? args.shift : nil
52
+
53
+ pattern = "\\.#{jquery_method || '\\w+'}\\("
54
+ pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
55
+ pattern = "#{pattern}#{PATTERN_HTML}"
56
+ pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
57
+
58
+ fragments = []
59
+ response.body.scan(Regexp.new(pattern)).each do |match|
60
+ doc = HTML::Document.new(unescape_js(match.first))
61
+ doc.root.children.each do |child|
62
+ fragments.push child if child.tag?
63
+ end
64
+ end
65
+
66
+ if fragments.empty?
67
+ opts = [jquery_method, jquery_opt, id].compact
68
+ flunk "No JQuery call matches #{opts.inspect}"
69
+ end
70
+
71
+ if block
72
+ begin
73
+ in_scope, @selected = @selected, fragments
74
+ yield
75
+ ensure
76
+ @selected = in_scope
77
+ end
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ # Unescapes a JS string.
84
+ def unescape_js(js_string)
85
+ # js encodes double quotes and line breaks.
86
+ unescaped= js_string.gsub('\"', '"')
87
+ unescaped.gsub!('\\\'', "'")
88
+ unescaped.gsub!(/\\\//, '/')
89
+ unescaped.gsub!('\n', "\n")
90
+ unescaped.gsub!('\076', '>')
91
+ unescaped.gsub!('\074', '<')
92
+ # js encodes non-ascii characters.
93
+ unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')}
94
+ unescaped
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,10 @@
1
+ require 'jquery/assert_select' if ::Rails.env.test?
2
+ require 'jquery/rails/engine' if ::Rails.version >= '3.1'
3
+ require 'jquery/rails/railtie'
4
+ require 'jquery/rails/version'
5
+
6
+ module Jquery
7
+ module Rails4
8
+ PROTOTYPE_JS = %w{prototype effects dragdrop controls}
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module Jquery
2
+ module Rails4
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ # Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
2
+ # get the minified version of the scripts included into the layout in production.
3
+ module Jquery
4
+ module Rails4
5
+ class Railtie < ::Rails::Railtie
6
+ config.before_configuration do
7
+ if config.action_view.javascript_expansions
8
+ jq_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.min) : %w(jquery)
9
+
10
+ # Merge the jQuery scripts, remove the Prototype defaults and finally add 'jquery_ujs'
11
+ # at the end, because load order is important
12
+ config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
13
+ config.action_view.javascript_expansions[:defaults] |= jq_defaults + ['jquery_ujs']
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Jquery
2
+ VERSION = "1.5.7"
3
+ module Rails4
4
+ VERSION = "0.0.1"
5
+ JQUERY_VERSION = "1.10.2"
6
+ JQUERY_UJS_VERSION = "e9e8b8fd3abb1571781bca7640e5c0c4d9cea2e3"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-rails-rails4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dancy Dong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.14'
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0.14'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ description: This gem integrates Juqery Rails 1.5.7 with the Rails 4.0 asset pipeline.
48
+ email:
49
+ - dancy@51shepherd.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - CHANGELOG.md
56
+ - CONTRIBUTING.md
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - LICENSE
60
+ - README.md
61
+ - Rakefile
62
+ - app/assets/javascripts/jquery.js
63
+ - app/assets/javascripts/jquery.min.js
64
+ - app/assets/javascripts/jquery.min.map
65
+ - app/assets/javascripts/jquery_ujs.js
66
+ - jquery-rails-rails4.gemspec
67
+ - lib/generators/jquery/install/install_generator.rb
68
+ - lib/jquery-rails.rb
69
+ - lib/jquery/assert_select.rb
70
+ - lib/jquery/rails.rb
71
+ - lib/jquery/rails/engine.rb
72
+ - lib/jquery/rails/railtie.rb
73
+ - lib/jquery/rails/version.rb
74
+ homepage: https://github.com/Dancydonbg/jquery-rails-rails4
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.6
92
+ requirements: []
93
+ rubyforge_project: jquery-rails-rails4
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Integration of Juqery Rails 1.5.7 with the Rails 4.0 asset pipeline
98
+ test_files: []