timepiece 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ca9f94a35c0ae355e6f8ad7f12ca5c6a88d90fd
4
- data.tar.gz: dad6b9ec23757434e6867f20d32a44d45d110403
3
+ metadata.gz: cffcf03a2b5b2bc7a97ae5d4efce3eba8dce7064
4
+ data.tar.gz: b56e96e36cebba51284288a3cda1a5324b7f054a
5
5
  SHA512:
6
- metadata.gz: 8aa986e4724d935119c8382ac45c93ae5324c517cd21ad0ab97e0177c214faa78ee1f316df3a69ce83cab03f247b7a10fd46b3d74cbb82dab804d2acc268037c
7
- data.tar.gz: 3678591c6d6af7f2c24050282041f1ccdda34c53788c347e6049461c726006c8f8a8612861ea5dffbaf7291c90f293bb194822a842ad2d00027e40277b6f2e54
6
+ metadata.gz: 1c5d907b73e131e18bc293dd54369367e06a40d458ea6010045068f5050720cd89db7d6184ed2995c56b4941a3e76dd87f739fbc3c24574f406c3a45677eff94
7
+ data.tar.gz: ff1df9a38af7bd9a094aa97ef07acd9204471e387d9c5c209eb41e50ea200555972caf3401795115ded59dbe0dad2b22c506039a9c7c96ab08243f9ef60eca27
@@ -1,10 +1,10 @@
1
1
  {<img src="https://badge.fury.io/rb/timepiece.svg" alt="Gem Version" />}[http://badge.fury.io/rb/timepiece]
2
2
 
3
- ## Timepiece
3
+ = Timepiece
4
4
 
5
5
  Timepiece is a Rails plugin providing a simple digital clock, accurate to your server's time and maintained by jQuery.
6
6
 
7
- ## Installation
7
+ == Installation
8
8
 
9
9
  1. Add Timepiece to your application's Gemfile
10
10
 
@@ -14,7 +14,7 @@ Timepiece is a Rails plugin providing a simple digital clock, accurate to your s
14
14
 
15
15
  //= require timepiece
16
16
 
17
- ## Usage
17
+ == Usage
18
18
 
19
19
  * Add a functional clock to your views
20
20
 
@@ -24,6 +24,30 @@ Timepiece is a Rails plugin providing a simple digital clock, accurate to your s
24
24
 
25
25
  <%= timepiece('London') %>
26
26
 
27
- * By default, Timepiece shows a 24 hour digital clock. You can show a 12 hour clock by specifying it explicitly.
27
+ * Show a 12 hour clock by specifying it explicitly
28
28
 
29
29
  <%= timepiece('London', '12') %>
30
+
31
+ By default the 12 hour clock displays time without any leading character, in the format '1:23pm'. You can add either a zero, as present on the 24 hour clock, or a leading space character the size of a numerical digit - useful for keeping your clocks aligned.
32
+
33
+ * To add a leading zero to hour values less than ten
34
+
35
+ <%= timepiece('London', '12', '0') %>
36
+
37
+ or
38
+
39
+ <%= timepiece('London', '12', 'zero') %>
40
+
41
+ * To add a space character
42
+
43
+ <%= timepiece('London', '12', '_') %>
44
+
45
+ or
46
+
47
+ <%= timepiece('London', '12', 'space') %>
48
+
49
+ You can apply your own styles to any part of the Timepiece clock. For instance, you can capitalize the AM/PM abbreviation by targeting the span with class 'timepiece-abbr'. By default, the abbreviations are displayed without punctuation. To add punctuation, you can specify it in the options.
50
+
51
+ * Add punctuation to am/pm abbreviation
52
+
53
+ <%= timepiece('London', '12', '0', '.') %>
@@ -53,7 +53,16 @@ function show_time(){
53
53
  $(e).data('hours', hours[i])
54
54
  abbr = 'am'
55
55
  }
56
- $('.timepiece-hours', $(e)).html(( $(e).data('hours') < 10 ? "0" : "" ) + $(e).data('hours'));
56
+ if($(e).attr("data-abbr_separator") == '.'){
57
+ abbr = abbr.replace(/([apm])/g, '$1.')
58
+ }
59
+ if($(e).attr("data-lead") == '0' || $(e).attr("data-lead") == 'zero' ){
60
+ $('.timepiece-hours', $(e)).html(( $(e).data('hours') < 10 ? "0" : "" ) + $(e).data('hours'));
61
+ }else if($(e).attr("data-lead") == '_' || $(e).attr("data-lead") == 'space' ){
62
+ $('.timepiece-hours', $(e)).html(( $(e).data('hours') < 10 ? "&#8199;" : "" ) + $(e).data('hours'));
63
+ }else{
64
+ $('.timepiece-hours', $(e)).html($(e).data('hours'));
65
+ }
57
66
  $('.timepiece-minutes', $(e)).html(( minutes[i] < 10 ? "0" : "" ) + minutes[i]);
58
67
  $('.timepiece-seconds', $(e)).html(( seconds[i] < 10 ? "0" : "" ) + seconds[i]);
59
68
  $('.timepiece-abbr', $(e)).html(abbr);
@@ -1,23 +1,33 @@
1
1
  module TimepieceHelper
2
- def timepiece(location = 'UTC', type = '24')
2
+ def timepiece(location = 'UTC', type = '24', lead = 'none', abbr_sep = 'none')
3
3
  Time.zone = location
4
4
  hours = Time.now.in_time_zone.strftime('%H')
5
5
  minutes = Time.now.in_time_zone.strftime('%M')
6
6
  seconds = Time.now.in_time_zone.strftime('%S')
7
- if type == '12' && hours.to_i > 12
8
- hours = hours.to_i - 12
7
+ if type == '12'
8
+ hours = hours.to_i
9
+ if hours > 12
10
+ hours = hours - 12
11
+ var = 'pm'
12
+ elsif hours == 0
13
+ hours = 12
14
+ var = 'am'
15
+ elsif hours == 12
16
+ var = 'pm'
17
+ elsif hours < 12
18
+ var = 'am'
19
+ end
9
20
  if hours < 10
10
- hours = '0' + hours.to_s
21
+ if lead == '0' || lead == 'zero'
22
+ hours = '0' + hours.to_s
23
+ elsif lead == '_' || lead == 'space'
24
+ hours = '&#8199;' + hours.to_s
25
+ end
11
26
  end
12
- var = 'pm'
13
- elsif type == '12' && hours.to_i == 0
14
- hours = 12
15
- var = 'am'
16
- elsif type == '12' && hours.to_i == 12
17
- var = 'pm'
18
- elsif type == '12' && hours.to_i < 12
19
- var = 'am'
20
- end
27
+ if abbr_sep == '.'
28
+ var = var.gsub(/([apm])/, '\1.')
29
+ end
30
+ end
21
31
  time = "<span class='timepiece-hours'>#{hours}</span>"\
22
32
  "<span class='timepiece-separator tp-separator-1'>:</span>"\
23
33
  "<span class='timepiece-minutes'>#{minutes}</span>"\
@@ -26,6 +36,6 @@ module TimepieceHelper
26
36
  if type == '12'
27
37
  time = time + "<span class='timepiece-abbr timepiece-abbr-#{var}'>#{var}</span>"
28
38
  end
29
- content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type)
39
+ content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type, 'data-lead' => lead, 'data-abbr_separator' => abbr_sep)
30
40
  end
31
41
  end
@@ -1,3 +1,3 @@
1
1
  module Timepiece
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timepiece
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom Bruce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails