sinatra_cyclist 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +70 -3
- data/examples/classic_application.rb +12 -0
- data/examples/config.ru +2 -0
- data/examples/modular_application.rb +16 -0
- data/lib/sinatra/cyclist/version.rb +1 -1
- data/lib/sinatra/cyclist.rb +6 -3
- metadata +6 -9
- data/spec/lib/cyclist_spec.rb +0 -9
- data/spec/spec_helper.rb +0 -6
- data/spec/support/classic_application.rb +0 -13
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# SinatraCyclist
|
2
2
|
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
3
|
## Installation
|
6
4
|
|
7
5
|
Add this line to your application's Gemfile:
|
@@ -18,7 +16,76 @@ Or install it yourself as:
|
|
18
16
|
|
19
17
|
## Usage
|
20
18
|
|
21
|
-
|
19
|
+
* For classic applications, require the gem and specify the routes you want to cycle through.
|
20
|
+
```ruby
|
21
|
+
require "sinatra"
|
22
|
+
require "sinatra/cyclist"
|
23
|
+
|
24
|
+
set :routes_to_cycle_through, [:page_1, :page_2]
|
25
|
+
|
26
|
+
get "/page_1" do
|
27
|
+
"Page 1"
|
28
|
+
end
|
29
|
+
|
30
|
+
get "/page_2" do
|
31
|
+
"Page 2"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
* For modular applications, require the gem, explicitly register the extension, and specify the routes.
|
36
|
+
```ruby
|
37
|
+
require "sinatra/base"
|
38
|
+
require "sinatra/cyclist"
|
39
|
+
|
40
|
+
class MyApp < Sinatra::Base
|
41
|
+
register Sinatra::Cyclist
|
42
|
+
|
43
|
+
set :routes_to_cycle_through, [:page_1, :page_2]
|
44
|
+
|
45
|
+
get "/page_1" do
|
46
|
+
"Page 1"
|
47
|
+
end
|
48
|
+
|
49
|
+
get "/page_2" do
|
50
|
+
"Page 2"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Then visit the http://localhost:4567/_cycle to start cycling!
|
56
|
+
|
57
|
+
### Dashing
|
58
|
+
If you are using [dashing](https://github.com/Shopify/dashing), update your `config.ru`
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require "sinatra/cyclist"
|
62
|
+
require 'dashing'
|
63
|
+
|
64
|
+
configure do
|
65
|
+
set :auth_token, 'YOUR_AUTH_TOKEN'
|
66
|
+
|
67
|
+
helpers do
|
68
|
+
def protected!
|
69
|
+
# Put any authentication code you want in here.
|
70
|
+
# This method is run before accessing any resource.
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
map Sinatra::Application.assets_prefix do
|
76
|
+
run Sinatra::Application.sprockets
|
77
|
+
end
|
78
|
+
|
79
|
+
set :routes_to_cycle_through, [:dashboard_1, :dashboard_2]
|
80
|
+
|
81
|
+
run Sinatra::Application
|
82
|
+
```
|
83
|
+
|
84
|
+
* Require `sinatra_cyclist` before `dashing` otherwise you will see this error:
|
85
|
+
|
86
|
+
> No such file or directory - sample/dashboards/_cycle.erb
|
87
|
+
|
88
|
+
* Set the `routes_to_cycle_through` before running the application.
|
22
89
|
|
23
90
|
## Contributing
|
24
91
|
|
data/examples/config.ru
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
require "sinatra/cyclist"
|
3
|
+
|
4
|
+
class MyApp < Sinatra::Base
|
5
|
+
register Sinatra::Cyclist
|
6
|
+
|
7
|
+
set :routes_to_cycle_through, [:page_1, :page_2]
|
8
|
+
|
9
|
+
get "/page_1" do
|
10
|
+
"Page 1"
|
11
|
+
end
|
12
|
+
|
13
|
+
get "/page_2" do
|
14
|
+
"Page 2"
|
15
|
+
end
|
16
|
+
end
|
data/lib/sinatra/cyclist.rb
CHANGED
@@ -5,13 +5,16 @@ module Sinatra
|
|
5
5
|
module Cyclist
|
6
6
|
def self.registered(app)
|
7
7
|
app.enable :sessions
|
8
|
+
app.set :routes_to_cycle_through, []
|
8
9
|
|
9
10
|
app.get "/_cycle" do
|
11
|
+
return if settings.routes_to_cycle_through.empty?
|
12
|
+
|
10
13
|
page_index = session[:_cycle_page_index] || -1
|
11
14
|
session[:_cycle_page_index] = page_index + 1
|
12
15
|
|
13
|
-
|
14
|
-
page = settings.
|
16
|
+
number_of_routes = settings.routes_to_cycle_through.length
|
17
|
+
page = settings.routes_to_cycle_through[session[:_cycle_page_index] % number_of_routes]
|
15
18
|
|
16
19
|
session[:_cycle_duration] ||= params[:duration] || 3
|
17
20
|
|
@@ -29,5 +32,5 @@ module Sinatra
|
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
register Cyclist
|
33
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_cyclist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -39,12 +39,12 @@ files:
|
|
39
39
|
- LICENSE
|
40
40
|
- README.md
|
41
41
|
- Rakefile
|
42
|
+
- examples/classic_application.rb
|
43
|
+
- examples/config.ru
|
44
|
+
- examples/modular_application.rb
|
42
45
|
- lib/sinatra/cyclist.rb
|
43
46
|
- lib/sinatra/cyclist/version.rb
|
44
47
|
- sinatra_cyclist.gemspec
|
45
|
-
- spec/lib/cyclist_spec.rb
|
46
|
-
- spec/spec_helper.rb
|
47
|
-
- spec/support/classic_application.rb
|
48
48
|
homepage: https://github.com/vrish88/sinatra_cyclist
|
49
49
|
licenses: []
|
50
50
|
post_install_message:
|
@@ -69,7 +69,4 @@ rubygems_version: 1.8.24
|
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|
71
71
|
summary: Sinatra can ride a bicycle over and over and over again
|
72
|
-
test_files:
|
73
|
-
- spec/lib/cyclist_spec.rb
|
74
|
-
- spec/spec_helper.rb
|
75
|
-
- spec/support/classic_application.rb
|
72
|
+
test_files: []
|
data/spec/lib/cyclist_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED