jquery-modal-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +30 -1
- data/demoapp/Gemfile +1 -1
- data/demoapp/db/test.sqlite3 +0 -0
- data/lib/jquery/modal/helpers/link_helpers.rb +27 -15
- data/lib/jquery/modal/rails/engine.rb +4 -0
- data/lib/jquery/modal/rails/version.rb +1 -1
- data/spec/jquery/modal/link_helpers_spec.rb +49 -0
- data/spec/spec_helper.rb +20 -0
- metadata +5 -2
data/Gemfile
CHANGED
@@ -1,4 +1,33 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.2.8'
|
4
|
+
|
5
|
+
# Bundle edge Rails instead:
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
7
|
+
|
8
|
+
gem 'sqlite3'
|
9
|
+
|
10
|
+
|
11
|
+
# Gems used only for assets and not required
|
12
|
+
# in production environments by default.
|
13
|
+
group :assets do
|
14
|
+
gem 'sass-rails', '~> 3.2.3'
|
15
|
+
gem 'coffee-rails', '~> 3.2.1'
|
16
|
+
|
17
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
18
|
+
# gem 'therubyracer', :platforms => :ruby
|
19
|
+
|
20
|
+
gem 'uglifier', '>= 1.0.3'
|
21
|
+
|
22
|
+
gem 'jquery-ui-rails'
|
23
|
+
end
|
24
|
+
|
25
|
+
gem 'jquery-rails'
|
2
26
|
|
3
27
|
# Specify your gem's dependencies in jquery-modal-rails.gemspec
|
4
28
|
gemspec
|
29
|
+
|
30
|
+
# add rspec
|
31
|
+
gem 'rspec'
|
32
|
+
gem 'rspec-rails'
|
33
|
+
gem 'shoulda', :require => false
|
data/demoapp/Gemfile
CHANGED
File without changes
|
@@ -9,25 +9,37 @@ module Jquery
|
|
9
9
|
# link_to(body, url, html_options = {})
|
10
10
|
# link_to(body, url)
|
11
11
|
#
|
12
|
-
def link_to_modal(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def link_to_modal(*args, &block)
|
13
|
+
if block_given?
|
14
|
+
options = args.first || {}
|
15
|
+
html_options = args.second
|
16
|
+
block_result = yield(*args)
|
17
|
+
link_to_modal(block_result, options, html_options)
|
18
|
+
else
|
19
|
+
name = args[0]
|
20
|
+
options = args[1] || {}
|
21
|
+
html_options = args[2] || {}
|
22
|
+
|
23
|
+
# extend the html_options
|
24
|
+
html_options[:rel] = "modal:open"
|
25
|
+
if (html_options.has_key?(:remote))
|
26
|
+
if (html_options[:remote] == true)
|
27
|
+
html_options[:rel] = "modal:open:ajaxpost"
|
28
|
+
end
|
29
|
+
|
30
|
+
# remove the remote tag
|
31
|
+
html_options.delete(:remote)
|
18
32
|
end
|
19
33
|
|
20
|
-
#
|
21
|
-
html_options.
|
22
|
-
end
|
23
|
-
# check if we have an id
|
24
|
-
html_options[:id] = UUIDTools::UUID.random_create().to_s unless html_options.has_key?(:id)
|
34
|
+
# check if we have an id
|
35
|
+
html_options[:id] = UUIDTools::UUID.random_create().to_s unless html_options.has_key?(:id)
|
25
36
|
|
26
|
-
|
27
|
-
|
37
|
+
# perform the normal link_to operation
|
38
|
+
html_link = link_to(name, options, html_options)
|
28
39
|
|
29
|
-
|
30
|
-
|
40
|
+
# emit both
|
41
|
+
html_link.html_safe
|
42
|
+
end
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jquery::Helpers do
|
4
|
+
include ActionView::Helpers, ::ERB::Util, ActionView::Context
|
5
|
+
include Jquery::Helpers
|
6
|
+
|
7
|
+
|
8
|
+
it "offers default link" do
|
9
|
+
link_to_modal("SimpleDialog", "http://www.google.de", :id => 1).should \
|
10
|
+
eq('<a href="http://www.google.de" id="1" rel="modal:open">SimpleDialog</a>')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "offers AJAX link" do
|
14
|
+
link_to_modal("SimpleDialog", "http://www.google.de", :id => 1, :remote => true).should \
|
15
|
+
eq('<a href="http://www.google.de" id="1" rel="modal:open:ajaxpost">SimpleDialog</a>')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "supports block for default link" do
|
19
|
+
link = link_to_modal("http://www.google.de", :id => 1) do
|
20
|
+
"SimpleDialog"
|
21
|
+
end
|
22
|
+
|
23
|
+
link.should eq('<a href="http://www.google.de" id="1" rel="modal:open">SimpleDialog</a>')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "supports block for AJAX link" do
|
27
|
+
link = link_to_modal("http://www.google.de", :id => 1, :remote => true) do
|
28
|
+
"SimpleDialog"
|
29
|
+
end
|
30
|
+
|
31
|
+
link.should eq('<a href="http://www.google.de" id="1" rel="modal:open:ajaxpost">SimpleDialog</a>')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "supports block for complex AJAX link" do
|
35
|
+
link = link_to_modal("http://www.google.de", :id => 1, :remote => true) do
|
36
|
+
content_tag(:div) do
|
37
|
+
content_tag(:p) do
|
38
|
+
"SimpleDialog"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
link.should eq('<a href="http://www.google.de" id="1" rel="modal:open:ajaxpost"><div><p>SimpleDialog</p></div></a>')
|
44
|
+
end
|
45
|
+
|
46
|
+
it "does not crash with only two paraemters" do
|
47
|
+
link_to_modal('New User Modal', "http://google.de").should_not be_nil
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
ENV['RAILS_ENV'] = 'test'
|
2
|
+
ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../')
|
3
|
+
|
4
|
+
require File.expand_path("../../demoapp/config/environment", __FILE__)
|
5
|
+
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.require(:default)
|
8
|
+
|
9
|
+
require 'rspec/rails'
|
10
|
+
require 'shoulda'
|
11
|
+
|
12
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
13
|
+
# in spec/support/ and its subdirectories.
|
14
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
15
|
+
|
16
|
+
#
|
17
|
+
# General config for RSpec
|
18
|
+
RSpec.configure do |config|
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-modal-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- demoapp/db/migrate/20120621084323_create_users.rb
|
136
136
|
- demoapp/db/schema.rb
|
137
137
|
- demoapp/db/seeds.rb
|
138
|
+
- demoapp/db/test.sqlite3
|
138
139
|
- demoapp/doc/README_FOR_APP
|
139
140
|
- demoapp/log/development.log
|
140
141
|
- demoapp/public/404.html
|
@@ -158,6 +159,8 @@ files:
|
|
158
159
|
- lib/jquery/modal/rails.rb
|
159
160
|
- lib/jquery/modal/rails/engine.rb
|
160
161
|
- lib/jquery/modal/rails/version.rb
|
162
|
+
- spec/jquery/modal/link_helpers_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
161
164
|
- vendor/assets/images/close.png
|
162
165
|
- vendor/assets/images/spinner.gif
|
163
166
|
- vendor/assets/javascripts/jquery.modal.js
|