-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
.bundle | ||
.config | ||
coverage | ||
Gemfile.lock | ||
InstalledFiles | ||
lib/bundler/man | ||
pkg | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
gem 'rake' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 肖剑秋 | ||
Copyright (c) 2014 Jianqiu Xiao <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
datetime_tag | ||
============ | ||
# datetime_tag_helper | ||
|
||
[](http://badge.fury.io/rb/datetime_tag_helper) [](http://travis-ci.org/swordray/datetime_tag_helper) [](https://gemnasium.com/swordray/datetime_tag_helper) [](https://codeclimate.com/github/swordray/datetime_tag_helper) | ||
|
||
ActionView Datetime Tag Helper | ||
|
||
## Requirements | ||
|
||
* Ruby ~> 2.0 | ||
* Rails | ||
|
||
## Installation | ||
|
||
Include the gem in your Gemfile: | ||
|
||
```ruby | ||
gem 'datetime_tag_helper' | ||
``` | ||
|
||
## Usage | ||
|
||
```ruby | ||
datetime_tag(time) | ||
``` | ||
|
||
## Examples | ||
|
||
```ruby | ||
= datetime_tag Time.now | ||
# => <span title="2014-03-18 19:24:24" class="datetime datetime_ago">less than a minute</span> | ||
``` | ||
```ruby | ||
= datetime_tag 5.hours.ago | ||
# => <span title="2014-03-18 06:24:24" class="datetime datetime_ago">about 5 hours</span> | ||
``` | ||
```ruby | ||
= datetime_tag 3.days.from_now | ||
# => <span title="2014-03-21 11:24:24" class="datetime datetime_from_now">3 days</span> | ||
``` | ||
|
||
## Credits | ||
|
||
* swordray @[ihaveu](http://www.ihaveu.com/home) @[shuhai](http://tw.shuhai.org/) @[leaf](http://leaf.iacger.com) | ||
|
||
## License | ||
|
||
Copyright © 2014 Jianqiu Xiao <[email protected]> under The [MIT License](http://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
task :default do |t| | ||
`gem build datetime_tag_helper.gemspec` | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$LOAD_PATH.push File.expand_path("../lib", __FILE__) | ||
require 'datetime_tag_helper/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "datetime_tag_helper" | ||
s.version = DatetimeTagHelper::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.author = ["Jianqiu Xiao"] | ||
s.email = ["[email protected]"] | ||
s.homepage = "https://github.com/swordray/datetime_tag_helper" | ||
s.summary = "ActionView Datetime Tag Helper" | ||
s.description = "ActionView Datetime Tag Helper." | ||
s.license = "MIT" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
s.required_ruby_version = "~> 2.0" | ||
|
||
s.add_dependency 'rails' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'action_view/helpers' | ||
|
||
module ActionView | ||
module Helpers | ||
# = Action View I18n Datetime Span Tag Helper | ||
module DatetimeTagHelper | ||
# Creates a span tag of the given +time+ with I18n time_ago_in_words format. | ||
def datetime_tag(time) | ||
content_tag(:span, time_ago_in_words(time), title: time.to_s(:db), class: (time.to_time > Time.now ? 'datetime datetime_from_now' : 'datetime datetime_ago')) if time.respond_to?(:to_time) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "action_view" | ||
require "action_view/helpers/datetime_tag_helper" | ||
|
||
ActionView::Base.send :include, ActionView::Helpers::DatetimeTagHelper if defined? Rails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module DatetimeTagHelper #:nodoc: | ||
VERSION = '0.0.1' | ||
end |