Module: MuckRakerGoogleHelper

Defined in:
app/helpers/muck_raker_google_helper.rb

Instance Method Summary collapse

Instance Method Details

#google_bookmark_display(feed, content_id = 'feed_display_content', number_of_items = 5, javascript_callback = nil) ⇒ Object

Render bookmarks from a given feed

feed: Url for which to generate the feed. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

number_of_items: Number of items to display for the given feed. javascript_callback: Name of a javascript method to call after the feed has finished loading. The

method should accept the feed uri and the content id. ie  feed_callback(uri, content_id).


81
82
83
84
85
86
# File 'app/helpers/muck_raker_google_helper.rb', line 81

def google_bookmark_display(feed,
                        content_id = 'feed_display_content',
                        number_of_items = 5,
                        javascript_callback = nil)
  render :partial => 'google/feed_bookmarks', :locals => { :feed => feed, :content_id => content_id, :number_of_items => number_of_items, :javascript_callback => javascript_callback }
end

#google_dynamic_feeds_vertical(feeds, content_id = 'dynamic_feed_vertical_content', options = { :numResults => 20, :stacked => true, :horizontal => false }) ⇒ Object

Render a google dynamic feed control.

feeds: An array of feeds to render each with a property ‘title’ and ‘uri’ defined content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

options: A hash containing the values to pass to the Google widget. The available options are defined here:

http://www.google.com/uds/solutions/dynamicfeed/reference.html.


11
12
13
14
15
# File 'app/helpers/muck_raker_google_helper.rb', line 11

def google_dynamic_feeds_vertical(feeds, 
                                  content_id = 'dynamic_feed_vertical_content', 
                                  options = { :numResults => 20, :stacked => true, :horizontal => false })
  render :partial => 'google/dynamic_feeds_vertical', :locals => { :feeds => feeds, :content_id => content_id, :options => options }
end

#google_feed_display(feed, content_id = 'feed_display_content', number_of_items = 5, javascript_callback = nil) ⇒ Object

Render contents from a given feed

feed: Url for which to generate the feed. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

number_of_items: Number of items to display for the given feed. javascript_callback: Name of a javascript method to call after the feed has finished loading. The

method should accept the feed uri and the content id. ie  feed_callback(uri, content_id).


65
66
67
68
69
70
# File 'app/helpers/muck_raker_google_helper.rb', line 65

def google_feed_display(feed,
                        content_id = 'feed_display_content',
                        number_of_items = 5,
                        javascript_callback = nil)
  render :partial => 'google/feed_display', :locals => { :feed => feed, :content_id => content_id, :number_of_items => number_of_items, :javascript_callback => javascript_callback }
end

#google_feed_photos(feed, content_id = 'feed_photo_content', number_of_images = 5, javascript_callback = nil) ⇒ Object

Render photos from a given feed

feed: Url for which to generate the feed. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

number_of_images: Number of images to get from the feed. javascript_callback: Name of a javascript method to call after the feed has finished loading. The

method should accept the feed uri and the content id. ie  feed_callback(uri, content_id).


49
50
51
52
53
54
# File 'app/helpers/muck_raker_google_helper.rb', line 49

def google_feed_photos(feed, 
                      content_id = 'feed_photo_content',
                      number_of_images = 5,
                      javascript_callback = nil)
  render :partial => 'google/feed_photos', :locals => { :feed => feed, :content_id => content_id, :number_of_images => number_of_images, :javascript_callback => javascript_callback }
end

#google_feed_search(query, content_id = 'feed_search_content') ⇒ Object

Find and output feeds related to the given query

query: A tag or search query to pass to Google. Google will find feeds that match this value. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.


23
24
25
# File 'app/helpers/muck_raker_google_helper.rb', line 23

def google_feed_search(query, content_id = 'feed_search_content')
  render :partial => 'google/feed_search', :locals => { :query => query, :content_id => content_id }
end

#google_feeds_display(feeds, number_of_items = 5, number_of_images = 10, javascript_callback = nil) ⇒ Object

Render a collection of feeds using google.

feeds: An array of feeds to render each with a property ‘title’ and ‘uri’ defined content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

number_of_images: Number of images to display if the feed is an image feed. options: A hash containing the values to pass to the Google widget. The available options are defined here:

http://www.google.com/uds/solutions/dynamicfeed/reference.html.


122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/helpers/muck_raker_google_helper.rb', line 122

def google_feeds_display(feeds,
                         number_of_items = 5,
                         number_of_images = 10,
                         javascript_callback = nil)
  photo_service_ids = Service.photo_services.map(&:id)
  photo_feeds = feeds.find_all { |feed| photo_service_ids.include?(feed.service_id) }
  data_feeds = feeds - photo_feeds
  render :partial => 'google/feeds_display', :locals => { :data_feeds => data_feeds,
                                                          :photo_feeds => photo_feeds,
                                                          :photo_service_ids => photo_service_ids,
                                                          :number_of_images => number_of_images,
                                                          :number_of_items => number_of_items,
                                                          :javascript_callback => javascript_callback }
end

#google_load_bookmarks_script(javascript_callback, uri, content_id) ⇒ Object



151
152
153
154
155
156
157
# File 'app/helpers/muck_raker_google_helper.rb', line 151

def google_load_bookmarks_script(javascript_callback, uri, content_id)
  google_load_template_script 'google_load_bookmarks', javascript_callback, uri, content_id do
    %Q{var status_class = 'even';
    if(i%2 > 0) { status_class = 'odd'; }
    jQuery('#' + content_id).append('<div class="hentry ' + status_class + '"><h4 class="title"><a class="bookmark-link" href="' + item.link + '" target="_blank">' + item.title + '</a></h4></div>');}
  end
end

#google_load_entries_script(javascript_callback, uri, content_id) ⇒ Object



143
144
145
146
147
148
149
# File 'app/helpers/muck_raker_google_helper.rb', line 143

def google_load_entries_script(javascript_callback, uri, content_id)
  google_load_template_script 'google_load_entries', javascript_callback, uri, content_id do
    %Q{var status_class = 'even';
    if(i%2 > 0) { status_class = 'odd'; }
    jQuery('#' + content_id).append('<div class="hentry ' + status_class + '"><h4 class="title"><a class="entry-link" href="#" target="blank">' + item.title + '</a><span class="entry-close"><a class="entry-link-close" href="#">#{t('muck.raker.close')}</a></span></h4><div class="entry">' + item.content + ' <p><a href="' + item.link + '">#{t('muck.raker.read_more')}</a></p></div></div>');}
  end
end

#google_load_images_script(javascript_callback, uri, content_id) ⇒ Object



137
138
139
140
141
# File 'app/helpers/muck_raker_google_helper.rb', line 137

def google_load_images_script(javascript_callback, uri, content_id)
  google_load_template_script 'google_load_images', javascript_callback, uri, content_id do
    %Q{jQuery('#' + content_id).append(jQuery(item.content).find('img').parent());}
  end
end

#google_load_template_script(method_name, javascript_callback, uri, content_id) ⇒ Object

Generates the template code used by all the calls to google.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'app/helpers/muck_raker_google_helper.rb', line 160

def google_load_template_script(method_name, javascript_callback, uri, content_id)
  included_name = "@#{method_name}_included"
  return '' if instance_variable_get(included_name) rescue false
  instance_variable_set(included_name, true)
  %Q{<script type="text/javascript">
  function #{method_name}(uri, content_id, number_of_items){
    jQuery('#' + content_id).html('');
    var feed = new google.feeds.Feed(uri);
    feed.setNumEntries(number_of_items);
    feed.load(function(result) {
      if (!result.error) {
        jQuery.each(result.feed.entries, function(i,item){
          #{yield}
          #{javascript_callback}('#{uri}', '#{content_id}');
        });
      } 
      if (result.error || result.feed.entries.length <= 0) {
        jQuery('#' + content_id).append('<div class="hentry">#{t('muck.raker.no_entries_found')}</div>');
      }
    });
  }
  </script>}
end

#google_muck_feed(feed, number_of_items = 5, number_of_images = 5, content_id = nil, javascript_callback = nil) ⇒ Object

Determines the type of feed and renders the appropriate content. For standard data feeds this will be a list of entries. For a feed with service type photo it will render photos, etc.

feed: Url for which to generate the feed. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

number_of_items: Number of items to display for the given feed. number_of_images: Number of images to display if the feed is an image feed. javascript_callback: Name of a javascript method to call after the feed has finished loading. The

method should accept the feed uri and the content id. ie  feed_callback(uri, content_id).


99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/muck_raker_google_helper.rb', line 99

def google_muck_feed(feed, number_of_items = 5, number_of_images = 5, content_id = nil, javascript_callback = nil)
  content_id ||= "feed_#{feed.id}_#{feed.title.parameterize}_#{feed.service.name.parameterize}"
  if feed.service.photo?
    google_feed_photos(feed, content_id, number_of_images, javascript_callback)
  elsif feed.service.bookmark?
    google_bookmark_display(feed, content_id, number_of_items, javascript_callback)
  elsif feed.service.video?
    # TODO for now video feeds are just data feeds. 
    google_feed_display(feed, content_id, number_of_items, javascript_callback)
  else
    google_feed_display(feed, content_id, number_of_items, javascript_callback)
  end
end

#google_slide_show(feed, content_id = 'slide_show_content', options = { :displayTime => 2000, :transistionTime => 600, :scaleImages => true, :fullControlPanel => true }) ⇒ Object

Generate a slide show from a feed feed: Url for which to generate the feed. content_id: Name of the div that will hold the widget google generates.

If this method is called more than once on a given page then you will need to 
specify different content_ids for each call.

options: A hash containing the values to pass to the Google widget. The available options are defined here:

http://www.google.com/uds/solutions/slideshow/index.html


34
35
36
37
38
# File 'app/helpers/muck_raker_google_helper.rb', line 34

def google_slide_show(feed, 
                      content_id = 'slide_show_content',
                      options = { :displayTime => 2000, :transistionTime => 600, :scaleImages => true, :fullControlPanel => true })
  render :partial => 'google/slide_show', :locals => { :feed => feed, :content_id => content_id, :options => options }
end