ryanlowe-client_date 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,12 @@
1
+
2
+ == 0.1.0
3
+
4
+ May 26
5
+ = added GitHub gemspec
6
+
7
+ May 1 2008
8
+ - move to GitHub
9
+
10
+ Sep 24 2007
11
+ - add installation instructions to README
12
+ - client_date plugin created from code in existing projects
data/MIT-LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2007-2008 Ryan Lowe
2
+
3
+ http://ryanlowe.ca
4
+ http://disruptiveagility.com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,60 @@
1
+
2
+ Hosted at GitHub since May 1, 2008
3
+ http://github.com/ryanlowe/client_date
4
+
5
+ Was hosted at Google Code
6
+ http://code.google.com/p/client-date/
7
+
8
+
9
+ = client_date
10
+
11
+ The client_date Ruby on Rails plugin uses client-side Javascript
12
+ to format a date/time in a view instead of the server. The client
13
+ is given UTC time for formatting so the server doesn't have to
14
+ store which time zone each user is in.
15
+
16
+ Of course it's also very handy for users that haven't logged in
17
+ or do not have a login.
18
+
19
+ == Installation
20
+
21
+ gem install ryanlowe-client_date --source http://gems.github.com/
22
+
23
+ == Setup
24
+
25
+ First include the ClientDate mixin in your ApplicationHelper.
26
+
27
+ module ApplicationHelper
28
+ include ClientDate
29
+ ...
30
+ end
31
+
32
+ Then copy the javascript code in javascripts/client_date.js to
33
+ your project. You can do this two ways:
34
+
35
+ 1. Copy client_date.js to your javascripts/ directory and
36
+ add it to your Rails project using javascript_include_tag.
37
+ 2. Copy the code in client_date.js to javascripts/application.js
38
+ which is pulled in by javascript_include_tag :defaults.
39
+
40
+ == Usage
41
+
42
+ In a view you can use:
43
+
44
+ format_date(date) # month, day
45
+ format_datetime(date) # month, day, hour, minute
46
+ format_datetime(date,true) # month, day, hour, minute, seconds
47
+
48
+ The date parameter should be a normal Ruby date, like the "datetime" used
49
+ in Rails migrations.
50
+
51
+ Example:
52
+
53
+ <p>Created at: <%= format_datetime(post.created_at) %></p>
54
+
55
+ == Customization
56
+
57
+ Change how client_date formats dates and times by changing the
58
+ fd() and fdt() Javascript functions.
59
+
60
+
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the client_date plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the client_date plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'ClientDate'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "client_date"
3
+ s.version = "0.1.0"
4
+ s.date = "2008-05-26"
5
+ s.summary = "Uses client-side Javascript to format a datetime instead of the Ruby on Rails server"
6
+ s.email = "rails@ryanlowe.ca"
7
+ s.homepage = "http://github.com/ryanlowe/client_date"
8
+ s.description = "Uses client-side Javascript to format a datetime instead of the Ruby on Rails server"
9
+ s.has_rdoc = false
10
+ s.authors = ["Ryan Lowe"]
11
+ s.files = ["README", "CHANGELOG", "MIT-LICENSE","Rakefile", "client_date.gemspec", "init.rb","lib/client_date.rb",
12
+ "test/client_date_test.rb","test/test_helper.rb"]
13
+ s.test_files = ["test/client_date_test.rb","test/test_helper.rb"]
14
+ s.rdoc_options = ["--main", "README"]
15
+ s.extra_rdoc_files = ["README","CHANGELOG"]
16
+ s.add_dependency("rails", ["> 2.0.0"])
17
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'client_date'
@@ -0,0 +1,29 @@
1
+ module ClientDate
2
+ def format_date(date)
3
+ return "" if date.nil?
4
+ assemble_javascript(date,"fd")
5
+ end
6
+
7
+ def format_datetime(date,seconds=false)
8
+ return "" if date.nil?
9
+ function = seconds ? "fdts" : "fdt"
10
+ assemble_javascript(date,function)
11
+ end
12
+
13
+ private
14
+
15
+ def date_params(date)
16
+ return "" if date.nil?
17
+ text = date.year.to_s + ","
18
+ text += date.month.to_s + ","
19
+ text += date.day.to_s + ","
20
+ text += date.hour.to_s + ","
21
+ text += date.min.to_s + ","
22
+ text += date.sec.to_s
23
+ text
24
+ end
25
+
26
+ def assemble_javascript(date,function)
27
+ "<script>"+function+"("+date_params(date)+");</script>"
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/client_date'
3
+
4
+ class ClientDateTest < Test::Unit::TestCase
5
+ include ClientDate
6
+
7
+ #
8
+ # format_date
9
+ #
10
+
11
+ def test_format_date
12
+ assert_equal "", format_date(nil)
13
+ assert_equal "<script>fd(2000,1,1,20,15,39);</script>", format_date(Time.gm(2000,"jan",1,20,15,39))
14
+ end
15
+
16
+ #
17
+ # format_datetime
18
+ #
19
+
20
+ def test_format_datetime
21
+ assert_equal "", format_datetime(nil)
22
+ assert_equal "<script>fdt(2000,1,1,20,15,47);</script>", format_datetime(Time.gm(2000,"jan",1,20,15,47))
23
+ end
24
+
25
+ def test_format_datetime_with_seconds
26
+ assert_equal "", format_datetime(nil,true)
27
+ assert_equal "<script>fdts(2000,1,1,20,15,23);</script>", format_datetime(Time.gm(2000,"jan",1,20,15,23),true)
28
+ end
29
+
30
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'active_support'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
6
+
7
+ RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ryanlowe-client_date
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Lowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ version:
24
+ description: Uses client-side Javascript to format a datetime instead of the Ruby on Rails server
25
+ email: rails@ryanlowe.ca
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
32
+ - CHANGELOG
33
+ files:
34
+ - README
35
+ - CHANGELOG
36
+ - MIT-LICENSE
37
+ - Rakefile
38
+ - client_date.gemspec
39
+ - init.rb
40
+ - lib/client_date.rb
41
+ - test/client_date_test.rb
42
+ - test/test_helper.rb
43
+ has_rdoc: false
44
+ homepage: http://github.com/ryanlowe/client_date
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.0.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Uses client-side Javascript to format a datetime instead of the Ruby on Rails server
70
+ test_files:
71
+ - test/client_date_test.rb
72
+ - test/test_helper.rb