twitter_bootstrap_helper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = TwitterBootstrapHelper
2
+
3
+ Refer to the rdoc documentation for this helper.
4
+
5
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TwitterBootstrapHelper'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,188 @@
1
+ module TwitterBootstrapHelper
2
+
3
+ # Creates an "i" tag with the given +icon+ class.
4
+ # * This also works with Font Awesome
5
+ def tb_icon(icon, options = {})
6
+ options = {
7
+ class: ""
8
+ }.merge(options)
9
+
10
+ style = "color: #{options[:color]}" if options[:color]
11
+ content_tag(:i, "", :class => "#{icon} #{options[:class]}", :style => style) unless icon.nil?
12
+ end
13
+
14
+ # This is a wrapper for the link_to helper
15
+ # ==== Options
16
+ # * <tt>:icon</tt> - Optionally display an icon before the name.
17
+ # * All other options are passed through the the link_to helper.
18
+ def tb_link(name, link="#", options = {})
19
+ options = {
20
+ icon: nil,
21
+ }.merge(options)
22
+
23
+ icon = nil
24
+ if options[:icon]
25
+ icon = options[:icon]
26
+ options.delete(:icon)
27
+ end
28
+
29
+ label = [].tap do |b|
30
+ b << tb_icon(icon) unless icon.nil?
31
+ b << name
32
+ end.join.html_safe
33
+
34
+ link_to(label, link, options)
35
+ end
36
+
37
+ # Creates a "button" tag. The class defaults to "btn" and the type defaults to :submit.
38
+ # ==== Options
39
+ # * <tt>:icon</tt> - Optionally display an icon on the button.
40
+ # * <tt>:class</tt> - Specify a class for the button. Defaults to "btn".
41
+ # * <tt>:type</tt> - Defaults to submit.
42
+ # * All other options are passed through to the the content_tag helper.
43
+ def tb_button(name, options = {})
44
+ options = {
45
+ class: "btn",
46
+ icon: nil,
47
+ type: :submit,
48
+ }.merge(options)
49
+
50
+ options = options.nil? ? default_options : default_options.merge(options)
51
+
52
+ icon = nil
53
+ if options[:icon]
54
+ icon = options[:icon]
55
+ options.delete(:icon)
56
+ end
57
+
58
+ button_label = [].tap do |b|
59
+ b << tb_icon(icon)
60
+ b << name
61
+ end.join.html_safe
62
+
63
+ content_tag(:button, button_label, options)
64
+ end
65
+
66
+ # Creates a badge containing the content "name"
67
+ # ==== Options
68
+ # * <tt>:class</tt> - Defaults to "badge", any other class specified will be appended to the "badge" class.
69
+ def tb_badge(name, options = {})
70
+ options = {
71
+ }.merge(options)
72
+
73
+ options[:class] = "badge #{options[:class]}"
74
+
75
+ content_tag(:span, name, options)
76
+ end
77
+
78
+ # Creates a label containing the content "name"
79
+ # ==== Options
80
+ # * <tt>:class</tt> - Defaults to "label", any other class specified will be appended to the "label" class.
81
+ def tb_label(name, options = {})
82
+ options = {
83
+ }.merge(options)
84
+
85
+ options[:class] = "label #{options[:class]}"
86
+
87
+ content_tag(:span, name, options)
88
+ end
89
+
90
+ # Creates an "li" tag formatted for a sidebar.
91
+ # ==== Options
92
+ # * <tt>:icon</tt> - Optionally display an icon.
93
+ # * <tt>:badge</tt> - Defaults to 0. Badge is only displayed if the value is greater than 0
94
+ # * <tt>:badge_class</tt> - Optional badge class to add. Eg "badge-success"
95
+ # * <tt>:active</tt> - adds the active class showing the item is selected
96
+ def tb_sidebar_link(name, link="#", options = {})
97
+ default_options = {
98
+ icon: nil,
99
+ badge: 0,
100
+ active: (request.fullpath == link)
101
+ }.merge(options)
102
+
103
+ icon = nil
104
+ li_class = []
105
+ i_class = []
106
+
107
+ if options[:icon]
108
+ icon = options[:icon]
109
+ options.delete(:icon)
110
+ end
111
+
112
+ if options[:active]
113
+ li_class << "active"
114
+ i_class << "icon-white"
115
+ end
116
+
117
+ i_class << icon
118
+ badge = options[:badge] > 0 ? " #{tb_badge(options[:badge], :class => "pull-right #{options[:badge_class]}")}".html_safe : ""
119
+ icon_tag = content_tag(:i, "", :class => i_class.join(" "))
120
+ content_tag(:li, link_to(icon_tag + name + badge, link, options), :class => li_class.empty? ? nil : li_class.join(" "))
121
+ end
122
+
123
+ ## Modal Helpers
124
+
125
+ # Creates a button with the given +name+ that will active a Twitter Bootstrap Modal with the id of +modal_id+.
126
+ # ==== Options
127
+ # * <tt>:data-toggle</tt> - Defaults to modal
128
+ # * All other options are passed to tb_link
129
+ def tb_modal_button(name, modal_id, options={})
130
+ options = {
131
+ "data-toggle" => "modal"
132
+ }.merge(options)
133
+
134
+ tb_link name, "##{modal_id}", options
135
+ end
136
+
137
+ # Creates a Twitter Bootstrap modal with the given +modal_id+
138
+ # ==== Options
139
+ # * <tt>:title</tt> - The title at the top of the modal
140
+ # * <tt>:fade</tt> - To specify whether the modal should animate in. Default: true
141
+ # * <tt>:cancel_label</tt> - The name of the cancel button. Default: Cancel
142
+ # * <tt>:cancel_class</tt> - The class of the cancel button. Default: "btn"
143
+ # * <tt>:ok_id</tt> - The id of the ok button. Useful for javascript actions
144
+ # * <tt>:ok_label</tt> - The label of the OK button. Default: OK
145
+ # * <tt>:ok_class</tt> - The class of the OK button. Default: "btn btn-primary"
146
+ # * <tt>:ok_link</tt> - The link for the ok button. Default: "#"
147
+ # * <tt>:remote</tt> - (untested) The remote link for the model to get it's content
148
+ def tb_modal(modal_id, content_or_options_with_block = nil, options = nil, &block)
149
+ default_options = {
150
+ title: "Alert",
151
+ fade: true,
152
+ cancel_label: "Cancel",
153
+ cancel_class: "btn",
154
+ ok_id: nil,
155
+ ok_label: "OK",
156
+ ok_class: "btn btn-primary",
157
+ ok_link: "#",
158
+ remote: nil,
159
+ }
160
+
161
+ if block_given?
162
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
163
+ content = capture(&block)
164
+ else
165
+ content = content_or_options_with_block
166
+ end
167
+
168
+ options = options.nil? ? default_options : default_options.merge(options)
169
+
170
+ content_tag :div, :id => modal_id, :class => "modal hide #{ options[:fade] ? "fade" : ""}", "data-remote" => options[:remote] do
171
+ [].tap do |modal|
172
+ modal << content_tag(:div, :class => "modal-header") do
173
+ [].tap do |header|
174
+ header << content_tag(:button, "&times;".html_safe, :class => "close", "data-dismiss" => "modal")
175
+ header << content_tag(:h3, options[:title])
176
+ end.join.html_safe
177
+ end
178
+ modal << content_tag(:div, content, :class => "modal-body")
179
+ modal << content_tag(:div, :class => "modal-footer") do
180
+ [].tap do |footer|
181
+ footer << link_to(options[:cancel_label], "#", "data-dismiss" => "modal", :class => options[:cancel_class])
182
+ footer << link_to(options[:ok_label], options[:ok_link], :class => options[:ok_class], :id => options[:ok_id])
183
+ end.join.html_safe
184
+ end
185
+ end.join.html_safe
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,9 @@
1
+ require 'twitter_bootstrap_helper/helpers/twitter_bootstrap_helper'
2
+
3
+ module TwitterBootstrapHelper
4
+ class Railtie < Rails::Railtie
5
+ initializer "TwitterBootstrapHelper" do
6
+ ActionView::Base.send :include, TwitterBootstrapHelper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TwitterBootstrapHelper
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,3 @@
1
+ module TwitterBootstrapHelper
2
+ require 'twitter_bootstrap_helper/railtie'
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twitter_bootstrap_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Monagle
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Helper methods for Rails to aid in creating Twitter Bootstrap Components
47
+ email:
48
+ - david.monagle@intrica.com.au
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/twitter_bootstrap_helper/helpers/twitter_bootstrap_helper.rb
54
+ - lib/twitter_bootstrap_helper/railtie.rb
55
+ - lib/twitter_bootstrap_helper/version.rb
56
+ - lib/twitter_bootstrap_helper.rb
57
+ - MIT-LICENSE
58
+ - Rakefile
59
+ - README.rdoc
60
+ homepage: https://github.com/intrica/twitter_bootstrap_helper
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ segments:
73
+ - 0
74
+ hash: -2840883431053187956
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ segments:
82
+ - 0
83
+ hash: -2840883431053187956
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Helper methods for Rails to aid in creating Twitter Bootstrap Components
90
+ test_files: []