week_calendar 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/weekly_calendar/version.rb +1 -1
- data/lib/weekly_calendar/view_helpers.rb +21 -8
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0a003ac52e10ae5790af3a88b6c0c46717c9262
|
4
|
+
data.tar.gz: 022bc733adc1d103db11311cd461ad9b1cdf1db7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2674e391099e736120bf3cbb57591399e35e155dfe63898292bf9da0b5862fdda755a1f4ef9b3b81e645306382babd46d6d46c27428d12851a58db41195a2d3
|
7
|
+
data.tar.gz: 7db00fe0b815470027aabbeef089285162cf0df21189ce4ca281235e23cef4f889b64b5bbc2b33008f82a938bf3760a2cb7af09dd7bc649dccfebaca6b316fbf
|
data/README.md
CHANGED
@@ -26,6 +26,12 @@ In erb file:
|
|
26
26
|
<% end %>
|
27
27
|
|
28
28
|
|
29
|
+
Options list:
|
30
|
+
|
31
|
+
* hidden_past: Default is false. Hidden the events of the calendar which are past.
|
32
|
+
* class: table css classes.
|
33
|
+
* empty_date: the value must be lambda has one argument that is datetime. e.g. lambda {|tt| tt.to_s }
|
34
|
+
|
29
35
|
|
30
36
|
|
31
37
|
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module WeeklyCalendar
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
|
+
# options:
|
5
|
+
# hiddent_past: with true or false value, when the value is true. display nothing in the past time gride
|
6
|
+
# class: table style class
|
7
|
+
# date_format:
|
8
|
+
|
4
9
|
def week_calender(events, options={}, &block)
|
5
10
|
raise 'WeeklyCalendar requires a block to be passed in' unless block_given?
|
6
11
|
|
@@ -14,14 +19,22 @@ module WeeklyCalendar
|
|
14
19
|
|
15
20
|
def default_options
|
16
21
|
{
|
17
|
-
|
18
|
-
|
22
|
+
:class => "table table-hover table-bordered",
|
23
|
+
:params => {},
|
24
|
+
:hidden_past => false,
|
25
|
+
:date_format => :short,
|
26
|
+
:time_selector => "starting_at",
|
27
|
+
:select_type => :included_by # include
|
19
28
|
}
|
20
29
|
end
|
21
30
|
|
22
|
-
def time_events(time, events, time_selector)
|
31
|
+
def time_events(time, events, time_selector, options)
|
23
32
|
ending = time.at_end_of_hour
|
24
|
-
|
33
|
+
if options[:select_type] == :include
|
34
|
+
events.select { |e| time >= e.starting_at && ending <= e.ending_at }
|
35
|
+
elsif options[:select_type] == :included_by
|
36
|
+
events.select { |e| time <= e.starting_at && ending >= e.ending_at }
|
37
|
+
end
|
25
38
|
end
|
26
39
|
|
27
40
|
def draw_calendar(events, options, block)
|
@@ -31,7 +44,7 @@ module WeeklyCalendar
|
|
31
44
|
days = [Date.current, Date.current+1, Date.current+2]
|
32
45
|
tags = []
|
33
46
|
content_tag(:table, :class => options[:class]) do
|
34
|
-
tags << content_tag(:thead, content_tag(:tr, [content_tag(:th, '')].concat(days.collect { |d| content_tag :th, d.to_s(:
|
47
|
+
tags << content_tag(:thead, content_tag(:tr, [content_tag(:th, '')].concat(days.collect { |d| content_tag :th, d.to_s(options[:date_format]) }).join.html_safe))
|
35
48
|
tags << content_tag(:tbody) do
|
36
49
|
times.collect do |t|
|
37
50
|
content_tag(:tr) do
|
@@ -41,9 +54,9 @@ module WeeklyCalendar
|
|
41
54
|
content_tag(:td) do
|
42
55
|
divs = []
|
43
56
|
cell_time = DateTime.civil_from_format( :local ,d.year, d.month, d.day, t.split(":")[0].to_i, t.split(":")[1].to_i, 0 )
|
44
|
-
curr_events = time_events(cell_time, events, options[:time_selector])
|
45
|
-
if Time.zone.now > cell_time
|
46
|
-
content_tag(:div, '
|
57
|
+
curr_events = time_events(cell_time, events, options[:time_selector], options)
|
58
|
+
if Time.zone.now > cell_time && options[:hidden_past]
|
59
|
+
divs << content_tag(:div, '')
|
47
60
|
else
|
48
61
|
if curr_events.empty? && options[:empty_date]
|
49
62
|
divs << options[:empty_date].call(cell_time)
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: week_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lester Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Generate a weekly calendar easily.
|
@@ -45,7 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
-
|
48
|
+
- .gitignore
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
@@ -65,12 +65,12 @@ require_paths:
|
|
65
65
|
- lib
|
66
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|