jquery_ui_rails_helpers 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ .rvmrc
3
+ *.gem
data/CHANGELOG ADDED
@@ -0,0 +1,16 @@
1
+ == 03-07-2009
2
+
3
+ * big change: removed the 2nd param for concat, rails no longer requires the binding be passed.
4
+ * added a helper for creating accordions
5
+
6
+ == 09-04-2008
7
+
8
+ * big change: renamed classes, and helper 'tabs_for' now requires a block
9
+
10
+ == 08-28-2008
11
+
12
+ * added the ability to call TabsRenderer.new with a block parameter
13
+
14
+ == 06-22-2008 initial import
15
+
16
+ * TabsRenderer added
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ui_helpers.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,83 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jquery_ui_rails_helpers (0.0.1)
5
+ rails (~> 3.0.0)
6
+ shoulda (~> 3.0.0.beta2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.3)
13
+ actionpack (= 3.0.3)
14
+ mail (~> 2.2.9)
15
+ actionpack (3.0.3)
16
+ activemodel (= 3.0.3)
17
+ activesupport (= 3.0.3)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.4)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.13)
23
+ rack-test (~> 0.5.6)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.3)
26
+ activesupport (= 3.0.3)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.4)
29
+ activerecord (3.0.3)
30
+ activemodel (= 3.0.3)
31
+ activesupport (= 3.0.3)
32
+ arel (~> 2.0.2)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.3)
35
+ activemodel (= 3.0.3)
36
+ activesupport (= 3.0.3)
37
+ activesupport (3.0.3)
38
+ arel (2.0.7)
39
+ builder (2.1.2)
40
+ erubis (2.6.6)
41
+ abstract (>= 1.0.0)
42
+ i18n (0.5.0)
43
+ mail (2.2.15)
44
+ activesupport (>= 2.3.6)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.16)
49
+ polyglot (0.3.1)
50
+ rack (1.2.1)
51
+ rack-mount (0.6.13)
52
+ rack (>= 1.0.0)
53
+ rack-test (0.5.7)
54
+ rack (>= 1.0)
55
+ rails (3.0.3)
56
+ actionmailer (= 3.0.3)
57
+ actionpack (= 3.0.3)
58
+ activerecord (= 3.0.3)
59
+ activeresource (= 3.0.3)
60
+ activesupport (= 3.0.3)
61
+ bundler (~> 1.0)
62
+ railties (= 3.0.3)
63
+ railties (3.0.3)
64
+ actionpack (= 3.0.3)
65
+ activesupport (= 3.0.3)
66
+ rake (>= 0.8.7)
67
+ thor (~> 0.14.4)
68
+ rake (0.8.7)
69
+ shoulda (3.0.0.beta2)
70
+ shoulda-context (~> 1.0.0.beta1)
71
+ shoulda-matchers (~> 1.0.0.beta1)
72
+ shoulda-context (1.0.0.beta1)
73
+ shoulda-matchers (1.0.0.beta1)
74
+ thor (0.14.6)
75
+ treetop (1.4.9)
76
+ polyglot (>= 0.3.1)
77
+ tzinfo (0.3.24)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ jquery_ui_rails_helpers!
data/README.textile ADDED
@@ -0,0 +1,77 @@
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
+ h2. TabsHelper
8
+
9
+ This helper simplifies the code required to use the jQuery UI Tab plugin.
10
+
11
+ <pre><code>
12
+ <% tabs_for do |tab| %>
13
+ <% tab.create('tab_one', 'Tab 1') do %>
14
+ # ... insert tab contents
15
+ <% end %>
16
+ <% tab.create('tab_two', 'Tab 2') do %>
17
+ # ... insert tab contents
18
+ <% end %>
19
+ <% end %>
20
+ </code></pre>
21
+
22
+ The above will generate this HTML in your view:
23
+
24
+ <pre><code>
25
+ <div id="tabs">
26
+ <ul>
27
+ <li><a href="#tab_one"><span>Tab 1</span></a></li>
28
+ <li><a href="#tab_two"><span>Tab 2</span></a></li>
29
+ </ul>
30
+ <div id="tab_one">
31
+ # ... insert tab contents
32
+ </div>
33
+ <div id="tab_two">
34
+ # ... insert tab contents
35
+ </div>
36
+ </div>
37
+ </code></pre>
38
+
39
+ Tabs will be rendered in the order you create them.
40
+
41
+ You can easily render a tab conditionally by appending your condition to the end of
42
+ the 'create' block as such ...
43
+
44
+ <pre><code>
45
+ <% tab.create('profile_tab', 'Your Profile') do %>
46
+ # ... insert tab contents
47
+ <% end unless @current_user.nil? %>
48
+ </code></pre>
49
+
50
+ You can pass HTML options to either the parent DIV or any individual tab's
51
+ DIV as you like ...
52
+
53
+ <pre><code>
54
+ <% tabs_for(:class => 'zippy') do |tab| %>
55
+ <% tab.create('tab_one', 'Tab 1', :style => 'background: #FFF') do %>
56
+ # ... insert tab contents
57
+ <% end %>
58
+ <% end %>
59
+ </code></pre>
60
+
61
+ The default DOM ID for the parent div is ... id="tabs" ... unless you pass in an HTML
62
+ option with a different value.
63
+
64
+ h2. AccordionsHelper
65
+
66
+ This helper simplifies the code required to use JQuery UIs Accordion plugin.
67
+
68
+ Usage is identical to the Tabs helper.
69
+
70
+ <pre><code>
71
+ <% accordions_for do |accordion| %>
72
+ <% accordion.create("dom_id", "accordion_title") do %>
73
+ # ... insert accordion contents
74
+ <% end %>
75
+ <% end %>
76
+ </code></pre>
77
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc 'Default: run unit tests.'
7
+ task :default => :test
8
+
9
+ desc 'Test the simple_form plugin.'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'lib'
12
+ t.libs << 'test'
13
+ t.pattern = 'test/**/*_test.rb'
14
+ t.verbose = true
15
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jquery_ui_rails_helpers/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jquery_ui_rails_helpers"
7
+ s.version = JqueryUiRailsHelpers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "jQuery UI Rails Helpers"
10
+ s.authors = ["CodeOfficer"]
11
+ s.email = ["codeofficer@gmail.com"]
12
+ s.homepage = "http://www.codeofficer.com/"
13
+ s.description = "jQuery UI Rails Helpers"
14
+
15
+ s.add_dependency("rails", "~> 3.0.0")
16
+ s.add_dependency("shoulda", "~> 3.0.0.beta2")
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.rubyforge_project = "jquery_ui_rails_helpers"
24
+ end
25
+
26
+
27
+
@@ -0,0 +1,47 @@
1
+ module AccordionsHelper
2
+ def accordions_for( *options, &block )
3
+ raise ArgumentError, "Missing block" unless block_given?
4
+ raw AccordionsHelper::AccordionsRenderer.new( *options, &block ).render
5
+ end
6
+
7
+ class AccordionsRenderer
8
+
9
+ def initialize( options={}, &block )
10
+ raise ArgumentError, "Missing block" unless block_given?
11
+
12
+ @template = eval( 'self', block.binding )
13
+ @options = options
14
+ @accordions = []
15
+
16
+ yield self
17
+ end
18
+
19
+ def create( accordion_id, accordion_text, options={}, &block )
20
+ raise "Block needed for AccordionsRenderer#CREATE" unless block_given?
21
+ @accordions << [ accordion_id, accordion_text, options, block ]
22
+ end
23
+
24
+ def render
25
+ content = @accordions.collect do |accordion|
26
+ accordion_head(accordion) << accordion_body(accordion)
27
+ end.join
28
+ content_tag( :div, raw(content), { :id => :accordions }.merge( @options ) )
29
+ end
30
+
31
+ private # ---------------------------------------------------------------------------
32
+
33
+ def accordion_head(accordion)
34
+ content_tag :h3, link_to(accordion[1], '#'), :id => accordion[0]
35
+ end
36
+
37
+ def accordion_body(accordion)
38
+ content_tag :div, capture( &accordion[3] )
39
+ end
40
+
41
+ def method_missing( *args, &block )
42
+ @template.send( *args, &block )
43
+ end
44
+
45
+ end
46
+ end
47
+
@@ -0,0 +1,19 @@
1
+ module JavascriptsHelper
2
+
3
+ def stylesheet(*args)
4
+ content_for(:head) { stylesheet_link_tag(*args) }
5
+ end
6
+
7
+ def javascript(*args)
8
+ content_for(:head) { javascript_include_tag(*args) }
9
+ end
10
+
11
+ def field_id_for_js(f, attribute)
12
+ "#{f.object_name}[#{attribute.to_s.sub(/\?$/,"")}]".gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
13
+ end
14
+
15
+ def field_name_for_js(f, attribute)
16
+ "#{f.object_name}[#{attribute.to_s.sub(/\?$/,"")}]"
17
+ end
18
+
19
+ end
@@ -0,0 +1,65 @@
1
+ # http://forum.jquery.com/topic/jquery-datepicker-pick-multiple-dates
2
+ # module JqueryUiRailsHelpers
3
+
4
+ module TabsHelper
5
+ def tabs_for( *options, &block )
6
+ raise ArgumentError, "Missing block" unless block_given?
7
+ raw TabsHelper::TabsRenderer.new( *options, &block ).render
8
+ end
9
+
10
+ class TabsRenderer
11
+
12
+ def initialize( options={}, &block )
13
+ raise ArgumentError, "Missing block" unless block_given?
14
+
15
+ @template = eval( 'self', block.binding )
16
+ @options = options
17
+ @tabs = []
18
+
19
+ yield self
20
+ end
21
+
22
+ def create( tab_id, tab_text, options={}, &block )
23
+ raise "Block needed for TabsRenderer#CREATE" unless block_given?
24
+ @tabs << [ tab_id, tab_text, options, block, {:ajax => false} ]
25
+ end
26
+
27
+ def create_ajax( link, tab_text, options={})
28
+ @tabs << [ link, tab_text, options, nil, {:ajax => true} ]
29
+ end
30
+
31
+ def render
32
+ content_tag( :div, raw([render_tabs, render_bodies].join), { :id => :tabs }.merge( @options ) )
33
+ end
34
+
35
+ private # ---------------------------------------------------------------------------
36
+
37
+ def render_tabs
38
+ content_tag :ul do
39
+ result = @tabs.collect do |tab|
40
+ if tab[4][:ajax]
41
+ content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "#{tab[0]}" ) )
42
+ else
43
+ content_tag( :li, link_to( content_tag( :span, raw(tab[1]) ), "##{tab[0]}" ) )
44
+ end
45
+ end.join
46
+ raw(result)
47
+ end
48
+ end
49
+
50
+ def render_bodies
51
+ @tabs.collect do |tab|
52
+ if tab[4][:ajax]
53
+ # there are no divs for ajaxed tabs
54
+ else
55
+ content_tag( :div, capture( &tab[3] ), tab[2].merge( :id => tab[0] ) )
56
+ end
57
+ end.join.to_s
58
+ end
59
+
60
+ def method_missing( *args, &block )
61
+ @template.send( *args, &block )
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryUiRailsHelpers
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'action_view'
2
+ require "jquery_ui_rails_helpers/version"
3
+ require 'helpers/javascripts_helper'
4
+ require 'helpers/tabs_helper'
5
+ require 'helpers/accordions_helper'
6
+
7
+ module JqueryUiRailsHelpers
8
+ end
9
+
10
+ ActionView::Base.send(:include, JavascriptsHelper)
11
+ ActionView::Base.send(:include, TabsHelper)
12
+ ActionView::Base.send(:include, AccordionsHelper)
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+
6
+ require 'test/unit'
7
+ require 'shoulda'
8
+ require 'action_controller'
9
+ require 'action_controller/test_case'
10
+ require 'action_view'
11
+ require 'action_view/template'
12
+ require 'action_view/test_case'
13
+
14
+ $:.unshift File.expand_path("../../lib", __FILE__)
15
+ require 'jquery_ui_rails_helpers'
16
+
17
+ class ActionView::TestCase
18
+
19
+ # Take care of the RuntimeError:
20
+ # In order to use #url_for, you must include routing helpers explicitly.
21
+ # For instance, `include Rails.application.routes.url_helpers
22
+ setup :shhhhhh_url_helpers
23
+
24
+ def shhhhhh_url_helpers
25
+ def @controller._routes
26
+ Module.new do
27
+ def self.url_helpers
28
+ Module.new
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class AccordionsHelperTest < ActionView::TestCase
4
+
5
+ context "creating accordions without a block syntax" do
6
+ should 'raises an exception' do
7
+ assert_raise ArgumentError do
8
+ @accordions = accordions_for
9
+ end
10
+ end
11
+ end
12
+
13
+ context "creating one set of accordions" do
14
+ setup do
15
+ @accordions = accordions_for do |accordion|
16
+ accordion.create('accordion_one', 'One') { "Accordion One." }
17
+ accordion.create('accordion_two', 'Two') { "Accordion Two." }
18
+ end
19
+ end
20
+
21
+ should 'have proper dom structure' do
22
+ render :text => @accordions
23
+ assert_select "div[id='accordions']", 1
24
+ assert_select "div[id='accordions'] h3[id='accordion_one']", 1
25
+ assert_select "div[id='accordions'] h3[id='accordion_one'] a", {:count => 1, :text => "One"}
26
+ assert_select "div[id='accordions'] h3[id='accordion_two']", 1
27
+ assert_select "div[id='accordions'] h3[id='accordion_two'] a", {:count => 1, :text => "Two"}
28
+ assert_select "div[id='accordions'] div", 2
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ # <div id="accordions">
35
+ # <h3 id="accordion_one"><a href="#">One</a></h3>
36
+ # <div>Accordion Two.</div>
37
+ # <h3 id="accordion_two"><a href="#">Two</a></h3>
38
+ # <div>Accordion One.</div>
39
+ # </div>
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class TabsHelperTest < ActionView::TestCase
4
+
5
+ context "creating tabs without a block syntax" do
6
+ should 'raises an exception' do
7
+ assert_raise ArgumentError do
8
+ @tabs = tabs_for
9
+ end
10
+ end
11
+ end
12
+
13
+ context "creating two tabs" do
14
+ setup do
15
+ @tabs = tabs_for do |tab|
16
+ tab.create('tab_one', 'One') { "Tab One." }
17
+ tab.create('tab_two', 'Two') { "Tab Two." }
18
+ end
19
+ puts @tabs
20
+ end
21
+
22
+ should 'have proper dom structure' do
23
+ render :text => @tabs
24
+ assert_select "div[id='tabs']", 1
25
+ assert_select "div[id='tabs'] ul", 1
26
+ assert_select "div[id='tabs'] ul li", 2
27
+ assert_select "div[id='tabs'] div[id='tab_one']", 1
28
+ assert_select "div[id='tabs'] div[id='tab_two']", 1
29
+ end
30
+ end
31
+
32
+ context "creating custom tabs" do
33
+ setup do
34
+ @tabs = tabs_for(:id => "my_tabs") do |tab|
35
+ tab.create_ajax('http://www.codeofficer.com/', 'Ajax')
36
+ end
37
+ end
38
+
39
+ should 'allow overriding the outter divs id' do
40
+ render :text => @tabs
41
+ assert_select "div[id='my_tabs']", 1
42
+ end
43
+
44
+ should 'allow ajaxed tabs' do
45
+ render :text => @tabs
46
+ assert_select "div[id='my_tabs'] ul li a[href='http://www.codeofficer.com/']", 1
47
+ assert_select "div[id='my_tabs'] div", 0
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ # <div id="tabs">
54
+ # <ul>
55
+ # <li><a href="#tab_one"><span>One</span></a></li>
56
+ # <li><a href="#tab_two"><span>Two</span></a></li>
57
+ # <li><a href="http://www.codeofficer.com/"><span>Ajax</span></a></li>
58
+ # </ul>
59
+ # <div id="tab_one">Tab One.</div>
60
+ # <div id="tab_two">Tab Two.</div>
61
+ # </div>
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_ui_rails_helpers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - CodeOfficer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-26 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: shoulda
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: -1848230022
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 0
50
+ - beta2
51
+ version: 3.0.0.beta2
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ description: jQuery UI Rails Helpers
55
+ email:
56
+ - codeofficer@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files: []
62
+
63
+ files:
64
+ - .gitignore
65
+ - CHANGELOG
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.textile
69
+ - Rakefile
70
+ - jquery_ui_rails_helpers.gemspec
71
+ - lib/helpers/accordions_helper.rb
72
+ - lib/helpers/javascripts_helper.rb
73
+ - lib/helpers/tabs_helper.rb
74
+ - lib/jquery_ui_rails_helpers.rb
75
+ - lib/jquery_ui_rails_helpers/version.rb
76
+ - test/test_helper.rb
77
+ - test/unit/helper/accordions_helper_test.rb
78
+ - test/unit/helper/tabs_helper_test.rb
79
+ has_rdoc: true
80
+ homepage: http://www.codeofficer.com/
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: jquery_ui_rails_helpers
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: jQuery UI Rails Helpers
113
+ test_files:
114
+ - test/test_helper.rb
115
+ - test/unit/helper/accordions_helper_test.rb
116
+ - test/unit/helper/tabs_helper_test.rb