Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit 3d5a101

Browse files
committed
first 🍺
0 parents  commit 3d5a101

11 files changed

Lines changed: 435 additions & 0 deletions

File tree

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in nprogress_rails.gemspec
4+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2013 Carlos Alexandro Becker
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.

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# nprogress_rails
2+
3+
This is basically a ruby gem for asset pipeline which includes the version
4+
0.1.0 of the awesome rstacruz' [nprogress](https://github.com/rstacruz/nprogress)
5+
library.
6+
7+
## Installation
8+
9+
Add this line to your application's Gemfile:
10+
11+
gem 'nprogress_rails'
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install nprogress_rails
20+
21+
## Usage
22+
23+
You basically have to add the requires.
24+
25+
In your `application.js.coffee` (or just JS):
26+
27+
```coffeescript
28+
#= require nprogress
29+
#= require nprogress_turbolinks
30+
```
31+
32+
The `nprogress_turbolinks` is required only if you use turbolinks. Otherwise,
33+
you will have to deal with show/hide the progress by your own.
34+
35+
Also, into your `application.css.scss` file:
36+
37+
```scss
38+
*= require nprogress
39+
*= require nprogress_bootstrap
40+
```
41+
42+
The `nprogress_bootstrap` is required if you use bootstrap and have a fixed
43+
toolbar or anything else. tl;dr: if the console shows no erros, but the
44+
progress doesn't appear, try this.
45+
46+
47+
## Contributing
48+
49+
1. Fork it
50+
2. Create your feature branch (`git checkout -b my-new-feature`)
51+
3. Commit your changes (`git commit -am 'Add some feature'`)
52+
4. Push to the branch (`git push origin my-new-feature`)
53+
5. Create new Pull Request

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

lib/nprogress_rails.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module NprogressRails
2+
class Engine < ::Rails::Engine
3+
end
4+
end

nprogress_rails.gemspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = "nprogress_rails"
7+
spec.version = "0.1.0.1"
8+
spec.authors = ["Carlos Alexandro Becker"]
9+
spec.email = ["caarlos0@gmail.com"]
10+
spec.description = %q{This is a gem for the rstacruz' nprogress implementation. It's based on version nprogress 0.1.0.}
11+
spec.summary = %q{Slim progress bars for Ajax'y applications. Inspired by Google, YouTube, and Medium.}
12+
spec.homepage = "http://carlosbecker.com/about"
13+
spec.license = "MIT"
14+
15+
spec.files = `git ls-files`.split($/)
16+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18+
spec.require_paths = ["lib"]
19+
20+
spec.add_development_dependency "bundler", "~> 1.3"
21+
spec.add_development_dependency "rake"
22+
end
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*! NProgress (c) 2013, Rico Sta. Cruz
2+
* http://ricostacruz.com/nprogress */
3+
4+
;(function(factory) {
5+
6+
if (typeof module === 'object') {
7+
module.exports = factory(this.jQuery || require('dom'));
8+
} else {
9+
this.NProgress = factory(this.jQuery);
10+
}
11+
12+
})(function($) {
13+
var NProgress = {};
14+
15+
NProgress.version = '0.1.0';
16+
17+
var Settings = NProgress.settings = {
18+
minimum: 0.08,
19+
easing: 'ease',
20+
speed: 200,
21+
trickle: true,
22+
trickleRate: 0.02,
23+
trickleSpeed: 800,
24+
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner"><div class="spinner-icon"></div></div>'
25+
};
26+
27+
/**
28+
* Updates configuration.
29+
*
30+
* NProgress.configure({
31+
* minimum: 0.1
32+
* });
33+
*/
34+
NProgress.configure = function(options) {
35+
$.extend(Settings, options);
36+
return this;
37+
};
38+
39+
/**
40+
* Last number.
41+
*/
42+
43+
NProgress.status = null;
44+
45+
/**
46+
* Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
47+
*
48+
* NProgress.set(0.4);
49+
* NProgress.set(1.0);
50+
*/
51+
52+
NProgress.set = function(n) {
53+
var started = NProgress.isStarted();
54+
55+
n = clamp(n, Settings.minimum, 1);
56+
NProgress.status = (n === 1 ? null : n);
57+
58+
var $progress = NProgress.render(!started),
59+
$bar = $progress.find('[role="bar"]'),
60+
speed = Settings.speed,
61+
ease = Settings.easing;
62+
63+
$progress[0].offsetWidth; /* Repaint */
64+
65+
$progress.queue(function(next) {
66+
$bar.css({
67+
transition: 'all '+speed+'ms '+ease,
68+
transform: 'translate3d('+toBarPerc(n)+'%,0,0)'
69+
});
70+
71+
if (n === 1) {
72+
// Fade out
73+
$progress.css({ transition: 'none', opacity: 1 });
74+
$progress[0].offsetWidth; /* Repaint */
75+
76+
setTimeout(function() {
77+
$progress.css({ transition: 'all '+speed+'ms linear', opacity: 0 });
78+
setTimeout(function() {
79+
NProgress.remove();
80+
next();
81+
}, speed);
82+
}, speed);
83+
} else {
84+
setTimeout(next, speed);
85+
}
86+
});
87+
88+
return this;
89+
};
90+
91+
NProgress.isStarted = function() {
92+
return typeof NProgress.status === 'number';
93+
};
94+
95+
/**
96+
* Shows the progress bar.
97+
* This is the same as setting the status to 0%, except that it doesn't go backwards.
98+
*
99+
* NProgress.start();
100+
*
101+
*/
102+
NProgress.start = function() {
103+
if (!NProgress.status) NProgress.set(0);
104+
105+
var work = function() {
106+
setTimeout(function() {
107+
if (!NProgress.status) return;
108+
NProgress.trickle();
109+
work();
110+
}, Settings.trickleSpeed);
111+
};
112+
113+
if (Settings.trickle) work();
114+
115+
return this;
116+
};
117+
118+
/**
119+
* Hides the progress bar.
120+
* This is the *sort of* the same as setting the status to 100%, with the
121+
* difference being `done()` makes some placebo effect of some realistic motion.
122+
*
123+
* NProgress.done();
124+
*
125+
* If `true` is passed, it will show the progress bar even if its hidden.
126+
*
127+
* NProgress.done(true);
128+
*/
129+
130+
NProgress.done = function(force) {
131+
if (!force && !NProgress.status) return this;
132+
133+
return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
134+
};
135+
136+
/**
137+
* Increments by a random amount.
138+
*/
139+
140+
NProgress.inc = function(amount) {
141+
var n = NProgress.status;
142+
143+
if (!n) {
144+
return NProgress.start();
145+
} else {
146+
if (typeof amount !== 'number') {
147+
amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
148+
}
149+
150+
n = clamp(n + amount, 0, 0.994);
151+
return NProgress.set(n);
152+
}
153+
};
154+
155+
NProgress.trickle = function() {
156+
return NProgress.inc(Math.random() * Settings.trickleRate);
157+
};
158+
159+
/**
160+
* (Internal) renders the progress bar markup based on the `template`
161+
* setting.
162+
*/
163+
164+
NProgress.render = function(fromStart) {
165+
if (NProgress.isRendered()) return $("#nprogress");
166+
$('html').addClass('nprogress-busy');
167+
168+
var $el = $("<div id='nprogress'>")
169+
.html(Settings.template);
170+
171+
var perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0);
172+
173+
$el.find('[role="bar"]').css({
174+
transition: 'all 0 linear',
175+
transform: 'translate3d('+perc+'%,0,0)'
176+
});
177+
178+
$el.appendTo(document.body);
179+
180+
return $el;
181+
};
182+
183+
/**
184+
* (Internal) Removes the element. Opposite of render().
185+
*/
186+
187+
NProgress.remove = function() {
188+
$('html').removeClass('nprogress-busy');
189+
$('#nprogress').remove();
190+
};
191+
192+
/**
193+
* Checks if the progress bar is rendered.
194+
*/
195+
196+
NProgress.isRendered = function() {
197+
return ($("#nprogress").length > 0);
198+
};
199+
200+
/**
201+
* Helpers
202+
*/
203+
204+
function clamp(n, min, max) {
205+
if (n < min) return min;
206+
if (n > max) return max;
207+
return n;
208+
}
209+
210+
/**
211+
* (Internal) converts a percentage (`0..1`) to a bar translateX
212+
* percentage (`-100%..0%`).
213+
*/
214+
215+
function toBarPerc(n) {
216+
return (-1 + n) * 100;
217+
}
218+
219+
return NProgress;
220+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(function() {
2+
$(document).on('page:fetch', function() { NProgress.start(); });
3+
$(document).on('page:load', function() { NProgress.done(); });
4+
});

0 commit comments

Comments
 (0)