rjs-if 0.0.3
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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +44 -0
- data/Rakefile +1 -0
- data/init.rb +14 -0
- data/lib/rjs-if.rb +2 -0
- data/lib/rjs/if/generator_if_blocks.rb +51 -0
- data/lib/rjs/if/javascript_element_proxy_extraction.rb +10 -0
- data/lib/rjs/if/railtie.rb +18 -0
- data/lib/rjs/if/version.rb +5 -0
- data/rjs-if.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWUxMjY5NmQ5MDk5ZmM0MDJmNWMzMmE5NjAwZGZiNTc3NjhjZmIzMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTBhNjhjNDI1MjRmMDU4NDAwZmYxZGEyZTRmY2I0ZDhkYTAyMzBlYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDUzNDk0ZjRmM2U4YzBiZjU2ZDMwNzRiODJmYjdhZTA2YTVhOGZjNzdkOTll
|
10
|
+
YTA0ZDMyZTIzMTI0MjFmYTIxMjI3NGNhYTQ5MGFlMjZkMjZmNGE0YmY0Njc1
|
11
|
+
MTY4YTQ1YTlkMTc1YjE3YWJhOTBkZDU3OGEzMWExNWEzODRjZmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmUwOWE5OGJlMjkyNmFmNzY1MmUzY2IwODhhMjRmN2Q0ODgwMzAxZDYwYjUx
|
14
|
+
Y2NmODhjYmVlNWY3ZjNlODRiYzlhNmU4ODUyNzI4YzU3YTVlN2RlOGNlMjk2
|
15
|
+
YzVlY2M1MWZmY2RiMjA2MjA2MjQ3NjE5ZjA1ODZjYTgxZGZhN2Y=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Daniel Vandersluis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= JavaScript IF/UNLESS blocks support
|
2
|
+
|
3
|
+
This plugin introduces support for IF/UNLESS blocks to
|
4
|
+
Rails' javascript generator.
|
5
|
+
|
6
|
+
== Usage
|
7
|
+
|
8
|
+
Lets say you want to produce javascript that will execute
|
9
|
+
blind_down visual effect to show some DOM element unless
|
10
|
+
it is already visible. To accomplish this you need an IF block:
|
11
|
+
|
12
|
+
|
13
|
+
update_page do |page|
|
14
|
+
page << "if( !($('#{element_id}').visible()) ) {"
|
15
|
+
page.visual_effect :blind_down, element_id
|
16
|
+
page << "}"
|
17
|
+
end
|
18
|
+
|
19
|
+
Instead you can use +if+ method that this plugin provides:
|
20
|
+
|
21
|
+
update_page do |page|
|
22
|
+
page.unless "$('#{element_id}').visible()" do
|
23
|
+
page.visual_effect :blind_down, element_id
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Also, you can make use of javascript element proxy in the expression:
|
28
|
+
|
29
|
+
update_page do |page|
|
30
|
+
page.unless page[element_id].visible do
|
31
|
+
page.visual_effect :blind_down, element_id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
== Download
|
36
|
+
|
37
|
+
Download it from http://rubyforge.org/projects/js-if-blocks/ or via Rails plug
|
38
|
+
in script:
|
39
|
+
./script/plugin install svn://rubyforge.org/var/svn/js-if-blocks/trunk/js-if-blocks
|
40
|
+
|
41
|
+
== Bugs & Feedback
|
42
|
+
|
43
|
+
If you encounter any bugs or has some feature proposal, feel free to email it to
|
44
|
+
maxim.kulkin@gmail.com.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/init.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generator_if_blocks'
|
2
|
+
require 'javascript_element_proxy_extraction'
|
3
|
+
|
4
|
+
ActiveSupport.on_load(:action_view) do
|
5
|
+
ActiveSupport.on_load(:after_initialize) do
|
6
|
+
ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.class_eval do
|
7
|
+
include GeneratorIfBlocks
|
8
|
+
end
|
9
|
+
|
10
|
+
ActionView::Helpers::JavaScriptProxy.class_eval do
|
11
|
+
include JavaScriptElementProxyExtraction
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/rjs-if.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module GeneratorIfBlocks
|
2
|
+
# Produces _if_ block, e.g.
|
3
|
+
#
|
4
|
+
# page.if "$('element_id').visible()" do
|
5
|
+
# page['element_id'].hide
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# will produce
|
9
|
+
#
|
10
|
+
# if( $('element_id').visible() ) {
|
11
|
+
# $("element_id").hide()
|
12
|
+
# }
|
13
|
+
#
|
14
|
+
# You can simplify if expression by using element proxies:
|
15
|
+
#
|
16
|
+
# page.if page['element_id'].visible do
|
17
|
+
# page['element_id'].hide
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
def if(expression)
|
21
|
+
self << "if( #{ javascript_for(expression) } ) {"
|
22
|
+
yield if block_given?
|
23
|
+
self << "}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Same as +if+ method, but produces _if_not_ block
|
27
|
+
def unless(expression)
|
28
|
+
self << "if( !( #{javascript_for(expression) } ) ) {"
|
29
|
+
yield if block_given?
|
30
|
+
self << "}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def elsif(expression)
|
34
|
+
self << "else if( #{javascript_for(expression) } ) {"
|
35
|
+
yield if block_given?
|
36
|
+
self << "}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Close javascript block and open an 'else' block
|
40
|
+
def else
|
41
|
+
self << "else {"
|
42
|
+
yield if block_given?
|
43
|
+
self << "}"
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def javascript_for(o)
|
49
|
+
o.respond_to?(:to_script) ? o.to_script : o.to_s
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rjs/if/generator_if_blocks"
|
2
|
+
require "rjs/if/javascript_element_proxy_extraction"
|
3
|
+
|
4
|
+
module RJS
|
5
|
+
module If
|
6
|
+
class Railtie < Rails::Railtie
|
7
|
+
config.after_initialize do
|
8
|
+
ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMethods.class_eval do
|
9
|
+
include GeneratorIfBlocks
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionView::Helpers::JavaScriptProxy.class_eval do
|
13
|
+
include JavaScriptElementProxyExtraction
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/rjs-if.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'rjs/if/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |gem|
|
8
|
+
gem.name = "rjs-if"
|
9
|
+
gem.version = RJS::If::VERSION
|
10
|
+
gem.authors = ["Daniel Vandersluis"]
|
11
|
+
gem.email = ["dvandersluis@selfmgmt.com"]
|
12
|
+
gem.description = "Add if/unless blocks to RJS"
|
13
|
+
gem.summary = "Add if and unless methods to the page object when working in RJS."
|
14
|
+
gem.homepage = "https://github.com/talentnest/rjs-if"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'activesupport', ['>= 3.0.0']
|
22
|
+
gem.add_dependency 'actionpack', ['>= 3.0.0']
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rjs-if
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Vandersluis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
type: :runtime
|
15
|
+
prerelease: false
|
16
|
+
name: activesupport
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
type: :runtime
|
29
|
+
prerelease: false
|
30
|
+
name: actionpack
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.0.0
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
description: Add if/unless blocks to RJS
|
42
|
+
email:
|
43
|
+
- dvandersluis@selfmgmt.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- init.rb
|
54
|
+
- lib/rjs-if.rb
|
55
|
+
- lib/rjs/if/generator_if_blocks.rb
|
56
|
+
- lib/rjs/if/javascript_element_proxy_extraction.rb
|
57
|
+
- lib/rjs/if/railtie.rb
|
58
|
+
- lib/rjs/if/version.rb
|
59
|
+
- rjs-if.gemspec
|
60
|
+
homepage: https://github.com/talentnest/rjs-if
|
61
|
+
licenses: []
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.1.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Add if and unless methods to the page object when working in RJS.
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|