Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for HTML5 time tag #816

Closed
wants to merge 1 commit into from

4 participants

@Cirex

If this is an acceptable patch I will write tests for it when I can. You can find additional examples in the Yard comments

en:
  time:
    formats:
      full: '%B %d, %Y @ %I:%M:%S %p'
time_tag(pull_request.created_at, :format => :full)

Would output:

<time datetime="2012-03-29T01:12:01Z">
  March 29, 2012 @ 01:12:01 AM
</time>
@DAddYE
Owner

Thanks! @nesquena ?

@nesquena
Owner

Yep I will take a look

@nesquena
Owner

@Cirex I like this and would like support for it but can you add a test or two and I will merge it in.

@DAddYE
Owner

@Cirex please add one or more tests so we can merge it. Thank you man!

@marcosdsanchez marcosdsanchez commented on the diff
padrino-helpers/lib/padrino-helpers/tag_helpers.rb
((21 lines not shown))
+ # time_tag(comment.created_at)
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => March 28, 2012 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, :pubdate => true)
+ # # => <time datetime="2012-03-28T17:56:23Z" pubdate>
+ # # => March 28, 2012 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, :format => :short)
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => 28 Mar 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, 'Less then a minute ago')

"Less then ... " should instead be "Less than..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@DAddYE
Owner

@Cirex test please ;)

@DAddYE
Owner

Request a pull request after test. Thanks so much @Cirex

@DAddYE DAddYE closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2012
  1. Support for HTML5 time tag

    Benjamin Bloch authored
This page is out of date. Refresh to see the latest.
Showing with 59 additions and 1 deletion.
  1. +59 −1 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
View
60 padrino-helpers/lib/padrino-helpers/tag_helpers.rb
@@ -25,7 +25,8 @@ module TagHelpers
:muted,
:readonly,
:required,
- :selected
+ :selected,
+ :pubdate
]
##
@@ -171,6 +172,63 @@ def input_tag(type, options = {})
end
##
+ # Creates an HTML time tag with the given time and options
+ #
+ # @param [Date, Time] time
+ # The time to be used in this tag
+ # @param [String] content
+ # The content inside of the the tag
+ # @param [Hash] options
+ # The HTML options to include in this tag
+ # @param [Proc] block
+ # The block returning HTML content
+ #
+ # @macro global_html_attributes
+ #
+ # @return [String]
+ # Generated HTML with specified +options+
+ #
+ # @example
+ # time_tag(comment.created_at)
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => March 28, 2012 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, :pubdate => true)
+ # # => <time datetime="2012-03-28T17:56:23Z" pubdate>
+ # # => March 28, 2012 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, :format => :short)
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => 28 Mar 14:02
+ # # => </time>
+ #
+ # time_tag(comment.created_at, 'Less then a minute ago')

"Less then ... " should instead be "Less than..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => Less then a minute ago
+ # # => </time>
+ #
+ # time_tag(comment.created_at) { 'Less then a minute ago' }
+ # # => <time datetime="2012-03-28T17:56:23Z">
+ # # => Less then a minute ago
+ # # => </time>
+ #
+ # @api public
+ def time_tag(time, *args, &block)
+ options = args.extract_options!
+ options.reverse_merge!(:datetime => time.utc.iso8601)
+
+ if block_given?
+ content_tag(:time, options, &block)
+ else
+ format = options.delete(:format) || :long
+ content = args.shift || localize(time, :format => format)
+ content_tag(:time, content, options)
+ end
+ end
+
+ ##
# Creates an HTML tag with the given name and options
#
# @param [Symbol] name
Something went wrong with that request. Please try again.