Module: CalendarsHelper

Defined in:
app/helpers/calendars_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_calendar_for(objects, *args, &block) ⇒ Object

Raises:

  • (ArgumentError)


2
3
4
5
6
7
8
9
10
11
# File 'app/helpers/calendars_helper.rb', line 2

def build_calendar_for(objects, *args, &block)
  raise ArgumentError, "Missing block" unless block_given?
  options = args.last.is_a?(Hash) ? args.pop : {}
  html_options = options[:html]
  builder = options[:builder] || Spud::Events::CalendarBuilder
  calendar = options[:calendar] || Spud::Events::Calendar

  content = with_output_buffer{block.call(builder.new(objects||[], self, calendar, options))}
  self.(:table, content, html_options, false)
end

#calendar_fore_color(backcolor) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/calendars_helper.rb', line 17

def calendar_fore_color(backcolor)
  fore_color = "ffffff"
  if backcolor.length != 6
    return fore_color
  end

  red = backcolor[0,2].hex
  green = backcolor[2,2].hex
  blue = backcolor[4,2].hex

  perceived_brightness = Math.sqrt(red*red*0.241 + green*green*0.691 + blue*blue*0.068)


  # average = (red+green+blue) / 3
  if(perceived_brightness >= 130)
    return "000000"
  else
    return fore_color
  end
end

#get_calendar_options(text_for_all) ⇒ Object



13
14
15
# File 'app/helpers/calendars_helper.rb', line 13

def get_calendar_options(text_for_all)
  options_for_select(SpudCalendar.all.collect { |f| [f.title, f.title.gsub(/([^A-Z0-9]+)/i, "-").downcase] }.insert(0, text_for_all), @current_calendar)
end


44
45
46
47
48
# File 'app/helpers/calendars_helper.rb', line 44

def link_to_next_calendar_month(date, url_for_options)
  date = date.advance(:months => 1)
  calendar = params[:calendar] ? params[:calendar] : nil
  link_to('Next Month »'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link next_calendar btn').html_safe
end


38
39
40
41
42
# File 'app/helpers/calendars_helper.rb', line 38

def link_to_previous_calendar_month(date, url_for_options)
  date = date.advance(:months => -1)
  calendar = params[:calendar] ? params[:calendar] : nil
  link_to('« Previous Month'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link previous_calendar btn').html_safe
end