From 5763eea40d7a4224d35c457c210100271c002cb4 Mon Sep 17 00:00:00 2001 From: William Ross Date: Wed, 5 Oct 2011 10:00:16 +0100 Subject: [PATCH] radius tags updated, made consistent with (now deprecated) event views --- README.md | 74 ++++++++++--------- app/controllers/events_controller.rb | 1 + app/models/event.rb | 4 + app/views/events/_event.html.haml | 7 +- config/initializers/radiant_config.rb | 2 +- config/locales/en.yml | 1 + config/routes.rb | 3 +- lib/event_calendar_tags.rb | 97 +++++++++++-------------- lib/radiant-event_calendar-extension.rb | 2 +- spec/lib/event_calendar_page_spec.rb | 8 +- spec/lib/event_calendar_tags_spec.rb | 5 +- 11 files changed, 102 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index 209c780..a06cd2d 100644 --- a/README.md +++ b/README.md @@ -65,44 +65,9 @@ Should be obvious. There are a few points to remember: * Recurrence is for the repetition of identical separate events. A single event that spans several days only needs to have the right start and end times. * End times are optional: an event with just a start time is just listed where it begins. -### Displaying events with the EventsController - -The events controller uses `share_layouts` to define various page parts that your layout can bring in. To use it, create a layout with any or all of these parts: - -* `title` is the page title and can also be shown with `r:title` -* `events` is a formatted list of events with date stamps and descriptions -* `continuing_events` is a compact list of events that have already begun but which continue into the period being shown -* `calendar` is a usual calendar block with links to months and days. Days without events are not linked. -* `pagination` is the usual will_paginate block. -* `faceting` here only gives the option to remove any date filters that have been applied. If you add the `taggable_events` extension it gets more useful. - -Set the config entry `event_calendar.layout` to the name of your layout and point a browser at /calendar to see what you've got. - -Here's a basic sample layout that should just work: - - - - - - <r:title /> - - - -

- - - - - - - - -One quirk that might go away: at the moment if there are few new events then the continuing events are moved into the events page part. Most layouts work better that way. - ### Displaying events with an EventCalendar page -Set up a new page at /events/ with the type 'EventCalendar'. To show a pageable calendar view of the current month, all you need is this: +This is the preferred method. Set up a new page at /events/ with the type 'EventCalendar'. To show a pageable calendar view of the current month, all you need is this: @@ -139,6 +104,43 @@ If you have another column in your layout, try adding this: For clickable thumbnails of coming months. +### Displaying events with the EventsController + +I think I'm going to deprecate this use some time soon: it's too hard to adapt to local circumstances. For now it still works: + +The events controller uses `share_layouts` to define various page parts that your layout can bring in. To use it, create a layout with any or all of these parts. + +* `title` is the page title and can also be shown with `r:title` +* `events` is a formatted list of events with date stamps and descriptions +* `continuing_events` is a compact list of events that have already begun but which continue into the period being shown +* `calendar` is a usual calendar block with links to months and days. Days without events are not linked. +* `pagination` is the usual will_paginate block. +* `faceting` here only gives the option to remove any date filters that have been applied. If you add the `taggable_events` extension it gets more useful. + +Set the config entry `event_calendar.layout` to the name of your layout and point a browser at /calendar to see what you've got. + +Here's a basic sample layout that should just work: + + + + + + <r:title /> + + + +

+ + + + + + + + +One quirk that might go away: at the moment if there are few new events then the continuing events are moved into the events page part. Most layouts work better that way. + ### Compatibility I've tested this with Darwin Calendar Server (on Ubuntu), with Google Calendar and with feeds published from iCal on a mac. It should work just as well with iCal server on OS X Server, and in theory any other CalDav-compliant back end. See http://caldav.calconnect.org/ for more possibilities. diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index ada269b..e2c78a3 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,5 +1,6 @@ class EventsController < SiteController require "uri" + require "ri_cal" include Radiant::Pagination::Controller helper_method :events, :all_events, :continuing_events, :period, :calendars, :list_description diff --git a/app/models/event.rb b/app/models/event.rb index 5ff2e50..838bd2d 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -191,6 +191,10 @@ def day I18n.l start_date, :format => :calendar_day_name end + def short_day + I18n.l start_date, :format => :calendar_short_day + end + def mday I18n.l start_date, :format => :calendar_day_of_month end diff --git a/app/views/events/_event.html.haml b/app/views/events/_event.html.haml index 9199921..f97928b 100644 --- a/app/views/events/_event.html.haml +++ b/app/views/events/_event.html.haml @@ -5,9 +5,12 @@ - event_master_id = event.master_id || event.id - repeating = true if @seen_events[event_master_id] - @seen_events[event_master_id] = true; - - cssclass = event.calendar ? "event #{event.calendar.slug}" : "event" + - cssclasses = ['event'] + - cssclasses << 'repeat' if repeating + - cssclasses << event.calendar.slug if event.calendar - %div{:class => cssclass} + + %div{:class => cssclasses.join(' ')} - unless no_date .datemark .mon= event.short_month diff --git a/config/initializers/radiant_config.rb b/config/initializers/radiant_config.rb index 9217a0e..7e06adc 100644 --- a/config/initializers/radiant_config.rb +++ b/config/initializers/radiant_config.rb @@ -1,6 +1,6 @@ Radiant.config do |config| config.namespace('event_calendar') do |calendar| - calendar.define 'path', :default => "/calendar", :allow_blank => false + calendar.define 'path', :default => "cal", :allow_blank => false calendar.define 'icals_path', :default => "/icals", :allow_blank => false calendar.define 'cache_duration', :type => :integer, :default => 3600, :units => 'seconds' calendar.define 'refresh_interval', :type => :integer, :default => 3600, :units => 'seconds' diff --git a/config/locales/en.yml b/config/locales/en.yml index 493de2c..0ed4c79 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -17,6 +17,7 @@ en: calendar_period_minicalendar_title: "%B %Y" calendar_period_minicalendar_month: "%B" calendar_month: "%B" + calendar_short_day: "%a" calendar_short_month: "%b" calendar_day_name: "%A" calendar_day_of_month: "%d" diff --git a/config/routes.rb b/config/routes.rb index 237c740..c6a12cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,8 @@ cal.calendars_home '/', :controller => 'events', :action => 'index' end - calendar_prefix = Radiant.config['event_calendar.path'] || "/calendar" + calendar_prefix = Radiant.config['event_calendar.path'] || "cal" + calendar_prefix = nil if calendar_prefix.blank? map.resources :events, :path_prefix => calendar_prefix, :only => [:index, :show] map.calendar "#{calendar_prefix}.:format", :controller => 'events', :action => 'index' map.calendar_year "#{calendar_prefix}/:year", :controller => 'events', :action => 'index' diff --git a/lib/event_calendar_tags.rb b/lib/event_calendar_tags.rb index e808e3f..810898c 100644 --- a/lib/event_calendar_tags.rb +++ b/lib/event_calendar_tags.rb @@ -359,43 +359,6 @@ class TagError < StandardError; end %{#{text}} end - desc %{ - Renders the path to the local .ics file for this calendar, suitable for read-only subscription in iCal or other calendar programs. - - Usage: -
- } - tag "calendar:ical_url" do |tag| - tag.locals.calendar.to_ics - end - - desc %{ - Renders a link to the local .ics file for this calendar, suitable for read-only subscription in iCal or other calendar programs. - Link attributes are passed through as usual. - - Usage: -
- } - tag "calendar:ical_link" do |tag| - options = tag.attr.dup - anchor = options['anchor'] ? "##{options.delete('anchor')}" : '' - attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip - attributes = " #{attributes}" unless attributes.empty? - text = tag.double? ? tag.expand : tag.render('calendar:name') - %{#{text}} - end - - desc %{ - Renders a small graphical link to the local .ics file for this calendar. - - Usage: -
- } - tag "calendar:ical_icon" do |tag| - text = tag.attr['text'] || '' - %{subscribe to #{tag.render('calendar:name')} #{text}} - end - #### Event:* tags #### display attributes of a single event @@ -426,7 +389,7 @@ class TagError < StandardError; end end end - [:id, :title, :description, :short_description, :location, :url, :facebook_id].each do |attribute| + [:id, :title, :description, :short_description, :location, :url, :facebook_id, :facebook_url].each do |attribute| desc %{ Renders the #{attribute} attribute of the current event. @@ -459,13 +422,16 @@ class TagError < StandardError; end end desc %{ - Renders the url of the facebook event corresponding to this event, if there is one. - - Usage: -
+ Sets the active calendar to that of the present event, if any. } - tag "event:facebook_url" do |tag| - tag.locals.event.facebook_url + tag "event:calendar" do |tag| + if tag.locals.calendar = tag.locals.event.calendar + if tag.double? + tag.expand + else + tag.locals.calendar.name + end + end end desc %{ @@ -497,6 +463,7 @@ class TagError < StandardError; end tag "event:facebook_link" do |tag| if tag.locals.event.facebook_id options = tag.attr.dup + options['class'] ||= 'facebook event' options['title'] ||= I18n.t('event_calendar_extension.view_on_facebook') attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip attributes = " #{attributes}" unless attributes.empty? @@ -546,8 +513,34 @@ class TagError < StandardError; end text = tag.double? ? tag.expand : I18n.t('event_calendar_extension.tweet_this') %{#{text}} end + + desc %{ + Renders the path to the local .ics file for this calendar, suitable for read-only subscription in iCal or other calendar programs. + + Usage: +
+ } + tag "calendar:ical_url" do |tag| + tag.locals.calendar.to_ics + end + + desc %{ + Renders a link to the ical representation of this event, which should drop the event into + a user's desktop calendar. Link attributes are passed through as usual. - #todo: venues:* tags + Usage: +
+ } + tag "event:ical_link" do |tag| + options = tag.attr.dup + options['title'] ||= I18n.t('event_calendar_extension.download_event') + options['class'] ||= 'ical download' + attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip + text = tag.double? ? tag.expand : I18n.t('event_calendar_extension.tweet_this') + %{#{text}} + end + + #TODO: venues:* tags desc %{ Renders a sensible location string, based on whatever venue information is available. @@ -800,15 +793,12 @@ class TagError < StandardError; end
} tag "event:datemark" do |tag| - html = "" - html << _datemark(tag.locals.event.start_date) - html - end - - def _datemark(date=Time.now) %{ -
#{Date::ABBR_MONTHNAMES[date.month]}#{"%02d" % date.mday}
- } +
+ #{tag.locals.event.short_day} + #{tag.locals.event.mday} +
+} end desc %{ @@ -818,7 +808,6 @@ def _datemark(date=Time.now) Usage:
- } tag "events:minimonth" do |tag| attr = parse_boolean_attributes(tag) diff --git a/lib/radiant-event_calendar-extension.rb b/lib/radiant-event_calendar-extension.rb index f65b64c..551ea06 100644 --- a/lib/radiant-event_calendar-extension.rb +++ b/lib/radiant-event_calendar-extension.rb @@ -1,5 +1,5 @@ module RadiantEventCalendarExtension - VERSION = '1.5.1' + VERSION = '1.5.2' SUMMARY = %Q{Event Calendar Extension for Radiant CMS} DESCRIPTION = "An event calendar extension that administers events locally or draws them from any ical or CalDAV publishers (Google Calendar, .Mac, Darwin Calendar Server, etc.)" URL = "http://github.com/radiant/radiant-event_calendar-extension" diff --git a/spec/lib/event_calendar_page_spec.rb b/spec/lib/event_calendar_page_spec.rb index 3f6bc77..ca79de6 100644 --- a/spec/lib/event_calendar_page_spec.rb +++ b/spec/lib/event_calendar_page_spec.rb @@ -12,12 +12,12 @@ end describe ".find_by_url" do - it "should return self to our own url" do - pages(:calendar).find_by_url("/#{pages(:calendar).slug}/").should == pages(:calendar) + it "should return self to our own path" do + pages(:calendar).find_by_path("/#{pages(:calendar).slug}/").should == pages(:calendar) end - it "should return self to any child url" do - pages(:calendar).find_by_url("/#{pages(:calendar).slug}/something").should == pages(:calendar) + it "should return self to any child path" do + pages(:calendar).find_by_path("/#{pages(:calendar).slug}/something").should == pages(:calendar) end end diff --git a/spec/lib/event_calendar_tags_spec.rb b/spec/lib/event_calendar_tags_spec.rb index ba7d2f8..00e678a 100644 --- a/spec/lib/event_calendar_tags_spec.rb +++ b/spec/lib/event_calendar_tags_spec.rb @@ -9,10 +9,9 @@ context "rendering event: tags" do before do Radiant.config['site.host'] = "test.host" - Radiant.config['event_calendar.path'] = "/test_calendar" end - [:id, :title, :description, :short_description, :location, :url, :facebook_id].each do |tag| + [:id, :title, :description, :short_description, :location, :url, :facebook_id, :facebook_url].each do |tag| it "event:#{tag}" do page.should render(%{}).as( event.send(tag.to_sym).to_s ) end @@ -20,7 +19,7 @@ it "event:ical_link" do page.should render(%{I}).as( - %{I} + %{I} ) end