ticker-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1a7f49e8f310991b5d61ea4a39ac05fd6fd9862
4
+ data.tar.gz: febec768144770551ca7b307679e7e0580301785
5
+ SHA512:
6
+ metadata.gz: 833b8f95e238c2068806fc3d6c8e8431e093b5fa8d0d8f716bdb45c6c38da47459ace9e339f1296abcba2de053915772cf5d7b5ae5271d6d46c729331f80dcb2
7
+ data.tar.gz: 3d40d8feeb78fc9cbb5a6fd33ed34c0b4391f7b0bcb35e5e4e8734e2b320721c7eb3958b068632221649802991521e19b99aea30bb52694ce6dafbb8105315b5
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
+
data/Dockerfile ADDED
@@ -0,0 +1,35 @@
1
+ # How to use it
2
+ # =============
3
+ #
4
+ # Visit http://blog.zedroot.org/using-docker-to-maintain-a-ruby-gem/
5
+
6
+ # ~~~~ Image base ~~~~
7
+ # Base image with the latest Ruby only
8
+ FROM litaio/ruby:2.2.2
9
+ MAINTAINER Guillaume Hain zedtux@zedroot.org
10
+
11
+
12
+ # ~~~~ Set up the environment ~~~~
13
+ ENV DEBIAN_FRONTEND noninteractive
14
+
15
+ # ~~~~ OS Maintenance ~~~~
16
+ RUN apt-get update && apt-get install -y git
17
+
18
+ # ~~~~ Rails Preparation ~~~~
19
+ # Rubygems and Bundler
20
+ RUN touch ~/.gemrc && \
21
+ echo "gem: --no-ri --no-rdoc" >> ~/.gemrc && \
22
+ gem install rubygems-update && \
23
+ update_rubygems && \
24
+ gem install bundler && \
25
+ mkdir -p /gem/
26
+
27
+ WORKDIR /gem/
28
+ ADD . /gem/
29
+ RUN bundle install
30
+
31
+ # Import the gem source code
32
+ VOLUME .:/gem/
33
+
34
+ ENTRYPOINT ["bundle", "exec"]
35
+ CMD ["rake", "-T"]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bootstrap-slider-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sammerset
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,43 @@
1
+ # Ticker-Rails
2
+
3
+ This Gem integrates https://github.com/BenjaminRH/jquery-ticker. The original has no public Github Repo, issues tracking etc.
4
+
5
+ It integrates this fork with your Rails project and is versioned to track the fork's version.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'ticker-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ticker-rails
20
+
21
+ ## Usage
22
+
23
+ This gem uses a Rails Engine to make JQuery ticker assets available to you.
24
+
25
+ Require the JavaScript files from your `application.js` or wherever needed using:
26
+
27
+ ```
28
+ //= require ticker-slider
29
+ ```
30
+
31
+ Require the CSS files from your `application.scss` or wherever needed using:
32
+
33
+ ```
34
+ *= require ticker-slider
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'fileutils'
3
+
4
+ desc 'Update the JQuery ticker Javascript and CSS files'
5
+ task :update_slider do
6
+ def download_slider(version)
7
+ base_url = 'https://github.com/BenjaminRH/jquery-ticker'
8
+ puts "Downlading JQuery ticker #{version} ..."
9
+ `curl -o vendor/assets/javascripts/jquery-ticker.js \
10
+ #{base_url}/jquery.ticker.js`
11
+ end
12
+
13
+ FileUtils.mkdir_p('vendor/assets/javascripts')
14
+ FileUtils.mkdir_p('vendor/assets/stylesheets')
15
+ download_slider(TickerRails::Rails::VERSION)
16
+ puts "\e[32mDone!\e[0m"
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'ticker-rails/version'
2
+
3
+ module TickerRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ # Make assets avaiable
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module TickerRails
2
+ module Rails
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ticker-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ticker-rails'
8
+ spec.version = TickerRails::Rails::VERSION
9
+ spec.authors = ['Sammerset']
10
+ spec.email = ['sammerset@ukr.net']
11
+ spec.description = %q{Make JQuery ticker available to Rails}
12
+ spec.summary = %q{This Gem integrates BenjaminRH's fork of JQuery ticker
13
+ with Rails, exposing its JavaScript and CSS assets via
14
+ a Rails Engine.}
15
+ spec.homepage = 'http://github.com/sammerset/ticker-rails'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'railties', '>= 3.2', '< 5.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,302 @@
1
+ /*!
2
+ * jQuery Ticker Plugin v1.2.1
3
+ * https://github.com/BenjaminRH/jquery-ticker
4
+ * https://github.com/sammerset/ticker-rails
5
+ *
6
+ * Copyright 2014 Benjamin Harris
7
+ * Released under the MIT license
8
+ */
9
+ (function($) {
10
+
11
+ // The ticker plugin
12
+ $.fn.ticker = function(options) {
13
+ // Extend our defaults with user-specified options
14
+ var opts = $.extend({}, $.fn.ticker.defaults, options);
15
+
16
+ // Handle each of the given containers
17
+ return this.each(function () {
18
+ // Setup the ticker elements
19
+ var tickerContainer = $(this); // Outer-most ticker container
20
+ var headlineContainer; // Inner headline container
21
+ var headlineElements = tickerContainer.find('li'); // Original headline elements
22
+ var headlines = []; // List of all the headlines
23
+ var headlineTagMap = {}; // Maps the indexes of the HTML tags in the headlines to the headline index
24
+ var outerTimeoutId; // Stores the outer ticker timeout id for pauses
25
+ var innerTimeoutId; // Stores the inner ticker timeout id for pauses
26
+ var currentHeadline = 0; // The index of the current headline in the list of headlines
27
+ var currentHeadlinePosition = 0; // The index of the current character in the current headline
28
+ var firstOuterTick = true; // Whether this is the first time doing the outer tick
29
+ var firstInnerTick = true; // Whether this is the first time doing the inner tick in this rendition of the outer one
30
+
31
+ var allowedTags = ['a', 'b', 'strong', 'span', 'i', 'em', 'u'];
32
+
33
+ if (opts.finishOnHover || opts.pauseOnHover) {
34
+ // Setup monitoring hover state
35
+ tickerContainer.removeClass('hover');
36
+ tickerContainer.hover(function() {
37
+ $(this).toggleClass('hover');
38
+ });
39
+ }
40
+
41
+ // Save all the headline text
42
+ var h, l;
43
+ headlineElements.each(function (index, element) {
44
+ h = stripTags($(this).html(), allowedTags); // Strip all but the allowed tags
45
+ l = locateTags(h); // Get the locations of the allowed tags
46
+ h = stripTags(h); // Remove all of the HTML tags from the headline
47
+ headlines.push(h); // Add the headline to the headlines list
48
+ headlineTagMap[headlines.length - 1] = l; // Associate the tag map with the headline
49
+ });
50
+
51
+ // Randomize?
52
+ if (opts.random) shuffleArray(headlines);
53
+
54
+ // Now delete all the elements and add the headline container
55
+ tickerContainer.find('ul').after('<div></div>').remove();
56
+ headlineContainer = tickerContainer.find('div');
57
+
58
+ // Function to actually do the outer ticker, and handle pausing
59
+ function outerTick() {
60
+ firstInnerTick = true;
61
+
62
+ if (firstOuterTick) {
63
+ firstOuterTick = false;
64
+ innerTick();
65
+ return;
66
+ }
67
+
68
+ outerTimeoutId = setTimeout(function () {
69
+ if (opts.pauseOnHover && tickerContainer.hasClass('hover')) {
70
+ // User is hovering over the ticker and pause on hover is enabled
71
+ clearTimeout(innerTimeoutId);
72
+ outerTick();
73
+ return;
74
+ }
75
+
76
+ innerTick();
77
+ }, opts.itemSpeed);
78
+ }
79
+
80
+ // Function to handle the ticking for individual headlines
81
+ function innerTick() {
82
+ if (firstInnerTick) {
83
+ firstInnerTick = false;
84
+ tick();
85
+ return;
86
+ }
87
+
88
+ if (currentHeadlinePosition > headlines[currentHeadline].length) {
89
+ advance();
90
+ return;
91
+ }
92
+
93
+ if (opts.finishOnHover && opts.pauseOnHover && tickerContainer.hasClass('hover') && currentHeadlinePosition <= headlines[currentHeadline].length) {
94
+ // Let's quickly complete the headline
95
+ // This is outside the timeout because we want to do this instantly without the pause
96
+
97
+ // Update the text
98
+ headlineContainer.html(getCurrentTick());
99
+ // Advance our position
100
+ currentHeadlinePosition += 1;
101
+
102
+ innerTick();
103
+ return;
104
+ }
105
+ else {
106
+ // Handle as normal
107
+ innerTimeoutId = setTimeout(function () {
108
+ if (opts.pauseOnHover && tickerContainer.hasClass('hover')) {
109
+ // User is hovering over the ticker and pause on hover is enabled
110
+ clearTimeout(innerTimeoutId);
111
+ innerTick();
112
+ return;
113
+ }
114
+
115
+ tick();
116
+ advance();
117
+ }, opts.cursorSpeed);
118
+ }
119
+ }
120
+
121
+ function advance() {
122
+ // Advance headline and reset character position, if it's at the end of the current headline
123
+ if (currentHeadlinePosition > headlines[currentHeadline].length) { // > here and not == because the ticker cursor takes an extra loop
124
+ currentHeadline += 1;
125
+ currentHeadlinePosition = 0;
126
+
127
+ // Reset the headline and character positions if we've cycled through all the headlines
128
+ if (currentHeadline == headlines.length) currentHeadline = 0;
129
+
130
+ // STOP! We've advanced a headline. Now we just need to pause.
131
+ clearTimeout(innerTimeoutId);
132
+ clearTimeout(outerTimeoutId);
133
+ outerTick();
134
+ }
135
+ }
136
+
137
+ // Do the individual ticks
138
+ function tick() {
139
+ // Now let's update the ticker with the current tick string
140
+ if (currentHeadlinePosition === 0 && opts.fade) {
141
+ clearTimeout(innerTimeoutId);
142
+
143
+ // Animate the transition if it's enabled
144
+ headlineContainer.fadeOut(opts.fadeOutSpeed, function () {
145
+ // Now it's faded out, let's update the text
146
+ headlineContainer.html(getCurrentTick());
147
+ // And fade in
148
+ headlineContainer.fadeIn(opts.fadeInSpeed, function () {
149
+ // Advance our position
150
+ currentHeadlinePosition += 1;
151
+ // And now we're in, let's start the thing off again without the delay
152
+ innerTick();
153
+ });
154
+ });
155
+ }
156
+ else {
157
+ // Update the text
158
+ headlineContainer.html(getCurrentTick());
159
+ // Advance our position
160
+ currentHeadlinePosition += 1;
161
+ clearTimeout(innerTimeoutId);
162
+ innerTick();
163
+ }
164
+ }
165
+
166
+ // Get the current tick string
167
+ function getCurrentTick() {
168
+ var cursor, i, j, location;
169
+ switch (currentHeadlinePosition % 2) {
170
+ case 1:
171
+ cursor = opts.cursorOne;
172
+ break;
173
+ case 0:
174
+ cursor = opts.cursorTwo;
175
+ break;
176
+ }
177
+
178
+ // Don't display the cursor this was the last character of the headline
179
+ if (currentHeadlinePosition >= headlines[currentHeadline].length) cursor = '';
180
+
181
+ // Generate the headline
182
+ var headline = '';
183
+ var openedTags = [];
184
+ for (i = 0; i < currentHeadlinePosition; i++) {
185
+ location = null;
186
+ // Check to see if there's meant to be a tag at this index
187
+ for (j = 0; j < headlineTagMap[currentHeadline].length; j++) {
188
+ // Find a tag mapped to this location, if one exists
189
+ if (headlineTagMap[currentHeadline][j] && headlineTagMap[currentHeadline][j].start === i) {
190
+ location = headlineTagMap[currentHeadline][j]; // It does exist!
191
+ break;
192
+ }
193
+ }
194
+
195
+ if (location) {
196
+ // Add the tag to the headline
197
+ headline += location.tag;
198
+
199
+ // Now deal with the tag for proper HTML
200
+ if (! location.selfClosing) {
201
+ if (location.tag.charAt(1) === '/') {
202
+ openedTags.pop();
203
+ }
204
+ else {
205
+ openedTags.push(location.name);
206
+ }
207
+ }
208
+ }
209
+
210
+ // Add the character to the headline
211
+ headline += headlines[currentHeadline][i];
212
+ }
213
+
214
+ // Now close the tags, if we need to (because it hasn't finished with all the text in the tag)
215
+ for (i = 0; i < openedTags.length; i++) {
216
+ headline += '</' + openedTags[i] + '>';
217
+ }
218
+
219
+ return headline + cursor;
220
+ }
221
+
222
+ // Start it
223
+ outerTick();
224
+ });
225
+ };
226
+
227
+ /**
228
+ * Randomize array element order in-place.
229
+ * Using Fisher-Yates shuffle algorithm.
230
+ */
231
+ function shuffleArray(array) {
232
+ for (var i = array.length - 1; i > 0; i--) {
233
+ var j = Math.floor(Math.random() * (i + 1));
234
+ var temp = array[i];
235
+ array[i] = array[j];
236
+ array[j] = temp;
237
+ }
238
+ return array;
239
+ }
240
+
241
+ /**
242
+ * Strip all HTML tags from a string.
243
+ * An array of safe tags can be passed, which will not be
244
+ * stripped from the string with the rest of the tags.
245
+ */
246
+ function stripTags(text, safeTags) {
247
+ safeTags = safeTags || [];
248
+ var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/img;
249
+ var comments = /<!--.*?-->/img;
250
+ return text.replace(comments, '').replace(tags, function (a, b) {
251
+ return safeTags.indexOf(b.toLowerCase()) !== -1 ? a : '';
252
+ });
253
+ }
254
+
255
+ /**
256
+ * Locates all of the requested tags in a string.
257
+ */
258
+ function locateTags(text, tagList) {
259
+ tagList = tagList || [];
260
+ var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/im;
261
+ var selfClosing = /\/\s{0,}>$/m;
262
+ var locations = [];
263
+ var match, location;
264
+
265
+ while ((match = tags.exec(text)) !== null) {
266
+ if (tagList.length === 0 || tagList.indexOf(match[1]) !== -1) {
267
+ location = {
268
+ tag: match[0],
269
+ name: match[1],
270
+ selfClosing: selfClosing.test(match[0]),
271
+ start: match.index,
272
+ end: match.index + match[0].length - 1
273
+ };
274
+ locations.push(location);
275
+
276
+ // Now remove this tag from the string
277
+ // so that each location will represent it in a string without any of the tags
278
+ text = text.slice(0, location.start) + text.slice(location.end + 1);
279
+
280
+ // Reset the regex
281
+ tags.lastIndex = 0;
282
+ }
283
+ }
284
+
285
+ return locations;
286
+ }
287
+
288
+ // Plugin default settings
289
+ $.fn.ticker.defaults = {
290
+ random: false, // Whether to display ticker items in a random order
291
+ itemSpeed: 3000, // The pause on each ticker item before being replaced
292
+ cursorSpeed: 50, // Speed at which the characters are typed
293
+ pauseOnHover: true, // Whether to pause when the mouse hovers over the ticker
294
+ finishOnHover: true, // Whether or not to complete the ticker item instantly when moused over
295
+ cursorOne: '_', // The symbol for the first part of the cursor
296
+ cursorTwo: '-', // The symbol for the second part of the cursor
297
+ fade: true, // Whether to fade between ticker items or not
298
+ fadeInSpeed: 600, // Speed of the fade-in animation
299
+ fadeOutSpeed: 300 // Speed of the fade-out animation
300
+ };
301
+
302
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ticker-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sammerset
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Make JQuery ticker available to Rails
62
+ email:
63
+ - sammerset@ukr.net
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Dockerfile
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/ticker-rails.rb
75
+ - lib/ticker-rails/version.rb
76
+ - ticker-rails.gemspec
77
+ - vendor/assets/javascripts/ticker-rails.js
78
+ homepage: http://github.com/sammerset/ticker-rails
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: This Gem integrates BenjaminRH's fork of JQuery ticker with Rails, exposing
102
+ its JavaScript and CSS assets via a Rails Engine.
103
+ test_files: []