simple_calendar 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,15 +24,20 @@ will be using with simple_calendar.
24
24
  We query the events we want to display as usual, and then render the
25
25
  calendar in the view like so:
26
26
 
27
- <%= calendar @events %>
27
+ <%= calendar @events do |event| %>
28
+ <div><%= link_to event.title, event %></div>
29
+ <% end %>
30
+
31
+ When the calendar is rendering, it yields to the block to allow you to
32
+ render whatever you like for the item. In this example, I use the title
33
+ attribute on the event with a link to the event.
28
34
 
29
35
  has_calendar has options that can be passed to it for configuration:
30
36
 
31
- has_calendar :title => :whatever, :start_time => :my_start_column
37
+ has_calendar :start_time => :my_start_column
32
38
 
33
39
  def whatever
34
40
  title + " ohai"
35
41
  end
36
42
 
37
- Start_time is the field for the start time of the event. Title is the
38
- text that will be displayed for the event on the calendar.
43
+ Start_time is the field for the start time of the event.
@@ -1,14 +1,10 @@
1
1
  module SimpleCalendar
2
2
  module ModelAdditions
3
3
  def has_calendar(options={})
4
- config = { :title => "title", :start_time => "start_time"}
4
+ config = { :start_time => "start_time"}
5
5
  config.update(options) if options.is_a?(Hash)
6
6
 
7
7
  class_eval <<-EOV
8
- def title_column
9
- #{config[:title]}
10
- end
11
-
12
8
  def start_time_column
13
9
  #{config[:start_time]}
14
10
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  module SimpleCalendar
2
2
  module ViewHelpers
3
- def calendar(events)
3
+ def calendar(events, &block)
4
4
  day = Date.civil((params[:year] || Time.zone.now.year).to_i, (params[:month] || Time.zone.now.month).to_i)
5
5
 
6
6
  content_tag :table, :class => "bordered-table calendar" do
7
- month_header(day) + day_header + body(day, events)
7
+ month_header(day) + day_header + body(day, events, block)
8
8
  end
9
9
  end
10
10
 
@@ -40,7 +40,7 @@ module SimpleCalendar
40
40
  end
41
41
  end
42
42
 
43
- def body(day, events)
43
+ def body(day, events, block)
44
44
  current_date = start_date(day).dup
45
45
 
46
46
  content_tag :tbody do
@@ -49,10 +49,10 @@ module SimpleCalendar
49
49
  weeks << content_tag(:tr) do
50
50
  tags = []
51
51
  while not current_date.saturday?
52
- tags << day(current_date, events)
52
+ tags << day(current_date, events, block)
53
53
  current_date = current_date.tomorrow
54
54
  end
55
- tags << day(current_date, events)
55
+ tags << day(current_date, events, block)
56
56
  current_date = current_date.tomorrow
57
57
  tags.join.html_safe
58
58
  end
@@ -61,11 +61,11 @@ module SimpleCalendar
61
61
  end
62
62
  end
63
63
 
64
- def day(date, events)
64
+ def day(date, events, block)
65
65
  content_tag :td do
66
66
  events = day_events(date, events)
67
67
  tags = [content_tag(:div, date.day, :class => "day")]
68
- tags += events.map { |e| content_tag(:div, e.title_column) } unless events.empty?
68
+ tags += events.map { |e| content_tag(:div, block.call(e)) } unless events.empty?
69
69
  tags.join.html_safe
70
70
  end
71
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-04 00:00:00.000000000Z
12
+ date: 2012-02-20 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: A simple Rails 3 calendar
15
15
  email: