tabs_for 0.1.0

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: a5e88929bd1f6434c1dda24591e39aa8abce256f
4
+ data.tar.gz: 310b909b1f575c8121b515b6b73e2b62a37b8986
5
+ SHA512:
6
+ metadata.gz: eb50966d68b7b228daa1f786a378ad197314d0fb5613a5f9028e0b8564ea91afe44bd35d767b63cb517a1df8fb62b813cf3b4a477a0c28550a9ee7d6b5e832ca
7
+ data.tar.gz: 6f2325ea924dd037bb804e29b000e862999d7f20f3740eddf95038816bee7c71a2d99c3c769d65283e746552efef59dcd8871b25d558fa96b43149fe4cc86ad1
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - 2.2.2
6
+ before_install: gem install bundler -v 1.10.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] 2015-08-12
4
+ ### Added
5
+ - Initial release. Handles tabs with panes. Supported options are
6
+ `active`, `css` and `icon`. Some basic translation handling.
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tabs_for.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Ole J. Rosendahl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ [travis]: https://travis-ci.org/blacktangent/tabs_for
2
+ [codeclimate]: https://codeclimate.com/github/blacktangent/tabs_for
3
+ [fontawesome]: https://fortawesome.github.io/Font-Awesome
4
+ [fontawesomerails]: https://github.com/bokmann/font-awesome-rails
5
+
6
+ # TabsFor
7
+
8
+ [![Build Status](https://travis-ci.org/blacktangent/tabs_for.svg?branch=master)][travis]
9
+ [![Code Climate](https://codeclimate.com/github/blacktangent/tabs_for/badges/gpa.svg)][codeclimate]
10
+ [![Test Coverage](https://codeclimate.com/github/blacktangent/tabs_for/badges/coverage.svg)][codeclimate]
11
+
12
+ ActiveView Helper for creating tabs with Bootstrap.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'tabs_for'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install tabs_for
29
+
30
+ The gem depends on [Bootstrap 3](http://getbootstrap.com/) to create the tabs. Bring bootstrap into
31
+ your project by using [Bootstrap for Sass](https://github.com/twbs/bootstrap-sass) or you preferred method.
32
+
33
+ Preferred icon and CSS framework is [Font Awesome][fontawesome] and the `help` option uses
34
+ [Font Awesome][fontawesome] to display the help icon. This dependency
35
+ could easily be removed in the future.
36
+ Bring [Font Awesome][fontawesome] into your project by using
37
+ [font-awesome-rails][fontawesomerails] or your preferred method.
38
+
39
+ ## Screenshot
40
+ ![Screenshot](https://cloud.githubusercontent.com/assets/1222916/9381832/42b92924-4765-11e5-930e-1c5f236173c3.png)
41
+
42
+ ## Usage
43
+
44
+ Generate the tabs with corresponding panes using the API below. `tab`
45
+ takes two arguments and a block. If a symbol is used and the symbol is
46
+ an attribute on the model it will get translated, else the string will
47
+ be used directly. `tab` requires a block, this will be used as content
48
+ in the tabs pane.
49
+
50
+ ```erb
51
+ <%= tabs_for @project do |b| %>
52
+ <%= b.tab :tasks, icon: "fa fa-tasks", size: @project.tasks.size, active: true do %>
53
+ <%= render partial: "tasks/table", locals: { tasks: @project.tasks } %>
54
+ <% end %>
55
+ <%= b.tab :people, icon: "fa fa-users", size: @project.people.size, label: "Members", help: "Only showing active users." do %>
56
+ <%= render partial: "people/table", locals: { people: @project.people } %>
57
+ <% end %>
58
+ <%= b.tab :statistics, icon: "fa fa-bar-chart" do %>
59
+ <%= render "statistics", object: @project %>
60
+ <% end %>
61
+ <%= b.tab :settings, icon: "fa fa-cogs" do %>
62
+ <%= render "settings", object: @project %>
63
+ <% end %>
64
+ <% end %>
65
+ ```
66
+
67
+ ## Options
68
+ Supported options for `tab`:
69
+
70
+ * __:active__ - Active tab, the contents will be shown upon rendering.
71
+ * __:label__ - Use custom label text in tab header.
72
+ * __:icon__ - Icon used next to tab header text
73
+ * __:size__ - Number of entires in tab pane. Use if tab pane contains
74
+ table or list.
75
+ * __:id__ - Override element's ID.
76
+ * __:help__ - Add help text shown on top of tab pane.
77
+
78
+ ## Development
79
+
80
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
81
+
82
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+
84
+ ## Contributing
85
+
86
+ Bug reports and pull requests are welcome on GitHub at https://github.com/blacktangent/tabs_for. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
87
+
88
+
89
+ ## License
90
+
91
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
92
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,110 @@
1
+ module TabsFor
2
+ module TabsForHelper
3
+
4
+ def tabs_for(object, &block)
5
+ content_tag(:ul, :class => "nav nav-tabs", :role => "tablist") do
6
+ capture TabBuilder.new(object, self), &block
7
+ end + content_tag(:div, :class => "tab-content") do
8
+ capture PaneBuilder.new(object, self), &block
9
+ end
10
+ end
11
+
12
+ class ViewBuilder
13
+ include ActionView::Helpers
14
+
15
+ attr_accessor :object, :template, :output_buffer
16
+
17
+ def initialize(object, template)
18
+ @object, @template = object, template
19
+ end
20
+
21
+ private
22
+
23
+ def identifier(attribute)
24
+ attribute.to_s.downcase
25
+ end
26
+
27
+ end
28
+
29
+ class TabBuilder < ViewBuilder
30
+
31
+ def tab(attribute, options = {})
32
+ content = if options[:label]
33
+ options.delete(:label)
34
+ elsif object.respond_to? attribute
35
+ human_name attribute
36
+ else
37
+ attribute.to_s.titleize
38
+ end
39
+
40
+ options[:id] ||= identifier(attribute)
41
+
42
+ if options[:size]
43
+ content += " " + content_tag(:span, options[:size], :class => "badge")
44
+ end
45
+
46
+ content_tag(:li, apply_options(attribute, options)) do
47
+ link_to "#" + identifier(attribute), apply_link_options(attribute, options) do
48
+ options[:icon] ? wrap_with_icon(content.html_safe, options) : content.html_safe
49
+ end
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def apply_link_options(attribute, options)
56
+ {
57
+ "aria-controls" => identifier(attribute),
58
+ "data-toggle" => "tab",
59
+ :role => "tab",
60
+ }
61
+ end
62
+
63
+ def apply_options(attribute, options)
64
+ {
65
+ :role => "presentation",
66
+ :class => options[:active] ? "active" : nil,
67
+ }
68
+ end
69
+
70
+ def human_name(attribute_name)
71
+ object.class.human_attribute_name attribute_name
72
+ end
73
+
74
+ def wrap_with_icon(content, options = {})
75
+ content_tag(:i, " ".html_safe + content, :class => options[:icon])
76
+ end
77
+
78
+ end
79
+
80
+ class PaneBuilder < ViewBuilder
81
+
82
+ def tab(attribute, options = {}, &block)
83
+ content = "".html_safe
84
+
85
+ if options[:help]
86
+ content += tag(:br)
87
+ content += content_tag(:p) do
88
+ content_tag(:i, " #{options[:help]}".html_safe, class: "fa fa-info-circle")
89
+ end
90
+ end
91
+
92
+ content += template.capture(&block)
93
+
94
+ content_tag(:div, content, apply_options(attribute, options))
95
+ end
96
+
97
+ private
98
+
99
+ def apply_options(attribute, options)
100
+ {
101
+ :role => "tabpanel",
102
+ :class => "tab-pane" + (options[:active] ? " active" : ""),
103
+ :id => options[:id] ? options[:id] : identifier(attribute),
104
+ }
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tabs_for"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ module TabsFor
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module TabsFor
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tabs_for.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "tabs_for/version"
2
+ require "rails/engine"
3
+ require "tabs_for/engine"
4
+ require "action_view"
5
+ require "helpers/tabs_for/tabs_for_helper"
6
+
7
+ module TabsFor
8
+ # Your code goes here...
9
+ end
data/tabs_for.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tabs_for/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tabs_for"
8
+ spec.version = TabsFor::VERSION
9
+ spec.authors = ["Ole J. Rosendahl"]
10
+ spec.email = ["ole.johnny.rosendahl@gmail.com"]
11
+
12
+ spec.summary = "ActiveView Helper for creating tabs with Bootstrap."
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/blacktangent/tabs_for"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib", "app"]
20
+
21
+ spec.add_dependency "rails", "~> 4.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 2.3"
26
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tabs_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ole J. Rosendahl
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-20 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: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.3'
69
+ description: ActiveView Helper for creating tabs with Bootstrap.
70
+ email:
71
+ - ole.johnny.rosendahl@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - app/helpers/tabs_for/tabs_for_helper.rb
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/tabs_for.rb
89
+ - lib/tabs_for/engine.rb
90
+ - lib/tabs_for/version.rb
91
+ - tabs_for.gemspec
92
+ homepage: https://github.com/blacktangent/tabs_for
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ - app
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: ActiveView Helper for creating tabs with Bootstrap.
117
+ test_files: []