sinatra_cyclist_multi 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f75250653f1bd09cfcb1aff0400b70c3d87ab39e
4
+ data.tar.gz: b6be1a3c3326c4b039f7eb8f68c4b3012dff0ef1
5
+ SHA512:
6
+ metadata.gz: 1b844166fa754c49a074fa6aa646cce68671764d22d738427ba5de36149dabf8b2ac9c9f18843c96e8ececc63689ccd90c5df674775602e315b428e82b1df36a
7
+ data.tar.gz: 82cee65afad8ecf68a881a55e952f9b4e54d50a549a8e242669a6580042b21bea6b7d8920b0934d6d7b0c086f5543405d92ffae69b8ebd40af6a190afa81a999
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
18
+ .idea
data/Dockerfile ADDED
@@ -0,0 +1,34 @@
1
+ FROM ruby:2.3-alpine
2
+ MAINTAINER nfa
3
+ RUN apk --update --no-cache add \
4
+ build-base \
5
+ nodejs \
6
+ zlib-dev \
7
+ libxml2-dev \
8
+ libxslt-dev \
9
+ sqlite-dev \
10
+ tzdata \
11
+ git \
12
+ && rm -rf /var/cache/apk/*
13
+
14
+ RUN cp /usr/share/zoneinfo/Europe/Paris /etc/localtime &&\
15
+ echo "Europe/Paris" > /etc/timezone
16
+
17
+ RUN bundle config --global build.nokogiri "--use-system-libraries" &&\
18
+ bundle config --global build.nokogumbo "--use-system-libraries" &&\
19
+ echo 'gem: --no-doc --no-ri' >> ~/.gemrc && chmod +r ~/.gemrc
20
+
21
+ ENV APP_HOME /app
22
+ RUN mkdir -p $APP_HOME
23
+ WORKDIR $APP_HOME
24
+
25
+ RUN gem install dashing
26
+ RUN dashing new . &&\
27
+ rm -f dashboards/sample* jobs/*.rb &&\
28
+ bundle
29
+ COPY test/dashing/ ./
30
+ COPY . ./lib/sinatra_cyclist_multi
31
+ RUN rm -rf ./lib/sinatra_cyclist_multi/examples
32
+
33
+ EXPOSE 8080:3030
34
+ CMD dashing start
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sinatra_cyclist.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Michael Lavrisha
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.
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Sinatra Cyclist Multi
2
+
3
+ This is a fork of the original gem [vrish88/sinatra_cyclist](https://github.com/vrish88/sinatra_cyclist), thank you vrish88.
4
+
5
+ Added option to use multiple cycled routes.
6
+
7
+ | cycled routes | routes pages | cycle time |
8
+ |--------------------------|---------------------------------------|--------------|
9
+ | first-cycled-route | ['dashboard1', 'dashboard2', 'dash3'] | 10 |
10
+ | another-cycled-route | ['dashboard12', 'dashboardY'] | 5 |
11
+ | prod-cycle-route | ['dashi', 'dashou', 'dashbord36'] | 45 |
12
+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'sinatra_cyclist_multi'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install sinatra_cyclist_multi
27
+
28
+ Installation into your code depends on how you are using Sinatra.
29
+
30
+ ## Configuration
31
+
32
+ If you need only one cycled route you can use [vrish88/sinatra_cyclist](https://github.com/vrish88/sinatra_cyclist) gem or set only one cycled route:
33
+
34
+ ```ruby
35
+ set :cycles_configuration, [
36
+ {cycled_route: '_cycle', routes: [:page1, :page2], cycle_duration: 15},
37
+ {cycled_route: '_cycle2', routes: [:page12, :page3, :page4], cycle_duration: 5},
38
+ {cycled_route: '_prod', routes: [:page7, :page4, :page5, :page6], cycle_duration: 45},
39
+ ]
40
+ ```
41
+
42
+ ### Dashing
43
+ If you are using [dashing](https://github.com/Shopify/dashing) update your `config.ru` to look something like:
44
+
45
+ ```ruby
46
+ require "sinatra/cyclist"
47
+ require 'dashing'
48
+
49
+ configure do
50
+ set :auth_token, 'YOUR_AUTH_TOKEN'
51
+
52
+ helpers do
53
+ def protected!
54
+ # Put any authentication code you want in here.
55
+ # This method is run before accessing any resource.
56
+ end
57
+ end
58
+ end
59
+
60
+ map Sinatra::Application.assets_prefix do
61
+ run Sinatra::Application.sprockets
62
+ end
63
+
64
+ set :cycles_configuration, [
65
+ {cycled_route: '_cycle', routes: [:page1, :page2], cycle_duration: 15},
66
+ {cycled_route: '_cycle2', routes: [:page12, :page3, :page4], cycle_duration: 5},
67
+ {cycled_route: '_prod', routes: [:page7, :page4, :page5, :page6], cycle_duration: 45},
68
+ ]
69
+
70
+ run Sinatra::Application
71
+ ```
72
+
73
+ * Require `sinatra_cyclist_multi` before `dashing` otherwise you will see this error:
74
+
75
+ > No such file or directory - sample/dashboards/_cycle.erb
76
+
77
+ * Set the `routes_to_cycle_through` before running the application.
78
+
79
+ ### Classic Applications
80
+ Require the gem and specify the routes you want to cycle through.
81
+
82
+ ```ruby
83
+ require "sinatra"
84
+ require "sinatra/cyclist"
85
+
86
+ set :cycles_configuration, [
87
+ {cycled_route: '_cycle', routes: [:page1, :page2], cycle_duration: 30},
88
+ ]
89
+
90
+ get "/page_1" do
91
+ "Page 1"
92
+ end
93
+
94
+ get "/page_2" do
95
+ "Page 2"
96
+ end
97
+ ```
98
+
99
+ ### Modular Applications
100
+ Require the gem, explicitly register the extension, and specify the routes.
101
+ ```ruby
102
+ require "sinatra/base"
103
+ require "sinatra/cyclist"
104
+
105
+ class MyApp < Sinatra::Base
106
+ register Sinatra::Cyclist
107
+
108
+ set :cycles_configuration, [
109
+ {cycled_route: '_cycle', routes: [:page1, :page2], cycle_duration: 30},
110
+ ]
111
+
112
+ get "/page_1" do
113
+ "Page 1"
114
+ end
115
+
116
+ get "/page_2" do
117
+ "Page 2"
118
+ end
119
+ end
120
+ ```
121
+
122
+ ## Usage
123
+ Now visit one of your configured cycled routes `/_cycle/#{cycled_route}` to start cycling!
124
+
125
+ You can also specify a duration (in seconds) in the params to the cycle action
126
+
127
+ ```
128
+ http://sinatra_app.com/_cycle/#{cycled_route}?duration=10
129
+ ```
130
+
131
+ /!\ **Do not use this gem with the original, it will conflict** /!\
132
+
133
+
134
+ ## Try it with on Dashing
135
+ You can try with the **Dockerfile** in test folder. Considering you have a working docker installation you can run:
136
+
137
+ ```shell
138
+ cd sinatra_cyclist_multi/test
139
+ docker build -t nfaa/cyclist . && docker run --name cyclist -p8080:3030 nfaa/cyclist
140
+ ```
141
+
142
+ There are three cycled routes configured:
143
+ ```
144
+ http://{docker host ip}:8080/_cycle/_cycle
145
+ http://{docker host ip}:8080/_cycle/cycle
146
+ http://{docker host ip}:8080/_cycle/prod
147
+ ```
148
+ ## Contributing
149
+
150
+ 1. Fork it
151
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
152
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
153
+ 4. Push to the branch (`git push origin my-new-feature`)
154
+ 5. Create new Pull Request
155
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -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
@@ -0,0 +1,47 @@
1
+ require "sinatra/base"
2
+ require_relative "cyclist/version"
3
+
4
+ module Sinatra
5
+ module Cyclist
6
+ def self.registered(app)
7
+ app.enable :sessions
8
+ app.set :cycles_configuration, []
9
+
10
+ app.get "/_cycle/:cycled_route" do
11
+ not_found if
12
+ settings.cycles_configuration.empty? or
13
+ settings.cycles_configuration.select{ |cycle|
14
+ cycle[:cycled_route] == params['cycled_route'] &&
15
+ cycle[:routes].is_a?(Array) &&
16
+ !cycle[:routes].empty?
17
+ }.empty?
18
+
19
+ cycle = settings.cycles_configuration.select{ |cycle|
20
+ cycle[:cycled_route] == params['cycled_route']
21
+ }.first
22
+
23
+ page_index = session[:_cycle_page_index] || -1
24
+ session[:_cycle_page_index] = page_index + 1
25
+
26
+ number_of_routes = cycle[:routes].length
27
+ page = cycle[:routes][session[:_cycle_page_index] % number_of_routes]
28
+
29
+ session[:_cycle_duration] = params[:duration] if params[:duration]
30
+ session[:_cycle_duration] = cycle[:cycle_duration]
31
+ session[:_cycled_route] = cycle[:cycled_route]
32
+ session[:_cycle] = true
33
+
34
+ redirect "/#{page}"
35
+ end
36
+
37
+ app.before do
38
+ if session[:_cycle]
39
+ headers["Refresh"] = "#{session[:_cycle_duration]}; url=/_cycle/#{session[:_cycled_route]}"
40
+ session[:_cycle] = false
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ register Cyclist
47
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Cyclist
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sinatra/cyclist/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Lavrisha", 'Nabil Abachouayb']
6
+ gem.email = ["michael.lavrisha@gmail.com", 'me@nabile.fr']
7
+ gem.description = %q{Cycle through pages at a regular interval}
8
+ gem.summary = %q{Sinatra can ride a bicycle over and over and over again}
9
+ gem.homepage = "https://github.com/faouzzz/sinatra_cyclist_multi"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "sinatra_cyclist_multi"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Sinatra::Cyclist::VERSION
17
+
18
+ gem.add_dependency "sinatra"
19
+
20
+ end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'dashing'
4
+ gem 'sinatra_cyclist_multi', path: './lib/sinatra_cyclist_multi'
@@ -0,0 +1,28 @@
1
+ require 'sinatra/cyclist'
2
+ require 'dashing'
3
+
4
+ configure do
5
+ set :auth_token, 'YOUR_AUTH_TOKEN'
6
+
7
+ helpers do
8
+ def protected!
9
+ # Put any authentication code you want in here.
10
+ # This method is run before accessing any resource.
11
+ end
12
+ end
13
+ end
14
+
15
+ map Sinatra::Application.assets_prefix do
16
+ run Sinatra::Application.sprockets
17
+ end
18
+
19
+ set :cycles_configuration, [
20
+ {cycled_route: '_cycle', routes: [:sample, :sample2], cycle_duration: 2},
21
+ {cycled_route: 'cycle', routes: [:sample2, :sample3, :sample4], cycle_duration: 5},
22
+ {cycled_route: 'prod', routes: [:sample1, :sample6, :sample5, :sample4], cycle_duration: 10},
23
+ {cycled_route: 'bad', routes: [], cycle_duration: 10}, # should redirect not_found
24
+ {cycled_route: 'baad', routes: '', cycle_duration: 10}, # should redirect not_found
25
+ {cycled_route: 'baaad', routes: nil, cycle_duration: 10}, # should redirect not_found
26
+ ]
27
+
28
+ run Sinatra::Application
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='0'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='1'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='2'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='3'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='4'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='5'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="gridster">
2
+ <ul>
3
+ <li data-row="1" data-col="1" data-sizex="4" data-sizey="2">
4
+ <div data-id="sample" data-view="Number" data-title="Dashboard" data-current='6'></div>
5
+ </li>
6
+ </ul>
7
+ </div>
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_cyclist_multi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Lavrisha
8
+ - Nabil Abachouayb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Cycle through pages at a regular interval
29
+ email:
30
+ - michael.lavrisha@gmail.com
31
+ - me@nabile.fr
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - Dockerfile
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - examples/classic_application.rb
43
+ - examples/config.ru
44
+ - examples/modular_application.rb
45
+ - lib/sinatra/cyclist.rb
46
+ - lib/sinatra/cyclist/version.rb
47
+ - sinatra_cyclist_multi.gemspec
48
+ - test/dashing/Gemfile
49
+ - test/dashing/config.ru
50
+ - test/dashing/dashboards/sample.erb
51
+ - test/dashing/dashboards/sample1.erb
52
+ - test/dashing/dashboards/sample2.erb
53
+ - test/dashing/dashboards/sample3.erb
54
+ - test/dashing/dashboards/sample4.erb
55
+ - test/dashing/dashboards/sample5.erb
56
+ - test/dashing/dashboards/sample6.erb
57
+ homepage: https://github.com/faouzzz/sinatra_cyclist_multi
58
+ licenses: []
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5.1
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Sinatra can ride a bicycle over and over and over again
80
+ test_files:
81
+ - test/dashing/Gemfile
82
+ - test/dashing/config.ru
83
+ - test/dashing/dashboards/sample.erb
84
+ - test/dashing/dashboards/sample1.erb
85
+ - test/dashing/dashboards/sample2.erb
86
+ - test/dashing/dashboards/sample3.erb
87
+ - test/dashing/dashboards/sample4.erb
88
+ - test/dashing/dashboards/sample5.erb
89
+ - test/dashing/dashboards/sample6.erb