jquelpers 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +26 -0
- data/Manifest +8 -0
- data/README.textile +111 -0
- data/Rakefile +15 -0
- data/jquelpers.gemspec +30 -0
- data/lib/jquelpers/accordion_helper.rb +56 -0
- data/lib/jquelpers/datepicker_helper.rb +17 -0
- data/lib/jquelpers/tabs_helper.rb +55 -0
- data/lib/jquelpers.rb +4 -0
- metadata +86 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
== 18-11-2010
|
2
|
+
Major Commit
|
3
|
+
* Support for Ajax in Tabs
|
4
|
+
* javascript is genarated by the helper, no need to add extra code in views.
|
5
|
+
* Add datepicker helper for the date picker provided in jQuery UI
|
6
|
+
|
7
|
+
== 16-11-2010
|
8
|
+
* Prevent dom id overriding.
|
9
|
+
create() do's not require an id anymore.
|
10
|
+
|
11
|
+
== 03-07-2009
|
12
|
+
|
13
|
+
* big change: removed the 2nd param for concat, rails no longer requires the binding be passed.
|
14
|
+
* added a helper for creating accordions
|
15
|
+
|
16
|
+
== 09-04-2008
|
17
|
+
|
18
|
+
* big change: renamed classes, and helper 'tabs_for' now requires a block
|
19
|
+
|
20
|
+
== 08-28-2008
|
21
|
+
|
22
|
+
* added the ability to call TabsRenderer.new with a block parameter
|
23
|
+
|
24
|
+
== 06-22-2008 initial import
|
25
|
+
|
26
|
+
* TabsRenderer added
|
data/Manifest
ADDED
data/README.textile
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
h1. What Is It?
|
2
|
+
|
3
|
+
These are some view helpers I use in Rails to better integrate jQuery UI into my sites.
|
4
|
+
|
5
|
+
I hope you find them useful.
|
6
|
+
|
7
|
+
original work by CodeOfficer
|
8
|
+
https://github.com/CodeOfficer/jquery-ui-rails-helpers
|
9
|
+
|
10
|
+
h2. Warning !
|
11
|
+
This fork is not anymore compatible with the original plugin.
|
12
|
+
If you decide to use this fork, you will have to rewrite your apps (for the best !)
|
13
|
+
|
14
|
+
|
15
|
+
h2. TabsHelper
|
16
|
+
|
17
|
+
This helper simplifies the code required to use the jQuery UI Tab plugin.
|
18
|
+
|
19
|
+
<pre><code>
|
20
|
+
<% tabs_for :tabs_container :jquery => "collapsible = true" do |tab| %>
|
21
|
+
<% tab.create('Tab 1') do %>
|
22
|
+
# ... insert tab contents
|
23
|
+
<% end %>
|
24
|
+
<% tab.create('Tab 2', :ajax => any_path) do %>
|
25
|
+
<% end %>
|
26
|
+
<% end %>
|
27
|
+
</code></pre>
|
28
|
+
|
29
|
+
The above will generate this HTML in your view: ( to be corrected with the new behaviours)
|
30
|
+
|
31
|
+
<pre><code>
|
32
|
+
<div id="tabs">
|
33
|
+
<ul>
|
34
|
+
<li><a href="#tabs_container_0"><span>Tab 1</span></a></li>
|
35
|
+
<li><a href="#tabs_container_1"><span>Tab 2</span></a></li>
|
36
|
+
</ul>
|
37
|
+
<div id="tabs_container_0">
|
38
|
+
# ... insert tab contents
|
39
|
+
</div>
|
40
|
+
<div id="tabs_container_1">
|
41
|
+
# ... insert tab contents
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</code></pre>
|
45
|
+
|
46
|
+
Tabs will be rendered in the order you create them.
|
47
|
+
|
48
|
+
You can easily render a tab conditionally by appending your condition to the end of
|
49
|
+
the 'create' block as such ... (Cancan gem in this exemple)
|
50
|
+
|
51
|
+
<pre><code>
|
52
|
+
<% tab.create('My Profile') do %>
|
53
|
+
# ... insert tab contents
|
54
|
+
<% end can? :read, Profile %>
|
55
|
+
</code></pre>
|
56
|
+
|
57
|
+
You can pass HTML options or JQuery options to either the parent DIV or any individual tab's
|
58
|
+
DIV (there is no JQuery options for each tab.) as you like ...
|
59
|
+
|
60
|
+
<pre><code>
|
61
|
+
<% tabs_for :tabs_container :jquery => "collapsible = true", :class => 'zippy' do |tab| %>
|
62
|
+
<% tab.create('Tab 1', :style => 'background: #FFF') do %>
|
63
|
+
# ... insert tab contents
|
64
|
+
<% end %>
|
65
|
+
<% end %>
|
66
|
+
</code></pre>
|
67
|
+
<strike>
|
68
|
+
The default DOM ID for the parent div is ... id="tabs" ... unless you pass in an HTML
|
69
|
+
option with a different value. And you SHOULD pass an id.
|
70
|
+
</strike>
|
71
|
+
Dom id's are automaticaly genrated, but you can override them (I told you, you can pass html options)
|
72
|
+
|
73
|
+
h2. AccordionsHelper
|
74
|
+
|
75
|
+
This helper simplifies the code required to use JQuery UIs Accordion plugin.
|
76
|
+
|
77
|
+
Usage is identical to the Tabs helper.
|
78
|
+
|
79
|
+
<pre><code>
|
80
|
+
<% accordions_for do |accordion| %>
|
81
|
+
<% accordion.create("accordion_title") do %>
|
82
|
+
# ... insert accordion contents
|
83
|
+
<% end %>
|
84
|
+
<% end %>
|
85
|
+
</code></pre>
|
86
|
+
|
87
|
+
h2. DatepickerHelper
|
88
|
+
|
89
|
+
This helper simplifies the code required to use JQuery UIs Datepicker plugin.
|
90
|
+
|
91
|
+
Usage is identical to others helpers.
|
92
|
+
|
93
|
+
<pre><code>
|
94
|
+
<% form_for do |f| %>
|
95
|
+
<% f.datepicker :date, :jquery => "any option" %>
|
96
|
+
<% end %>
|
97
|
+
</code></pre>
|
98
|
+
|
99
|
+
or outside a form_for :
|
100
|
+
<pre><code>
|
101
|
+
<% datepicker_tag :object_name, :date, :jquery => "any option" %>
|
102
|
+
</code></pre>
|
103
|
+
|
104
|
+
h2. Todo.
|
105
|
+
h3. Gemification (will come soon)
|
106
|
+
h3. I18n the DatepickerHelper
|
107
|
+
h3. Autoload Jquery and Jquery UI
|
108
|
+
h3. write documentation
|
109
|
+
h3. Write tests (if some body explain me why and how)
|
110
|
+
h3. Other helpers (Autocompletion will come, ... any idea ?)
|
111
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('jquelpers') do |p|
|
6
|
+
p.description = "Provide Rails helpers for jquery-UI plugins"
|
7
|
+
p.url = "http://github.com/elmatou/jquery-ui-rails-helpers/"
|
8
|
+
p.author = "El Matou"
|
9
|
+
p.email = "elmatou@gmail.com"
|
10
|
+
p.version = "0.0.1"
|
11
|
+
p.changes = "First release (testing)"
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/jquelpers.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{jquelpers}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["El Matou"]
|
9
|
+
s.date = %q{2010-11-19}
|
10
|
+
s.description = %q{Provide Rails helpers for jquery-UI plugins}
|
11
|
+
s.email = %q{elmatou@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "README.textile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/tabs_helper.rb"]
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "README.textile", "Rakefile", "lib/jquelpers.rb", "lib/jquelpers/accordion_helper.rb", "lib/jquelpers/datepicker_helper.rb", "lib/jquelpers/tabs_helper.rb", "jquelpers.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/elmatou/jquery-ui-rails-helpers/}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jquelpers", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{jquelpers}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{Provide Rails helpers for jquery-UI plugins}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AccordionHelper
|
2
|
+
|
3
|
+
def accordion_for(method, options ={}, &block )
|
4
|
+
raise ArgumentError, "Missing block" unless block_given?
|
5
|
+
|
6
|
+
options = {:id => method.to_s }.merge!(options)
|
7
|
+
concat javascript_tag "$(document).ready(function() {$(\"##{options[:id]}\").accordion({#{options.delete(:jquery)}}); });"
|
8
|
+
concat AccordionHelper::AccordionRenderer.new( options, &block ).render
|
9
|
+
end
|
10
|
+
|
11
|
+
class AccordionRenderer
|
12
|
+
|
13
|
+
def initialize( options={}, &block )
|
14
|
+
raise ArgumentError, "Missing block" unless block_given?
|
15
|
+
|
16
|
+
@template = eval( 'self', block.binding )
|
17
|
+
@options = options
|
18
|
+
@accordions = []
|
19
|
+
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def create( accordion_text, options={}, &block )
|
24
|
+
raise "Block needed for AccordionsRenderer#CREATE" unless block_given?
|
25
|
+
@accordions << [ @options[:id].to_s + "_" + @accordions.count.to_s, accordion_text, options, block ]
|
26
|
+
end
|
27
|
+
|
28
|
+
def render
|
29
|
+
content_tag :div, { :id => :accordions }.merge( @options ) do
|
30
|
+
@accordions.collect do |accordion|
|
31
|
+
accordion_head(accordion) + accordion_body(accordion)
|
32
|
+
end.join
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private # ---------------------------------------------------------------------------
|
37
|
+
|
38
|
+
def accordion_head(accordion)
|
39
|
+
content_tag :h3, :id => accordion[0] do
|
40
|
+
link_to accordion[1], '#'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def accordion_body(accordion)
|
45
|
+
content_tag :div do
|
46
|
+
capture( &accordion[3] )
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing( *args, &block )
|
51
|
+
@template.send( *args, &block )
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DatepickerHelper
|
2
|
+
def datepicker_tag(object, method, options = {})
|
3
|
+
jquery = options.delete(:jquery)
|
4
|
+
concat text_field(object.class.name.downcase, method, options)
|
5
|
+
javascript_tag "$(document).ready(function() {$(#{object.class.name.downcase}_#{method.to_s}).datepicker({#{jquery}}); });"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ActionView
|
10
|
+
module Helpers
|
11
|
+
class FormBuilder
|
12
|
+
def datepicker(method, options = {})
|
13
|
+
@template.datepicker_tag(@object, method, options.merge(:object => @object))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module TabsHelper
|
2
|
+
|
3
|
+
def tabs_for(method, options = {}, &block )
|
4
|
+
raise ArgumentError, "Missing block" unless block_given?
|
5
|
+
|
6
|
+
options = {:id => method.to_s }.merge!(options)
|
7
|
+
concat javascript_tag "$(document).ready(function() {$(\"##{options[:id]}\").tabs({#{options.delete(:jquery)}}); });"
|
8
|
+
concat TabsHelper::TabsRenderer.new(options, &block ).render
|
9
|
+
end
|
10
|
+
|
11
|
+
class TabsRenderer
|
12
|
+
|
13
|
+
def initialize( options={}, &block )
|
14
|
+
raise ArgumentError, "Missing block" unless block_given?
|
15
|
+
|
16
|
+
@template = eval( 'self', block.binding )
|
17
|
+
@options = options
|
18
|
+
@tabs = []
|
19
|
+
|
20
|
+
yield self
|
21
|
+
end
|
22
|
+
|
23
|
+
def create( title, options={}, &block )
|
24
|
+
raise "Block needed for TabsRenderer#CREATE" unless block_given?
|
25
|
+
ajax = options.delete(:ajax)
|
26
|
+
@tabs << [ @options[:id].to_s + "_" + @tabs.count.to_s, title, options, block, ajax ]
|
27
|
+
end
|
28
|
+
|
29
|
+
def render
|
30
|
+
content_tag( :div, [render_tabs, render_bodies], { :id => @options[:id] })
|
31
|
+
end
|
32
|
+
|
33
|
+
private # ---------------------------------------------------------------------------
|
34
|
+
|
35
|
+
def render_tabs
|
36
|
+
content_tag :ul do
|
37
|
+
@tabs.collect do |tab|
|
38
|
+
content_tag( :li, link_to( content_tag( :span, tab[1] ), tab[4] || "##{tab[0]}" ) )
|
39
|
+
end.join
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_bodies
|
44
|
+
@tabs.collect do |tab|
|
45
|
+
content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) )
|
46
|
+
end.join.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
def method_missing( *args, &block )
|
50
|
+
@template.send( *args, &block )
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/jquelpers.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquelpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- El Matou
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-19 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Provide Rails helpers for jquery-UI plugins
|
23
|
+
email: elmatou@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- CHANGELOG
|
30
|
+
- README.textile
|
31
|
+
- lib/jquelpers.rb
|
32
|
+
- lib/jquelpers/accordion_helper.rb
|
33
|
+
- lib/jquelpers/datepicker_helper.rb
|
34
|
+
- lib/jquelpers/tabs_helper.rb
|
35
|
+
files:
|
36
|
+
- CHANGELOG
|
37
|
+
- Manifest
|
38
|
+
- README.textile
|
39
|
+
- Rakefile
|
40
|
+
- lib/jquelpers.rb
|
41
|
+
- lib/jquelpers/accordion_helper.rb
|
42
|
+
- lib/jquelpers/datepicker_helper.rb
|
43
|
+
- lib/jquelpers/tabs_helper.rb
|
44
|
+
- jquelpers.gemspec
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/elmatou/jquery-ui-rails-helpers/
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --line-numbers
|
52
|
+
- --inline-source
|
53
|
+
- --title
|
54
|
+
- Jquelpers
|
55
|
+
- --main
|
56
|
+
- README.textile
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 11
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
- 2
|
77
|
+
version: "1.2"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: jquelpers
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Provide Rails helpers for jquery-UI plugins
|
85
|
+
test_files: []
|
86
|
+
|