radiant-event_calendar-extension 1.4.10 → 1.4.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,14 +35,16 @@ class EventsController < SiteController
35
35
 
36
36
  def show
37
37
  @event = Event.find(params[:id])
38
- format.html {
39
- timeout = (Radiant::Config['event_calendar:cache_duration'] || self.class.cache_timeout || 3600).seconds
40
- expires_in timeout.to_i, :public => true, :private => false
41
- }
42
- format.ics {
43
- ical = RiCal.Calendar { |cal| cal.add_subcomponent(@event.to_ri_cal) }
44
- send_data ical, :filename => "#{@event.title.slugify}.ics"
45
- }
38
+ respond_to do |format|
39
+ format.html {
40
+ timeout = (Radiant::Config['event_calendar:cache_duration'] || self.class.cache_timeout || 3600).seconds
41
+ expires_in timeout.to_i, :public => true, :private => false
42
+ }
43
+ format.ics {
44
+ ical = RiCal.Calendar { |cal| cal.add_subcomponent(@event.to_ri_cal) }
45
+ send_data ical.to_s, :filename => "#{@event.title.slugify}.ics"
46
+ }
47
+ end
46
48
  end
47
49
 
48
50
  ### helper methods
@@ -1,4 +1,5 @@
1
1
  - no_date ||= false
2
+ - @seen_events ||= []
2
3
 
3
4
  - if event
4
5
  - event_master_id = event.master_id || event.id
@@ -15,7 +15,7 @@
15
15
  = @event.facebook_id
16
16
 
17
17
  - content_for :facebook_url do
18
- = event.facebook_url
18
+ = @event.facebook_url
19
19
 
20
20
  #events
21
21
  = yield :event
@@ -33,8 +33,10 @@ en:
33
33
  calendar_day_name: "%A"
34
34
  calendar_day_of_month: "%d"
35
35
  event_calendar_extension:
36
+ download_event: "Download event"
36
37
  view_on_facebook: "view on facebook"
37
38
  attend_on_facebook: "attend on facebook"
39
+ tweet_this: "Tweet this"
38
40
 
39
41
  # all this is going to be moved into the more conventional activerecord and event_calendar_extension namespaces when I get a chance.
40
42
  refresh_calendar: "refresh calendar"
@@ -1,4 +1,5 @@
1
1
  require 'chronic'
2
+ require 'uri'
2
3
 
3
4
  module EventCalendarTags
4
5
  include Radiant::Taggable
@@ -399,6 +400,7 @@ module EventCalendarTags
399
400
  #### display attributes of a single event
400
401
 
401
402
  tag "event" do |tag|
403
+ tag.locals.event ||= get_event(tag)
402
404
  raise TagError, "can't have r:event without an event" unless tag.locals.event
403
405
  tag.expand
404
406
  end
@@ -466,17 +468,36 @@ module EventCalendarTags
466
468
  tag.locals.event.facebook_url
467
469
  end
468
470
 
471
+ desc %{
472
+ Renders a link to the ical file for this single event. This is not a subscription link,
473
+ and updates to the event will not be propagated: for that you need the webcal link to
474
+ a calendar or set of events. This is just a quick way to get an event in someone's diary.
475
+
476
+ Usage:
477
+ <pre><code><r:event:ical_link class="ical" /></code></pre>
478
+ }
479
+ tag "event:ical_link" do |tag|
480
+ options = tag.attr.dup
481
+ options['title'] ||= I18n.t('event_calendar_extension.download_event')
482
+ attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
483
+ attributes = " #{attributes}" unless attributes.empty?
484
+ text = tag.double? ? tag.expand : I18n.t('event_calendar_extension.download_event')
485
+ url = File.join(Radiant.config['event_calendar.path'], 'events', "#{tag.locals.event.id}.ics")
486
+ %{<a href="#{url}"#{attributes}>#{text}</a>}
487
+ end
488
+
469
489
  desc %{
470
490
  Renders a link to the facebook version of this event, if any. Attributes are
471
491
  passed through in the usual way and if the tag is double its rendered contents
472
492
  will become the link text.
473
493
 
474
494
  Usage:
475
- <pre><code><r:facebook_link class="facebook event" /></code></pre>
495
+ <pre><code><r:event:facebook_link class="facebook event" /></code></pre>
476
496
  }
477
497
  tag "event:facebook_link" do |tag|
478
498
  if tag.locals.event.facebook_id
479
499
  options = tag.attr.dup
500
+ options['title'] ||= I18n.t('event_calendar_extension.view_on_facebook')
480
501
  attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
481
502
  attributes = " #{attributes}" unless attributes.empty?
482
503
  text = tag.double? ? tag.expand : I18n.t('event_calendar_extension.view_on_facebook')
@@ -484,6 +505,48 @@ module EventCalendarTags
484
505
  end
485
506
  end
486
507
 
508
+ desc %{
509
+ Renders a twitter 'tweet this' link poopulated with information about this event.
510
+ This links to a twitter 'intent' to give you more control over the presentation.
511
+ If you want the basic tweet-this button with a counter, you don't need any radius tags.
512
+
513
+ Twitter-specific attributes:
514
+
515
+ * **text** is the prepared text you may want to suggest to your twitterer.
516
+ * **via** is the name of the account referred to in the link (ie yours, probably)
517
+ * **hashtags** is the hashtag(s) that will be included in the suggested tweet. Omit the hash.
518
+ * **related** is the (comma-separated) list of accounts the twitterer will be invited to
519
+ follow. A justification can be :appended to each name.
520
+
521
+ These attributes will be URL-encoded for you and appended to the twitter url. All other link
522
+ attributes are passed through in the usual way and if the tag is double its rendered contents
523
+ will become the link text.
524
+
525
+ Usage:
526
+ <pre><code><r:event:tweet_link class="twitter" via="spanner_org" hashtag="radiant:smart cms for small teams" /></code></pre>
527
+
528
+ For this to work your page must also include the twitter widgets javascript call:
529
+
530
+ <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
531
+
532
+ For more information see https://dev.twitter.com/docs/intents#tweet-intent
533
+ }
534
+ tag "event:tweet_link" do |tag|
535
+ options = tag.attr.dup
536
+ options['title'] ||= I18n.t('event_calendar_extension.tweet_this')
537
+ event_url = "http://" + Radiant.config['site.host'] + tag.locals.page.url + "#event_" + tag.locals.event.id.to_s
538
+ qs = ["url=#{URI.escape(event_url)}"]
539
+ qs << "text=#{URI.escape(options.delete('text'))}" if options['text']
540
+ qs << "via=#{URI.escape(options.delete('via'))}" if options['via']
541
+ qs << "related=#{URI.escape(options.delete('related'))}" if options['related']
542
+ qs << "hashtags=#{URI.escape(options.delete('hashtags'))}" if options['hashtags']
543
+ twitter_url = "https://twitter.com/intent/tweet?" + qs.join('&amp;')
544
+ attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
545
+ attributes = " #{attributes}" unless attributes.empty?
546
+ text = tag.double? ? tag.expand : I18n.t('event_calendar_extension.tweet_this')
547
+ %{<a href="#{twitter_url}"#{attributes}>#{text}</a>}
548
+ end
549
+
487
550
  #todo: venues:* tags
488
551
 
489
552
  desc %{
@@ -1026,6 +1089,16 @@ private
1026
1089
  ef.find(:all, standard_find_options(tag))
1027
1090
  end
1028
1091
 
1092
+ # I don't suppose this is used much but it's useful in testing
1093
+
1094
+ def get_event(tag)
1095
+ if event_id = tag.attr.delete('id')
1096
+ tag.locals.event = Event.find_by_id(event_id)
1097
+ elsif event_title = tag.attr.delete('title')
1098
+ tag.locals.event = Event.find_by_title(event_title)
1099
+ end
1100
+ end
1101
+
1029
1102
  # other extensions - eg taggable_events - will chain the event_finder to add more scopes
1030
1103
 
1031
1104
  def event_finder(tag)
@@ -1,5 +1,5 @@
1
1
  module RadiantEventCalendarExtension
2
- VERSION = '1.4.10'
2
+ VERSION = '1.4.12'
3
3
  SUMMARY = %Q{Event Calendar Extension for Radiant CMS}
4
4
  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.)"
5
5
  URL = "http://github.com/radiant/radiant-event_calendar-extension"
@@ -9,6 +9,7 @@ class CalendarEventsDataset < Dataset::Base
9
9
  end
10
10
  create_event 'spanning', :title => "Simple Event", :start_date => "2009-11-03 09:00:00", :end_date => "2009-11-04 17:00:00"
11
11
  create_event 'allday', :title => "All Day Event", :start_date => "2009-11-03 09:00:00", :end_date => "2009-11-04 17:00:00", :all_day => true
12
+ create_event 'facebooked', :title => "Facebook Event", :start_date => "2009-11-03 09:00:00", :end_date => "2009-11-04 17:00:00", :facebook_id => "101"
12
13
  end
13
14
  end
14
15
 
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe EventCalendarTags do
4
+ dataset :calendar_pages, :calendar_events
5
+ let(:page) { pages(:calendar) }
6
+ let(:event) { events(:simple) }
7
+ let(:fbe) { events(:facebooked) }
8
+
9
+ context "rendering event: tags" do
10
+ before do
11
+ Radiant.config['site.host'] = "test.host"
12
+ Radiant.config['event_calendar.path'] = "/test_calendar"
13
+ end
14
+
15
+ [:id, :title, :description, :short_description, :location, :url, :facebook_id].each do |tag|
16
+ it "event:#{tag}" do
17
+ page.should render(%{<r:event id="#{event.id}"><r:event:#{tag} /></r:event>}).as( event.send(tag.to_sym).to_s )
18
+ end
19
+ end
20
+
21
+ it "event:ical_link" do
22
+ page.should render(%{<r:event id="#{event.id}"><r:event:ical_link class="ical">I</r:event:ical_link></r:event>}).as(
23
+ %{<a href="/test_calendar/events/#{event.id}.ics" title="Download event" class="ical">I</a>}
24
+ )
25
+ end
26
+
27
+ it "event:facebook_link" do
28
+ page.should render(%{<r:event id="#{fbe.id}"><r:event:facebook_link class="fb">F</r:event:facebook_link></r:event>}).as(
29
+ %{<a href="http://www.facebook.com/event.php?eid=#{fbe.facebook_id}" title="view on facebook" class="fb">F</a>}
30
+ )
31
+ page.should render(%{<r:event id="#{event.id}"><r:event:facebook_link class="fb">F</r:event:facebook_link></r:event>}).as( "" )
32
+ end
33
+
34
+ it "event:tweet_link" do
35
+ page.should render(%{<r:event id="#{event.id}"><r:event:tweet_link class="twit" text="foo: & bar" via="me" related="they">T</r:event:tweet_link></r:event>}).as(
36
+ %{<a href="https://twitter.com/intent/tweet?url=http://test.host/calendar/%23event_#{event.id}&amp;text=foo:%20&%20bar&amp;via=me&amp;related=they" title="Tweet this" class="twit">T</a>}
37
+ )
38
+ end
39
+ end
40
+
41
+ end
@@ -29,6 +29,13 @@ describe Event do
29
29
  @event.duration.should == 0
30
30
  end
31
31
  end
32
+
33
+ describe "A facebook event" do
34
+ it "should return a facebook url" do
35
+ events(:facebooked).facebook_url.should == "http://www.facebook.com/event.php?eid=101"
36
+ events(:simple).facebook_url.should be_nil
37
+ end
38
+ end
32
39
 
33
40
  describe "A spanning event" do
34
41
  before do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-event_calendar-extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 10
10
- version: 1.4.10
9
+ - 12
10
+ version: 1.4.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Loren Johnson
@@ -191,6 +191,7 @@ files:
191
191
  - spec/files/dummy.ics
192
192
  - spec/files/ny.ics
193
193
  - spec/lib/event_calendar_page_spec.rb
194
+ - spec/lib/event_calendar_tags_spec.rb
194
195
  - spec/models/calendar_spec.rb
195
196
  - spec/models/event_spec.rb
196
197
  - spec/models/ical_spec.rb
@@ -201,7 +202,7 @@ has_rdoc: true
201
202
  homepage: http://github.com/radiant/radiant-event_calendar-extension
202
203
  licenses: []
203
204
 
204
- post_install_message: "\n Add this to your radiant project with:\n\n config.gem 'radiant-event_calendar-extension', :version => '~> 1.4.10'\n\n "
205
+ post_install_message: "\n Add this to your radiant project with:\n\n config.gem 'radiant-event_calendar-extension', :version => '~> 1.4.12'\n\n "
205
206
  rdoc_options: []
206
207
 
207
208
  require_paths:
@@ -240,6 +241,7 @@ test_files:
240
241
  - spec/files/dummy.ics
241
242
  - spec/files/ny.ics
242
243
  - spec/lib/event_calendar_page_spec.rb
244
+ - spec/lib/event_calendar_tags_spec.rb
243
245
  - spec/models/calendar_spec.rb
244
246
  - spec/models/event_spec.rb
245
247
  - spec/models/ical_spec.rb