qui-tabs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ =QUI: tabs
2
+
3
+ Gem for rails to create nice tabs with a few lines o code.
4
+
5
+ See: {http://qui.saepia.net}[http://qui.saepia.net] for details.
6
+
7
+ Copyright (c) 2010 [Marcin Lewandowski], released under the MIT license.
@@ -0,0 +1,115 @@
1
+ module QUI
2
+ module Tabs
3
+ module MainHelper
4
+ def tabs_javascript
5
+ <<-END
6
+ var Tab = {
7
+ _all : {},
8
+
9
+ create : function(options) {
10
+ this._all[options["id"]] = options;
11
+ if(options["custom_html_id"])
12
+ this._all[options["id"]]["html_id"] = options["custom_html_id"]
13
+ else
14
+ this._all[options["id"]]["html_id"] = "tabs_" + options["id"];
15
+
16
+ },
17
+
18
+ find : function(id) {
19
+ var obj = {
20
+ id : id,
21
+ setCurrent : function(index) {
22
+ for(var i = 0; i < Tab._all[id]["count"]; i++) {
23
+ var e = document.getElementById(Tab._all[id]["html_id"] + "_tab_" + i + "_header");
24
+ if(e.className == "current") {
25
+ e.className = "";
26
+ break;
27
+ }
28
+ }
29
+ var e = document.getElementById(Tab._all[id]["html_id"] + "_tab_" + index + "_header");
30
+ e.className = "current";
31
+
32
+ for(var i = 0; i < Tab._all[id]["count"]; i++) {
33
+ var e = document.getElementById(Tab._all[id]["html_id"] + "_tab_" + i + "_body");
34
+ if(e.className == "current") {
35
+ e.className = "";
36
+ break;
37
+ }
38
+ }
39
+ var e = document.getElementById(Tab._all[id]["html_id"] + "_tab_" + index + "_body");
40
+ e.className = "current";
41
+
42
+ }
43
+ }
44
+
45
+ return obj;
46
+ }
47
+ }
48
+ END
49
+ end
50
+
51
+ def tabs(options)
52
+ @tabs_count ||= 0
53
+ raise RuntimeError, "@tabs_count must be integer" unless @tabs_count.is_a? Fixnum
54
+
55
+ default_id = "tabs_#{@tabs_count}"
56
+ options[:id] ||= default_id
57
+
58
+ headers = ""
59
+ bodies = ""
60
+
61
+ options[:tabs].each_with_index do |tab, i|
62
+ if tab[:header][:text]
63
+ if tab[:header][:text].is_a? Symbol
64
+ header = t(tab[:header][:text])
65
+ else
66
+ header = tab[:header][:text].to_s
67
+ end
68
+ elsif tab[:header][:inline]
69
+ header = ERB.new(tab[:header][:inline]).result
70
+ elsif tab[:header][:partial]
71
+ header = capture { render :partial => tab[:header][:partial] }
72
+ else
73
+ header = ""
74
+ end
75
+
76
+ headers << content_tag(:a, header, :id => "#{options[:id]}_tab_#{i}_header", :class => (i == 0 ? "current" : "" ), :href => "#", :onclick => "Tab.find(#{@tabs_count}).setCurrent(#{escape_javascript(i.to_s)}); return false;")
77
+
78
+ if tab[:body][:text]
79
+ if tab[:body][:text].is_a? Symbol
80
+ body = t(tab[:body][:text])
81
+ else
82
+ body = tab[:body][:text].to_s
83
+ end
84
+ elsif tab[:body][:inline]
85
+ body = ERB.new(tab[:body][:inline]).result
86
+ elsif tab[:body][:partial]
87
+ body = capture { render :partial => tab[:body][:partial] }
88
+ else
89
+ body = ""
90
+ end
91
+
92
+ bodies << content_tag(:div, body, :id => "#{options[:id]}_tab_#{i}_body", :class => (i == 0 ? "current" : "" ))
93
+ end
94
+
95
+ result = "<div class=\"tabs\" id=\"#{options[:id]}\">"
96
+ result << "<div class=\"header\">"
97
+ result << headers
98
+ result << "</div>"
99
+
100
+ result << "<div class=\"body\">"
101
+ result << bodies
102
+ result << "</div>"
103
+ result << "</div>"
104
+
105
+ js_options = { :id => @tabs_count, :count => options[:tabs].size }
106
+ js_options.merge!({ :custom_html_id => options[:id] }) unless options[:id] == default_id
107
+ result << javascript_tag("Tab.create(#{js_options.to_json});")
108
+
109
+ @tabs_count += 1
110
+
111
+ result
112
+ end
113
+ end
114
+ end
115
+ end
data/lib/qui-tabs.rb ADDED
@@ -0,0 +1 @@
1
+ require 'qui-tabs-main-helper.rb'
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ ActionView::Base.send :include, QUI::Tabs::MainHelper
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qui-tabs
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
+ - Marcin Lewandowski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-18 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "qUI: rails helpers for generating tabs"
23
+ email: saepia@saepia.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - lib/qui-tabs-main-helper.rb
32
+ - lib/qui-tabs.rb
33
+ - rails/init.rb
34
+ - README.rdoc
35
+ has_rdoc: true
36
+ homepage: http://qui.saepia.net
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: "qUI: rails helpers for generating tabs"
69
+ test_files: []
70
+