date_from_now_in_words 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 62bb3e05e5187f501a7d256afc58fcf6a1e47687
4
+ data.tar.gz: 651289497bbb1a8270148fd8dfbe664ff98da6e4
5
+ SHA512:
6
+ metadata.gz: 1fd7d8128f030dacf2309635fdd5797cb32543639eb62d22854a5eb3cc2bdb65e5b2e9945eb74f85df23b4f52483443e3c12ee1620600599eee2866d191c4e8c
7
+ data.tar.gz: 565e7e030e4226ff45cef07ba64a7e72b6861ecaf826e4312470dd82ec9255c0596a2897ffda8be3fd746529e67a825446ed449695586a96e917b41be9ab6b2b
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in date_from_now_in_words.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kevcha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # DateFromNowInWords
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/date_from_now_in_words`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'date_from_now_in_words'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install date_from_now_in_words
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/date_from_now_in_words.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "date_from_now_in_words"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ en:
2
+ date:
3
+ distance_in_words:
4
+ x_years_ago:
5
+ one: "about 1 year ago"
6
+ other: "about %{count} years ago"
7
+ x_months_ago:
8
+ one: "about 1 month ago"
9
+ other: "about %{count} months ago"
10
+ x_days_ago: "%{count} days ago"
11
+ last_x: "last %{day}"
12
+ yesterday: "yesterday"
13
+ today: "today"
14
+ tomorrow: "tomorrow"
15
+ next_x: "next %{day}"
16
+ in_x_days: "in %{count} days"
17
+ in_x_months:
18
+ one: "in about 1 month"
19
+ other: "in about %{count} months"
20
+ in_x_years:
21
+ one: "in about 1 year"
22
+ other: "in about %{count} years"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'date_from_now_in_words/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'date_from_now_in_words'
8
+ spec.version = DateFromNowInWords::VERSION
9
+ spec.authors = ['Kévin Chavanne']
10
+ spec.email = ['kevin@craftsmen.io']
11
+
12
+ spec.summary = 'date_from_now_in_words rails helper'
13
+ spec.description = 'Adds a date_from_now_in_words helper for rails similar to time_ago_in_words built in one.'
14
+ spec.homepage = 'http://github.com/kevcha/date_from_now_in_words'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.4'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ require 'date_from_now_in_words/version'
5
+ require 'date_from_now_in_words/view_helpers'
6
+ require 'date_from_now_in_words/railtie' if defined?(Rails)
7
+
8
+ I18n.load_path << File.expand_path(File.dirname(__FILE__) + '/../config/locales/en.yml')
@@ -0,0 +1,9 @@
1
+ require 'date_from_now_in_words/view_helpers'
2
+
3
+ module DateFromNowInWords
4
+ class Railtie < Rails::Railtie
5
+ initializer 'date_from_now_in_words.view_helpers' do
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module DateFromNowInWords
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,66 @@
1
+ module DateFromNowInWords
2
+ module ViewHelpers
3
+ def date_from_now_in_words(to_date = 0, options = {})
4
+ options = {
5
+ scope: :'date.distance_in_words'
6
+ }.merge!(options)
7
+
8
+ from_date = Date.current
9
+ to_date = to_date.to_date if to_date.respond_to?(:to_date)
10
+ distance_in_days = to_date - from_date
11
+
12
+ I18n.with_options(options) do |locale|
13
+ case distance_in_days
14
+ when -344..-29
15
+ locale.t(
16
+ :x_months_ago,
17
+ count: (distance_in_days / 30.0).round.abs
18
+ )
19
+ when -28..-8
20
+ locale.t(
21
+ :x_days_ago,
22
+ count: distance_in_days.round.abs
23
+ )
24
+ when -7..-2
25
+ locale.t(
26
+ :last_x,
27
+ day: I18n.t('date.day_names')[to_date.wday].downcase
28
+ )
29
+ when -1
30
+ locale.t(:yesterday)
31
+ when 0
32
+ locale.t(:today)
33
+ when 1
34
+ locale.t(:tomorrow)
35
+ when 2..7
36
+ locale.t(
37
+ :next_x,
38
+ day: I18n.t('date.day_names')[to_date.wday].downcase
39
+ )
40
+ when 8..28
41
+ locale.t(
42
+ :in_x_days,
43
+ count: distance_in_days.round
44
+ )
45
+ when 29..344
46
+ locale.t(
47
+ :in_x_months,
48
+ count: (distance_in_days / 30.0).round
49
+ )
50
+ else
51
+ if distance_in_days > 0
52
+ locale.t(
53
+ :in_x_years,
54
+ count: (distance_in_days / 365).round
55
+ )
56
+ else
57
+ locale.t(
58
+ :x_years_ago,
59
+ count: (distance_in_days / 365).round.abs
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: date_from_now_in_words
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kévin Chavanne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.2.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.2.4
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.11'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.11'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: Adds a date_from_now_in_words helper for rails similar to time_ago_in_words
76
+ built in one.
77
+ email:
78
+ - kevin@craftsmen.io
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - ".rspec"
85
+ - ".travis.yml"
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - config/locales/en.yml
93
+ - date_from_now_in_words.gemspec
94
+ - lib/date_from_now_in_words.rb
95
+ - lib/date_from_now_in_words/railtie.rb
96
+ - lib/date_from_now_in_words/version.rb
97
+ - lib/date_from_now_in_words/view_helpers.rb
98
+ homepage: http://github.com/kevcha/date_from_now_in_words
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: date_from_now_in_words rails helper
122
+ test_files: []