bootstrap_rails_helpers 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap_rails_helpers.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 JD Hendrickson
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.
@@ -0,0 +1,29 @@
1
+ # BootstrapRailsHelpers
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bootstrap_rails_helpers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bootstrap_rails_helpers
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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootstrap_rails_helpers/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bootstrap_rails_helpers"
8
+ gem.version = BootstrapRailsHelpers::VERSION
9
+ gem.authors = ["JD Hendrickson"]
10
+ gem.email = ["jd@digitalopera.com"]
11
+ gem.description = %q{Adds helpers to your Rails application to make working with Twitter's Bootsrap event better.}
12
+ gem.summary = %q{Adds helpers to your Rails application to make working with Twitter's Bootsrap event better.}
13
+ gem.homepage = ""
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
+ end
@@ -0,0 +1,7 @@
1
+ require "Rails"
2
+ require "bootstrap_rails_helpers/version"
3
+ require "bootstrap_rails_helpers/helpers.rb"
4
+
5
+ module BootstrapRailsHelpers
6
+ ActionView::Base.send :include, BootstrapRailsHelper
7
+ end
@@ -0,0 +1,116 @@
1
+ module BootstrapRailsHelper
2
+ #
3
+ # active_li_link_to
4
+ # ==============================
5
+ # options
6
+ # :module
7
+ # The controller or module that defines what this <li> is active for.
8
+ # :li_options
9
+ # Any valid options that you can pass to content_tag helper
10
+ # :link_to_options
11
+ # Any valid options supported by the standard rails link_to helper
12
+ # :icon
13
+ # CSS class name of the icon to be displayed with the link
14
+ #
15
+ def active_li_link_to(link_text, link_to_path, options={})
16
+ li_options = options.fetch(:li_options, {})
17
+ link_to_options = options.fetch(:link_to_options, {})
18
+ icon_class = options.fetch(:icon_class, nil)
19
+ module_pattern = options.fetch(:module, nil)
20
+ action_pattern = options.fetch(:action, nil)
21
+
22
+ unless module_pattern.nil?
23
+ module_match = Regexp.escape(controller.class.to_s).match(module_pattern).present?
24
+ action_match = (action_pattern.nil?) ? true : Regexp.escape(action_name).match(action_pattern).present?
25
+ active = module_match && action_match
26
+
27
+
28
+ # Mark the LI as active
29
+ if active
30
+ if li_options.key?(:class)
31
+ css_classes = li_options[:class].split(/\s/)
32
+ css_classes << "active"
33
+ li_options[:class] = css_classes.join(' ')
34
+ else
35
+ li_options[:class] = "active"
36
+ end
37
+ end
38
+ end
39
+
40
+ link_text = (icon_class.blank?) ? link_text : "<i class=\"icon #{icon_class}\"></i> #{link_text}"
41
+
42
+ content_tag :li, li_options do
43
+ link_to link_to_path, link_to_options do
44
+ link_text.html_safe
45
+ end
46
+ end
47
+ end
48
+
49
+ #
50
+ # button_link_to
51
+ # ==========================
52
+ # If you want to include an icon with your button link, use the :icon_class
53
+ # option to specify which icon-{class} you want to use.
54
+ #
55
+ # type can be any valid twitter bootstrap button type
56
+ # btn-primary => "primary"
57
+ # btn-warning => "warning"
58
+ # btn-info => "info"
59
+ # btn-success => "success"
60
+ # btn-danger => "danger"
61
+ # btn-inverse => "inverse"
62
+ # btn-link => "link" - Bootstrap v2.1.x ONLY
63
+ #
64
+ def button_link_to(link_text, link_to_path, type=nil, options={})
65
+ link_to_options = options.fetch(:link_to_options, {})
66
+ icon_class = options.fetch(:icon_class, nil)
67
+ css_classes = (link_to_options[:class] || []).split(/\s/)
68
+
69
+ link_text = (icon_class.blank?) ? link_text : "<i class=\"icon #{icon_class}\"></i> #{link_text}"
70
+
71
+ css_classes << "btn"
72
+ css_classes << "btn-#{type}" unless type.blank?
73
+ link_to_options[:class] = css_classes.join(" ")
74
+
75
+ link_to link_to_path, link_to_options do
76
+ link_text.html_safe
77
+ end
78
+ end
79
+
80
+ # Breadcrumb Helper
81
+ # Generates HTML for displaying breadcrumbs.
82
+ #
83
+ # Built for the Twitter Bootstrap CSS rules
84
+ #
85
+ # USAGE
86
+ # =================================
87
+ # Will yield: Home / Section 1 / ...
88
+ #
89
+ # <% breadcrumbs(
90
+ # { :name => "Home", :path => path_to_link_to },
91
+ # { :name => "Section1", :path => path_to_link_to },
92
+ # ...
93
+ # ) %>
94
+ #
95
+ # In your layout file, where you want the breadcrumbs to appear, add:
96
+ # <%= yield :breadcrumbs %>
97
+ #
98
+ def breadcrumbs(*trail)
99
+ html = "<div id=\"breadcrumb_wrapper\">"
100
+ html += "<div class=\"container\">"
101
+ html += "<ul class=\"breadcrumb\">"
102
+ trail.each_with_index do |step,idx|
103
+ html += "<li>"
104
+ html += (step[:path].blank?) ? step[:name] : "#{link_to step[:name], step[:path]}"
105
+ html += "<span class=\"divider\">/</span>" unless idx == (trail.size - 1)
106
+ html += "</li>"
107
+ end
108
+ html += "</ul>"
109
+ html += "</div>"
110
+ html += "</div>"
111
+
112
+ content_for :breadcrumbs do
113
+ html.html_safe
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module BootstrapRailsHelpers
2
+ VERSION = "0.2.1"
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap_rails_helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - JD Hendrickson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Adds helpers to your Rails application to make working with Twitter's
15
+ Bootsrap event better.
16
+ email:
17
+ - jd@digitalopera.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bootstrap_rails_helpers.gemspec
28
+ - lib/bootstrap_rails_helpers.rb
29
+ - lib/bootstrap_rails_helpers/helpers.rb
30
+ - lib/bootstrap_rails_helpers/version.rb
31
+ homepage: ''
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.17
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Adds helpers to your Rails application to make working with Twitter's Bootsrap
55
+ event better.
56
+ test_files: []