Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the generator compatible with mongoid #52

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 5 additions & 4 deletions generators/event_calendar/templates/jq_javascript.js
Original file line number Diff line number Diff line change
@@ -3,19 +3,20 @@
* Handles when events span rows, or don't have a background color
*/
jQuery(document).ready(function($) {
var highlight_color = "#2EAC6A";
var highlight_color = "#6ABEFF";
var bg_color = null;

// highlight events that have a background color
$(".ec-event-bg").live("mouseover", function() {
event_id = $(this).attr("data-event-id");
event_class_name = $(this).attr("data-event-class");
$("#ec-"+event_class_name+"-"+event_id).css("background-color", highlight_color);
bg_color = $(".ec-"+event_class_name+"-"+event_id).css("background-color");
$(".ec-"+event_class_name+"-"+event_id).css("background-color", highlight_color);
});
$(".ec-event-bg").live("mouseout", function() {
event_id = $(this).attr("data-event-id");
event_class_name = $(this).attr("data-event-class");
event_color = $(this).attr("data-color");
$("#ec-"+event_class_name+"-"+event_id).css("background-color", event_color);
$(".ec-"+event_class_name+"-"+event_id).css("background-color", bg_color);
});

// highlight events that don't have a background color
4 changes: 4 additions & 0 deletions generators/event_calendar/templates/stylesheet.css
Original file line number Diff line number Diff line change
@@ -169,6 +169,10 @@ a.ec-day-link {
white-space: nowrap;
}

.ec-event-bg {
background-color: #9aa4ad;
}

.ec-event :hover {
/* doesn't look as good as js highlighting */
/* background-color: #2eac6a; */
8 changes: 4 additions & 4 deletions lib/event_calendar/calendar_helper.rb
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ def calendar(options = {}, &block)
# but they are needed to perform height calculations
:width => nil,
:height => 500,
:day_names_height => 18,
:day_names_height => 25,
:day_nums_height => 18,
:event_height => 18,
:event_margin => 1,
@@ -213,7 +213,7 @@ def calendar(options = {}, &block)

cal << %(<td class="ec-event-cell" colspan="#{(dates[1]-dates[0]).to_i + 1}" )
cal << %(style="padding-top: #{options[:event_margin]}px;">)
cal << %(<div id="ec-#{class_name}-#{event.id}" class="ec-event )
cal << %(<div id="ec-#{class_name}-#{event.id}" class="ec-event ec-#{class_name}-#{event.id} )
if class_name != "event"
cal << %(ec-#{class_name} )
end
@@ -222,7 +222,7 @@ def calendar(options = {}, &block)
cal << %(style="color: #{event.color}; )
else
cal << %(ec-event-bg" )
cal << %(style="background-color: #{event.color}; )
#cal << %(style="background-color: #{event.color}; )
end

cal << %(padding-top: #{options[:event_padding_top]}px; )
@@ -341,7 +341,7 @@ def cal_row_heights(options)
# if we reached the end of the week, calculate this row's height
if index % 7 == 0
total_event_height = options[:event_height] + options[:event_margin]
calc_row_height = (num_event_rows * total_event_height) + options[:day_nums_height] + options[:event_margin]
calc_row_height = ((num_event_rows+2) * total_event_height) + options[:day_nums_height] + options[:event_margin]
row_height = [min_height, calc_row_height].max
row_heights << row_height
num_event_rows = 0
4 changes: 3 additions & 1 deletion lib/generators/event_calendar/event_calendar_generator.rb
Original file line number Diff line number Diff line change
@@ -38,7 +38,9 @@ def do_it
empty_directory "app/views/#{view_name}"
template "view.html.erb", File.join("app/views/#{view_name}/index.html.erb")
template "helper.rb.erb", "app/helpers/#{helper_name}.rb"
migration_template "migration.rb.erb", "db/migrate/create_#{table_name}.rb"
unless defined? Mongoid
migration_template "migration.rb.erb", "db/migrate/create_#{table_name}.rb"
end
route "match '/#{view_name}(/:year(/:month))' => '#{view_name}#index', :as => :#{named_route_name}, :constraints => {:year => /\\d{4}/, :month => /\\d{1,2}/}"
end

16 changes: 16 additions & 0 deletions lib/generators/event_calendar/templates/model.rb.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
<% if defined? Mongoid %>
class <%= model_class_name %>
include Mongoid::Document
include Mongoid::Timestamps

field :name, :type => String
field :start_at, :type => DateTime
field :end_at, :type => DateTime
<%- if options[:use_all_day] -%>
field :all_day, :type => Boolean, :default => false
<%- end -%>
<%- if options[:use_color] -%>
field :color, :type => String
<%- end -%>
<% else %>
class <%= model_class_name %> < ActiveRecord::Base
<% end %>
has_event_calendar
end