jekyll-timeago 0.11.1 → 0.12.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cb1b9580a2bff4f79b9aaa8800cd9ef82d0f654
4
- data.tar.gz: '0931603a4e01b5e7e3a2d77c4d15366513260017'
3
+ metadata.gz: f57c4e0c53276d82a61f42b10703c7231c0bb6ab
4
+ data.tar.gz: 4a3df430759408fe8838463d1264557e9080ec66
5
5
  SHA512:
6
- metadata.gz: 344bba34a825cc5441184f09ea54631718e660e14dad850fd140b25afdac0b3cbac0f874ca05def93cecbc9eac9ae8a3a41fdefa3d6a1af4fa6a5d7baac8cd12
7
- data.tar.gz: 025c1ea71723a06f2e00bda1b4efbd879bb7d117a60cd54ca0a76381d01af2b5c8293504aefd0874181c3ffde9dbbbc9f2d6f22b4444a9803dbaf8bb34040846
6
+ metadata.gz: ed67ca75b17804ca091d0f41731cb526622653c3a9a363ce7a9d0edb507b4648fec872ff5b5effa067330b248a0e7cb5688c24d308a4de8751aea369e9606ee5
7
+ data.tar.gz: db9204fdae404fd4e5ebb4f90ebd357cb18621e4f8275ffd147abefd32a008200d375996da4ea6fba82f42068fffbefa2a4ee149eb662fe8c5786bb77dd48e08
data/README.md CHANGED
@@ -10,9 +10,9 @@ Main features:
10
10
 
11
11
  - Compute distance of dates, in words, ie: `1 week and 2 days ago`, `5 months ago`, `in 1 year`
12
12
  - Future times
13
- - Out of the box support for `Jekyll` (`v1`, `v2` and `v3`) projects, available as a Liquid Filter and as a Liquid Tag
14
- - Localization (i18n)
15
- - Level of detail
13
+ - Out of the box support for `Jekyll` projects, available as a Liquid Filter and as a Liquid Tag
14
+ - Localization
15
+ - Level of detail customization
16
16
  - Command line utility
17
17
 
18
18
  In fact, `jekyll-timeago` started as an extension for the [Liquid](https://github.com/Shopify/liquid) template engine, to be used in Jekyll and Octopress backed sites. But actually, you can use it easily in any Ruby project.
@@ -37,41 +37,48 @@ Or install it yourself as:
37
37
 
38
38
  ## Usage
39
39
 
40
- The gem provides the `#timeago` method:
40
+ The gem provides the `timeago` method:
41
41
 
42
42
  ```ruby
43
43
  Jekyll::Timeago.timeago(from, to = Date.today, options = {})
44
44
  ```
45
45
 
46
+ You can include the method in the current context by including the module (so you can call directly the `timeago` method without using the whole scope):
47
+
48
+ ```ruby
49
+ include Jekyll::Timeago
50
+ ```
51
+
46
52
  Examples:
47
53
 
48
54
  ```ruby
49
- >> Jekyll::Timeago.timeago(Date.today)
55
+ >> timeago(Date.today)
50
56
  => "today"
51
- >> Jekyll::Timeago.timeago(Date.today.prev_day)
57
+ >> timeago(Date.today.prev_day)
52
58
  => "yesterday"
53
- >> Jekyll::Timeago.timeago(Date.today.prev_day(10))
59
+ >> timeago(Date.today.prev_day(10))
54
60
  => "1 week and 3 days ago"
55
- >> Jekyll::Timeago.timeago(Date.today.prev_day(100))
61
+ >> timeago(Date.today.prev_day(100))
56
62
  => "3 months and 1 week ago"
57
- >> Jekyll::Timeago.timeago(Date.today.prev_day(500))
63
+ >> timeago(Date.today.prev_day(500))
58
64
  => "1 year and 4 months ago"
59
- >> Jekyll::Timeago.timeago('2010-1-1', '2012-1-1')
65
+ >> timeago('2010-1-1', '2012-1-1')
60
66
  => "2 years ago"
61
- >> Jekyll::Timeago.timeago(Date.today.next_day)
67
+ >> timeago(Date.today.next_day)
62
68
  => "tomorrow"
63
- >> Jekyll::Timeago.timeago(Date.today.next_day(7))
69
+ >> timeago(Date.today.next_day(7))
64
70
  => "in 1 week"
65
- >> Jekyll::Timeago.timeago(Date.today.next_day(1000))
71
+ >> timeago(Date.today.next_day(1000))
66
72
  => "in 2 years and 8 months"
67
73
  ```
68
74
 
69
- **NOTE** If you have the gem installed in your system, and you're not using Bundler (probably because you're are writing a basic script), don't forget to require the library first:
75
+ **NOTE** If you have the gem installed in your system globally, and you're not using Bundler (probably because you're are writing a basic script), don't forget to require the library first:
70
76
 
71
77
  ```ruby
72
78
  require 'jekyll-timeago'
79
+ include Jekyll::Timeago
73
80
 
74
- puts Jekyll::Timeago.timeago('2030-1-1')
81
+ puts timeago('2030-1-1')
75
82
  ```
76
83
 
77
84
  ### Options
@@ -81,26 +88,26 @@ puts Jekyll::Timeago.timeago('2030-1-1')
81
88
  To use a different language:
82
89
 
83
90
  ```ruby
84
- >> Jekyll::Timeago.timeago(Date.today.prev_day(200), locale: :es)
91
+ >> timeago(Date.today.prev_day(200), locale: :es)
85
92
  => "hace 6 meses y 2 semanas"
86
- >> Jekyll::Timeago.timeago(Date.today.prev_day(200), locale: :fr)
93
+ >> timeago(Date.today.prev_day(200), locale: :fr)
87
94
  => "il y a environ 6 mois et 2 semaines"
88
95
  ```
89
96
 
90
- Read more about the localization options [here](#i18n).
97
+ Read more about the localization options [here](#localization).
91
98
 
92
99
  * `depth`
93
100
 
94
101
  You are able to change the level of detail (from 1 up to 4, 2 by default) to get higher or lower granularity:
95
102
 
96
103
  ```ruby
97
- >> Jekyll::Timeago.timeago(Date.today.prev_day(2000), depth: 3)
104
+ >> timeago(Date.today.prev_day(2000), depth: 3)
98
105
  => "5 years, 5 months and 3 weeks ago"
99
- >> Jekyll::Timeago.timeago(Date.today.prev_day(2000), depth: 4)
106
+ >> timeago(Date.today.prev_day(2000), depth: 4)
100
107
  => "5 years, 5 months, 3 weeks and 4 days ago"
101
108
  ```
102
109
 
103
- ## I18n
110
+ ## Localization
104
111
 
105
112
  By default, `jekyll-timego` already provides translations for some languages. You can check the list [here](lib/locales/). However, you are able to provide your own translations, or even override the originals, easily.
106
113
 
@@ -109,14 +116,16 @@ This project uses the [mini_i18n](https://github.com/markets/mini_i18n) gem unde
109
116
  ```ruby
110
117
  MiniI18n.configure do |config|
111
118
  config.load_translations('/path_to_your_translations_files/*.yml')
112
- config.default_locale = :en
119
+ config.default_locale = :es
113
120
  end
114
121
  ```
115
122
 
116
- If you want to contribute and support more languages by default, please feel free to send a pull request.
123
+ If you want to contribute and support more default languages, please feel free to send a pull request.
117
124
 
118
125
  ## CLI
119
126
 
127
+ You can also `jekyll-timeago` from the command line:
128
+
120
129
  ```
121
130
  > jekyll-timeago --help
122
131
  > jekyll-timeago 2016-1-1
@@ -127,7 +136,7 @@ il y a environ 2 années et 6 mois
127
136
 
128
137
  ### Console
129
138
 
130
- Starts a custom IRB session with the `#timeago` method included:
139
+ Starts a custom IRB session with the `timeago` method included:
131
140
 
132
141
  ```
133
142
  > jekyll-timeago --console
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.add_dependency "mini_i18n", '>= 0.4.0'
18
+ spec.add_dependency "mini_i18n", '>= 0.8.0'
19
19
 
20
20
  spec.add_development_dependency "jekyll", ">= 1.5"
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -46,10 +46,6 @@ module Jekyll
46
46
  (1..MAX_DEPTH_LEVEL).include?(depth) ? depth : DEFAULT_DEPTH_LEVEL
47
47
  end
48
48
 
49
- def t(key, options = {})
50
- MiniI18n.translate(key, @options.merge(options))
51
- end
52
-
53
49
  # Days passed to time ago sentence
54
50
  def time_ago_to_now(from, to, depth)
55
51
  days_passed = (to - from).to_i
@@ -63,12 +59,16 @@ module Jekyll
63
59
  sentence = to_sentence(slots)
64
60
 
65
61
  if future
66
- "#{t(:prefix_future)} #{sentence} #{t(:suffix_future)}".strip
62
+ t(:future, date_range: sentence)
67
63
  else
68
- "#{t(:prefix)} #{sentence} #{t(:suffix)}".strip
64
+ t(:past, date_range: sentence)
69
65
  end
70
66
  end
71
67
 
68
+ def t(key, options = {})
69
+ MiniI18n.translate(key, @options.merge(options))
70
+ end
71
+
72
72
  # Builds time ranges: ['1 month', '5 days']
73
73
  # - days_passed: integer in absolute
74
74
  # - depth: level of detail
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Timeago
3
- VERSION = "0.11.1"
3
+ VERSION = "0.12.0"
4
4
  end
5
5
  end
data/lib/locales/de.yml CHANGED
@@ -2,21 +2,19 @@ de:
2
2
  today: 'heute'
3
3
  yesterday: 'gestern'
4
4
  tomorrow: 'morgen'
5
+ past: '%{date_range} zuvor'
6
+ future: 'in %{date_range}'
5
7
  last_word_connector: 'und'
6
8
  words_connector: ', '
7
- suffix: 'zuvor'
8
- prefix: ''
9
- suffix_future: ''
10
- prefix_future: 'in'
11
9
  years:
12
10
  one: '1 Jahr'
13
- many: "%{count} Jahre"
11
+ other: "%{count} Jahre"
14
12
  months:
15
13
  one: '1 Monat'
16
- many: '%{count} Monate'
14
+ other: '%{count} Monate'
17
15
  weeks:
18
16
  one: '1 Woche'
19
- many: '%{count} Wochen'
17
+ other: '%{count} Wochen'
20
18
  days:
21
19
  one: '1 Tag'
22
- many: '%{count} Tage'
20
+ other: '%{count} Tage'
data/lib/locales/en.yml CHANGED
@@ -2,21 +2,19 @@ en:
2
2
  today: 'today'
3
3
  yesterday: 'yesterday'
4
4
  tomorrow: 'tomorrow'
5
+ past: '%{date_range} ago'
6
+ future: 'in %{date_range}'
5
7
  last_word_connector: 'and'
6
8
  words_connector: ', '
7
- suffix: 'ago'
8
- prefix: ''
9
- suffix_future: ''
10
- prefix_future: 'in'
11
9
  years:
12
10
  one: '1 year'
13
- many: "%{count} years"
11
+ other: "%{count} years"
14
12
  months:
15
13
  one: '1 month'
16
- many: '%{count} months'
14
+ other: '%{count} months'
17
15
  weeks:
18
16
  one: '1 week'
19
- many: '%{count} weeks'
17
+ other: '%{count} weeks'
20
18
  days:
21
19
  one: '1 day'
22
- many: '%{count} days'
20
+ other: '%{count} days'
data/lib/locales/es.yml CHANGED
@@ -2,21 +2,19 @@ es:
2
2
  today: 'hoy'
3
3
  yesterday: 'ayer'
4
4
  tomorrow: 'mañana'
5
+ past: 'hace %{date_range}'
6
+ future: 'en %{date_range}'
5
7
  last_word_connector: 'y'
6
8
  words_connector: ', '
7
- suffix: ''
8
- prefix: 'hace'
9
- suffix_future: ''
10
- prefix_future: 'en'
11
9
  years:
12
10
  one: '1 año'
13
- many: "%{count} años"
11
+ other: "%{count} años"
14
12
  months:
15
13
  one: '1 mes'
16
- many: '%{count} meses'
14
+ other: '%{count} meses'
17
15
  weeks:
18
16
  one: '1 semana'
19
- many: '%{count} semanas'
17
+ other: '%{count} semanas'
20
18
  days:
21
19
  one: '1 día'
22
- many: '%{count} días'
20
+ other: '%{count} días'
data/lib/locales/fr.yml CHANGED
@@ -2,21 +2,19 @@ fr:
2
2
  today: "aujourd'hui"
3
3
  yesterday: 'hier'
4
4
  tomorrow: 'demain'
5
+ past: 'il y a environ %{date_range}'
6
+ future: 'dans %{date_range}'
5
7
  last_word_connector: 'et'
6
8
  words_connector: ', '
7
- suffix: ''
8
- prefix: 'il y a environ'
9
- suffix_future: ''
10
- prefix_future: 'dans'
11
9
  years:
12
10
  one: '1 année'
13
- many: "%{count} années"
11
+ other: "%{count} années"
14
12
  months:
15
13
  one: '1 mois'
16
- many: '%{count} mois'
14
+ other: '%{count} mois'
17
15
  weeks:
18
16
  one: '1 semaine'
19
- many: '%{count} semaines'
17
+ other: '%{count} semaines'
20
18
  days:
21
19
  one: '1 jour'
22
- many: '%{count} jours'
20
+ other: '%{count} jours'
data/lib/locales/it.yml CHANGED
@@ -2,21 +2,19 @@ it:
2
2
  today: 'oggi'
3
3
  yesterday: 'ieri'
4
4
  tomorrow: 'domani'
5
+ past: '%{date_range} fa'
6
+ future: 'fra %{date_range}'
5
7
  last_word_connector: 'e'
6
8
  words_connector: ', '
7
- suffix: 'fa'
8
- prefix: ''
9
- suffix_future: ''
10
- prefix_future: 'fra'
11
9
  years:
12
10
  one: '1 anno'
13
- many: "%{count} anni"
11
+ other: "%{count} anni"
14
12
  months:
15
13
  one: '1 mese'
16
- many: '%{count} mesi'
14
+ other: '%{count} mesi'
17
15
  weeks:
18
16
  one: '1 settimana'
19
- many: '%{count} settimane'
17
+ other: '%{count} settimane'
20
18
  days:
21
19
  one: '1 giorno'
22
- many: '%{count} giorni'
20
+ other: '%{count} giorni'
data/lib/locales/pt.yml CHANGED
@@ -2,21 +2,19 @@ pt:
2
2
  today: 'hoje'
3
3
  yesterday: 'ontem'
4
4
  tomorrow: 'amanhã'
5
+ past: '%{date_range} atrás'
6
+ future: 'em %{date_range}'
5
7
  last_word_connector: 'e'
6
8
  words_connector: ', '
7
- suffix: 'atrás'
8
- prefix: ''
9
- suffix_future: ''
10
- prefix_future: 'em'
11
9
  years:
12
10
  one: '1 ano'
13
- many: "%{count} anos"
11
+ other: "%{count} anos"
14
12
  months:
15
13
  one: '1 mês'
16
- many: '%{count} meses'
14
+ other: '%{count} meses'
17
15
  weeks:
18
16
  one: '1 semana'
19
- many: '%{count} semanas'
17
+ other: '%{count} semanas'
20
18
  days:
21
19
  one: '1 dia'
22
- many: '%{count} dias'
20
+ other: '%{count} dias'
@@ -1,2 +1,2 @@
1
1
  es:
2
- prefix: ''
2
+ past: '%{date_range}'
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require 'jekyll-timeago'
4
4
 
5
5
  RSpec.configure do |config|
6
6
  config.order = :random
7
+ config.include Jekyll::Timeago
7
8
 
8
9
  SOURCE_DIR = File.expand_path('../source', __FILE__)
9
10
  DEST_DIR = File.expand_path('../_site', __FILE__)
@@ -21,8 +22,4 @@ RSpec.configure do |config|
21
22
  def configuration_file
22
23
  YAML.load_file(File.join(SOURCE_DIR, '_config.yml'))
23
24
  end
24
-
25
- def timeago(from, to = Date.today, options = {})
26
- Jekyll::Timeago.timeago(from, to, options)
27
- end
28
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-timeago
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-04 00:00:00.000000000 Z
11
+ date: 2018-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_i18n
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.0
19
+ version: 0.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.0
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jekyll
29
29
  requirement: !ruby/object:Gem::Requirement