Giter VIP home page Giter VIP logo

semantic_date_time_tags's Introduction

Semantic DateTime Tags

Gem Version

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.

This allows, for example, highlighting today's dates:

time.date.semantic.current_date {
  background-color: yellow;
}

Hiding current year via CSS:

time.date.semantic.current_year {
  span.year {
    display: none;
  }
}

Or, in the case of date ranges, avoiding repetition of year in both dates:

span.date_range.semantic.same_year {
  time.date.semantic.from {
    span.year {
      display: none;
    }
  }
}

See the included SCSS example for more.

Installation

Add this line to your application's Gemfile:

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:

/*
 *= require 'semantic_date_time_tags/default'
 */

Or if you like to use some of the mixins, import them like this:

@import "semantic_date_time_tags/partials/mixins";

Usage

In your views:

Date

<%= semantic_date_tag(Date.today) %>

Will result in the following markup:

<time class="date semantic current_date current_year" datetime="2014-09-26">
  <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
</time>

DateTime

<%= semantic_date_time_tag(DateTime.now) %>

Will result in the following markup:

<time class="date_time semantic current_date current_year" datetime="2014-09-26T15:35:56+02:00">
  <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span> <span class="hours H">15</span><span class="sep">:</span><span class="minutes M">35</span>
</time>

Date Range

<%= semantic_date_range_tag(Date.today, Date.tomorrow) %>

Will result in the following markup:

<span class="date_range semantic same_year same_month">
  <time class="date semantic current_date current_year from">
    <span class="day d">26</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
  </time>
  <span class="date_range_separator"></span>
  <time class="date semantic current_year to">
    <span class="day d">27</span><span class="sep">.</span><span class="month m">9</span><span class="sep">.</span><span class="year Y">2014</span>
  </time>
</span>

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

semantic_date_time_tags's People

Contributors

tomasc avatar sebastianlyserena avatar

Stargazers

Jakub Straka avatar Alexander ADAM avatar

Watchers

 avatar James Cloos avatar Asger Behncke Jacobsen avatar  avatar

semantic_date_time_tags's Issues

Spaces not properly marked as separators

When using a format where date, month and year are separated by spaces, the spaces are not marked as separators.

They should be marked the same as other separators (., , / etc.):

<span class="separator"> </span>

AM / PM is registered as separator

When using AM/PM for Time displays:

en:
  time:
    formats:
      full: "%I.%M %p"

AM/PM is tagged as a separator:

<time class="semantic time whole_hour whole_minute">
<span class="hours I">10</span><span class="sep">.</span><span class="minutes M">00</span> <span class="sep">AM</span>
</time>

The day format %A is not parsed

%A which displays the name of the day (e.g. Saturday) is currently not being parsed.

Should be parsed as day, or perhaps even day_name?

Multiple components of the same type messes up the parser

When using the following format

"%A %b %-d, %Y %y"

The result is this

<time datetime="2015-07-16" class="semantic date current_date current_year">
  <span class="month b">Thursday</span>
  <span class="sep"> </span>
  <span class="day d">Jul</span>
  <span class="sep">, </span>
  <span class="year Y">6</span>
</time>

It seems having multiple of the same component (in this case the day and year twice) will mess up the output.

Allow passing locale scope to tags

Would be nice to be able to do this:

semantic_date_tag(date, :events)

Which would then fetch the locale from that scope

en:
  events:
    date:
      formats:
        full: "%-d.%-m.%Y"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.