Flux rss en place
This commit is contained in:
parent
0572dea806
commit
a76e23c109
@ -1,14 +1,31 @@
|
|||||||
class EventsController < InheritedResources::Base
|
class EventsController < InheritedResources::Base
|
||||||
def index
|
def index
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {
|
||||||
if (params[:year] and !params[:month])
|
if (params[:year] and !params[:month])
|
||||||
# Whole year calendar
|
# Whole year calendar
|
||||||
@events = Event.year(params[:year] || Date.today.year)
|
@events = Event.year(params[:year] || Date.today.year)
|
||||||
else
|
else
|
||||||
@events = Event.month(params[:year] || Date.today.year, params[:month] || Date.today.month)
|
@events = Event.month(params[:year] || Date.today.year, params[:month] || Date.today.month)
|
||||||
end
|
end
|
||||||
if (params[:region] && params[:region].present?)
|
if (params[:region] && params[:region].present? && params[:region] != 'all')
|
||||||
@events = @events.region(params[:region])
|
@events = @events.region(params[:region])
|
||||||
end
|
end
|
||||||
|
if (params[:tag])
|
||||||
|
@events = @events.tag(params[:tag])
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
format.rss {
|
||||||
|
@events = Event.where('start_time >= now()').order(start_time: :asc).limit(25)
|
||||||
|
if (params[:region] && params[:region].present? && params[:region] != 'all')
|
||||||
|
@events = @events.region(params[:region])
|
||||||
|
end
|
||||||
|
if (params[:tag])
|
||||||
|
@events = @events.tag(params[:tag])
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -10,4 +10,5 @@ class Event < ActiveRecord::Base
|
|||||||
"#{year}-#{month.to_i-1}-1", "#{year}-#{month.to_i+2}-1"
|
"#{year}-#{month.to_i-1}-1", "#{year}-#{month.to_i+2}-1"
|
||||||
}
|
}
|
||||||
scope :region, -> region { where region: region }
|
scope :region, -> region { where region: region }
|
||||||
|
scope :tag, -> tag { where "tags like ?", "%#{tag}%" }
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
= label_tag :region, Region.model_name.human
|
= label_tag :region, Region.model_name.human
|
||||||
= select_tag :region,
|
= select_tag :region,
|
||||||
options_from_collection_for_select(Region.all, 'id', 'name', params[:region]),
|
options_from_collection_for_select(Region.all, 'id', 'name', params[:region]),
|
||||||
prompt: t('region_selector')
|
prompt: t('.all_regions')
|
||||||
|
|
||||||
- if (params[:year] and !params[:month])
|
- if (params[:year] and !params[:month])
|
||||||
-# Whole year calendar
|
-# Whole year calendar
|
||||||
@ -20,22 +20,23 @@
|
|||||||
- params[:month] = i
|
- params[:month] = i
|
||||||
|
|
||||||
= calendar @events, { prev_text: '', next_text: '', start_day: :monday,
|
= calendar @events, { prev_text: '', next_text: '', start_day: :monday,
|
||||||
params: { region: params[:region] } } do |event|
|
params: { region: params[:region], tag: params[:tag] } } do |event|
|
||||||
%ul.events
|
%ul.events
|
||||||
%li.event
|
%li.event
|
||||||
= link_to event.url do
|
= link_to event do
|
||||||
%strong= event.city
|
%strong= event.city
|
||||||
= event.title
|
= event.title
|
||||||
|
|
||||||
- else
|
- else
|
||||||
= calendar @events, { prev_text: '<<', next_text: '>>', start_day: :monday,
|
= calendar @events, { prev_text: '<<', next_text: '>>', start_day: :monday,
|
||||||
params: { region: params[:region] } } do |event|
|
params: { region: params[:region], tag: params[:tag] } } do |event|
|
||||||
%ul.events
|
%ul.events
|
||||||
%li.event
|
%li.event
|
||||||
= link_to event.url do
|
= link_to event do
|
||||||
%strong= event.city
|
%strong= event.city
|
||||||
= event.title
|
= event.title
|
||||||
|
|
||||||
.formats
|
.formats
|
||||||
=t '.calendar_in'
|
=t '.calendar_in'
|
||||||
rss, iCal ou calendrier Google
|
= link_to 'rss', events_url(:rss)
|
||||||
|
, iCal ou calendrier Google
|
||||||
|
54
app/views/events/index.rss.builder
Normal file
54
app/views/events/index.rss.builder
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
xml.instruct!
|
||||||
|
|
||||||
|
xml.tag! 'rdf:RDF', 'xmlns:rdf' => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
|
||||||
|
'xmlns' => "http://purl.org/rss/1.0/", 'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
|
||||||
|
'xmlns:sy' => "http://purl.org/rss/1.0/modules/syndication/",
|
||||||
|
'xmlns:admin' => "http://webns.net/mvcb/", 'xmlns:cc' => "http://web.resource.org/cc/",
|
||||||
|
'xmlns:content' => "http://purl.org/rss/1.0/modules/content/",
|
||||||
|
'xmlns:georss' => "http://www.georss.org/georss" do
|
||||||
|
xml.channel 'rdf:about' => root_url do
|
||||||
|
xml.title "Agenda du Libre [ #{params[:region].present? && params[:region] != 'all' ? Region.find(params[:region]).name : t('.all_regions')} ]"
|
||||||
|
xml.description 'Agenda des événements autour du Logiciel Libre'
|
||||||
|
xml.link 'http://www.agendadulibre.org'
|
||||||
|
xml.tag! 'dc:language', 'fr'
|
||||||
|
xml.tag! 'dc:creator', 'AgendaDuLibre.org'
|
||||||
|
|
||||||
|
xml.items do
|
||||||
|
xml.tag! 'rdf:Seq' do
|
||||||
|
for event in @events
|
||||||
|
xml.tag! 'rdf:li', 'rdf:resource' => event_url(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for event in @events
|
||||||
|
xml.item 'rdf:about' => event_url(event) do
|
||||||
|
xml.title "#{event.city}: #{event.title}, #{l event.start_time.to_date, format: :long}"
|
||||||
|
xml.link event_url event
|
||||||
|
xml.tag! 'dc:identifier', "#{event.id}@agendadulibre.org"
|
||||||
|
xml.tag! 'dc:date', event.start_time
|
||||||
|
xml.tag! 'georss:point', City.find_all_by_majname(event.city.upcase).collect { |c| "#{c.latitude} #{c.longitude}" }.first
|
||||||
|
|
||||||
|
content = "<h2><em>#{event.city}</em>: #{event.title}</h2>
|
||||||
|
<h3>Date et lieu</h3>
|
||||||
|
<p>#{l event.start_time.to_date, format: :long},
|
||||||
|
de #{event.start_time.hour}h#{event.start_time.min} à #{event.end_time.hour}h#{event.end_time.min}.</p>
|
||||||
|
<p>À <em><a href=\"http://fr.wikipedia.org/wiki/#{event.city}\">#{event.city}</a></em>,
|
||||||
|
<a href=\"http://fr.wikipedia.org/wiki/#{event.region.name}\">#{event.region.name}</a></p>
|
||||||
|
<h3>Description</h3>
|
||||||
|
#{event.description}
|
||||||
|
<h3>Informations</h3>
|
||||||
|
<p>Site Web: <a href=\"#{event.url}\">#{event.url}</a></p>
|
||||||
|
<p>Contact: #{mail_to event.contact.sub('@', ' CHEZ ').sub('.', ' POINT '), event.contact.sub('@', ' CHEZ ').sub('.', ' POINT ')}</p>
|
||||||
|
"
|
||||||
|
|
||||||
|
if (event.tags && event.tags.present?)
|
||||||
|
content += "<p>Tags: #{event.tags.split.collect { |tag| link_to tag, events_url(tag: tag) }.join(', ')}</p>"
|
||||||
|
end
|
||||||
|
|
||||||
|
xml.description strip_tags(content)
|
||||||
|
xml.tag! 'content:encoded', content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -17,7 +17,7 @@
|
|||||||
= @event.city
|
= @event.city
|
||||||
%p
|
%p
|
||||||
%b Region:
|
%b Region:
|
||||||
= @event.region
|
= @event.region.name
|
||||||
%p
|
%p
|
||||||
%b Locality:
|
%b Locality:
|
||||||
= @event.locality
|
= @event.locality
|
||||||
@ -27,9 +27,6 @@
|
|||||||
%p
|
%p
|
||||||
%b Contact:
|
%b Contact:
|
||||||
= @event.contact
|
= @event.contact
|
||||||
%p
|
|
||||||
%b Contact:
|
|
||||||
= @event.contact
|
|
||||||
%p
|
%p
|
||||||
%b Submitter:
|
%b Submitter:
|
||||||
= @event.submitter
|
= @event.submitter
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
%footer.bottom
|
%footer.bottom
|
||||||
%nav
|
%nav
|
||||||
= link_to t('.propose'), new_event_path
|
= link_to t('.propose'), new_event_path
|
||||||
= link_to t('.rss'), users_url
|
= link_to t('.rss'), events_url(:rss)
|
||||||
= link_to t('.ical'), users_url
|
= link_to t('.ical'), users_url
|
||||||
= link_to t('.map'), users_url
|
= link_to t('.map'), users_url
|
||||||
= link_to t('.tags'), users_url
|
= link_to t('.tags'), users_url
|
||||||
|
@ -3,3 +3,5 @@
|
|||||||
# Add new mime types for use in respond_to blocks:
|
# Add new mime types for use in respond_to blocks:
|
||||||
# Mime::Type.register "text/richtext", :rtf
|
# Mime::Type.register "text/richtext", :rtf
|
||||||
# Mime::Type.register_alias "text/html", :iphone
|
# Mime::Type.register_alias "text/html", :iphone
|
||||||
|
|
||||||
|
Mime::Type.register "text/xml", :rss
|
||||||
|
@ -2,7 +2,7 @@ fr:
|
|||||||
show: Voir
|
show: Voir
|
||||||
edit: Éditer
|
edit: Éditer
|
||||||
destroy: Supprimer
|
destroy: Supprimer
|
||||||
region_selector: Toutes les régions
|
|
||||||
|
|
||||||
attributes:
|
attributes:
|
||||||
id: ID
|
id: ID
|
||||||
@ -52,6 +52,8 @@ fr:
|
|||||||
- Jeudi
|
- Jeudi
|
||||||
- Vendredi
|
- Vendredi
|
||||||
- Samedi
|
- Samedi
|
||||||
|
formats:
|
||||||
|
long: "le %A %d %B %Y"
|
||||||
|
|
||||||
layouts:
|
layouts:
|
||||||
application:
|
application:
|
||||||
@ -70,3 +72,4 @@ fr:
|
|||||||
events:
|
events:
|
||||||
index:
|
index:
|
||||||
calendar_in: Ce calendrier en
|
calendar_in: Ce calendrier en
|
||||||
|
all_regions: Toutes les régions
|
||||||
|
Loading…
Reference in New Issue
Block a user