calendariffic 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/calendariffic.gemspec +3 -2
- data/lib/calendariffic.rb +2 -70
- data/lib/calendariffic/action_view.rb +71 -0
- metadata +7 -6
data/calendariffic.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'calendariffic'
|
16
|
-
s.version = '0.0.
|
17
|
-
s.date = '2012-02-
|
16
|
+
s.version = '0.0.2'
|
17
|
+
s.date = '2012-02-09'
|
18
18
|
s.rubyforge_project = 'calendariffic'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -154,6 +154,7 @@ Gem::Specification.new do |s|
|
|
154
154
|
init.rb
|
155
155
|
install.rb
|
156
156
|
lib/calendariffic.rb
|
157
|
+
lib/calendariffic/action_view.rb
|
157
158
|
rails/init.rb
|
158
159
|
tasks/calendariffic_tasks.rake
|
159
160
|
test/calendariffic_test.rb
|
data/lib/calendariffic.rb
CHANGED
@@ -1,73 +1,5 @@
|
|
1
1
|
module Calendariffic
|
2
|
-
VERSION = '0.0.
|
3
|
-
|
4
|
-
=begin rdoc
|
5
|
-
===Creates a DHTML pop-up calendar icon and an associated text-box to display the selected date.
|
6
|
-
|
7
|
-
<b>_calendar_is_before_text_</b>: boolean to determine whether the calendar icon is placed before or after the text-box
|
8
|
-
e.g. true will produce <img ... /><input type="text" ... /> whereas false will generate <input type="text" ... /><img ... />
|
9
|
-
|
10
|
-
<b>_text_name_</b>: specifies the name and id attributes of the text-box. The user MUST specify this value and it MUST be different from the value specified in image_name.
|
11
|
-
|
12
|
-
<b>_image_source_</b>: relative path specifying the location of an icon to represent the pop-up calendar.
|
13
|
-
Several calendar icons are located in public/images/calendariffic
|
14
|
-
|
15
|
-
<b>_image_name_</b>: the name and id you want associated with your calendar icon. The user MUST specify this value and it MUST be different from the value specified in text_name.
|
16
|
-
|
17
|
-
<b>_date_format_</b>: the format in which the date will appear within the text_box. See table below for valid abbreviations for date.
|
18
|
-
a date_format of nil will default to mm/dd/yy.
|
19
|
-
|
20
|
-
<b>_text_value_</b>: the initial value you want to show up within the text box (e.g. '07/04/2007')
|
21
|
-
if the user passes the string 'today' the text_value will initially display today's date in whichever format is specified by the date_format parameter.
|
22
|
-
the 'today' string is case-insensitive.
|
23
|
-
|
24
|
-
<b>_text_attributes_</b>: any other attributes that can be placed into an <input type="text" /> HTML element can be placed here within a Hash. e.g. {:class => 'myfavoriteclass'}
|
25
|
-
|
26
|
-
<b>_image_attributes_</b>: any other attributes that can be placed into an <img src="" ... /> HTML element can be placed here within a Hash. e.g. {:alt => 'cal'}
|
27
|
-
|
2
|
+
VERSION = '0.0.2'
|
28
3
|
|
29
|
-
|
30
|
-
%a abbreviated weekday name
|
31
|
-
%A full weekday name
|
32
|
-
%b abbreviated month name
|
33
|
-
%B full month name
|
34
|
-
%C century number
|
35
|
-
%d the day of the month ( 00 .. 31 )
|
36
|
-
%e the day of the month ( 0 .. 31 )
|
37
|
-
%j day of the year ( 000 .. 366 )
|
38
|
-
%m month ( 01 .. 12 )
|
39
|
-
%n a newline character
|
40
|
-
%s number of seconds since Epoch (since Jan 01 1970 00:00:00 UTC)
|
41
|
-
%t a tab character
|
42
|
-
%U, %W, %V the week number
|
43
|
-
%u the day of the week ( 1 .. 7, 1 = MON )
|
44
|
-
%w the day of the week ( 0 .. 6, 0 = SUN )
|
45
|
-
%y year without the century ( 00 .. 99 )
|
46
|
-
%Y year including the century ( ex. 1979 )
|
47
|
-
%% a literal % character
|
48
|
-
=end
|
49
|
-
def calendariffic_input(calendar_is_before_text, text_name, image_source, image_name, date_format, text_value, text_attributes={}, image_attributes={})
|
50
|
-
text_attributes[:id] ||= text_name
|
51
|
-
image_attributes['name'] = image_name unless image_name.nil?
|
52
|
-
image_attributes['id'] = image_name unless image_name.nil?
|
53
|
-
date_format = '%d-%m-%Y' if date_format.nil?
|
54
|
-
text_value = current_date.strftime(date_format) if text_value.nil?
|
55
|
-
|
56
|
-
imt = image_tag image_source, image_attributes
|
57
|
-
tft = text_field_tag(text_name, text_value, text_attributes)
|
58
|
-
script = "<script language='javascript'>set_cal('#{text_attributes[:id]}', '#{image_name}', '#{date_format}');</script>"
|
59
|
-
calendar_is_before_text ? "#{imt}#{tft}#{script}" : "#{tft}#{imt}#{script}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def calendar(name, value=nil)
|
64
|
-
date_format = '%d-%m-%Y'
|
65
|
-
value = value.strftime(date_format)if value.respond_to?(:day)
|
66
|
-
value = '' if value.nil?
|
67
|
-
calendariffic_input(false, name, 'calendariffic/date.png', "#{name}_img", '%d-%m-%Y', value, {:readonly => 'false'}, {})
|
68
|
-
end
|
69
|
-
|
70
|
-
# Uses Date.current to be more accurate for Rails applications
|
71
|
-
def current_date
|
72
|
-
Date.respond_to? :current ? Date.current : Date.today
|
4
|
+
require 'calendariffic/action_view'
|
73
5
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module FormTagHelper
|
4
|
+
def calendar_tag(name, value = Date.current, *args)
|
5
|
+
options = args.extract_options!
|
6
|
+
|
7
|
+
date_format = '%d-%m-%Y'
|
8
|
+
value = value.strftime(date_format) if value.respond_to?(:day)
|
9
|
+
|
10
|
+
name = name.to_s if name.is_a?(Symbol)
|
11
|
+
|
12
|
+
options[:id] = options[:id] || name.gsub(/\]$/, '').gsub(/\]\[/, '[').gsub(/[\[\]]/, '_')
|
13
|
+
options[:size] ||= 10
|
14
|
+
options[:maxlength] ||= 10
|
15
|
+
options[:class] ||= ''
|
16
|
+
options[:class] += ' calendar_text'
|
17
|
+
options[:class] += ' warn_in_past' if options[:warn_in_past]
|
18
|
+
|
19
|
+
calendariffic_input(false, name, 'calendariffic/date.png', "#{options[:id]}_img", date_format, value, options, {}).html_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
# Uses Date.current to be more accurate for Rails applications
|
23
|
+
def current_date
|
24
|
+
Date.respond_to?(:current) ? Date.current : Date.today
|
25
|
+
end
|
26
|
+
|
27
|
+
# = Creates a DHTML pop-up calendar icon and an associated text-box to display the selected date.
|
28
|
+
#
|
29
|
+
# *calendar_is_before_text*: boolean to determine whether the calendar icon is placed before or after the text-box
|
30
|
+
# e.g. true will produce <img ... /><input type="text" ... /> whereas false will generate <input type="text" ... /><img ... />
|
31
|
+
# *text_name*: specifies the name and id attributes of the text-box. The user MUST specify this value and it MUST be different from the value specified in image_name.
|
32
|
+
# *image_source*: relative path specifying the location of an icon to represent the pop-up calendar.
|
33
|
+
# Several calendar icons are located in public/images/calendariffic
|
34
|
+
# *image_name*: the name and id you want associated with your calendar icon. The user MUST specify this value and it MUST be different from the value specified in text_name.
|
35
|
+
# *date_format*: the format in which the date will appear within the text_box. See table below for valid abbreviations for date.
|
36
|
+
# a date_format of nil will default to mm/dd/yy.
|
37
|
+
# *text_value*: the initial value you want to show up within the text box (e.g. '07/04/2007')
|
38
|
+
# if the user passes the string 'today' the text_value will initially display today's date in whichever format is specified by the date_format parameter.
|
39
|
+
# the 'today' string is case-insensitive.
|
40
|
+
# *text_attributes*: any other attributes that can be placed into an <input type="text" /> HTML element can be placed here within a Hash. e.g. {:class => 'myfavoriteclass'}
|
41
|
+
# *image_attributes*: any other attributes that can be placed into an <img src="" ... /> HTML element can be placed here within a Hash. e.g. {:alt => 'cal'}
|
42
|
+
|
43
|
+
def calendariffic_input(calendar_is_before_text, text_name, image_source, image_name, date_format, text_value, text_attributes={}, image_attributes={})
|
44
|
+
text_attributes[:id] ||= text_name
|
45
|
+
image_attributes[:name] = image_name if image_name
|
46
|
+
image_attributes[:id] = image_name if image_name
|
47
|
+
date_format = '%d-%m-%Y' if date_format.nil?
|
48
|
+
text_value ||= current_date.strftime(date_format)
|
49
|
+
|
50
|
+
imt = image_tag image_source, image_attributes
|
51
|
+
tft = text_field_tag(text_name, text_value, text_attributes)
|
52
|
+
script = "<script language='javascript'>set_cal('#{text_attributes[:id]}', '#{image_name}', '#{date_format}');</script>"
|
53
|
+
calendar_is_before_text ? "#{imt}#{tft}#{script}" : "#{tft}#{imt}#{script}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module DateHelper
|
58
|
+
def calendar(object_name, method, options = {})
|
59
|
+
value = options[:object] || Date.current
|
60
|
+
calendar_tag("#{object_name}[#{method}]", value, options.merge(:id => "#{object_name}_#{method}"))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class FormBuilder
|
65
|
+
def calendar(method, options = {})
|
66
|
+
@template.calendar(@object_name, method, options.merge(:object => @object.send(method)))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calendariffic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-09 00:00:00.000000000 +10:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &22362840 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 2.3.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *22362840
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &22362200 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
version: 3.0.0
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
|
-
version_requirements: *
|
39
|
+
version_requirements: *22362200
|
40
40
|
description: ! "This gems provides some helpers for ActionView to\n make creating
|
41
41
|
calendar helpers in forms easier."
|
42
42
|
email: michael@noack.com.au
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- init.rb
|
149
149
|
- install.rb
|
150
150
|
- lib/calendariffic.rb
|
151
|
+
- lib/calendariffic/action_view.rb
|
151
152
|
- rails/init.rb
|
152
153
|
- tasks/calendariffic_tasks.rake
|
153
154
|
- test/calendariffic_test.rb
|