tb_events 1.1.0 → 1.1.1
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.
- checksums.yaml +4 -4
- data/README.md +13 -1
- data/app/controllers/admin/calendar_events_controller.rb +4 -4
- data/app/controllers/calendar_events_controller.rb +10 -2
- data/app/controllers/calendars_controller.rb +19 -17
- data/app/helpers/calendars_helper.rb +47 -15
- data/app/models/spud/spud_calendar_event_model.rb +25 -0
- data/app/models/spud_calendar.rb +14 -0
- data/app/models/spud_calendar_event.rb +1 -17
- data/app/views/admin/calendar_events/_calendar.html.erb +8 -9
- data/app/views/admin/calendar_events/index.html.erb +13 -12
- data/app/views/calendar_events/index.html.erb +22 -0
- data/app/views/calendar_events/show.html.erb +3 -1
- data/app/views/calendars/show.html.erb +18 -15
- data/config/routes.rb +2 -3
- data/db/migrate/20140723203144_add_identifier_to_spud_calendars.rb +6 -0
- data/lib/spud_events/calendar_builder.rb +54 -0
- data/lib/spud_events/configuration.rb +6 -0
- data/lib/spud_events/engine.rb +23 -0
- data/lib/spud_events/version.rb +3 -0
- data/lib/tb_events.rb +2 -2
- metadata +14 -17
- data/app/views/calendars/_calendar.html.erb +0 -26
- data/app/views/calendars/_calendar_options.html.erb +0 -4
- data/config/application.rb +0 -50
- data/config/boot.rb +0 -6
- data/lib/spud/events/calendar.rb +0 -85
- data/lib/spud/events/calendar_builder.rb +0 -58
- data/lib/spud/events/configuration.rb +0 -8
- data/lib/spud/events/engine.rb +0 -26
- data/lib/spud/events/table_builder.rb +0 -88
- data/lib/spud/events/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ca504c53537c7bc54b51a125ba37c634178c642
|
4
|
+
data.tar.gz: 86e08177acdec807e628158425f7c5784c5de182
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca45dd287b503984f0a62b724c0b48c0baf64693aa358940222a940d0d667dc2d6fda4fa04a38ee8827429ba5f7e658dba6de43e7c1cd6e953543914638f5470
|
7
|
+
data.tar.gz: 638b894bcea5694c23536385bc57326913945cc3e0d6926d4f55bad29b756fff727c67035882e1e54f50e083a46908063dcc4665651a71ee576e9d150cdc52c0
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Configruations
|
|
24
24
|
|
25
25
|
* Set the layout for the calendar pages (Defualt is layouts/spud/calendar)
|
26
26
|
|
27
|
-
|
27
|
+
SpudEvents.configure do |config|
|
28
28
|
config.calendar_layout = 'application'
|
29
29
|
end
|
30
30
|
|
@@ -36,6 +36,18 @@ Configruations
|
|
36
36
|
*= require spud/events
|
37
37
|
*/
|
38
38
|
|
39
|
+
## View Helpers
|
40
|
+
|
41
|
+
TB Events comes with a handful of view helpers for generating calendars. See the Rdoc documentation for detailed information.
|
42
|
+
|
43
|
+
Return a calendar as an html table for the given date:
|
44
|
+
|
45
|
+
spud_calendar_for_date(date)
|
46
|
+
|
47
|
+
Return a calendar for the given date, populated with event data:
|
48
|
+
|
49
|
+
spud_calendar_for_events(events, date, opts)
|
50
|
+
|
39
51
|
Testing
|
40
52
|
-----------------
|
41
53
|
|
@@ -8,14 +8,14 @@ class Admin::CalendarEventsController < Admin::ApplicationController
|
|
8
8
|
|
9
9
|
def index
|
10
10
|
if params[:month]
|
11
|
-
year = params[:year] ? params[:year] :
|
11
|
+
year = params[:year] ? params[:year].to_i : Date.today.year
|
12
12
|
begin
|
13
|
-
@calendar_date =
|
13
|
+
@calendar_date = Date.new(year, params[:month].to_i)
|
14
14
|
rescue
|
15
|
-
@calendar_date =
|
15
|
+
@calendar_date = Date.today
|
16
16
|
end
|
17
17
|
else
|
18
|
-
@calendar_date =
|
18
|
+
@calendar_date = Date.today
|
19
19
|
end
|
20
20
|
|
21
21
|
if params[:spud_calendar] && calendar = SpudCalendar.find_by_title(params[:spud_calendar].titleize)
|
@@ -1,8 +1,16 @@
|
|
1
1
|
class CalendarEventsController < ApplicationController
|
2
|
+
|
3
|
+
respond_to :html, :json
|
4
|
+
layout SpudEvents.config.calendar_layout
|
2
5
|
|
3
|
-
|
4
|
-
|
6
|
+
def index
|
7
|
+
@events = SpudCalendarEvent.ordered.paginate(:per_page => 10, :page => params[:page])
|
8
|
+
respond_with @events
|
9
|
+
end
|
10
|
+
|
5
11
|
def show
|
6
12
|
@event = SpudCalendarEvent.find(params[:id])
|
13
|
+
respond_with @event
|
7
14
|
end
|
15
|
+
|
8
16
|
end
|
@@ -1,30 +1,32 @@
|
|
1
1
|
class CalendarsController < ApplicationController
|
2
2
|
|
3
|
-
|
3
|
+
respond_to :html, :json
|
4
|
+
layout SpudEvents.config.calendar_layout
|
5
|
+
before_action :get_calendar_date
|
4
6
|
|
5
7
|
def show
|
6
|
-
if params[:month]
|
7
|
-
year = params[:year] ? params[:year] : Time.new.year
|
8
|
-
begin
|
9
|
-
@calendar_date = Time.local(year, params[:month])
|
10
|
-
rescue
|
11
|
-
@calendar_date = default_date
|
12
|
-
end
|
13
|
-
else
|
14
|
-
@calendar_date = default_date
|
15
|
-
end
|
16
8
|
if params[:calendar] && calendar = SpudCalendar.find_by_title(params[:calendar].titleize)
|
17
|
-
@events = calendar.spud_calendar_events.
|
9
|
+
@events = calendar.spud_calendar_events.in_month_of(@calendar_date).order(:start_at).to_a
|
18
10
|
else
|
19
|
-
@events = SpudCalendarEvent.
|
11
|
+
@events = SpudCalendarEvent.in_month_of(@calendar_date).order(:start_at).to_a
|
20
12
|
end
|
21
13
|
@current_calendar = params[:calendar] ? params[:calendar] : 0
|
22
|
-
|
14
|
+
respond_with @events
|
23
15
|
end
|
24
16
|
|
25
|
-
|
26
|
-
tempDate = Time.new
|
27
|
-
return Time.local(tempDate.year,tempDate.month)
|
17
|
+
private
|
28
18
|
|
19
|
+
def get_calendar_date
|
20
|
+
if params[:month]
|
21
|
+
year = params[:year] ? params[:year].to_i : Date.today.year
|
22
|
+
begin
|
23
|
+
@calendar_date = Date.new(year, params[:month].to_i)
|
24
|
+
rescue
|
25
|
+
@calendar_date = Date.today
|
26
|
+
end
|
27
|
+
else
|
28
|
+
@calendar_date = Date.today
|
29
|
+
end
|
29
30
|
end
|
31
|
+
|
30
32
|
end
|
@@ -1,29 +1,61 @@
|
|
1
1
|
module CalendarsHelper
|
2
2
|
|
3
|
-
|
3
|
+
# Builds a calendar for the given date
|
4
|
+
#
|
5
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
6
|
+
# * opts:
|
7
|
+
# - headers: Array of weekday headers (optional)
|
8
|
+
#
|
9
|
+
def spud_calendar_for_date(date, opts={})
|
10
|
+
SpudEvents::CalendarBuilder.new(self, date, opts).table do |day|
|
11
|
+
concat content_tag(:span, day.day.to_s, :class => 'calendar-day')
|
12
|
+
if block_given?
|
13
|
+
yield(day)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Builds a calendar for the given date, with events
|
19
|
+
#
|
20
|
+
# * events: An array or relation of SpudCalendarEvent records
|
21
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
22
|
+
# * opts:
|
23
|
+
# - headers: Array of weekday headers (optional)
|
24
|
+
#
|
25
|
+
def spud_calendar_for_events(events, date, opts={})
|
26
|
+
events_grouped = events.group_by(&:start_date)
|
27
|
+
builder = SpudEvents::CalendarBuilder.new(self, date, opts).table do |day|
|
28
|
+
events = events_grouped[day] || []
|
29
|
+
if block_given?
|
30
|
+
yield(day, events)
|
31
|
+
else
|
32
|
+
## TODO
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Builds a calendar for the given date
|
38
|
+
#
|
39
|
+
# * identifier: Symbol for the SpudCalendar you wish to display
|
40
|
+
# * date: Determines the month to be displayed. Given date will have the "today" css class
|
41
|
+
# * opts:
|
42
|
+
# - headers: Array of weekday headers (optional)
|
43
|
+
#
|
44
|
+
def spud_calendar_for_identifier(identifier, date, opts)
|
45
|
+
## TODO
|
46
|
+
end
|
47
|
+
|
48
|
+
def link_to_previous_calendar_month(date)
|
4
49
|
date = date.advance(:months => -1)
|
5
50
|
calendar = params[:calendar] ? params[:calendar] : nil
|
6
51
|
link_to('« Previous Month'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link previous_calendar btn').html_safe
|
7
52
|
end
|
8
53
|
|
9
|
-
def link_to_next_calendar_month(date
|
54
|
+
def link_to_next_calendar_month(date)
|
10
55
|
date = date.advance(:months => 1)
|
11
56
|
calendar = params[:calendar] ? params[:calendar] : nil
|
12
57
|
link_to('Next Month »'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link next_calendar btn').html_safe
|
13
58
|
end
|
14
|
-
|
15
|
-
def build_calendar_for(objects, *args, &block)
|
16
|
-
raise ArgumentError, "Missing block" unless block_given?
|
17
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
18
|
-
html_options = options[:html]
|
19
|
-
builder = options[:builder] || Spud::Events::CalendarBuilder
|
20
|
-
content = with_output_buffer{block.call(builder.new(objects||[], self, options))}
|
21
|
-
self.content_tag(:table, content, html_options, false)
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_calendar_options(text_for_all)
|
25
|
-
options_for_select(SpudCalendar.all.collect { |f| [f.title, f.title.gsub(/([^A-Z0-9]+)/i, "-").downcase] }.insert(0, text_for_all), @current_calendar)
|
26
|
-
end
|
27
59
|
|
28
60
|
def calendar_fore_color(backcolor)
|
29
61
|
fore_color = "ffffff"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Spud::SpudCalendarEventModel < ActiveRecord::Base
|
2
|
+
self.table_name = 'spud_calendar_events'
|
3
|
+
|
4
|
+
belongs_to :spud_calendar
|
5
|
+
validates_presence_of :title, :start_at, :end_at, :spud_calendar_id
|
6
|
+
|
7
|
+
scope :ordered, ->{ order('start_at desc') }
|
8
|
+
scope :in_month_of, ->(date){ where(:start_at => date.beginning_of_month...date.end_of_month) }
|
9
|
+
scope :upcoming, ->(limit=false){ where('start_at >= ?', Date.today).order('start_at asc').limit(limit) }
|
10
|
+
|
11
|
+
def start_date
|
12
|
+
return start_at.to_date
|
13
|
+
end
|
14
|
+
|
15
|
+
def days_span
|
16
|
+
return (end_at.to_date - start_at.to_date).to_i + 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def falls_on?(day)
|
20
|
+
start_date = start_at.beginning_of_day.to_date
|
21
|
+
end_date = end_at.end_of_day.to_date
|
22
|
+
return day >= start_date && day <= end_date
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/app/models/spud_calendar.rb
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
class SpudCalendar < ActiveRecord::Base
|
2
2
|
has_many :spud_calendar_events, :dependent => :destroy
|
3
3
|
validates_presence_of :title, :color
|
4
|
+
validates :identifier, :presence => true, :uniqueness => true
|
5
|
+
|
6
|
+
before_validation :set_identifier
|
7
|
+
|
8
|
+
scope :with_identifier, ->(identifier){ where(:identifier => identifier).first }
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def set_identifier
|
13
|
+
if identifier.nil? && title.present?
|
14
|
+
self.identifier = title.parameterize.underscore
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
end
|
@@ -1,19 +1,3 @@
|
|
1
|
-
class SpudCalendarEvent <
|
2
|
-
belongs_to :spud_calendar
|
3
|
-
validates_presence_of :title, :start_at, :end_at, :spud_calendar_id
|
4
|
-
|
5
|
-
def self.in_month_of(month)
|
6
|
-
where(["spud_calendar_events.start_at <= ? AND spud_calendar_events.start_at >= ?", month.end_of_month, month.beginning_of_month])
|
7
|
-
end
|
8
|
-
|
9
|
-
def days_span
|
10
|
-
return (end_at.to_date - start_at.to_date).to_i + 1
|
11
|
-
end
|
12
|
-
|
13
|
-
def falls_on?(day)
|
14
|
-
start_date = start_at.beginning_of_day.to_date
|
15
|
-
end_date = end_at.end_of_day.to_date
|
16
|
-
return day >= start_date && day <= end_date
|
17
|
-
end
|
1
|
+
class SpudCalendarEvent < Spud::SpudCalendarEventModel
|
18
2
|
|
19
3
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
<p><%= link_to_next_admin_calendar_month(@calendar_date, :class => "btn") %></p>
|
2
2
|
<p><%= link_to_previous_admin_calendar_month(@calendar_date, :class => "btn") %></p>
|
3
3
|
|
4
|
-
<%=
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
<%
|
10
|
-
|
4
|
+
<%= spud_calendar_for_events(@calendar_events, @calendar_date, :headers => ['S', 'M', 'T', 'W', 'T', 'F', 'S']) do |day, events| %>
|
5
|
+
<span class="calendar-day">
|
6
|
+
<%= day.day %>
|
7
|
+
</span>
|
8
|
+
<ul class="calendar-events">
|
9
|
+
<% events.each do |event| %>
|
10
|
+
<li><%= link_to truncate(event.title, :length => 25), edit_admin_calendar_event_path(event.id) %></li>
|
11
11
|
<% end %>
|
12
|
-
|
13
|
-
<% end %>
|
12
|
+
</ul>
|
14
13
|
<% end %>
|
@@ -1,20 +1,21 @@
|
|
1
|
-
<%=content_for :data_controls do%>
|
2
|
-
<%= link_to "New Event", new_admin_calendar_event_path, :class => "btn
|
3
|
-
<%end%>
|
4
|
-
<%=content_for :detail do%>
|
5
|
-
<h3>Calendar Events - <%= @calendar_date.strftime('%B %Y') %></h3>
|
1
|
+
<%= content_for :data_controls do %>
|
2
|
+
<%= link_to "New Event", new_admin_calendar_event_path, :class => "btn right" %>
|
3
|
+
<% end %>
|
6
4
|
|
7
|
-
|
8
|
-
<%= render :partial => 'calendar' %>
|
9
|
-
</div>
|
5
|
+
<%= content_for :detail do %>
|
10
6
|
|
11
|
-
<
|
7
|
+
<h3>Calendar Events - <%= @calendar_date.strftime('%B %Y') %></h3>
|
8
|
+
|
9
|
+
<div id="spud_events_admin_calendar">
|
10
|
+
<%= render :partial => 'calendar' %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<ul id="spud_events_admin_calendar_legend">
|
12
14
|
<%= render :partial => 'admin/calendars/calendar_legend', :collection => @calendars, :as => :calendar %>
|
13
15
|
<li>
|
14
16
|
<%= link_to("New Calendar", new_admin_calendar_path, :class => "btn btn-primary btn-small pull-right") %>
|
15
17
|
<br style="clear:right;"/>
|
16
18
|
</li>
|
17
|
-
</ul>
|
18
|
-
|
19
|
+
</ul>
|
19
20
|
|
20
|
-
<%end%>
|
21
|
+
<% end %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1>Events</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<tr>
|
5
|
+
<th>Title</th>
|
6
|
+
<th>Date</th>
|
7
|
+
<th> </th>
|
8
|
+
</tr>
|
9
|
+
<tbody>
|
10
|
+
<% cache(@events) do %>
|
11
|
+
<% @events.each do |event| %>
|
12
|
+
<tr>
|
13
|
+
<td><%= event.title %></td>
|
14
|
+
<td><%= event.start_at.strftime('%D') %></td>
|
15
|
+
<td><%= link_to 'Details', calendar_event_path(event) %></td>
|
16
|
+
</tr>
|
17
|
+
<% end %>
|
18
|
+
<% end %>
|
19
|
+
</tbody>
|
20
|
+
</table>
|
21
|
+
|
22
|
+
<%= will_paginate(@events) %>
|
@@ -2,4 +2,6 @@
|
|
2
2
|
<p><b>Calendar:</b> <%= @event.spud_calendar.title %></p>
|
3
3
|
<p><em><%= @event.start_at %> - <%= @event.end_at %></em></p>
|
4
4
|
<%= simple_format(@event.description) %>
|
5
|
-
|
5
|
+
|
6
|
+
<p><%= link_to 'Events List', calendar_events_path %> | <%= link_to 'Calendar', calendar_path %></p>
|
7
|
+
|
@@ -1,16 +1,19 @@
|
|
1
|
-
|
2
|
-
<div id="spud_events_calendar">
|
3
|
-
<%= render :partial => 'calendar', :locals => {:date => @calendar_date} %>
|
4
|
-
</div>
|
1
|
+
<% @page_title = @calendar_date.strftime("Events Calendar %B %Y") %>
|
5
2
|
|
6
|
-
<
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
</
|
3
|
+
<h1><%= @page_title %></h1>
|
4
|
+
|
5
|
+
<nav id="events-calendar-nav">
|
6
|
+
<%= link_to_previous_calendar_month(@calendar_date) %>
|
7
|
+
<%= link_to_next_calendar_month(@calendar_date) %>
|
8
|
+
</nav>
|
9
|
+
|
10
|
+
<%= spud_calendar_for_events(@events, @calendar_date) do |day, events| %>
|
11
|
+
<span class="calendar-day">
|
12
|
+
<%= day.day %>
|
13
|
+
</span>
|
14
|
+
<ul class="calendar-events">
|
15
|
+
<% events.each do |event| %>
|
16
|
+
<li><%= link_to truncate(event.title, :length => 25), calendar_event_path(event.id) %></li>
|
17
|
+
<% end %>
|
18
|
+
</ul>
|
19
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
3
|
# Calendar
|
4
|
-
get 'calendar
|
5
|
-
|
4
|
+
get 'calendar(/:month/:year)' => "calendars#show", :as => :calendar
|
5
|
+
resources :calendar_events, :only => [:index, :show], :path => '/events'
|
6
6
|
|
7
7
|
namespace :admin do
|
8
|
-
# Events
|
9
8
|
resources :calendar_events, :except => [:index]
|
10
9
|
resources :calendars, :except => [:index]
|
11
10
|
get 'events(/:month(/:year(/:calendar)))' => "calendar_events#index", :as => "list_spud_calendar_events"
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class SpudEvents::CalendarBuilder
|
2
|
+
|
3
|
+
DEFAULT_HEADERS = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
4
|
+
START_DAY = :sunday
|
5
|
+
|
6
|
+
delegate :content_tag, :to => :view
|
7
|
+
attr_accessor :view, :date, :callback
|
8
|
+
|
9
|
+
def initialize(view, date, opts)
|
10
|
+
@view = view
|
11
|
+
@date = date
|
12
|
+
@headers = opts.delete(:headers) || DEFAULT_HEADERS
|
13
|
+
end
|
14
|
+
|
15
|
+
def table(&block)
|
16
|
+
@callback = block
|
17
|
+
content_tag :table, :class => "calendar" do
|
18
|
+
header + week_rows
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def header
|
25
|
+
content_tag :tr do
|
26
|
+
@headers.map { |day| content_tag :th, day }.join.html_safe
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def week_rows
|
31
|
+
weeks.map do |week|
|
32
|
+
content_tag :tr do
|
33
|
+
week.map { |day| day_cell(day) }.join.html_safe
|
34
|
+
end
|
35
|
+
end.join.html_safe
|
36
|
+
end
|
37
|
+
|
38
|
+
def day_cell(day)
|
39
|
+
content_tag :td, view.capture(day, &callback), :class => day_classes(day), 'data-date' => day.strftime('%F')
|
40
|
+
end
|
41
|
+
|
42
|
+
def day_classes(day)
|
43
|
+
classes = ['day-cell']
|
44
|
+
classes << "today" if day == Date.today
|
45
|
+
classes << "not-month" if day.month != date.month
|
46
|
+
classes.empty? ? nil : classes.join(" ")
|
47
|
+
end
|
48
|
+
|
49
|
+
def weeks
|
50
|
+
first = date.beginning_of_month.beginning_of_week(START_DAY)
|
51
|
+
last = date.end_of_month.end_of_week(START_DAY)
|
52
|
+
(first..last).to_a.in_groups_of(7)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'tb_core'
|
2
|
+
|
3
|
+
module SpudEvents
|
4
|
+
class Engine < Rails::Engine
|
5
|
+
engine_name :tb_events
|
6
|
+
config.autoload_paths << "#{root}/lib"
|
7
|
+
|
8
|
+
initializer :admin do
|
9
|
+
Spud::Core.configure do |config|
|
10
|
+
config.admin_applications += [{:name => "Events", :thumbnail => "spud/admin/events_thumb.png", :url => "/admin/events",:order => 10}]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
initializer :assets do |config|
|
15
|
+
Spud::Core.append_admin_javascripts('spud/admin/events')
|
16
|
+
Spud::Core.append_admin_stylesheets('spud/admin/events')
|
17
|
+
Rails.application.config.assets.precompile += [
|
18
|
+
"spud/events.*",
|
19
|
+
"spud/admin/events.*"
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/tb_events.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Westlake Design
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -126,16 +126,16 @@ dependencies:
|
|
126
126
|
name: database_cleaner
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0.0
|
131
|
+
version: 1.0.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.0.0
|
138
|
+
version: 1.0.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: simplecov
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- app/helpers/admin/calendar_events_helper.rb
|
206
206
|
- app/helpers/admin/calendars_helper.rb
|
207
207
|
- app/helpers/calendars_helper.rb
|
208
|
+
- app/models/spud/spud_calendar_event_model.rb
|
208
209
|
- app/models/spud_calendar.rb
|
209
210
|
- app/models/spud_calendar_event.rb
|
210
211
|
- app/views/admin/calendar_events/_calendar.html.erb
|
@@ -216,22 +217,18 @@ files:
|
|
216
217
|
- app/views/admin/calendars/_form.html.erb
|
217
218
|
- app/views/admin/calendars/edit.html.erb
|
218
219
|
- app/views/admin/calendars/new.html.erb
|
220
|
+
- app/views/calendar_events/index.html.erb
|
219
221
|
- app/views/calendar_events/show.html.erb
|
220
|
-
- app/views/calendars/_calendar.html.erb
|
221
|
-
- app/views/calendars/_calendar_options.html.erb
|
222
222
|
- app/views/calendars/show.html.erb
|
223
|
-
- config/application.rb
|
224
|
-
- config/boot.rb
|
225
223
|
- config/routes.rb
|
226
224
|
- db/migrate/20120216191833_create_spud_calendars.rb
|
227
225
|
- db/migrate/20120216192531_create_spud_calendar_events.rb
|
228
226
|
- db/migrate/20130214131628_add_location_to_spud_calendar_event.rb
|
229
|
-
-
|
230
|
-
- lib/
|
231
|
-
- lib/
|
232
|
-
- lib/
|
233
|
-
- lib/
|
234
|
-
- lib/spud/events/version.rb
|
227
|
+
- db/migrate/20140723203144_add_identifier_to_spud_calendars.rb
|
228
|
+
- lib/spud_events/calendar_builder.rb
|
229
|
+
- lib/spud_events/configuration.rb
|
230
|
+
- lib/spud_events/engine.rb
|
231
|
+
- lib/spud_events/version.rb
|
235
232
|
- lib/tb_events.rb
|
236
233
|
homepage:
|
237
234
|
licenses: []
|
@@ -252,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
249
|
version: '0'
|
253
250
|
requirements: []
|
254
251
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.2.
|
252
|
+
rubygems_version: 2.2.2
|
256
253
|
signing_key:
|
257
254
|
specification_version: 4
|
258
255
|
summary: Twice Baked Events engine
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<div>
|
2
|
-
<h2><%= date.strftime("%B %Y") %></h2>
|
3
|
-
<% build_calendar_for @events, :year => date.year, :month => date.month do |t| %>
|
4
|
-
<%= raw t.head('S', 'M', 'T', 'W', 'T', 'F', 'S') %>
|
5
|
-
<% t.day do |day, tasks| %>
|
6
|
-
<%= content_tag :span, day.day, :class => (tasks.count > 0 ? "spud_events_calendar_date spud_events_calendar_date_active" : "spud_events_calendar_date") %>
|
7
|
-
<% end %>
|
8
|
-
<% end %>
|
9
|
-
</div>
|
10
|
-
|
11
|
-
<nav id="spud_events_calendar_nav">
|
12
|
-
<%= link_to_previous_calendar_month(@calendar_date, {:controller => 'spud/events/calendars', :action => :show}) %>
|
13
|
-
<%= link_to_next_calendar_month(@calendar_date, {:controller => 'spud/events/calendars', :action => :show}) %>
|
14
|
-
</nav>
|
15
|
-
|
16
|
-
<%= build_calendar_for @events, :year => date.year, :month => date.month do |t| %>
|
17
|
-
<%= raw t.head('S', 'M', 'T', 'W', 'T', 'F', 'S') %>
|
18
|
-
<%= t.day do |day, tasks| %>
|
19
|
-
<div class="spud_events_calendar_date_container">
|
20
|
-
<%= content_tag :span, day.day, :class => (tasks.count > 0 ? "spud_events_calendar_date spud_events_calendar_date_active" : "spud_events_calendar_date") %>
|
21
|
-
<% tasks.each do |task| %>
|
22
|
-
<%= link_to task.title[0,25], "#", :class => "spud_events_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)};" %>
|
23
|
-
<% end %>
|
24
|
-
</div>
|
25
|
-
<% end %>
|
26
|
-
<% end %>
|
data/config/application.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'rails/all'
|
4
|
-
|
5
|
-
if defined?(Bundler)
|
6
|
-
# If you precompile assets before deploying to production, use this line
|
7
|
-
Bundler.require *Rails.groups(:assets => %w(development test))
|
8
|
-
# If you want your assets lazily compiled in production, use this line
|
9
|
-
# Bundler.require(:default, :assets, Rails.env)
|
10
|
-
end
|
11
|
-
|
12
|
-
module Spud
|
13
|
-
module Events
|
14
|
-
class Application < Rails::Application
|
15
|
-
# Settings in config/environments/* take precedence over those specified here.
|
16
|
-
# Application configuration should go into files in config/initializers
|
17
|
-
# -- all .rb files in that directory are automatically loaded.
|
18
|
-
|
19
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
20
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
21
|
-
|
22
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
23
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
24
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
25
|
-
|
26
|
-
# Activate observers that should always be running.
|
27
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
28
|
-
|
29
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
30
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
31
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
32
|
-
|
33
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
34
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
35
|
-
# config.i18n.default_locale = :de
|
36
|
-
|
37
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
38
|
-
config.encoding = "utf-8"
|
39
|
-
|
40
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
41
|
-
config.filter_parameters += [:password]
|
42
|
-
|
43
|
-
# Enable the asset pipeline
|
44
|
-
config.assets.enabled = true
|
45
|
-
|
46
|
-
# Version of your assets, change this if you want to expire all your assets
|
47
|
-
config.assets.version = '1.0'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/config/boot.rb
DELETED
data/lib/spud/events/calendar.rb
DELETED
@@ -1,85 +0,0 @@
|
|
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
|
@@ -1,58 +0,0 @@
|
|
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
|
data/lib/spud/events/engine.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'tb_core'
|
2
|
-
|
3
|
-
module Spud
|
4
|
-
module Events
|
5
|
-
class Engine < Rails::Engine
|
6
|
-
engine_name :tb_events
|
7
|
-
|
8
|
-
config.autoload_paths << File.expand_path("../../..", __FILE__)
|
9
|
-
|
10
|
-
initializer :admin do
|
11
|
-
Spud::Core.configure do |config|
|
12
|
-
config.admin_applications += [{:name => "Events", :thumbnail => "spud/admin/events_thumb.png", :url => "/admin/events",:order => 10}]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
initializer :assets do |config|
|
17
|
-
Spud::Core.append_admin_javascripts('spud/admin/events')
|
18
|
-
Spud::Core.append_admin_stylesheets('spud/admin/events')
|
19
|
-
Rails.application.config.assets.precompile += [
|
20
|
-
"spud/events.*",
|
21
|
-
"spud/admin/events.*"
|
22
|
-
]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
module Spud
|
2
|
-
module Events
|
3
|
-
class TableBuilder
|
4
|
-
include ::ActionView::Helpers::TagHelper
|
5
|
-
|
6
|
-
def initialize(objects, template, options)
|
7
|
-
raise ArgumentError, "TableBuilder expects an Array but found a #{objects.inspect}" unless objects.is_a? Array
|
8
|
-
@objects, @template, @options = objects, template, options
|
9
|
-
end
|
10
|
-
|
11
|
-
def head(*args, &block)
|
12
|
-
if block_given?
|
13
|
-
@template.content_tag(:thead, nil, options_from_hash(args), true, &block)
|
14
|
-
else
|
15
|
-
@num_of_columns = args.size
|
16
|
-
content = args.collect do |c|
|
17
|
-
@template.content_tag(:th, c)
|
18
|
-
end.join("\n").html_safe
|
19
|
-
@template.content_tag(:thead, @template.content_tag(:tr,content,{},false))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def head_r(*args, &block)
|
24
|
-
raise ArgumentError, "Missing block" unless block_given?
|
25
|
-
options = options_from_hash(args)
|
26
|
-
head do
|
27
|
-
@template.content_tag(:tr, nil, options, true, &block)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def body(*args, &block)
|
32
|
-
raise ArgumentError, "Missing block" unless block_given?
|
33
|
-
options = options_from_hash(args)
|
34
|
-
content = @objects.collect do |c|
|
35
|
-
@template.with_output_buffer{block.call(c)}
|
36
|
-
end.join("\n").html_safe
|
37
|
-
@template.content_tag(:tbody, content, options, false)
|
38
|
-
end
|
39
|
-
|
40
|
-
def body_r(*args, &block)
|
41
|
-
raise ArgumentError, "Missing block" unless block_given?
|
42
|
-
options = options_from_hash(args)
|
43
|
-
tds = @objects.collect do |thing|
|
44
|
-
@template.with_output_buffer{block.call(thing)}
|
45
|
-
end
|
46
|
-
content = tds.collect do |td|
|
47
|
-
@template.content_tag(:tr,td, {}, false)
|
48
|
-
end.join("\n").html_safe
|
49
|
-
"\n#{@template.content_tag(:tbody, content, options, false)}".html_safe
|
50
|
-
end
|
51
|
-
|
52
|
-
def r(*args, &block)
|
53
|
-
raise ArgumentError, "Missing block" unless block_given?
|
54
|
-
options = options_from_hash(args)
|
55
|
-
@template.content_tag(:tr, nil, options, true, &block)
|
56
|
-
end
|
57
|
-
|
58
|
-
def h(*args, &block)
|
59
|
-
if block_given?
|
60
|
-
@template.content_tag(:th, nil, options_from_hash(args), true, &block)
|
61
|
-
else
|
62
|
-
content = args.shift
|
63
|
-
@template.content_tag(:th, content, options_from_hash(args))
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def d(*args, &block)
|
68
|
-
if block_given?
|
69
|
-
@template.content_tag(:td, nil, options_from_hash(args), true, &block)
|
70
|
-
else
|
71
|
-
content = args.shift
|
72
|
-
@template.content_tag(:td, content, options_from_hash(args))
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def options_from_hash(args)
|
79
|
-
args.last.is_a?(Hash) ? args.pop : {}
|
80
|
-
end
|
81
|
-
|
82
|
-
# def content_tag(tag, content, *args, &block)
|
83
|
-
# options = options_from_hash(args)
|
84
|
-
# @template.content_tag(tag, content, options, &block)
|
85
|
-
# end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|