tab_builder 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/open_hash.rb +56 -0
- data/lib/tab_builder/builder.rb +7 -0
- data/lib/tab_builder/drawer.rb +60 -0
- data/lib/tab_builder/tab.rb +60 -0
- data/lib/tab_builder/tab_set.rb +38 -0
- data/lib/tab_builder/version.rb +3 -0
- data/lib/tab_builder.rb +6 -0
- data/tab_builder.gemspec +24 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Daniel Vandersluis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# TabBuilder
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tab_builder'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tab_builder
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/open_hash.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
class OpenHash < ActiveSupport::HashWithIndifferentAccess
|
2
|
+
class << self
|
3
|
+
def [](hash = {})
|
4
|
+
new(hash)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(hash = {})
|
9
|
+
super
|
10
|
+
self.default = hash.default
|
11
|
+
end
|
12
|
+
|
13
|
+
def dup
|
14
|
+
self.class.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def convert_value(value)
|
19
|
+
if value.is_a? Hash
|
20
|
+
OpenHash[value].tap do |oh|
|
21
|
+
oh.each do |k, v|
|
22
|
+
oh[k] = convert_value(v) if v.is_a? Hash
|
23
|
+
end
|
24
|
+
end
|
25
|
+
elsif value.is_a?(Array)
|
26
|
+
value.dup.replace(value.map { |e| convert_value(e) })
|
27
|
+
else
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def method_missing(name, *args, &block)
|
33
|
+
method = name.to_s
|
34
|
+
|
35
|
+
case method
|
36
|
+
when %r{.=$}
|
37
|
+
super unless args.length == 1
|
38
|
+
self[method[0...-1]] = args.first
|
39
|
+
|
40
|
+
when %r{.\?$}
|
41
|
+
super unless args.empty?
|
42
|
+
self.key?(method[0...-1].to_sym)
|
43
|
+
|
44
|
+
when %r{^_.}
|
45
|
+
ret = self.send(method[1..-1], *args, &block)
|
46
|
+
(ret.is_a?(Hash) and meth != :_default) ? OpenHash[ret] : ret
|
47
|
+
|
48
|
+
else
|
49
|
+
if key?(method) or !respond_to?(method)
|
50
|
+
self[method]
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module TabBuilder
|
2
|
+
module Drawer
|
3
|
+
def self.draw(tabset, context, &block)
|
4
|
+
@context = context
|
5
|
+
|
6
|
+
content_for :style do
|
7
|
+
stylesheet_link_tag "tabbed"
|
8
|
+
end
|
9
|
+
|
10
|
+
out = ActiveSupport::SafeBuffer.new
|
11
|
+
out << content_tag(:div, :class => 'tabstrip') do
|
12
|
+
content_tag(:ul, :class => 'tabs') do
|
13
|
+
tabset.inject(ActiveSupport::SafeBuffer.new) do |html, tab|
|
14
|
+
current = false
|
15
|
+
|
16
|
+
if !tab.current.nil?
|
17
|
+
current = (tab.current.call === true)
|
18
|
+
else
|
19
|
+
tab.paths.each do |path|
|
20
|
+
if p = Rails.application.routes.recognize_path(path.url, :method => path[:method])
|
21
|
+
current = (p[:controller] == params[:controller] and p[:action] == params[:action])
|
22
|
+
break if current
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
current = (tab.controller == params[:controller]) unless current
|
27
|
+
end
|
28
|
+
|
29
|
+
if current
|
30
|
+
html << content_tag(:li, :class => "tab current") do
|
31
|
+
content_tag(:span, tab.name)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
html << content_tag(:li, :class => "tab") do
|
35
|
+
link_to(tab.name, tab.root.url)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
html
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
out << content_tag(:div, :class => "tab_content") do
|
45
|
+
content_tag(:div, :class => 'tab_content_inner') { @context.capture(&block) }
|
46
|
+
end if block_given?
|
47
|
+
|
48
|
+
out
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.method_missing(name, *args, &block)
|
52
|
+
# Pass methods along to the context, if it responds to them (allows for helpers, etc. to be used):
|
53
|
+
if @context.respond_to? name
|
54
|
+
@context.send(name, *args, &block)
|
55
|
+
else
|
56
|
+
super(name, *args, &block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module TabBuilder
|
2
|
+
class Tab
|
3
|
+
attr_accessor :paths, :controller
|
4
|
+
|
5
|
+
delegate :options, :to => :@tabset
|
6
|
+
|
7
|
+
def initialize(tabset, name, context, &block)
|
8
|
+
@tabset = tabset
|
9
|
+
@name = name
|
10
|
+
@context = context
|
11
|
+
@current = nil
|
12
|
+
|
13
|
+
@paths = []
|
14
|
+
@controller = nil
|
15
|
+
|
16
|
+
# Copy over context instance variables
|
17
|
+
@context.instance_variables.each do |iv|
|
18
|
+
instance_variable_set(iv, @context.instance_variable_get(iv)) unless instance_variable_defined? iv
|
19
|
+
end
|
20
|
+
|
21
|
+
instance_eval &block if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
I18n.t("#{options.string_prefix}#{@name}")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define the path(s) for this tab (ie. what paths correspond to this tab)
|
29
|
+
def path(url, options = {})
|
30
|
+
url = url_for(url.merge(:only_path => false)) if url.is_a? Hash
|
31
|
+
@paths << OpenHash.new({ :url => url, :method => options.delete(:method) || :get })
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get the root path (ie. what path the tab links to
|
35
|
+
def root
|
36
|
+
@paths.first
|
37
|
+
end
|
38
|
+
|
39
|
+
# Getter/setter for controller
|
40
|
+
def controller(name = nil)
|
41
|
+
@controller = name if name
|
42
|
+
@controller
|
43
|
+
end
|
44
|
+
|
45
|
+
# Override how to specify a current tab
|
46
|
+
def current(&block)
|
47
|
+
@current = block if block_given?
|
48
|
+
@current
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(name, *args, &block)
|
52
|
+
# Pass methods along to the context, if it responds to them (allows for helpers, etc. to be used):
|
53
|
+
if @context.respond_to? name
|
54
|
+
@context.send(name, *args, &block)
|
55
|
+
else
|
56
|
+
super(name, *args, &block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module TabBuilder
|
2
|
+
class TabSet
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options, context, &block)
|
8
|
+
@options = options.to_openhash || OpenHash.new
|
9
|
+
@context = context
|
10
|
+
@tabs = []
|
11
|
+
|
12
|
+
# Copy over context instance variables
|
13
|
+
@context.instance_variables.each do |iv|
|
14
|
+
instance_variable_set(iv, @context.instance_variable_get(iv)) unless instance_variable_defined? iv
|
15
|
+
end
|
16
|
+
|
17
|
+
instance_eval &block if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def each
|
21
|
+
@tabs.each { |i| yield i }
|
22
|
+
end
|
23
|
+
|
24
|
+
def add(tab)
|
25
|
+
@tabs << tab
|
26
|
+
end
|
27
|
+
alias_method :<<, :add
|
28
|
+
|
29
|
+
def draw(&block)
|
30
|
+
Drawer.draw(self, @context, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def method_missing(name, *args, &block)
|
34
|
+
tab = Tab.new(self, name, @context, &block)
|
35
|
+
self << tab
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/tab_builder.rb
ADDED
data/tab_builder.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tab_builder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "tab_builder"
|
8
|
+
gem.version = TabBuilder::VERSION
|
9
|
+
gem.authors = ["Daniel Vandersluis"]
|
10
|
+
gem.email = ["dvandersluis@selfmgmt.com"]
|
11
|
+
gem.description = %q{DSL for building tabbed containers in Rails}
|
12
|
+
gem.summary = %q{DSL for building tabbed containers in Rails}
|
13
|
+
gem.homepage = "https://github.com/dvandersluis/tab_builder"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency "i18n"
|
21
|
+
gem.add_dependency "activesupport", "> 3.0.0"
|
22
|
+
gem.add_dependency "actionpack", "> 3.0.0"
|
23
|
+
gem.add_dependency "railties", "> 3.0.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tab_builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Vandersluis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
type: :runtime
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ! '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
name: i18n
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>'
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 3.0.0
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>'
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 3.0.0
|
45
|
+
name: activesupport
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
48
|
+
type: :runtime
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>'
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
61
|
+
name: actionpack
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
type: :runtime
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>'
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.0.0
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>'
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.0.0
|
77
|
+
name: railties
|
78
|
+
description: DSL for building tabbed containers in Rails
|
79
|
+
email:
|
80
|
+
- dvandersluis@selfmgmt.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- lib/open_hash.rb
|
91
|
+
- lib/tab_builder.rb
|
92
|
+
- lib/tab_builder/builder.rb
|
93
|
+
- lib/tab_builder/drawer.rb
|
94
|
+
- lib/tab_builder/tab.rb
|
95
|
+
- lib/tab_builder/tab_set.rb
|
96
|
+
- lib/tab_builder/version.rb
|
97
|
+
- tab_builder.gemspec
|
98
|
+
homepage: https://github.com/dvandersluis/tab_builder
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: DSL for building tabbed containers in Rails
|
122
|
+
test_files: []
|
123
|
+
has_rdoc:
|