logical_tabs 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/Gemfile.lock +105 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +115 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/doc/README +2 -0
- data/lib/generators/logical_tabs/install/install_generator.rb +75 -0
- data/lib/generators/logical_tabs/install/templates/javascripts/logical_tabs_jquery.js +688 -0
- data/lib/generators/logical_tabs/install/templates/javascripts/logical_tabs_prototype.js +256 -0
- data/lib/generators/logical_tabs/install/templates/stylesheets/logical_tabs.css +69 -0
- data/lib/generators/logical_tabs/install/templates/stylesheets/sass/logical_tabs.sass +69 -0
- data/lib/logical_tabs.rb +8 -0
- data/lib/logical_tabs/helper.rb +24 -0
- data/lib/logical_tabs/tab_pane.rb +74 -0
- data/lib/logical_tabs/tabbed_panel.rb +98 -0
- metadata +127 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'logical_tabs/tab_pane'
|
2
|
+
|
3
|
+
module LogicalTabs
|
4
|
+
class DuplicateTabID < Exception
|
5
|
+
end
|
6
|
+
|
7
|
+
# a collection of tabs with their associated panes, I.E. a tabbed panel
|
8
|
+
class TabbedPanel
|
9
|
+
attr_reader :tabs, :base_id
|
10
|
+
|
11
|
+
# view must be an instance of ActionView::Base. This class
|
12
|
+
# depends on it for access to the capture and content_tag methods
|
13
|
+
def initialize(view, options = {})
|
14
|
+
@view = view
|
15
|
+
@tabs = []
|
16
|
+
@base_id = options[:base_id] || build_generic_id(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_generic_id(options)
|
20
|
+
base_id = "tabbed_panel".html_safe
|
21
|
+
base_id += "_#{options[:seq]}".html_safe if options[:seq]
|
22
|
+
base_id
|
23
|
+
end
|
24
|
+
|
25
|
+
# Add a new tab (with pane) to this tabbed panel. Either pass
|
26
|
+
# a block with the content for the panel, or pass :content => 'my_content'.
|
27
|
+
#
|
28
|
+
# Name is required and serves as the internal identifier for the tab. By
|
29
|
+
# default, it is also the displayed text of the tab.
|
30
|
+
#
|
31
|
+
#
|
32
|
+
# Other options:
|
33
|
+
# :base_id The string used as the beginning of the ID for CSS
|
34
|
+
# IDs for the tab and pane. :base_id => 'foo' will
|
35
|
+
# generate a tab with ID 'foo_tab' and a panel with ID
|
36
|
+
# 'foo_panel'. Defaults to name.downcase
|
37
|
+
#
|
38
|
+
# :tab_text The text to display in the tab. Defaults to name.
|
39
|
+
#
|
40
|
+
# :content The content for the panel itself, in HTML
|
41
|
+
def add_tab(name, options = {}, &block)
|
42
|
+
# debugger
|
43
|
+
options[:content] ||= v.capture(&block)
|
44
|
+
tab = TabPane.new(self, name, options)
|
45
|
+
if @tabs.any?{ |t| t.base_id == tab.base_id }
|
46
|
+
raise DuplicateTabID
|
47
|
+
else
|
48
|
+
@tabs << tab
|
49
|
+
end
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Render a UL containing all the tabs as LIs. Which tab is
|
54
|
+
# shown as selected is determined by the return value of selected?
|
55
|
+
def render_tabs
|
56
|
+
v.content_tag(:ul,
|
57
|
+
@tabs.map{ |tab| tab.render_tab(selected?(tab)) }.join.html_safe,
|
58
|
+
:class => 'tabs'.html_safe
|
59
|
+
).html_safe
|
60
|
+
end
|
61
|
+
|
62
|
+
# Render a sequence of DIVs containing the panes.
|
63
|
+
def render_panes
|
64
|
+
v.content_tag(:div,
|
65
|
+
@tabs.map{ |tab| tab.render_pane(selected?(tab)) }.join.html_safe,
|
66
|
+
:class => 'panes'.html_safe
|
67
|
+
).html_safe
|
68
|
+
end
|
69
|
+
|
70
|
+
# render the entire tabbed panel and all contents.
|
71
|
+
def render
|
72
|
+
out = v.content_tag(:div,
|
73
|
+
render_tabs + render_panes,
|
74
|
+
:id => @base_id.to_s.html_safe,
|
75
|
+
:class => 'tabbed_panel'.html_safe
|
76
|
+
).html_safe
|
77
|
+
out
|
78
|
+
end
|
79
|
+
|
80
|
+
# For the moment, the first tab is the one selected
|
81
|
+
def selected_tab
|
82
|
+
@tabs.first
|
83
|
+
end
|
84
|
+
|
85
|
+
def selected?(tab)
|
86
|
+
tab == selected_tab
|
87
|
+
end
|
88
|
+
|
89
|
+
# returns the array of TabPanes
|
90
|
+
def tabs
|
91
|
+
@tabs
|
92
|
+
end
|
93
|
+
|
94
|
+
# shortcut to the View
|
95
|
+
def v; @view end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logical_tabs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 63
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 0.8.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Evan Dorn
|
14
|
+
- Judson Lester
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-03-01 00:00:00 -08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rspec
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 5
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 5
|
34
|
+
version: "1.5"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 1.0.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rcov
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: " LogicalTabs assists in the creation of a tabbed panel UI for Rails apps\n with several advantages. A Rails helper generates the tedious (but\n semantically clean) HTML structures for you. Tab selection persists across\n page loads, the page is functional when JavaScript and/or CSS are\n unavaliable. Sensible default print styling allows printouts\n to show all the panel content. JavaScript is provided for use with\n either jQuery or Prototype.\n"
|
68
|
+
email: evan@lrdesign.com
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.rdoc
|
80
|
+
- Rakefile
|
81
|
+
- VERSION
|
82
|
+
- lib/generators/logical_tabs/install/install_generator.rb
|
83
|
+
- lib/generators/logical_tabs/install/templates/javascripts/logical_tabs_jquery.js
|
84
|
+
- lib/generators/logical_tabs/install/templates/javascripts/logical_tabs_prototype.js
|
85
|
+
- lib/generators/logical_tabs/install/templates/stylesheets/logical_tabs.css
|
86
|
+
- lib/generators/logical_tabs/install/templates/stylesheets/sass/logical_tabs.sass
|
87
|
+
- lib/logical_tabs/helper.rb
|
88
|
+
- lib/logical_tabs/tab_pane.rb
|
89
|
+
- lib/logical_tabs/tabbed_panel.rb
|
90
|
+
- lib/logical_tabs.rb
|
91
|
+
- doc/README
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://lrdesign.com/tools
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
post_install_message: Another tidy package brought to you by Logical Reality Design
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib/
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Tabbed panel UI tool for Rails
|
126
|
+
test_files: []
|
127
|
+
|