sinatra_cyclist 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- TODO: Write usage instructions here
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
 
@@ -0,0 +1,12 @@
1
+ require "sinatra"
2
+ require "sinatra/cyclist"
3
+
4
+ set :routes_to_cycle_through, [:page_1, :page_2]
5
+
6
+ get "/page_1" do
7
+ "Page 1"
8
+ end
9
+
10
+ get "/page_2" do
11
+ "Page 2"
12
+ end
@@ -0,0 +1,2 @@
1
+ require "./modular_application"
2
+ run MyApp
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Cyclist
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -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
- number_of_views = settings.views.length
14
- page = settings.views[session[:_cycle_page_index] % number_of_views]
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
- Sinatra::Base.register Cyclist
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.1
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-24 00:00:00.000000000 Z
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: []
@@ -1,9 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Sinatra
4
- describe Cyclist do
5
- it "registers itself as an extension" do
6
- Base.extensions.should include Sinatra::Cyclist
7
- end
8
- end
9
- end
data/spec/spec_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require "rspec"
2
- require "sinatra"
3
- require "sinatra/cyclist"
4
-
5
- Sinatra::Application.environment = :test
6
- Bundler.require :default, Sinatra::Application.environment
@@ -1,13 +0,0 @@
1
- require "sinatra"
2
- require "debugger"
3
- require_relative "../../lib/sinatra/cyclist"
4
-
5
- set :views, [:page_1, :page_2]
6
-
7
- get "/page_1" do
8
- "Page 1"
9
- end
10
-
11
- get "/page_2" do
12
- "Page 2"
13
- end