bh 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/README.md +60 -7
- data/gemfiles/Gemfile.rails-3.x +5 -0
- data/gemfiles/Gemfile.rails-4.x +5 -0
- data/lib/bh/helpers/cdn_helper.rb +50 -0
- data/lib/bh/railtie.rb +2 -0
- data/lib/bh/version.rb +1 -1
- data/spec/helpers/alert_helper_spec.rb +2 -0
- data/spec/helpers/cdn_helper_spec.rb +76 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd20f354ba7792ddb18ca83618d77b0510bbc3c8
|
4
|
+
data.tar.gz: 447b0f2f6e06aaabbba876616a29db1d2a4e577f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d18cd3d04c5d8f1af19bf3ead08f17e27045b4c592ba7e68ed72e9b1102ad9d922ae8f14036a69872aeceadedda75aebf3679704b03d1d6dcedb7762ee897dc
|
7
|
+
data.tar.gz: b0de752c4c5cd633e5683f1cf6bba061cc16eea865165b12d7e5f5adaee5a33233ea28248431d5b4108f07aa768a4912cd22b0e2aa1a8cbe1b0e1542b881c733
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 0.0.3 - 2014-08-15
|
10
|
+
|
11
|
+
* [FEATURE] Add `bootstrap_css`, `bootstrap_theme_css` and `bootstrap_js`
|
12
|
+
|
9
13
|
## 0.0.2 - 2014-08-15
|
10
14
|
|
11
15
|
* [FEATURE] Add `alert_box` helper
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
Bh - Bootstrap Helpers
|
2
2
|
======================
|
3
3
|
|
4
|
-
Bh provides a set of
|
4
|
+
Bh provides a set of helpers that streamlines the use of
|
5
5
|
[Bootstrap components](http://getbootstrap.com/components) in Rails views.
|
6
6
|
|
7
|
+
The **full documentation** is available at [rubydoc.info](http://rubydoc.info/github/Fullscreen/bh/master/frames).
|
8
|
+
|
9
|
+
[![Build Status](http://img.shields.io/travis/Fullscreen/bh/master.svg)](https://travis-ci.org/Fullscreen/bh)
|
10
|
+
[![Coverage Status](http://img.shields.io/coveralls/Fullscreen/bh/master.svg)](https://coveralls.io/r/Fullscreen/bh)
|
11
|
+
[![Dependency Status](http://img.shields.io/gemnasium/Fullscreen/bh.svg)](https://gemnasium.com/Fullscreen/bh)
|
12
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/Fullscreen/bh.svg)](https://codeclimate.com/github/Fullscreen/bh)
|
13
|
+
[![Online docs](http://img.shields.io/badge/docs-✓-green.svg)](http://rubydoc.info/github/Fullscreen/bh/master/frames)
|
14
|
+
[![Gem Version](http://img.shields.io/gem/v/bh.svg)](http://rubygems.org/gems/bh)
|
15
|
+
|
7
16
|
Bootstrap is a great framework, but requires to write many lines of HTML code
|
8
17
|
even for simple components.
|
9
18
|
For instance, you need to write the following HTML to show a _dismissible alert_:
|
@@ -22,7 +31,7 @@ Writing this for every _dismissible alert_ in a web site is cumbersome,
|
|
22
31
|
repetitive, and prone to errors.
|
23
32
|
|
24
33
|
Bh offers a solution to this problem by means of a set of helper methods.
|
25
|
-
The example above can be with just one line of code:
|
34
|
+
The example above can be rewritten with just one line of code:
|
26
35
|
|
27
36
|
```erb
|
28
37
|
<%= alert_box 'You accepted the Terms of service.', dismissible: true %>
|
@@ -37,7 +46,7 @@ How to install
|
|
37
46
|
|
38
47
|
Bh is meant to be included in Rails apps by adding this line to the Gemfile:
|
39
48
|
|
40
|
-
gem 'bh', '~> 0.0.
|
49
|
+
gem 'bh', '~> 0.0.3'
|
41
50
|
|
42
51
|
Since the gem follows [Semantic Versioning](http://semver.org),
|
43
52
|
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
|
@@ -47,11 +56,11 @@ and a new version of Bh is released.
|
|
47
56
|
Adding 'bh' to your Gemfile is all you need!
|
48
57
|
From now on, you will be able to use any of the following Bh helpers in your Rails views.
|
49
58
|
|
50
|
-
|
51
|
-
|
59
|
+
AlertHelper
|
60
|
+
===========
|
52
61
|
|
53
62
|
To include [Boostrap alert boxes](http://getbootstrap.com/components/#alerts)
|
54
|
-
in your Rails views, you can use the [alert_box](
|
63
|
+
in your Rails views, you can use the [alert_box](http://rubydoc.info/github/Fullscreen/bh/master/Bh/AlertHelper) helper.
|
55
64
|
Here are some examples.
|
56
65
|
|
57
66
|
Basic alerts
|
@@ -155,6 +164,49 @@ highlighted text and appropriately styled links:
|
|
155
164
|
|
156
165
|
![alert-complex](https://cloud.githubusercontent.com/assets/7408595/3936903/7c1b70f0-24a7-11e4-95ee-11f6920ddd4d.png)
|
157
166
|
|
167
|
+
CdnHelper
|
168
|
+
=========
|
169
|
+
|
170
|
+
To load the CSS and JS files of Bootstrap from
|
171
|
+
[BootstrapCDN](http://getbootstrap.com/getting-started/#download), you can use
|
172
|
+
the [bootstrap_css](http://rubydoc.info/github/Fullscreen/bh/master/Bh/CdnHelper),
|
173
|
+
[bootstrap_theme_css](http://rubydoc.info/github/Fullscreen/bh/master/Bh/CdnHelper) and
|
174
|
+
[bootstrap_js](http://rubydoc.info/github/Fullscreen/bh/master/Bh/CdnHelper) helpers.
|
175
|
+
Here are some examples.
|
176
|
+
|
177
|
+
Load the latest Bootstrap assets
|
178
|
+
--------------------------------
|
179
|
+
|
180
|
+
```erb
|
181
|
+
<%= stylesheet_link_tag bootstrap_css, bootstrap_theme_css, :application %>
|
182
|
+
<%= javascript_include_tag bootstrap_js, :application %>
|
183
|
+
```
|
184
|
+
|
185
|
+
will generate the HTML to load the latest versions of Bootstrap CSS, Bootstrap
|
186
|
+
Theme CSS and Bootstrap JS from MaxCDN, before your application assets:
|
187
|
+
|
188
|
+
```html
|
189
|
+
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
|
190
|
+
<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" media="screen" rel="stylesheet" type="text/css" />
|
191
|
+
<link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
|
192
|
+
|
193
|
+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
|
194
|
+
<script src="/assets/application.js" type="text/javascript"></script>
|
195
|
+
```
|
196
|
+
|
197
|
+
Load a specific version of a Bootstrap asset
|
198
|
+
--------------------------------------------
|
199
|
+
|
200
|
+
```erb
|
201
|
+
<%= stylesheet_link_tag bootstrap_css(version: '3.1.0', minified: false, scheme: :http) %>
|
202
|
+
```
|
203
|
+
|
204
|
+
will generate the HTML to load the non-minified 3.1.0 versions of Bootstrap CSS
|
205
|
+
over HTTP scheme:
|
206
|
+
|
207
|
+
```html
|
208
|
+
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
|
209
|
+
```
|
158
210
|
|
159
211
|
How to release new versions
|
160
212
|
===========================
|
@@ -178,7 +230,8 @@ Bh needs your support!
|
|
178
230
|
|
179
231
|
If you find that a method is missing, fork the project, add the missing code,
|
180
232
|
write the appropriate tests, then submit a pull request, and it will gladly
|
181
|
-
be merged! If you need an inspiration, look at the
|
233
|
+
be merged! If you need an inspiration, look at the
|
234
|
+
[TODO](https://github.com/Fullscreen/bh/blob/master/TODO.md).
|
182
235
|
|
183
236
|
To run the tests, simply type `rspec` on the command line.
|
184
237
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Bh
|
2
|
+
# Provides methods to retrieve the URLs of Bootstrap stylesheets and
|
3
|
+
# Javascript files from Bootstrap CDN
|
4
|
+
# @see http://www.bootstrapcdn.com
|
5
|
+
module CdnHelper
|
6
|
+
# @return [String] the URL of the Bootstrap CSS file
|
7
|
+
# @param [Hash] options the options for which CSS file to retrieve.
|
8
|
+
# @option options [String] :version the version of Bootstrap.
|
9
|
+
# @option options [String] :scheme the URI scheme to use.
|
10
|
+
# @option options [Boolean] :minified whether to use the minified version.
|
11
|
+
def bootstrap_css(options = {})
|
12
|
+
bootstrap_asset options.merge(name: 'bootstrap', extension: 'css')
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [String] the URL of the Bootstrap Theme CSS file
|
16
|
+
# @param [Hash] options the options for which CSS file to retrieve.
|
17
|
+
# @option options [String] :version the version of Bootstrap.
|
18
|
+
# @option options [String] :scheme the URI scheme to use.
|
19
|
+
# @option options [Boolean] :minified whether to use the minified version.
|
20
|
+
def bootstrap_theme_css(options = {})
|
21
|
+
bootstrap_asset options.merge(name: 'bootstrap-theme', extension: 'css')
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] the URL of the Bootstrap JS file
|
25
|
+
# @param [Hash] options the options for which JS file to retrieve.
|
26
|
+
# @option options [String] :version the version of Bootstrap.
|
27
|
+
# @option options [String] :scheme the URI scheme to use.
|
28
|
+
# @option options [Boolean] :minified whether to use the minified version.
|
29
|
+
def bootstrap_js(options = {})
|
30
|
+
bootstrap_asset options.merge(name: 'bootstrap', extension: 'js')
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# @return [String] the version of Bootstrap assets to use if unspecified.
|
36
|
+
def bootstrap_version
|
37
|
+
'3.2.0'
|
38
|
+
end
|
39
|
+
|
40
|
+
def bootstrap_asset(options = {})
|
41
|
+
version = options.fetch :version, bootstrap_version
|
42
|
+
extension = options[:extension]
|
43
|
+
name = options[:name]
|
44
|
+
name = "#{name}.min" if options.fetch(:minified, true)
|
45
|
+
scheme = "#{options[:scheme]}:" if options[:scheme]
|
46
|
+
host = '//netdna.bootstrapcdn.com'
|
47
|
+
"#{scheme}#{host}/bootstrap/#{version}/#{extension}/#{name}.#{extension}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/bh/railtie.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'bh/helpers/alert_helper'
|
2
|
+
require 'bh/helpers/cdn_helper'
|
2
3
|
require 'bh/helpers/url_helper'
|
3
4
|
|
4
5
|
module Bh
|
5
6
|
class Railtie < Rails::Railtie
|
6
7
|
initializer 'bh.add_helpers' do
|
7
8
|
ActionView::Base.send :include, AlertHelper
|
9
|
+
ActionView::Base.send :include, CdnHelper
|
8
10
|
ActionView::Base.send :include, UrlHelper
|
9
11
|
end
|
10
12
|
end
|
data/lib/bh/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bh/helpers/cdn_helper'
|
3
|
+
require 'open-uri'
|
4
|
+
include Bh::CdnHelper
|
5
|
+
|
6
|
+
describe 'bootstrap_css' do
|
7
|
+
let(:file) { open bootstrap_css(options), ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
8
|
+
|
9
|
+
describe 'with the HTTP scheme, links to an existing file' do
|
10
|
+
let(:options) { {scheme: :http} }
|
11
|
+
it{ expect(file).to be }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'with the HTTPS scheme, links to an existing file' do
|
15
|
+
let(:options) { {scheme: :https} }
|
16
|
+
it{ expect(file).to be }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'non-minified, links to an existing file' do
|
20
|
+
let(:options) { {scheme: :http, minified: false} }
|
21
|
+
it{ expect(file).to be }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'given a legacy version, links to an existing file' do
|
25
|
+
let(:options) { {scheme: :https, version: '3.1.0'} }
|
26
|
+
it{ expect(file).to be }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'bootstrap_theme_css' do
|
31
|
+
let(:file) { open bootstrap_theme_css(options), ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
32
|
+
|
33
|
+
describe 'with the HTTP scheme, links to an existing file' do
|
34
|
+
let(:options) { {scheme: :http} }
|
35
|
+
it{ expect(file).to be }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'with the HTTPS scheme, links to an existing file' do
|
39
|
+
let(:options) { {scheme: :https} }
|
40
|
+
it{ expect(file).to be }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'non-minified, links to an existing file' do
|
44
|
+
let(:options) { {scheme: :http, minified: false} }
|
45
|
+
it{ expect(file).to be }
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'given a legacy version, links to an existing file' do
|
49
|
+
let(:options) { {scheme: :https, version: '3.1.0'} }
|
50
|
+
it{ expect(file).to be }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'bootstrap_js' do
|
55
|
+
let(:file) { open bootstrap_js(options), ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
56
|
+
|
57
|
+
describe 'with the HTTP scheme, links to an existing file' do
|
58
|
+
let(:options) { {scheme: :http} }
|
59
|
+
it{ expect(file).to be }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'with the HTTPS scheme, links to an existing file' do
|
63
|
+
let(:options) { {scheme: :https} }
|
64
|
+
it{ expect(file).to be }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'non-minified, links to an existing file' do
|
68
|
+
let(:options) { {scheme: :http, minified: false} }
|
69
|
+
it{ expect(file).to be }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'given a legacy version, links to an existing file' do
|
73
|
+
let(:options) { {scheme: :https, version: '3.1.0'} }
|
74
|
+
it{ expect(file).to be }
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Baccigalupo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
119
|
- ".rspec"
|
120
|
+
- ".travis.yml"
|
120
121
|
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- MIT-LICENSE
|
@@ -124,12 +125,16 @@ files:
|
|
124
125
|
- Rakefile
|
125
126
|
- TODO.md
|
126
127
|
- bh.gemspec
|
128
|
+
- gemfiles/Gemfile.rails-3.x
|
129
|
+
- gemfiles/Gemfile.rails-4.x
|
127
130
|
- lib/bh.rb
|
128
131
|
- lib/bh/helpers/alert_helper.rb
|
132
|
+
- lib/bh/helpers/cdn_helper.rb
|
129
133
|
- lib/bh/helpers/url_helper.rb
|
130
134
|
- lib/bh/railtie.rb
|
131
135
|
- lib/bh/version.rb
|
132
136
|
- spec/helpers/alert_helper_spec.rb
|
137
|
+
- spec/helpers/cdn_helper_spec.rb
|
133
138
|
- spec/helpers/url_helper_spec.rb
|
134
139
|
- spec/spec_helper.rb
|
135
140
|
homepage: http://github.com/Fullscreen/bh
|
@@ -159,6 +164,7 @@ summary: Bh provides a set of powerful helpers that streamlines the use of Boots
|
|
159
164
|
components in Rails views.
|
160
165
|
test_files:
|
161
166
|
- spec/helpers/alert_helper_spec.rb
|
167
|
+
- spec/helpers/cdn_helper_spec.rb
|
162
168
|
- spec/helpers/url_helper_spec.rb
|
163
169
|
- spec/spec_helper.rb
|
164
170
|
has_rdoc:
|