Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
swordray committed Mar 18, 2014
1 parent 86da040 commit 850d11b
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.bundle
.config
coverage
Gemfile.lock
InstalledFiles
lib/bundler/man
pkg
Expand Down
Empty file added .travis.yml
Empty file.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gemspec

gem 'rake'
2 changes: 1 addition & 1 deletion LICENSE
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
Expand Down
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
datetime_tag
============
# datetime_tag_helper

[![Gem Version](https://badge.fury.io/rb/datetime_tag_helper.png)](http://badge.fury.io/rb/datetime_tag_helper) [![Build Status](https://secure.travis-ci.org/swordray/datetime_tag_helper.png?branch=master)](http://travis-ci.org/swordray/datetime_tag_helper) [![Dependency Status](https://gemnasium.com/swordray/datetime_tag_helper.png?travis)](https://gemnasium.com/swordray/datetime_tag_helper) [![Code Climate](https://codeclimate.com/github/swordray/datetime_tag_helper.png)](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).
3 changes: 3 additions & 0 deletions Rakefile
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
23 changes: 23 additions & 0 deletions datetime_tag_helper.gemspec
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
13 changes: 13 additions & 0 deletions lib/action_view/helpers/datetime_tag_helper.rb
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
4 changes: 4 additions & 0 deletions lib/datetime_tag_helper.rb
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
3 changes: 3 additions & 0 deletions lib/datetime_tag_helper/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module DatetimeTagHelper #:nodoc:
VERSION = '0.0.1'
end

0 comments on commit 850d11b

Please sign in to comment.