bottle_rocket 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91321a4ab71fd3fb895722d62832129df63d6524
4
+ data.tar.gz: f1ec6f383eb0f769d8b7a595b4a7205f7a817617
5
+ SHA512:
6
+ metadata.gz: 630cdc8a94a20ea6aae79facb8240e127791a1d8f3f1f7cf7247c26d764ab55b9b89ecbc6ace03617be7b3e292a0ad33d2a38db0010f6a3fbf412955addb1690
7
+ data.tar.gz: 12fdee9b6a1481e39e05aeee63f4d123fcb3f1e5638bf2b1cc62f49692f5cb6abbbddd67000a6b38566a78f97a8ff01d1961f5e0de5d2fae95522a51cdd1620c
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ pkg/
@@ -0,0 +1 @@
1
+ countdown
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p0
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in countdown.gemspec
4
+ gemspec
5
+
6
+ gem 'time_spanner'
7
+
8
+ group :test do
9
+ platforms :mswin, :mingw do
10
+ gem 'win32console', '1.3.0'
11
+ end
12
+
13
+ gem 'minitest'
14
+ gem 'minitest-reporters'
15
+ end
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bottle_rocket (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (4.0.0)
10
+ activesupport (= 4.0.0)
11
+ builder (~> 3.1.0)
12
+ erubis (~> 2.7.0)
13
+ rack (~> 1.5.2)
14
+ rack-test (~> 0.6.2)
15
+ activesupport (4.0.0)
16
+ i18n (~> 0.6, >= 0.6.4)
17
+ minitest (~> 4.2)
18
+ multi_json (~> 1.3)
19
+ thread_safe (~> 0.1)
20
+ tzinfo (~> 0.3.37)
21
+ ansi (1.4.3)
22
+ atomic (1.1.10)
23
+ builder (3.1.4)
24
+ erubis (2.7.0)
25
+ hashie (2.0.5)
26
+ i18n (0.6.4)
27
+ minitest (4.7.5)
28
+ minitest-reporters (0.14.20)
29
+ ansi
30
+ builder
31
+ minitest (>= 2.12, < 5.0)
32
+ powerbar
33
+ multi_json (1.7.7)
34
+ powerbar (1.0.11)
35
+ ansi (~> 1.4.0)
36
+ hashie (>= 1.1.0)
37
+ rack (1.5.2)
38
+ rack-test (0.6.2)
39
+ rack (>= 1.0)
40
+ railties (4.0.0)
41
+ actionpack (= 4.0.0)
42
+ activesupport (= 4.0.0)
43
+ rake (>= 0.8.7)
44
+ thor (>= 0.18.1, < 2.0)
45
+ rake (10.1.0)
46
+ thor (0.18.1)
47
+ thread_safe (0.1.0)
48
+ atomic
49
+ time_spanner (1.0.0)
50
+ tzinfo (0.3.37)
51
+ win32console (1.3.0-x86-mingw32)
52
+
53
+ PLATFORMS
54
+ x86-mingw32
55
+
56
+ DEPENDENCIES
57
+ bottle_rocket!
58
+ bundler (~> 1.3)
59
+ minitest
60
+ minitest-reporters
61
+ railties
62
+ rake
63
+ time_spanner
64
+ win32console (= 1.3.0)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andreas Busold
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.
@@ -0,0 +1,167 @@
1
+ bottle_rocket
2
+ =========
3
+
4
+ Work in progress!
5
+ Adds a countdown to your views. Countdown is updated via JavaScript.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'countdown'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install countdown
20
+
21
+ ### Rails 3.1 or greater (with asset pipeline *enabled*)
22
+
23
+ Add the countdown javascript file to `app/assets/javascripts/application.js`:
24
+
25
+ ```js
26
+ //= require countdown
27
+ ```
28
+
29
+ ### Rails 3.0 (or greater with asset pipeline *disabled*)
30
+
31
+ Run the generator:
32
+ ```sh
33
+ rails generate countdown:install
34
+ ```
35
+ Running the generator will copy 'countdown.js' over to the `public\javascripts` directory.
36
+ Be sure to add `countdown.js` to your layout file:
37
+ ```ruby
38
+ <%= javascript_include_tag 'countdown' %>
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```ruby
44
+ <%= countdown from: Time.now + 28.hours %>
45
+ ```
46
+ results in a countdown like this:
47
+
48
+ <pre>
49
+ 1d03h59m59s
50
+ </pre>
51
+
52
+ or to count down from another time than now:
53
+ ```ruby
54
+ <%= countdown to: Time.now - 2.months, from: Time.parse '2012-09-27 01:07:00' %>
55
+ ```
56
+
57
+ The countdown is updated every second and the generated html looks like this:
58
+
59
+ ```html
60
+ <div class="countdown">
61
+ <span class="days">
62
+ <span class="day unit-1">1</span>
63
+ <span class="separator days">d</span>
64
+ </span>
65
+ <span class="hours">
66
+ <span class="hour unit-0">0</span>
67
+ <span class="hour unit-3">3</span>
68
+ <span class="separator hours">h</span>
69
+ </span>
70
+ <span class="minutes">
71
+ <span class="minute unit-5">5</span>
72
+ <span class="minute unit-9">9</span>
73
+ <span class="separator minutes">m</span>
74
+ </span>
75
+ <span class="seconds">
76
+ <span class="second unit-5">5</span>
77
+ <span class="second unit-9">9</span>
78
+ <span class="separator seconds">s</span>
79
+ </span>
80
+ </div>
81
+ ```
82
+
83
+ ### Options
84
+
85
+ ####:step
86
+
87
+ Define how often the counter should be updated via Javascript.
88
+ Possible steps are:
89
+ <pre>:milliseconds, :seconds, :minutes, :hours, :days</pre>
90
+
91
+ Defaults to the smallest unit value specified.
92
+
93
+ ####:units
94
+
95
+ Define which time units should be displayed and how they should be ordered.
96
+
97
+ Available keys are:
98
+ <pre>:millenniums, :centuries, :decades, :years, :months, :weeks, :days, :hours, :minutes, :seconds, :milliseconds, :microseconds, :nanoseconds</pre>
99
+
100
+ Default is
101
+ ```ruby
102
+ [:days, :hours, :minutes, :seconds]
103
+ ```
104
+ ####:separators
105
+
106
+ Define how different time units are separated from each other.
107
+
108
+ Available keys are:
109
+ <pre>:millenniums, :centuries, :decades, :years, :months, :weeks, :days, :hours, :minutes, :seconds, :milliseconds, :microseconds, :nanoseconds</pre>
110
+
111
+ Default is
112
+ ```ruby
113
+ { millenniums: {value: 'MN'},
114
+ centuries: {value: 'C'},
115
+ decades: {value: 'D'},
116
+ years: {value: 'Y'},
117
+ months: {value: 'M'},
118
+ weeks: {value: 'w'},
119
+ days: {value: 'd'},
120
+ hours: {value: 'h'},
121
+ minutes: {value: 'm'},
122
+ seconds: {value: 's'},
123
+ milliseconds: {value: 'ms'},
124
+ microseconds: {value: 'µs'},
125
+ nanoseconds: {value: 'ns'} }
126
+ ```
127
+ You can singularize separators by supplying a hash e.g
128
+ ```ruby
129
+ days: {value: 'days', singular: 'day'}
130
+ ```
131
+ By default separators are displayed after the corresponding time unit.
132
+ To display them before to the units use this option:
133
+ ```ruby
134
+ seconds: {value: 'seconds:', align: :before}
135
+ ```
136
+ results in this:
137
+
138
+ <pre>
139
+ seconds:1
140
+ </pre>
141
+
142
+ ####:leading_zeroes
143
+
144
+ Set to false to remove leading zeroes (e.g 08:00:00 => 8:00:00)
145
+
146
+ Defaults to <pre>true</pre>.
147
+
148
+ ## Countup
149
+
150
+ For a reverse countdown starting at 00:00:00 use the countup method using the same options:
151
+
152
+ ```ruby
153
+ <%= countup from: Time.now to: Time.now + 1.hour %>
154
+ ```
155
+
156
+ ## TODO:
157
+
158
+ - Everything
159
+ - Note to me: How to define a callback, which happens after a complete countdown/-up?
160
+
161
+ ## Contributing
162
+
163
+ 1. Fork it
164
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
165
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
166
+ 4. Push to the branch (`git push origin my-new-feature`)
167
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Run tests'
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = true
11
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bottle_rocket/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bottle_rocket'
8
+ spec.version = BottleRocket::VERSION
9
+ spec.authors = ['Andreas Busold']
10
+ spec.email = ['an.bu@gmx.net']
11
+ spec.description = %q{Work in progress! Adds a countdown to your views. Countdown is updated via JavaScript.}
12
+ spec.summary = %q{Work in progress! Adds a countdown to your views. Countdown is updated via JavaScript.}
13
+ spec.homepage = 'https://github.com/neopoly/bottle_rocket'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'railties'
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'time_spanner'
2
+
3
+ require 'bottle_rocket/version'
4
+ require 'bottle_rocket/content_tag'
5
+ require 'bottle_rocket/tag_builders'
6
+ require 'bottle_rocket/view_helpers'
7
+
8
+ if defined? Rails
9
+ require 'bottle_rocket/engine' if ::Rails.version >= '3.1'
10
+ require 'bottle_rocket/railtie'
11
+ end
@@ -0,0 +1,23 @@
1
+ module BottleRocket
2
+ module ContentTags
3
+
4
+ class ContentTag
5
+ attr_reader :tag_type, :attributes
6
+
7
+ def initialize(tag_type, attributes={})
8
+ @tag_type = tag_type
9
+ @attributes = attributes
10
+ end
11
+
12
+ def to_s(&block)
13
+ "<#{tag_type} #{html_attributes}>" + (block_given? ? yield : '') + "</#{tag_type}>"
14
+ end
15
+
16
+ def html_attributes
17
+ attributes.map {|k, v| "#{k}=\"#{v}\"" }.join(' ')
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ module BottleRocket
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module BottleRocket
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'countdown.view_helpers' do
4
+ ActionView::Base.send :include, ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'bottle_rocket/tag_builders/unit_separator_builder'
2
+ require 'bottle_rocket/tag_builders/time_unit_builder'
3
+ require 'bottle_rocket/tag_builders/unit_container_builder'
4
+ require 'bottle_rocket/tag_builders/countdown_builder'
@@ -0,0 +1,45 @@
1
+ # encoding: UTF-8
2
+ # TODO: 'railsify' only here -> safe_buffer
3
+
4
+ module BottleRocket
5
+ module TagBuilders
6
+
7
+ class CountdownBuilder
8
+ include ::BottleRocket::ContentTags
9
+ include TimeSpanner
10
+
11
+ DEFAULT_DIRECTION = :down
12
+ DEFAULT_STEPS = :seconds
13
+ DEFAULT_UNITS = [:days, :hours, :minutes, :seconds]
14
+ DEFAULT_SEPARATORS = { millenniums: {value: 'MN'}, centuries: {value: 'C'}, decades: {value: 'D'}, years: {value: 'Y'}, months: {value: 'M'}, weeks: {value: 'w'}, days: {value: 'd'}, hours: {value: 'h'}, minutes: {value: 'm'}, seconds: {value: 's'}, milliseconds: {value: 'ms'}, microseconds: {value: 'µs'}, nanoseconds: {value: 'ns'} }
15
+
16
+ attr_reader :direction, :steps, :units, :separators, :time_span
17
+
18
+ def initialize(options)
19
+ now = Time.now
20
+ from = options.delete(:from) || now
21
+ to = options.delete(:to) || now
22
+
23
+ @direction = options.delete(:direction) || DEFAULT_DIRECTION
24
+ @steps = options.delete(:steps) || DEFAULT_STEPS
25
+ @units = options.delete(:units) || DEFAULT_UNITS
26
+ @separators = options.delete(:separators) || DEFAULT_SEPARATORS
27
+ @time_span = TimeSpan.new(from, to, units)
28
+ end
29
+
30
+ def attributes
31
+ { :class => 'countdown', :'data-direction' => direction.to_s, :'data-steps' => steps.to_s }
32
+ end
33
+
34
+ def to_html
35
+ ContentTag.new(:div, attributes).to_s do
36
+ units.map do |unit|
37
+ UnitContainerBuilder.new(unit, time_span[unit], separators[unit]).to_html
38
+ end.join
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,22 @@
1
+ module BottleRocket
2
+ class TimeUnitBuilder
3
+ include ::BottleRocket::ContentTags
4
+
5
+ attr_reader :unit, :value
6
+
7
+ def initialize(unit, value)
8
+ @unit = unit
9
+ @value = value
10
+ end
11
+
12
+ def one?
13
+ [-1, 1].include? value
14
+ end
15
+
16
+ def to_html
17
+ ContentTag.new(:span, class: "#{unit}-#{value}").to_s do
18
+ value.to_s
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module BottleRocket
2
+ module TagBuilders
3
+
4
+ class UnitContainerBuilder
5
+ include ::BottleRocket::ContentTags
6
+
7
+ attr_reader :unit, :time_unit, :unit_separator
8
+
9
+ def initialize(unit, unit_value, separator_options)
10
+ @unit = unit
11
+ @time_unit = TimeUnitBuilder.new unit, unit_value
12
+ @unit_separator = UnitSeparatorBuilder.new unit, separator_options.merge(singularize: singularize?)
13
+ end
14
+
15
+ def singularize?
16
+ time_unit.one?
17
+ end
18
+
19
+ def to_html
20
+ ContentTag.new(:span, class: unit.to_s).to_s do
21
+ if unit_separator.after?
22
+ [time_unit.to_html, unit_separator.to_html].join
23
+ else
24
+ [unit_separator.to_html, time_unit.to_html].join
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ module BottleRocket
2
+ module TagBuilders
3
+
4
+ class UnitSeparatorBuilder
5
+ include ::BottleRocket::ContentTags
6
+
7
+ DEFAULT_ALIGN = :after
8
+ DEFAULT_SINGULARIZE = false
9
+
10
+ attr_reader :unit, :value, :align, :singular, :singularize
11
+
12
+ def initialize(unit, options={})
13
+ @unit = unit
14
+ @value = options.delete(:value)
15
+ @align = options.delete(:align) || DEFAULT_ALIGN
16
+ @singular = options.delete(:singular)
17
+ @singularize = options.delete(:singularize) || DEFAULT_SINGULARIZE
18
+ end
19
+
20
+ def attributes
21
+ { :class => "separator #{unit}", :'data-singular' => (singular || value), :'data-plural' => value }
22
+ end
23
+
24
+ def after?
25
+ @align == DEFAULT_ALIGN
26
+ end
27
+
28
+ def before?
29
+ !after?
30
+ end
31
+
32
+ def singularize_value
33
+ singular && singularize ? singular : value
34
+ end
35
+
36
+ def to_html
37
+ ContentTag.new(:span, attributes).to_s do
38
+ singularize_value.to_s
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module BottleRocket
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ module BottleRocket
2
+ module ViewHelpers
3
+ include ::BottleRocket::TagBuilders
4
+
5
+ def countdown(options={})
6
+ safe_buffer CountdownBuilder.new(options).to_html
7
+ end
8
+
9
+ def countup(options={})
10
+ safe_buffer CountdownBuilder.new(options.merge(direction: :up)).to_html
11
+ end
12
+
13
+
14
+ private
15
+
16
+ def safe_buffer(string)
17
+ defined?(Rails) ? ActiveSupport::SafeBuffer.new(string) : string
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'rails'
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < '3.1' || !::Rails.application.config.assets.enabled
5
+ module BottleRocket
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ desc 'This generator installs countdown'
9
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
10
+
11
+ def copy
12
+ say_status('copying', 'countdown', :green)
13
+ copy_file 'countdown.js', 'public/javascripts/countdown.js'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ else
19
+ module BottleRocket
20
+ module Generators
21
+ class InstallGenerator < ::Rails::Generators::Base
22
+ desc 'Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps'
23
+
24
+ def do_nothing
25
+ say_status('deprecated', 'You are using Rails 3.1 with the asset pipeline enabled, so this generator is not needed.')
26
+ say_status('', 'The necessary files are already in your asset pipeline.')
27
+ say_status('', 'Just add `//= require countdown` to your app/assets/javascripts/application.js')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module ContentTags
5
+ class ContentTagTest < TestCase
6
+
7
+ before do
8
+ @tag = ContentTag.new(:div)
9
+ end
10
+
11
+ it 'should convert tag to string with block given' do
12
+ string = 'test'
13
+ tag = @tag.to_s { string }
14
+
15
+ assert tag.is_a?(String)
16
+ assert tag.include?('<div')
17
+ assert tag.include?('</div>')
18
+ assert tag.include?(string)
19
+ end
20
+
21
+ it 'should convert tag to string without block' do
22
+ tag = @tag.to_s
23
+
24
+ assert tag.is_a?(String)
25
+ assert tag.include?('<div')
26
+ assert tag.include?('</div>')
27
+ end
28
+
29
+ it 'converts attributes to html attributes' do
30
+ tag = ContentTag.new(:div, {:class => 'some-class', :'data-test' => '5'})
31
+
32
+ assert_equal 'class="some-class" data-test="5"', tag.html_attributes
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module TagBuilders
5
+
6
+ class CountdownBuilderTest < TestCase
7
+
8
+ before do
9
+ from = Time.now
10
+ to = from + 1
11
+ @counter = CountdownBuilder.new(from: from, to: to)
12
+ end
13
+
14
+ it 'should initialize with default values' do
15
+ assert @counter.time_span.is_a?(Hash)
16
+ assert_equal CountdownBuilder::DEFAULT_DIRECTION, @counter.direction
17
+ assert_equal CountdownBuilder::DEFAULT_UNITS, @counter.units
18
+ assert_equal CountdownBuilder::DEFAULT_SEPARATORS, @counter.separators
19
+ end
20
+
21
+ it 'creates html' do
22
+ assert @counter.to_html.is_a?(String)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module TagBuilders
5
+
6
+ class TimeUnitBuilderTest < TestCase
7
+
8
+ before do
9
+ @time_unit = TimeUnitBuilder.new(:minutes, 1)
10
+ end
11
+
12
+ it 'has value' do
13
+ assert_equal 1, @time_unit.value
14
+ end
15
+
16
+ it 'has unit' do
17
+ assert_equal :minutes, @time_unit.unit
18
+ end
19
+
20
+ it 'has a 1 value' do
21
+ [-1, 1].each do |n|
22
+ time_unit = TimeUnitBuilder.new(:minutes, n)
23
+
24
+ assert time_unit.one?
25
+ end
26
+ end
27
+
28
+ it 'has no 1 value' do
29
+ [-2, 0, 2].each do |n|
30
+ time_unit = TimeUnitBuilder.new(:minutes, n)
31
+
32
+ refute time_unit.one?
33
+ end
34
+ end
35
+
36
+ it 'creates html' do
37
+ assert_equal '<span class="minutes-1">1</span>', @time_unit.to_html
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module TagBuilders
5
+
6
+ class UnitContainerBuilderTest < TestCase
7
+
8
+ before do
9
+ @unit_tag_builder = UnitContainerBuilder.new(:minutes, 1, {value: 'm'})
10
+ end
11
+
12
+ it 'has unit' do
13
+ assert_equal :minutes, @unit_tag_builder.unit
14
+ end
15
+
16
+ it 'has time_unit' do
17
+ assert @unit_tag_builder.time_unit.is_a?(TimeUnitBuilder)
18
+ end
19
+
20
+ it 'has unit_separator' do
21
+ assert @unit_tag_builder.unit_separator.is_a?(UnitSeparatorBuilder)
22
+ end
23
+
24
+ it 'singularizes' do
25
+ assert @unit_tag_builder.singularize?
26
+ end
27
+
28
+ it 'does not singularize' do
29
+ unit_tag_builder = UnitContainerBuilder.new(:minutes, 0, {value: 'm'})
30
+
31
+ refute unit_tag_builder.singularize?
32
+ end
33
+
34
+ it 'creates html' do
35
+ expected = '<span class="minutes"><span class="minutes-1">1</span><span class="separator minutes" data-singular="m" data-plural="m">m</span></span>'
36
+
37
+ assert_equal expected, @unit_tag_builder.to_html
38
+ end
39
+
40
+ it 'creates html with separator aligned before' do
41
+ expected = '<span class="minutes"><span class="separator minutes" data-singular="m" data-plural="m">m</span><span class="minutes-1">1</span></span>'
42
+ unit_tag_builder = UnitContainerBuilder.new(:minutes, 1, {value: 'm', align: :before})
43
+
44
+ assert_equal expected, unit_tag_builder.to_html
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module TagBuilders
5
+
6
+ class UnitSeparatorBuilderTest < TestCase
7
+
8
+ before do
9
+ @separator = UnitSeparatorBuilder.new(:minutes, {value: 'm'})
10
+ end
11
+
12
+ it 'has value' do
13
+ assert_equal 'm', @separator.value
14
+ end
15
+
16
+ it 'has unit' do
17
+ assert_equal :minutes, @separator.unit
18
+ end
19
+
20
+ it 'has default alignment' do
21
+ assert_equal UnitSeparatorBuilder::DEFAULT_ALIGN, @separator.align
22
+ refute @separator.before?
23
+ assert @separator.after?
24
+ end
25
+
26
+ it 'overwrites default alignment' do
27
+ separator = UnitSeparatorBuilder.new(:minutes, {value: 'm', align: :before})
28
+
29
+ assert_equal :before, separator.align
30
+ assert separator.before?
31
+ refute separator.after?
32
+ end
33
+
34
+ it 'singularizes' do
35
+ separator = UnitSeparatorBuilder.new(:minutes, {value: 'minutes', singularize: true, singular: 'minute' })
36
+
37
+ assert_equal 'minute', separator.singularize_value
38
+ end
39
+
40
+ it 'does not singularize if no singular value is given' do
41
+ separator = UnitSeparatorBuilder.new(:minutes, {value: 'minutes', singularize: true })
42
+
43
+ assert_equal 'minutes', separator.singularize_value
44
+ end
45
+
46
+ it 'does not singularize when disabled' do
47
+ separator = UnitSeparatorBuilder.new(:minutes, {value: 'minutes', singularize: false, singular: 'minute' })
48
+
49
+ assert_equal 'minutes', separator.singularize_value
50
+ end
51
+
52
+ it 'creates html' do
53
+ expected = '<span class="separator minutes" data-singular="m" data-plural="m">m</span>'
54
+
55
+ assert_equal expected, @separator.to_html
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module BottleRocket
4
+ module ViewHelpers
5
+ class ViewHelpersTest < TestCase
6
+
7
+ before do
8
+ @view = FakeView.new
9
+ end
10
+
11
+ it 'creates a default 24h countdown' do
12
+ from = Time.now
13
+ to = from + 1
14
+
15
+ assert @view.countdown(from: from, to: to).is_a?(String)
16
+ end
17
+
18
+ it 'creates a default 24h countup' do
19
+ from = Time.now
20
+ to = from + 1
21
+
22
+ assert @view.countup(from: from, to: to).is_a?(String)
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'minitest/reporters'
4
+ require 'bottle_rocket'
5
+
6
+ #MiniTest::Reporters.use!
7
+
8
+ class TestCase < Minitest::Spec
9
+ end
10
+
11
+ class FakeView
12
+ include ::BottleRocket::ViewHelpers
13
+ end
@@ -0,0 +1,2 @@
1
+ // Javascript goes in here
2
+ alert("test");
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bottle_rocket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Busold
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Work in progress! Adds a countdown to your views. Countdown is updated
56
+ via JavaScript.
57
+ email:
58
+ - an.bu@gmx.net
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .idea/.name
65
+ - .idea/.rakeTasks
66
+ - .idea/bottle_rocket.iml
67
+ - .idea/encodings.xml
68
+ - .idea/misc.xml
69
+ - .idea/modules.xml
70
+ - .idea/scopes/scope_settings.xml
71
+ - .idea/vcs.xml
72
+ - .idea/workspace.xml
73
+ - .ruby-gemset
74
+ - .ruby-version
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bottle_rocket.gemspec
81
+ - lib/bottle_rocket.rb
82
+ - lib/bottle_rocket/content_tag.rb
83
+ - lib/bottle_rocket/engine.rb
84
+ - lib/bottle_rocket/railtie.rb
85
+ - lib/bottle_rocket/tag_builders.rb
86
+ - lib/bottle_rocket/tag_builders/countdown_builder.rb
87
+ - lib/bottle_rocket/tag_builders/time_unit_builder.rb
88
+ - lib/bottle_rocket/tag_builders/unit_container_builder.rb
89
+ - lib/bottle_rocket/tag_builders/unit_separator_builder.rb
90
+ - lib/bottle_rocket/version.rb
91
+ - lib/bottle_rocket/view_helpers.rb
92
+ - lib/generators/bottle_rocket/install/install_generator.rb
93
+ - test/bottle_rocket/content_tag_test.rb
94
+ - test/bottle_rocket/tag_builders/countdown_builder_test.rb
95
+ - test/bottle_rocket/tag_builders/time_unit_builder_test.rb
96
+ - test/bottle_rocket/tag_builders/unit_container_builder_test.rb
97
+ - test/bottle_rocket/tag_builders/unit_separator_builder_test.rb
98
+ - test/bottle_rocket/view_helpers_test.rb
99
+ - test/test_helper.rb
100
+ - vendor/assets/javascripts/countdown.js
101
+ homepage: https://github.com/neopoly/bottle_rocket
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.0
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Work in progress! Adds a countdown to your views. Countdown is updated via
125
+ JavaScript.
126
+ test_files:
127
+ - test/bottle_rocket/content_tag_test.rb
128
+ - test/bottle_rocket/tag_builders/countdown_builder_test.rb
129
+ - test/bottle_rocket/tag_builders/time_unit_builder_test.rb
130
+ - test/bottle_rocket/tag_builders/unit_container_builder_test.rb
131
+ - test/bottle_rocket/tag_builders/unit_separator_builder_test.rb
132
+ - test/bottle_rocket/view_helpers_test.rb
133
+ - test/test_helper.rb