rails-bootstrap-tabs 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9387ee7d3a1b5eb0317ee1754f6990fef284f409
|
4
|
+
data.tar.gz: bb0a3016597dd703d25ecf09a8a6192830ab5953
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bb7c59df9ab48adb88e52d9169c42a2bd11b9d4c77e344ce07739ef80b3eb22400a46437721a8728cc291cd90f2759e42bc44be84839a5f089b309f993a455b
|
7
|
+
data.tar.gz: a464a0da3c2c7348b0e3178200339e474254040d3850874e3f750190b8b581457174752d72a7dd413dbaac2b222b2c0f36292791ee8fcbefe83ac2b0412cee61
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails-bootstrap-tabs/helpers/tabs_helper'
|
2
|
+
|
3
|
+
module RailsBootstrapTabs
|
4
|
+
module Rails
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
initializer "rails-bootstrap-tabs" do
|
7
|
+
ActionView::Base.send :include, RailsBootstrapTabs::Helpers::TabsHelper
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RailsBootstrapTabs::Renderers
|
2
|
+
class TabsRenderer
|
3
|
+
def initialize(template, *args, &block)
|
4
|
+
@template = template
|
5
|
+
@args = args || []
|
6
|
+
@options = args[0] || {}
|
7
|
+
@block = block
|
8
|
+
@tabs = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def rstr
|
12
|
+
(0...8).map { ('a'.ord + rand(26)).chr }.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
@block.call(Context.new(self))
|
17
|
+
prepare_tabs
|
18
|
+
render_tabs(@tabs) + render_panes(@tabs, @options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def prepare_tabs
|
22
|
+
@tabs.each.with_index do |tab, index|
|
23
|
+
tab.options[:anchor] ||= "tab-#{index}-#{rstr}"
|
24
|
+
end
|
25
|
+
active_tab = @tabs.find { |t| t.options[:active] }
|
26
|
+
active_tab ||= @tabs.first
|
27
|
+
@tabs.each { |t| t.options.delete(:active) }
|
28
|
+
active_tab.options[:active] = true if active_tab
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_tabs(tabs)
|
32
|
+
content_tag :ul, class: 'nav nav-tabs' do
|
33
|
+
tabs.map do |tab|
|
34
|
+
options = tab.options
|
35
|
+
content_tag :li, class: ('active' if options[:active]) do
|
36
|
+
link_to tab.name, "##{options[:anchor]}", data: { toggle: 'tab' }
|
37
|
+
end
|
38
|
+
end.join("\n").html_safe
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def render_panes(tabs, options)
|
43
|
+
content_class = 'tab-content'
|
44
|
+
content_class << " #{options[:content_class]}" if options[:content_class]
|
45
|
+
|
46
|
+
content_tag :div, class: content_class do
|
47
|
+
tabs.map do |tab|
|
48
|
+
options = tab.options
|
49
|
+
pane_class = 'tab-pane'
|
50
|
+
pane_class << ' active' if options[:active]
|
51
|
+
content_tag :div, id: options[:anchor].to_s, class: pane_class do
|
52
|
+
tab.block.call if tab.block
|
53
|
+
end
|
54
|
+
end.join("\n").html_safe
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def tab(name, options, &block)
|
59
|
+
@tabs << Tab.new(name, options, block)
|
60
|
+
end
|
61
|
+
|
62
|
+
class Context
|
63
|
+
include ActionView::Helpers::TagHelper
|
64
|
+
|
65
|
+
def initialize(renderer)
|
66
|
+
@renderer = renderer
|
67
|
+
end
|
68
|
+
|
69
|
+
def tab(name, options = {}, &block)
|
70
|
+
@renderer.tab(name, options, &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def method_missing(*args, &block)
|
75
|
+
@template.send(*args, &block)
|
76
|
+
end
|
77
|
+
|
78
|
+
Tab = Struct.new(:name, :options, :block)
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-bootstrap-tabs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Reshetnikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.11
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.11
|
27
|
+
description: A Rails plugin to build bootstrap tabs
|
28
|
+
email:
|
29
|
+
- resivalex@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/rails-bootstrap-tabs.rb
|
35
|
+
- lib/rails-bootstrap-tabs/helpers/tabs_helper.rb
|
36
|
+
- lib/rails-bootstrap-tabs/rails/engine.rb
|
37
|
+
- lib/rails-bootstrap-tabs/renderers/tabs_renderer.rb
|
38
|
+
- lib/rails-bootstrap-tabs/version.rb
|
39
|
+
homepage: https://github.com/resivalex/rails-bootstrap-tabs
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 2.4.5
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: A Rails plugin to build bootstrap tabs
|
63
|
+
test_files: []
|