https://github.com/tomasc/semantic_date_time_tags
Rails helpers for handling dates and time.
https://github.com/tomasc/semantic_date_time_tags
Last synced: about 1 year ago
JSON representation
Rails helpers for handling dates and time.
- Host: GitHub
- URL: https://github.com/tomasc/semantic_date_time_tags
- Owner: tomasc
- License: mit
- Created: 2014-08-14T07:21:48.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2025-04-02T12:25:31.000Z (about 1 year ago)
- Last Synced: 2025-04-02T13:27:03.145Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 119 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Semantic DateTime Tags
[](http://badge.fury.io/rb/semantic_date_time_tags)
Set of Rails helpers that mark up Date, DateTime instances and their ranges with sensible combination of (html5) tags, data attributes and CSS classes so that their display can be easily controlled via CSS.
The generated markup takes into account Date/Time formats as specified in the [I18n localizations](http://guides.rubyonrails.org/i18n.html#adding-date-time-formats).
This allows, for example, highlighting today's dates:
```css
time.date.semantic.current_date {
background-color: yellow;
}
```
Hiding current year via CSS:
```css
time.date.semantic.current_year {
span.year {
display: none;
}
}
```
Or, in the case of date ranges, avoiding repetition of year in both dates:
```css
span.date_range.semantic.same_year {
time.date.semantic.from {
span.year {
display: none;
}
}
}
```
See the included [SCSS example](/lib/assets/stylesheets/semantic_date_time_tags.css.scss) for more.
## Installation
Add this line to your application's Gemfile:
```Ruby
gem 'semantic_date_time_tags'
```
And then execute:
```
$ bundle
```
Or install it yourself as:
```
$ gem install semantic_date_time_tags
```
If you want to use the default css you can include it like this:
```css
/*
*= require 'semantic_date_time_tags/default'
*/
```
Or if you like to use some of the mixins, import them like this:
```scss
@import "semantic_date_time_tags/partials/mixins";
```
## Usage
In your views:
### Date
```Ruby
<%= semantic_date_tag(Date.today) %>
```
Will result in the following markup:
```HTML
```
### DateTime
```Ruby
<%= semantic_date_time_tag(DateTime.now) %>
```
Will result in the following markup:
```HTML
```
### Date Range
```Ruby
<%= semantic_date_range_tag(Date.today, Date.tomorrow) %>
```
Will result in the following markup:
```HTML
–
```
## Contributing
1. Fork it ( https://github.com/tomasc/semantic_date_time_tags/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request