-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Russell Jones
committed
Jun 22, 2008
0 parents
commit a41e3a1
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
== 06-22-2008 initial import | ||
|
||
* TabsRenderer added |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
JQuery UI Rails Helpers Readme | ||
---------------------------------------------------------------- | ||
|
||
* Web: http://www.codeofficer.com/ | ||
* Email: spam*@*codeofficer*dot*com | ||
* JQuery: http://www.jquery.com/ | ||
* JQuery UI: http://ui.jquery.com/ | ||
|
||
These are some view helpers I use in Rails to better integrate JQuery UI in my sites. | ||
|
||
Maybe you will find them useful as well. | ||
|
||
These include ... | ||
|
||
|
||
TabsRenderer | ||
---------------------------------------------------------------- | ||
|
||
This helper simplifies the code required to use JQuery UIs Tabs plugin. | ||
|
||
There are 3 steps to rendering a tab ... initialize, create and render. | ||
|
||
<% tabs = TabsRenderer.new(self) %> | ||
<% tabs.create('tab_one', 'Tab 1') do %> | ||
# ... insert tab contents | ||
<% end %> | ||
<% tabs.create('tab_two', 'Tab 2') do %> | ||
# ... insert tab contents | ||
<% end %> | ||
<%= tabs.render %> | ||
|
||
The above will generate this HTML in your view: | ||
|
||
<div id="tabs"> | ||
<ul> | ||
<li><a href="#tab_one"><span>Tab 1</span></a></li> | ||
<li><a href="#tab_two"><span>Tab 2</span></a></li> | ||
</ul> | ||
<div id="tab_one"> | ||
# ... insert tab contents | ||
</div> | ||
<div id="tab_two"> | ||
# ... insert tab contents | ||
</div> | ||
</div> | ||
|
||
Tabs will be rendered in the order you create them. | ||
|
||
You can easily render a tab conditionally by appending your condition to the end of | ||
the 'create' block as such ... | ||
|
||
<% tabs.create('profile_tab', 'Your Profile') do %> | ||
# ... insert tab contents | ||
<% end unless @current_user.nil? %> | ||
|
||
You can pass HTML options to either the parent DIV or any individual tab's | ||
DIV as you like ... | ||
|
||
<% tabs = TabsRenderer.new(self, :class = 'flora') %> | ||
<% tabs.create('tab_one', 'Tab 1', :style => 'background: #FFF') do %> | ||
# ... insert tab contents | ||
<% end %> | ||
<%= tabs.render %> | ||
|
||
The default DOM ID for the parent div is ... id="tabs" ... unless you pass in an HTML | ||
option with a different value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class TabsRenderer | ||
|
||
def initialize(template, options={}) | ||
@template = template | ||
@options = options | ||
@tabs = [] | ||
end | ||
|
||
def create(tab_id, tab_text, options={}, &block) | ||
raise "Block needed for TabsRenderer#CREATE" unless block_given? | ||
@tabs << [tab_id, tab_text, options, block] | ||
end | ||
|
||
def render | ||
content_tag(:div, (render_tabs + render_bodies), {:id => :tabs}.merge(@options)) | ||
end | ||
|
||
private # --------------------------------------------------------------------------- | ||
|
||
def render_tabs | ||
content_tag :ul do | ||
@tabs.collect do |tab| | ||
content_tag(:li, link_to(content_tag(:span, tab[1]), "##{tab[0]}") ) | ||
end | ||
end | ||
end | ||
|
||
def render_bodies | ||
@tabs.collect do |tab| | ||
content_tag(:div, capture(&tab[3]), tab[2].merge(:id => tab[0])) | ||
end.to_s | ||
end | ||
|
||
def method_missing(*args, &block) | ||
@template.send(*args, &block) | ||
end | ||
|
||
end |