Method: GCal4Ruby::Service#to_iframe
- Defined in:
- lib/gcal4ruby/service.rb
#to_iframe(cals, params = {}, colors = {}) ⇒ Object
Helper function to return a formatted iframe embedded google calendar. Parameters are:
-
cals: either an array of calendar ids, or :all for all calendars, or :first for the first (usally default) calendar
-
params: a hash of parameters that affect the display of the embedded calendar. Accepts any parameter that the google iframe recognizes. Here are the most common:
height:: the height of the embedded calendar in pixels
width:: the width of the embedded calendar in pixels
title:: the title to display
bgcolor:: the background color. Limited choices, see google docs for allowable values.
showTitle:: set to '0' to hide the title
showDate:: set to '0' to hide the current date
showNav:: set to '0 to hide the navigation tools
showPrint:: set to '0' to hide the print icon
showTabs:: set to '0' to hide the tabs
showCalendars:: set to '0' to hide the calendars selection drop down
showTz:: set to '0' to hide the timezone selection
border:: the border width in pixels
dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
ctz:: The timezone to convert event times to
-
colors: a hash of calendar ids as key and color values as associated hash values. Example: => ‘#7A367A’
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gcal4ruby/service.rb', line 131 def to_iframe(cals, params = {}, colors = {}) params[:height] ||= "600" params[:width] ||= "600" params[:title] ||= (self.account ? self.account : '') params[:bgcolor] ||= "#FFFFFF" params[:border] ||= "0" params.each{|key, value| params[key] = CGI::escape(value)} output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}&" if cals.is_a?(Array) for c in cals output += "src=#{c}&" if colors and colors[c] output += "color=%23#{colors[c].gsub("#", "")}&" end end elsif cals == :all cal_list = calendars() for c in cal_list output += "src=#{c.id}&" end elsif cals == :first cal_list = calendars() output += "src=#{cal_list[0].id}&" end "<iframe src='http://www.google.com/calendar/embed?#{output}' style='#{params[:border]} px solid;' width='#{params[:width]}' height='#{params[:height]}' frameborder='#{params[:border]}' scrolling='no'></iframe>" end |