tb_events 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzAxNDliNzk5MTIzZjVjNDAwYzc5Y2M4NTRiNzFjMTg4YWQ2ZWJiYg==
4
+ ZmMyNDc4N2IzN2I4NWVlYTlkNTM5ODM3NTQ0YTVkY2ZiZjFhYWE3NA==
5
5
  data.tar.gz: !binary |-
6
- ZjYzYTc4MTQ5ZWFkOGQ4ODUwNGY0YzEyYWU2MTgwNzQ0ZTMxOTFkNA==
6
+ NDgzMTViOGY5MjNkMGI1Zjg3ZDBjZDU4Y2M4ZjZiZWQwZTU5YzFkOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZmJlMzgyYzZkZWEzYjliZWIzYmNkMDhlMzQwMjVlMjc4OTNhZjcxYTI2NzMz
10
- NWQ3MWMzNTQ1MWFjZjQ1OGNmNjZlNWUwZjNiOGZlZGI2MjdiOWNkYTUxOWY0
11
- ZGE5NTU1NTRjNTViYjMyZGY4MjhiNWFmODA3NzM2OTRkYTViNGU=
9
+ ZDAzOWU5ZDIwNDY1NDVkNWQ0ZDg2MzliYjA0Yjg0NzgxNWIxN2RiNDhlMzI5
10
+ Y2M2ODk2ODA4Yjg2ODg1OTk3OTc0ZTVjMjIyNTNkNWQ4MzQ1ZTY0YzhhZDNl
11
+ NmIxNzc4MTdmMTJjOTRlZjYyNzI3YmQ2N2Y3Njk1MzhjOGJjMWE=
12
12
  data.tar.gz: !binary |-
13
- MjdkZWFlM2Q3ZjIxMjkxMTc0NDNmZGFlMzU2ZTdiMTFhMzVjMDk2NjVmY2Ux
14
- ZDlhY2IyMjY0MjQwZmMwNjk4MmY2NGQwNGYwMDkzMGRjYTNmYzExMzJjMGVj
15
- ZDY4NDNhNzk3MzEwNjI1Yzg4ZDI5ZTk1NTFhYzk2OGU3MGMxNDQ=
13
+ MzdhZWI5Yzk2NWY3ZmUyOGU5ZjNjMjliMDk3NjlhZGM0ZTU0Njk2YzBlYTA2
14
+ NGU5ZWYzOTM2ODEzZGM5MGQwYWUxZjZkNjQ0ZTU3NWU3NzVkN2IzNTgwM2Q4
15
+ NTg1NGM1NTExNDlkY2ZkODUzYTk5OTE0ZGI5Njg0ZDA1ZDg2ZDE=
@@ -17,9 +17,7 @@ module CalendarsHelper
17
17
  options = args.last.is_a?(Hash) ? args.pop : {}
18
18
  html_options = options[:html]
19
19
  builder = options[:builder] || Spud::Events::CalendarBuilder
20
- calendar = options[:calendar] || Spud::Events::Calendar
21
-
22
- content = with_output_buffer{block.call(builder.new(objects||[], self, calendar, options))}
20
+ content = with_output_buffer{block.call(builder.new(objects||[], self, options))}
23
21
  self.content_tag(:table, content, html_options, false)
24
22
  end
25
23
 
@@ -8,4 +8,14 @@ class SpudCalendarEvent < ActiveRecord::Base
8
8
  where(["spud_calendar_events.start_at <= ? AND spud_calendar_events.start_at >= ?", month.end_of_month, month.beginning_of_month])
9
9
  end
10
10
 
11
+ def days_span
12
+ return (end_at.to_date - start_at.to_date).to_i + 1
13
+ end
14
+
15
+ def falls_on?(day)
16
+ start_date = start_at.beginning_of_day.to_date
17
+ end_date = end_at.end_of_day.to_date
18
+ return day >= start_date && day <= end_date
19
+ end
20
+
11
21
  end
@@ -7,7 +7,7 @@
7
7
  <div class="spud_events_admin_calendar_date_container">
8
8
  <%= content_tag :span, day.day, :class => (tasks.count > 0 ? "spud_events_admin_calendar_date spud_events_admin_calendar_date_active" : "spud_events_admin_calendar_date") %>
9
9
  <% tasks.each do |task| %>
10
- <%= link_to task.title[0,25], edit_spud_admin_calendar_event_path(task.id), :class => "spud_events_admin_calendar_event_marker spud_events_calendar_event_#{task.spud_calendar_id}", :style => "background-color: \##{task.spud_calendar.color}; color:\##{calendar_fore_color(task.spud_calendar.color)}" %>
10
+ <%= link_to truncate(task.title, :length => 25), edit_spud_admin_calendar_event_path(task.id), :class => "spud_events_admin_calendar_event_marker spud_events_calendar_event_#{task.spud_calendar_id}", :style => "background-color: \##{task.spud_calendar.color}; color:\##{calendar_fore_color(task.spud_calendar.color)}" %>
11
11
  <% end %>
12
12
  </div>
13
13
  <% end %>
@@ -0,0 +1,85 @@
1
+ module Spud
2
+ module Events
3
+ class Calendar
4
+ attr_accessor :first_weekday, :last_weekday, :month
5
+
6
+ def initialize(options={})
7
+ @year = options[:year] || Time.now.year
8
+ @month = options[:month] || Time.now.month
9
+ @first_day_of_week = options[:first_day_of_week] || 0
10
+ @first_weekday = first_day_of_week(@first_day_of_week)
11
+ @last_weekday = last_day_of_week(@first_day_of_week)
12
+ @first = Date.civil(@year, @month, 1)
13
+ @last = Date.civil(@year, @month, -1)
14
+ end
15
+
16
+ def each_day
17
+ first_day.upto(last_day) do |day|
18
+ yield(day)
19
+ end
20
+ end
21
+
22
+ def last_day
23
+ last = @last
24
+ while(last.wday % 7 != @last_weekday % 7)
25
+ last = last.next
26
+ end
27
+ last
28
+ end
29
+
30
+ def first_day
31
+ first = @first - 6
32
+ while(first.wday % 7 != (@first_weekday) % 7)
33
+ first = first.next
34
+ end
35
+ first
36
+ end
37
+
38
+ def objects_for_days(objects, day_method, end_method)
39
+ unless @objects_for_days
40
+ @objects_for_days = {}
41
+ days.each do |day|
42
+ tasks = []
43
+ objects.each do |object|
44
+ start_date = object.send(day_method.to_sym).beginning_of_day.to_date
45
+ end_date = object.send(end_method.to_sym).end_of_day.to_date
46
+ if day >= start_date && day <= end_date
47
+ tasks.push(object)
48
+ end
49
+ end
50
+ @objects_for_days[day.strftime("%Y-%m-%d")] = [day, tasks]
51
+ end
52
+ end
53
+ @objects_for_days
54
+ end
55
+
56
+ def days
57
+ unless @days
58
+ @days = []
59
+ each_day{|day| @days << day}
60
+ end
61
+ @days
62
+ end
63
+
64
+ def mjdays
65
+ unless @mjdays
66
+ @mdays = []
67
+ each_day{|day| @days << day}
68
+ end
69
+ @days
70
+ end
71
+
72
+ def first_day_of_week(day)
73
+ day
74
+ end
75
+
76
+ def last_day_of_week(day)
77
+ if day > 0
78
+ day - 1
79
+ else
80
+ 6
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,58 @@
1
+ module Spud
2
+ module Events
3
+ class CalendarBuilder < Spud::Events::TableBuilder
4
+
5
+ def initialize(objects, template, options)
6
+ super(objects, template, options)
7
+ @calendar = Spud::Events::Calendar.new(options)
8
+ @today = options[:today] || Time.now
9
+ end
10
+
11
+ def day(*args,&block)
12
+ raise ArgumentError, "Missing block" unless block_given?
13
+ options = options_from_hash(args)
14
+ day_method = options.delete(:day_method) || :start_at
15
+ end_method = options.delete(:end_method) || :end_at
16
+ id_pattern = options.delete(:id)
17
+ activity_class = options.delete(:activity)
18
+ output = ""
19
+ @calendar.objects_for_days(@objects, day_method, end_method).to_a.sort{|a1, a2| a1.first <=> a2.first }.each do |o|
20
+ key, array = o
21
+ day, objects = array
22
+
23
+ output << @template.tag(:tr,options,true) if (day.wday == @calendar.first_weekday)
24
+ output << @template.tag(:td,td_options(day, id_pattern, (objects.empty? ? nil: activity_class)), true)
25
+ output << @template.with_output_buffer{block.call(day, objects)}
26
+ output << '</td>'
27
+ output << '</tr>' if (day.wday == @calendar.last_weekday)
28
+ end
29
+ @template.content_tag(:tbody, output.html_safe, {}, false)
30
+ end
31
+
32
+ private
33
+
34
+ def objects_for_days
35
+ @calendar.objects_for_days(@objects)
36
+ end
37
+
38
+ def td_options(day, id_pattern, activity_class)
39
+ options = {}
40
+ if(day.strftime("%Y-%m-%d") == @today.strftime("%Y-%m-%d"))
41
+ options[:class] = 'today'
42
+ elsif(day.month != @calendar.month)
43
+ options[:class] = 'notmonth'
44
+ elsif(day.wday == 0 or day.wday == 6)
45
+ options[:class] = 'weekend'
46
+ elsif activity_class
47
+ options[:class] = activity_class
48
+ end
49
+ if id_pattern
50
+ options[:id] = day.strftime(id_pattern)
51
+ end
52
+
53
+ options
54
+ end
55
+
56
+ end
57
+ end
58
+ end
File without changes
@@ -2,30 +2,25 @@ require 'tb_core'
2
2
 
3
3
  module Spud
4
4
  module Events
5
- class Engine < Rails::Engine
5
+ class Engine < Rails::Engine
6
6
  engine_name :tb_events
7
7
 
8
- def self.require_model(model_name)
9
- require "#{root}/app/models/#{model_name}"
10
- end
8
+ config.autoload_paths << File.expand_path("../../..", __FILE__)
11
9
 
12
- def self.require_controller(controller_name)
13
- require "#{root}/app/controllers/#{controller_name}"
14
- end
15
10
  initializer :admin do
16
11
  Spud::Core.configure do |config|
17
12
  config.admin_applications += [{:name => "Events", :thumbnail => "spud/admin/events_thumb.png", :url => "/spud/admin/events",:order => 10}]
18
13
  end
19
14
  end
15
+
20
16
  initializer :assets do |config|
21
17
  Spud::Core.append_admin_javascripts('spud/admin/events')
22
18
  Spud::Core.append_admin_stylesheets('spud/admin/events')
23
-
24
19
  Rails.application.config.assets.precompile += [
25
20
  "spud/events.*",
26
21
  "spud/admin/events.*"
27
22
  ]
28
- end
29
- end
23
+ end
24
+ end
30
25
  end
31
26
  end
@@ -14,7 +14,7 @@ module Spud
14
14
  else
15
15
  @num_of_columns = args.size
16
16
  content = args.collect do |c|
17
- @template.content_tag(:th,c)
17
+ @template.content_tag(:th, c)
18
18
  end.join("\n").html_safe
19
19
  @template.content_tag(:thead, @template.content_tag(:tr,content,{},false))
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Events
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
- end
5
+ end
data/lib/tb_events.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Spud
2
2
  module Events
3
- require 'spud_events/configuration'
4
- require 'spud_events/engine' if defined?(Rails)
5
- require 'spud_events/table_builder'
6
- require 'spud_events/calendar_builder'
3
+ require 'spud/events/configuration'
4
+ require 'spud/events/engine' if defined?(Rails)
7
5
  end
8
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tb_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Woods
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-19 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -224,11 +224,12 @@ files:
224
224
  - db/migrate/20120216191833_create_spud_calendars.rb
225
225
  - db/migrate/20120216192531_create_spud_calendar_events.rb
226
226
  - db/migrate/20130214131628_add_location_to_spud_calendar_event.rb
227
- - lib/spud_events/calendar_builder.rb
228
- - lib/spud_events/configuration.rb
229
- - lib/spud_events/engine.rb
230
- - lib/spud_events/table_builder.rb
231
- - lib/spud_events/version.rb
227
+ - lib/spud/events/calendar.rb
228
+ - lib/spud/events/calendar_builder.rb
229
+ - lib/spud/events/configuration.rb
230
+ - lib/spud/events/engine.rb
231
+ - lib/spud/events/table_builder.rb
232
+ - lib/spud/events/version.rb
232
233
  - lib/tb_events.rb
233
234
  - Rakefile
234
235
  - README.md
@@ -251,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
252
  version: '0'
252
253
  requirements: []
253
254
  rubyforge_project:
254
- rubygems_version: 2.0.3
255
+ rubygems_version: 2.0.7
255
256
  signing_key:
256
257
  specification_version: 4
257
258
  summary: Twice Baked Events engine
@@ -1,133 +0,0 @@
1
- module Spud
2
- module Events
3
- class CalendarBuilder < Spud::Events::TableBuilder
4
- def initialize(objects, template, calendar, options)
5
- super(objects, template, options)
6
- @calendar = calendar.new(options)
7
- @today = options[:today] || Time.now
8
- end
9
-
10
- def day(*args,&block)
11
- raise ArgumentError, "Missing block" unless block_given?
12
- options = options_from_hash(args)
13
- day_method = options.delete(:day_method) || :start_at
14
- id_pattern = options.delete(:id)
15
- activity_class = options.delete(:activity)
16
- output = ""
17
- @calendar.objects_for_days(@objects, day_method).to_a.sort{|a1, a2| a1.first <=> a2.first }.each do |o|
18
- key, array = o
19
- day, objects = array
20
-
21
- output << @template.tag(:tr,options,true) if (day.wday == @calendar.first_weekday)
22
- output << @template.tag(:td,td_options(day, id_pattern, (objects.empty? ? nil: activity_class)), true)
23
- output << @template.with_output_buffer{block.call(day, objects)}
24
- output << '</td>'
25
- output << '</tr>' if (day.wday == @calendar.last_weekday)
26
- end
27
- @template.content_tag(:tbody, output.html_safe, {}, false)
28
- end
29
-
30
- private
31
-
32
- def objects_for_days
33
- @calendar.objects_for_days(@objects)
34
- end
35
-
36
- def td_options(day, id_pattern, activity_class)
37
- options = {}
38
- if(day.strftime("%Y-%m-%d") == @today.strftime("%Y-%m-%d"))
39
- options[:class] = 'today'
40
- elsif(day.month != @calendar.month)
41
- options[:class] = 'notmonth'
42
- elsif(day.wday == 0 or day.wday == 6)
43
- options[:class] = 'weekend'
44
- elsif activity_class
45
- options[:class] = activity_class
46
- end
47
- if id_pattern
48
- options[:id] = day.strftime(id_pattern)
49
- end
50
-
51
- options
52
- end
53
-
54
- end
55
-
56
- class Calendar
57
- attr_accessor :first_weekday, :last_weekday, :month
58
- def initialize(options={})
59
- @year = options[:year] || Time.now.year
60
- @month = options[:month] || Time.now.month
61
- @first_day_of_week = options[:first_day_of_week] || 0
62
- @first_weekday = first_day_of_week(@first_day_of_week)
63
- @last_weekday = last_day_of_week(@first_day_of_week)
64
- @first = Date.civil(@year, @month, 1)
65
- @last = Date.civil(@year, @month, -1)
66
- end
67
-
68
- def each_day
69
- first_day.upto(last_day) do |day|
70
- yield(day)
71
- end
72
- end
73
-
74
- def last_day
75
- last = @last
76
- while(last.wday % 7 != @last_weekday % 7)
77
- last = last.next
78
- end
79
- last
80
- end
81
-
82
- def first_day
83
- first = @first - 6
84
- while(first.wday % 7 != (@first_weekday) % 7)
85
- first = first.next
86
- end
87
- first
88
- end
89
-
90
- def objects_for_days(objects, day_method)
91
- unless @objects_for_days
92
- @objects_for_days = {}
93
- days.each{|day| @objects_for_days[day.strftime("%Y-%m-%d")] = [day, []]}
94
- objects.each do |o|
95
- date = o.send(day_method.to_sym).strftime("%Y-%m-%d")
96
- if @objects_for_days[date]
97
- @objects_for_days[date][1] << o
98
- end
99
- end
100
- end
101
- @objects_for_days
102
- end
103
-
104
- def days
105
- unless @days
106
- @days = []
107
- each_day{|day| @days << day}
108
- end
109
- @days
110
- end
111
-
112
- def mjdays
113
- unless @mjdays
114
- @mdays = []
115
- each_day{|day| @days << day}
116
- end
117
- @days
118
- end
119
-
120
- def first_day_of_week(day)
121
- day
122
- end
123
-
124
- def last_day_of_week(day)
125
- if day > 0
126
- day - 1
127
- else
128
- 6
129
- end
130
- end
131
- end
132
- end
133
- end