public
Rubygem
Description: Uses client-side Javascript to format a datetime instead of the Ruby on Rails server.
Homepage: http://www.disruptiveagility.com/plugin/client_date
Clone URL: git://github.com/ryanlowe/client_date.git
client_date / README
100644 60 lines (37 sloc) 1.59 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
Hosted at GitHub since May 1, 2008
http://github.com/ryanlowe/client_date
 
Was hosted at Google Code
http://code.google.com/p/client-date/
 
 
= client_date
 
The client_date Ruby on Rails plugin uses client-side Javascript
to format a date/time in a view instead of the server. The client
is given UTC time for formatting so the server doesn't have to
store which time zone each user is in.
 
Of course it's also very handy for users that haven't logged in
or do not have a login.
 
== Installation
 
  gem install ryanlowe-client_date --source http://gems.github.com/
 
== Setup
 
  First include the ClientDate mixin in your ApplicationHelper.
 
    module ApplicationHelper
      include ClientDate
      ...
    end
 
  Then copy the javascript code in javascripts/client_date.js to
  your project. You can do this two ways:
 
  1. Copy client_date.js to your javascripts/ directory and
     add it to your Rails project using javascript_include_tag.
  2. Copy the code in client_date.js to javascripts/application.js
     which is pulled in by javascript_include_tag :defaults.
 
== Usage
 
  In a view you can use:
  
  format_date(date) # month, day
  format_datetime(date) # month, day, hour, minute
  format_datetime(date,true) # month, day, hour, minute, seconds
  
  The date parameter should be a normal Ruby date, like the "datetime" used
  in Rails migrations.
  
  Example:
  
  <p>Created at: <%= format_datetime(post.created_at) %></p>
  
== Customization
 
  Change how client_date formats dates and times by changing the
  fd() and fdt() Javascript functions.