sinatra_cyclist 0.0.2 → 0.0.3
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 +52 -40
- data/lib/sinatra/cyclist.rb +6 -1
- data/lib/sinatra/cyclist/version.rb +2 -2
- metadata +52 -33
data/README.md
CHANGED
@@ -14,48 +14,10 @@ Or install it yourself as:
|
|
14
14
|
|
15
15
|
$ gem install sinatra_cyclist
|
16
16
|
|
17
|
-
|
18
|
-
|
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!
|
17
|
+
Installation into your code depends on how you are using Sinatra.
|
56
18
|
|
57
19
|
### Dashing
|
58
|
-
If you are using [dashing](https://github.com/Shopify/dashing)
|
20
|
+
If you are using [dashing](https://github.com/Shopify/dashing) update your `config.ru` to look something like:
|
59
21
|
|
60
22
|
```ruby
|
61
23
|
require "sinatra/cyclist"
|
@@ -87,6 +49,54 @@ run Sinatra::Application
|
|
87
49
|
|
88
50
|
* Set the `routes_to_cycle_through` before running the application.
|
89
51
|
|
52
|
+
### Classic Applications
|
53
|
+
Require the gem and specify the routes you want to cycle through.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require "sinatra"
|
57
|
+
require "sinatra/cyclist"
|
58
|
+
|
59
|
+
set :routes_to_cycle_through, [:page_1, :page_2]
|
60
|
+
|
61
|
+
get "/page_1" do
|
62
|
+
"Page 1"
|
63
|
+
end
|
64
|
+
|
65
|
+
get "/page_2" do
|
66
|
+
"Page 2"
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
### Modular Applications
|
71
|
+
Require the gem, explicitly register the extension, and specify the routes.
|
72
|
+
```ruby
|
73
|
+
require "sinatra/base"
|
74
|
+
require "sinatra/cyclist"
|
75
|
+
|
76
|
+
class MyApp < Sinatra::Base
|
77
|
+
register Sinatra::Cyclist
|
78
|
+
|
79
|
+
set :routes_to_cycle_through, [:page_1, :page_2]
|
80
|
+
|
81
|
+
get "/page_1" do
|
82
|
+
"Page 1"
|
83
|
+
end
|
84
|
+
|
85
|
+
get "/page_2" do
|
86
|
+
"Page 2"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
## Usage
|
92
|
+
Now visit `/_cycle` to start cycling!
|
93
|
+
|
94
|
+
You can also specify a duration (in seconds) in the params to the cycle action
|
95
|
+
|
96
|
+
```
|
97
|
+
http://sinatra_app.com/_cycle?duration=10
|
98
|
+
```
|
99
|
+
|
90
100
|
## Contributing
|
91
101
|
|
92
102
|
1. Fork it
|
@@ -94,3 +104,5 @@ run Sinatra::Application
|
|
94
104
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
95
105
|
4. Push to the branch (`git push origin my-new-feature`)
|
96
106
|
5. Create new Pull Request
|
107
|
+
|
108
|
+

|
data/lib/sinatra/cyclist.rb
CHANGED
@@ -6,6 +6,7 @@ module Sinatra
|
|
6
6
|
def self.registered(app)
|
7
7
|
app.enable :sessions
|
8
8
|
app.set :routes_to_cycle_through, []
|
9
|
+
app.set :cycle_duration, 3
|
9
10
|
|
10
11
|
app.get "/_cycle" do
|
11
12
|
return if settings.routes_to_cycle_through.empty?
|
@@ -16,7 +17,11 @@ module Sinatra
|
|
16
17
|
number_of_routes = settings.routes_to_cycle_through.length
|
17
18
|
page = settings.routes_to_cycle_through[session[:_cycle_page_index] % number_of_routes]
|
18
19
|
|
19
|
-
|
20
|
+
if params[:duration]
|
21
|
+
session[:_cycle_duration] = params[:duration]
|
22
|
+
end
|
23
|
+
|
24
|
+
session[:_cycle_duration] ||= settings.cycle_duration
|
20
25
|
|
21
26
|
session[:_cycle] = true
|
22
27
|
|
metadata
CHANGED
@@ -1,39 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_cyclist
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Michael Lavrisha
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2013-09-10 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
15
22
|
name: sinatra
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
30
35
|
description: Cycle through pages at a regular interval
|
31
|
-
email:
|
36
|
+
email:
|
32
37
|
- michael.lavrisha@gmail.com
|
33
38
|
executables: []
|
39
|
+
|
34
40
|
extensions: []
|
41
|
+
|
35
42
|
extra_rdoc_files: []
|
36
|
-
|
43
|
+
|
44
|
+
files:
|
37
45
|
- .gitignore
|
38
46
|
- Gemfile
|
39
47
|
- LICENSE
|
@@ -45,28 +53,39 @@ files:
|
|
45
53
|
- lib/sinatra/cyclist.rb
|
46
54
|
- lib/sinatra/cyclist/version.rb
|
47
55
|
- sinatra_cyclist.gemspec
|
56
|
+
has_rdoc: true
|
48
57
|
homepage: https://github.com/vrish88/sinatra_cyclist
|
49
58
|
licenses: []
|
59
|
+
|
50
60
|
post_install_message:
|
51
61
|
rdoc_options: []
|
52
|
-
|
62
|
+
|
63
|
+
require_paths:
|
53
64
|
- lib
|
54
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
66
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
75
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
66
83
|
requirements: []
|
84
|
+
|
67
85
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.4.2
|
69
87
|
signing_key:
|
70
88
|
specification_version: 3
|
71
89
|
summary: Sinatra can ride a bicycle over and over and over again
|
72
90
|
test_files: []
|
91
|
+
|