schedular 0.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.
Files changed (74) hide show
  1. data/.document +7 -0
  2. data/.gitignore +25 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +57 -0
  6. data/VERSION +1 -0
  7. data/app/views/schedular/events/_calendar.html.erb +28 -0
  8. data/app/views/schedular/events/_form.html.erb +22 -0
  9. data/app/views/schedular/events/edit.html.erb +13 -0
  10. data/app/views/schedular/events/index.html.erb +26 -0
  11. data/app/views/schedular/events/new.html.erb +12 -0
  12. data/app/views/schedular/events/show.html.erb +29 -0
  13. data/config/routes.rb +5 -0
  14. data/generators/schedular_migrations/schedular_migrations_generator.rb +7 -0
  15. data/generators/schedular_migrations/templates/schedular_migrations.rb +27 -0
  16. data/generators/schedular_views/schedular_views_generator.rb +20 -0
  17. data/lib/schedular.rb +17 -0
  18. data/lib/schedular/event.rb +39 -0
  19. data/lib/schedular/events_controller.rb +93 -0
  20. data/lib/schedular/locale/schedular.es.yml +22 -0
  21. data/lib/schedular/time.rb +25 -0
  22. data/rails/init.rb +1 -0
  23. data/test/helper.rb +15 -0
  24. data/test/rails_app/README +243 -0
  25. data/test/rails_app/Rakefile +10 -0
  26. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  27. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  28. data/test/rails_app/app/views/layouts/application.html.erb +17 -0
  29. data/test/rails_app/config/boot.rb +110 -0
  30. data/test/rails_app/config/database.yml +22 -0
  31. data/test/rails_app/config/environment.rb +41 -0
  32. data/test/rails_app/config/environments/development.rb +17 -0
  33. data/test/rails_app/config/environments/production.rb +28 -0
  34. data/test/rails_app/config/environments/test.rb +28 -0
  35. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/rails_app/config/initializers/inflections.rb +10 -0
  37. data/test/rails_app/config/initializers/mime_types.rb +5 -0
  38. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  39. data/test/rails_app/config/initializers/session_store.rb +15 -0
  40. data/test/rails_app/config/locales/en.yml +5 -0
  41. data/test/rails_app/config/routes.rb +43 -0
  42. data/test/rails_app/doc/README_FOR_APP +2 -0
  43. data/test/rails_app/lib/event.rb +3 -0
  44. data/test/rails_app/public/404.html +30 -0
  45. data/test/rails_app/public/422.html +30 -0
  46. data/test/rails_app/public/500.html +30 -0
  47. data/test/rails_app/public/favicon.ico +0 -0
  48. data/test/rails_app/public/images/rails.png +0 -0
  49. data/test/rails_app/public/index.html +275 -0
  50. data/test/rails_app/public/javascripts/application.js +2 -0
  51. data/test/rails_app/public/javascripts/controls.js +963 -0
  52. data/test/rails_app/public/javascripts/dragdrop.js +973 -0
  53. data/test/rails_app/public/javascripts/effects.js +1128 -0
  54. data/test/rails_app/public/javascripts/prototype.js +4320 -0
  55. data/test/rails_app/public/robots.txt +5 -0
  56. data/test/rails_app/script/about +4 -0
  57. data/test/rails_app/script/console +3 -0
  58. data/test/rails_app/script/dbconsole +3 -0
  59. data/test/rails_app/script/destroy +3 -0
  60. data/test/rails_app/script/generate +3 -0
  61. data/test/rails_app/script/performance/benchmarker +3 -0
  62. data/test/rails_app/script/performance/profiler +3 -0
  63. data/test/rails_app/script/plugin +3 -0
  64. data/test/rails_app/script/runner +3 -0
  65. data/test/rails_app/script/server +3 -0
  66. data/test/rails_app/test/performance/browsing_test.rb +9 -0
  67. data/test/rails_app/test/test_helper.rb +38 -0
  68. data/test/rails_app/tmp/restart.txt +0 -0
  69. data/test/support/migrations.rb +22 -0
  70. data/test/test_event.rb +107 -0
  71. data/test/test_events_controller.rb +280 -0
  72. data/test/test_partials.rb +54 -0
  73. data/test/test_time.rb +62 -0
  74. metadata +217 -0
@@ -0,0 +1,7 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ generators/**/*.rb
6
+ config/**/*.rb
7
+ LICENSE
@@ -0,0 +1,25 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ schedular.gemspec
21
+
22
+ ## PROJECT::SPECIFIC
23
+ test/rails_app/db
24
+ test/rails_app/log
25
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Macario Ortega
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = events
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Macario Ortega. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "schedular"
8
+ gem.summary = %Q{Bare Bones Events CMS Rails Engine}
9
+ gem.description = %Q{Bare Bones Events CMS Rails Engine, event dates can be inputed as text in spanish, english date recognition is next.}
10
+ gem.email = "macarui@gmail.com"
11
+ gem.homepage = "http://github.com/maca/schedular"
12
+ gem.authors = ["Macario Ortega"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ gem.add_dependency 'table_builder', '>= 0.2.3'
15
+ gem.add_dependency 'eventual', '>= 0.5.3'
16
+ gem.add_dependency 'es-mx-locale', '>= 0.1.1'
17
+
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "schedular #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,28 @@
1
+ <%- current_month = Date.civil year.to_i, month.to_i -%>
2
+
3
+ <% calendar_for events, :year => current_month.year, :month => current_month.month, :html => {:id => 'events-calendar'} do |c| %>
4
+ <%- c.head do -%>
5
+ <%- c.r :class => :links do -%>
6
+ <%- c.h :colspan => 2 do -%>
7
+ <%- prev = current_month << 1 -%>
8
+ <%= link_to '&lt;&lt;', monthly_schedule_path(:year => prev.year, :month => prev.month) %>
9
+ <%- end -%>
10
+ <%- c.h :colspan => 3 do -%>
11
+ <%= link_to I18n.l(current_month, :format => :short_month).capitalize, monthly_schedule_path(:year => current_month.year, :month => current_month.month) %>
12
+ <%- end -%>
13
+ <%- c.h :colspan => 2 do -%>
14
+ <%- follow = current_month >> 1 -%>
15
+ <%= link_to '&gt;&gt;', monthly_schedule_path(:year => follow.year, :month => follow.month) %>
16
+ <%- end -%>
17
+ <%- end -%>
18
+ <%= c.r I18n.t('date.abbr_day_names').map { |day| "<th>#{day}</th>" } %>
19
+ <%- end -%>
20
+
21
+ <% c.day :day_method => lambda{ |e| e.times.map{ |t| t.value} } do |date, events| %>
22
+ <%- if events.empty? -%>
23
+ <span class='day-number'><%= date.day %></span>
24
+ <%- else -%>
25
+ <%= link_to date.day, daily_schedule_path(:year => date.year, :month => date.month, :day => date.day), :class => 'day-number' %>
26
+ <%- end -%>
27
+ <% end %>
28
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <% form_for @event do |f| %>
2
+ <%= f.error_messages %>
3
+
4
+ <p>
5
+ <%= f.label :name %>
6
+ <%= f.text_field :name %>
7
+ </p>
8
+
9
+ <p>
10
+ <%= f.label :dates %>
11
+ <%= f.text_area :dates %>
12
+ </p>
13
+
14
+ <p>
15
+ <%= f.label :description %>
16
+ <%= f.text_area :description %>
17
+ </p>
18
+
19
+ <p>
20
+ <%= f.submit %>
21
+ </p>
22
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <h1><%= I18n.t 'views.headers.edit', :model => Schedular::Event.human_name %></h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <p class='actions'>
6
+ <%= link_to I18n.t('views.actions.show'), @event %> |
7
+ <%= link_to I18n.t('views.actions.back'), schedular_events_path %>
8
+ </p>
9
+
10
+ <%- content_for :calendar do -%>
11
+ <%- month = current_month || Date.today -%>
12
+ <%= render 'calendar', :events => @month_events, :month => month.month, :year => month.year %>
13
+ <%- end -%>
@@ -0,0 +1,26 @@
1
+ <h1>
2
+ <%- date = Date.civil params[:year].to_i, params[:month].to_i, (params[:day] || 1).to_i -%>
3
+ <%- date = I18n.l date, :format => (params[:day] ? :long : :month) -%>
4
+ <%= I18n.t 'schedular.views.events.headers.listing', :date => date %>
5
+ </h1>
6
+
7
+ <%- for event in @events -%>
8
+ <dl>
9
+ <dt><%= link_to event.name, event %></dt>
10
+ <dd class='description'>
11
+ <%= event.description %>
12
+ </dd>
13
+ <dd class='admin'>
14
+ <%= link_to I18n.t('views.actions.edit'), edit_schedular_event_path(event) %> |
15
+ <%= link_to I18n.t('views.actions.destroy'), event, :method => :delete, :confirm => I18n.t('views.prompts.confirm_destroy', :model => Schedular::Event.human_name) %>
16
+ </dd>
17
+ </dl>
18
+ <%- end -%>
19
+
20
+ <p class='actions'>
21
+ <%= link_to I18n.t('views.actions.create', :model => Schedular::Event.human_name), new_schedular_event_path %>
22
+ </p>
23
+
24
+ <%- content_for :calendar do -%>
25
+ <%= render 'calendar', :events => @month_events, :month => params[:month], :year => params[:year] %>
26
+ <%- end -%>
@@ -0,0 +1,12 @@
1
+ <h1><%= I18n.t 'views.headers.new', :model => Schedular::Event.human_name %></h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <p class='actions'>
6
+ <%= link_to I18n.t('views.actions.back'), schedular_events_path %>
7
+ </p>
8
+
9
+ <%- content_for :calendar do -%>
10
+ <%- month = current_month || Date.today -%>
11
+ <%= render 'calendar', :events => @month_events, :month => month.month, :year => month.year %>
12
+ <%- end -%>
@@ -0,0 +1,29 @@
1
+ <h1><%= h @event.name %></h1>
2
+
3
+ <p>
4
+ <%= @event.class.human_attribute_name :name %><br/>
5
+ <%= h @event.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <%= @event.class.human_attribute_name :dates %><br/>
10
+ <%= h @event.dates %>
11
+ </p>
12
+
13
+ <p>
14
+ <%= @event.class.human_attribute_name :description %><br/>
15
+ <%= h @event.description %>
16
+ </p>
17
+
18
+ <p class='actions'>
19
+ <%= link_to I18n.t('views.actions.edit'), edit_schedular_event_path(@event) %>
20
+ |
21
+ <%= link_to I18n.t('views.actions.destroy'), @event, :confirm => I18n.t('views.prompts.confir_destroy', :model => @event.class.human_name), :method => :delete %>
22
+ |
23
+ <%= link_to I18n.t('views.actions.back'), schedular_events_path %>
24
+ </p>
25
+
26
+ <%- content_for :calendar do -%>
27
+ <%- month = current_month || Date.today -%>
28
+ <%= render 'calendar', :events => @month_events, :month => month.month, :year => month.year %>
29
+ <%- end -%>
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.daily_schedule "/events/:year/:month/:day.:format", :controller => 'schedular/events', :requirements => {:year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/}
3
+ map.monthly_schedule "/events/:year/:month.:format", :controller => 'schedular/events', :requirements => {:year => /\d{4}/, :month => /\d{1,2}/}
4
+ map.resources :events, :controller => 'schedular/events', :name_prefix => 'schedular_'
5
+ end
@@ -0,0 +1,7 @@
1
+ class SchedularMigrationsGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'schedular_migrations.rb', 'db/migrate', :migration_file_name => "schedular_migrations"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ class SchedularMigrations < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :schedular_events do |t|
4
+ t.string :name
5
+ t.string :dates
6
+ t.text :description
7
+ t.timestamps
8
+ end
9
+
10
+ create_table :schedular_times do |t|
11
+ t.datetime :value
12
+ t.boolean :all_day
13
+ t.timestamps
14
+ end
15
+
16
+ create_table :schedular_events_times, :id => false do |t|
17
+ t.integer :time_id
18
+ t.integer :event_id
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :schedular_events
24
+ drop_table :schedular_times
25
+ drop_table :schedular_events_times
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ class SchedularViewsGenerator < Rails::Generator::Base
2
+ def initialize *args
3
+ super
4
+ @source_root = options[:source] || File.join(spec.path, '..', '..')
5
+ end
6
+
7
+ def manifest
8
+ record do |m|
9
+ m.directory "app/views"
10
+
11
+ directory = nil
12
+ Dir.glob("#{@source_root}/app/views/**/*.erb").each do |file|
13
+ file = file.gsub("#{ @source_root }/", "")
14
+ m.directory directory = File.dirname(file) if directory != File.dirname(file)
15
+ m.file file, file
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,17 @@
1
+ require 'eventual'
2
+ require 'table_builder'
3
+ require 'es-mx-locale'
4
+
5
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ require "schedular/time"
8
+ require "schedular/event"
9
+ require "schedular/events_controller"
10
+
11
+ # Load locale files
12
+ I18n.load_path += Dir.glob "#{ File.dirname(__FILE__) }/schedular/locale/*.yml"
13
+
14
+
15
+ # Load class openings
16
+ Dir.glob(Rails.root.join('engines', 'schedular', '**', '*.rb')).each { |f| require f }
17
+
@@ -0,0 +1,39 @@
1
+ module Schedular
2
+ class Event < ActiveRecord::Base
3
+ set_table_name :schedular_events
4
+ has_and_belongs_to_many :times, :join_table => :schedular_events_times, :class_name => 'Schedular::Time'#, :order => 'value asc'
5
+
6
+ validates_presence_of :name, :dates
7
+ validate :times_not_empty
8
+
9
+ named_scope :all, {}
10
+ named_scope :include_times, :include => :times
11
+ named_scope :by_time_or_period, lambda{ |time|
12
+ time = Range === time || DateTime === time ? time : (time..time+1)
13
+ {:conditions => {'schedular_times.value' => time}, :include => :times }
14
+ }
15
+
16
+ def dates= dates
17
+ parsed = Eventual.parse dates, :lang => I18n.locale
18
+
19
+ self.times = parsed.map do |time|
20
+ # TODO: This method is soooo uneficient
21
+ all_day = !(DateTime === time)
22
+ Schedular::Time.all_day(all_day).by_time_or_period(time).first || Schedular::Time.new(:value => time, :all_day => all_day)
23
+ end if parsed
24
+
25
+ self['dates'] = dates
26
+ end
27
+
28
+ def self.by_params params
29
+ return all unless params[:year] and params[:month] #TODO: Find by year
30
+ day = Date.civil params[:year].to_i, params[:month].to_i, (params[:day] || 1).to_i
31
+ params[:day] ? by_time_or_period(day) : by_time_or_period(day..day >> 1)
32
+ end
33
+
34
+ private
35
+ def times_not_empty
36
+ errors.add(:dates, I18n.t('activerecord.errors.messages.invalid')) if self.dates and self.times.empty?
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,93 @@
1
+ module Schedular
2
+ class EventsController < ::ApplicationController
3
+ helper_method :current_month
4
+
5
+ def index
6
+ today = Date.today
7
+ return redirect_to(monthly_schedule_path(:year => params[:year] || today.year, :month => today.month)) unless params[:year] && params[:month]
8
+
9
+ @events = Event.by_params(params).include_times
10
+ @month_events = params[:day] ? Event.by_params(params.merge(:day => nil)) : @events
11
+
12
+ session[:current_month] = Date.civil params[:year].to_i, params[:month].to_i
13
+
14
+ respond_to do |format|
15
+ format.html {}
16
+ format.xml { render :xml => @events }
17
+ format.json { render :json => @events }
18
+ end
19
+ end
20
+
21
+ def show
22
+ @event = Event.find params[:id]
23
+ respond_to do |format|
24
+ format.html {}
25
+ format.xml { render :xml => @event }
26
+ format.json { render :json => @event }
27
+ end
28
+ end
29
+
30
+ def new
31
+ @event = Event.new
32
+ respond_to do |format|
33
+ format.html {}
34
+ format.xml { render :xml => @event }
35
+ format.json { render :json => @event }
36
+ end
37
+ end
38
+
39
+ def edit
40
+ @event = Event.find params[:id]
41
+ end
42
+
43
+ def create
44
+ @event = Event.new params[:schedular_event]
45
+
46
+ respond_to do |format|
47
+ if @event.save
48
+ # flash[:notice] = 'Event was successfully created.'
49
+ format.html { redirect_to @event }
50
+ format.xml { render :xml => @event, :status => :created, :location => @event }
51
+ format.json { render :json => @event, :status => :created, :location => @event }
52
+ else
53
+ format.html { render :action => "new" }
54
+ format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
55
+ format.json { render :json => @event.errors, :status => :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ def update
61
+ @event = Event.find params[:id]
62
+
63
+ respond_to do |format|
64
+ if @event.update_attributes params[:schedular_event]
65
+ # flash[:notice] = 'Event was successfully created.'
66
+ format.html { redirect_to @event }
67
+ format.xml { render :xml => @event, :status => :ok, :location => @event }
68
+ format.json { render :json => @event, :status => :ok, :location => @event }
69
+ else
70
+ format.html { render :action => "new" }
71
+ format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
72
+ format.json { render :json => @event.errors, :status => :unprocessable_entity }
73
+ end
74
+ end
75
+ end
76
+
77
+ def destroy
78
+ @event = Event.find params[:id]
79
+ @event.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to schedular_events_url }
83
+ format.xml { head :ok }
84
+ format.json { head :ok }
85
+ end
86
+ end
87
+
88
+ private
89
+ def current_month
90
+ session[:current_month]
91
+ end
92
+ end
93
+ end