diff --git a/Gemfile b/Gemfile index 0c09722..3194ed4 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source "http://rubygems.org" gemspec gem 'refinerycms', '~> 2.0.0' +gem 'refinerycms-i18n', :git => 'git://github.com/parndt/refinerycms-i18n.git' # Refinery/rails should pull in the proper versions of these group :assets do diff --git a/Gemfile.lock b/Gemfile.lock index 696b692..c8db693 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,16 @@ +GIT + remote: git://github.com/parndt/refinerycms-i18n.git + revision: 2a6d35554421d4e0a2ebeba6eb291bcd0ade9291 + specs: + refinerycms-i18n (2.1.0.dev) + rails-i18n (~> 0.6.5) + refinerycms-core (~> 2.0) + routing-filter (~> 0.3.0) + PATH remote: . specs: - refinerycms-calendar (2.0.1) + refinerycms-calendar (2.0.2) refinerycms-core (~> 2.0.3) GEM @@ -84,7 +93,6 @@ GEM activemodel (>= 3.0.0) activerecord (>= 3.0.0) paper_trail (~> 2) - growl (1.0.3) guard (1.0.3) ffi (>= 0.5.0) thor (>= 0.14.6) @@ -98,6 +106,8 @@ GEM railties (>= 3.2.0, < 5.0) thor (~> 0.14) json (1.7.3) + libnotify (0.1.4) + ffi (>= 0.6.2) libwebsocket (0.1.3) addressable mail (2.4.4) @@ -129,6 +139,8 @@ GEM activesupport (= 3.2.3) bundler (~> 1.0) railties (= 3.2.3) + rails-i18n (0.6.5) + i18n (~> 0.5) railties (3.2.3) actionpack (= 3.2.3) activesupport (= 3.2.3) @@ -137,7 +149,8 @@ GEM rdoc (~> 3.4) thor (~> 0.14.6) rake (0.9.2.2) - rb-fsevent (0.9.1) + rb-inotify (0.8.8) + ffi (>= 0.5.0) rdoc (3.12) json (~> 1.4) refinerycms (2.0.3) @@ -186,6 +199,8 @@ GEM rack-test (~> 0.6.0) refinerycms-core (= 2.0.3) rspec-rails (~> 2.8.1) + routing-filter (0.3.1) + actionpack rspec (2.8.0) rspec-core (~> 2.8.0) rspec-expectations (~> 2.8.0) @@ -245,17 +260,18 @@ DEPENDENCIES coffee-rails factory_girl_rails generator_spec - growl (~> 1.0.3) guard-spork jquery-rails jruby-openssl + libnotify (~> 0.1.3) mysql2 pg rb-fchange (~> 0.0.5) - rb-fsevent (>= 0.3.9) + rb-inotify (>= 0.5.1) rb-notifu (~> 0.0.4) refinerycms (~> 2.0.0) refinerycms-calendar! + refinerycms-i18n! refinerycms-testing (~> 2.0.0) sass-rails spork (= 0.9.0.rc9) diff --git a/app/controllers/refinery/calendar/admin/events_controller.rb b/app/controllers/refinery/calendar/admin/events_controller.rb index 19a1e3d..e1639b0 100644 --- a/app/controllers/refinery/calendar/admin/events_controller.rb +++ b/app/controllers/refinery/calendar/admin/events_controller.rb @@ -7,7 +7,8 @@ class EventsController < ::Refinery::AdminController crudify :'refinery/calendar/event', :xhr_paging => true, :sortable => false, - :order => "'from' DESC" + :order => "'from' DESC", + :include => [:translations] private def find_venues diff --git a/app/controllers/refinery/calendar/admin/venues_controller.rb b/app/controllers/refinery/calendar/admin/venues_controller.rb index a6fce1e..9fdf91a 100644 --- a/app/controllers/refinery/calendar/admin/venues_controller.rb +++ b/app/controllers/refinery/calendar/admin/venues_controller.rb @@ -7,7 +7,8 @@ class VenuesController < ::Refinery::AdminController :title_attribute => 'name', :xhr_paging => true, :sortable => false, - :order => 'created_at DESC' + :order => 'created_at DESC', + :include => [:translations] end end end diff --git a/app/models/refinery/calendar/event.rb b/app/models/refinery/calendar/event.rb index 93f02bd..55780a8 100644 --- a/app/models/refinery/calendar/event.rb +++ b/app/models/refinery/calendar/event.rb @@ -1,9 +1,11 @@ module Refinery module Calendar class Event < Refinery::Core::BaseModel - extend FriendlyId - friendly_id :title, :use => :slugged + translates :title, :excerpt, :description, :slug + + extend FriendlyId + friendly_id :title, :use => [:slugged, :globalize] belongs_to :venue @@ -13,23 +15,43 @@ class Event < Refinery::Core::BaseModel :venue_id, :excerpt, :description, :featured, :position + attr_accessor :locale + delegate :name, :address, :to => :venue, :prefix => true, :allow_nil => true + class Translation + attr_accessible :locale + end + class << self def upcoming - where('refinery_calendar_events.from >= ?', Time.now) + where('refinery_calendar_events.from >= ?', Time.now).with_globalize end def featured - where(:featured => true) + where(:featured => true).with_globalize end def archive - where('refinery_calendar_events.from < ?', Time.now) + where('refinery_calendar_events.from < ?', Time.now).with_globalize + end + + # Wrap up the logic of finding the events based on the translations table. + def with_globalize(conditions = {}) + conditions = {:locale => ::Globalize.locale}.merge(conditions) + globalized_conditions = {} + conditions.keys.each do |key| + if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s) + globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key) + end + end + # A join implies readonly which we don't really want. + joins(:translations).where(globalized_conditions).where(conditions).readonly(false) end + end end end diff --git a/app/models/refinery/calendar/venue.rb b/app/models/refinery/calendar/venue.rb index 41ef5a3..ca870dc 100644 --- a/app/models/refinery/calendar/venue.rb +++ b/app/models/refinery/calendar/venue.rb @@ -1,9 +1,17 @@ module Refinery module Calendar class Venue < Refinery::Core::BaseModel + translates :name has_many :events validates :name, :presence => true, :uniqueness => true attr_accessible :name, :address, :url, :phone, :position + + attr_accessor :locale + + class Translation + attr_accessible :locale + end + end end end diff --git a/app/views/refinery/calendar/admin/events/_event.html.erb b/app/views/refinery/calendar/admin/events/_event.html.erb index 962decc..153a8cf 100644 --- a/app/views/refinery/calendar/admin/events/_event.html.erb +++ b/app/views/refinery/calendar/admin/events/_event.html.erb @@ -1,7 +1,15 @@