Module: MuckRakerGoogleHelper

Defined in:
app/helpers/muck_raker_google_helper.rb

Instance Method Summary collapse

Instance Method Details

#feed_class(feed) ⇒ Object

Given a feed attempts to assign an appropriate class



62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/muck_raker_google_helper.rb', line 62

def feed_class(feed)
  if feed.service.photo?
    "feed-photos"
  elsif feed.service.bookmark?
    "feed-bookmarks"
  elsif feed.service.video?
    "feed-videos"
  elsif feed.service.music?
    "feed-music"
  end
end

#feed_content_id(feed) ⇒ Object

Generates a valid dom id for the feed



75
76
77
# File 'app/helpers/muck_raker_google_helper.rb', line 75

def feed_content_id(feed)
  "feed_#{feed.id}_#{feed.title.parameterize}_#{feed.service.name.parameterize}".gsub('+', '-')
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.


32
33
34
35
36
# File 'app/helpers/muck_raker_google_helper.rb', line 32

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_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.


44
45
46
# File 'app/helpers/muck_raker_google_helper.rb', line 44

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(feeds, show_controls = false, number_of_items = 6, number_of_images = 20, number_of_videos = 6, use_uri_for_control = false, run_load_scripts = false, javascript_callback = 'google_load_complete') ⇒ Object

Render feeds using Google’s api feeds: Feed object. show_controls: Indicates whether or not to show editing controls. ie Remove number_of_items: Number of items to display for the given feed. number_of_images: Number of images to get from the feed. number_of_videos: Number of videos to get from the feed. use_uri_for_control: If set to true then a hidden field will be generated containing the feed’s uri. If false then the hidden field will contain the feed’s service id. This is used to

regenerate the feed after submission to the server.

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).


13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/muck_raker_google_helper.rb', line 13

def google_feeds(feeds, show_controls = false, number_of_items = 6, number_of_images = 20, number_of_videos = 6, 
                use_uri_for_control = false, run_load_scripts = false, javascript_callback = 'google_load_complete')
  render :partial => 'google/feed', :collection => feeds, :locals => {:number_of_items => number_of_items,
                                                                     :number_of_images => number_of_images,
                                                                     :number_of_videos => number_of_videos,
                                                                     :javascript_callback => javascript_callback,
                                                                     :show_controls => show_controls,
                                                                     :use_uri_for_control => use_uri_for_control,
                                                                     :run_load_scripts => run_load_scripts}
end

#google_load_bookmarks_script(javascript_callback, uri, content_id) ⇒ Object



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

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



133
134
135
136
137
138
139
# File 'app/helpers/muck_raker_google_helper.rb', line 133

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



124
125
126
127
128
129
130
131
# File 'app/helpers/muck_raker_google_helper.rb', line 124

def google_load_images_script(javascript_callback, uri, content_id)
  google_load_template_script 'google_load_images', javascript_callback, uri, content_id do
    %Q{var link = jQuery(item.content).find('img').parent('a');
    link.attr('rel', '#{content_id}');
    link.addClass('feed-photo');
    jQuery('#' + content_id).append(link);}
  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.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/helpers/muck_raker_google_helper.rb', line 150

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_load_videos_script(javascript_callback, uri, content_id) ⇒ Object



115
116
117
118
119
120
121
122
# File 'app/helpers/muck_raker_google_helper.rb', line 115

def google_load_videos_script(javascript_callback, uri, content_id)
  google_load_template_script 'google_load_videos', javascript_callback, uri, content_id do
    %Q{var link = jQuery(item.content).find('img').parent('a');
    link.attr('rel', '#{content_id}');
    link.addClass('feed-video');
    jQuery('#' + content_id).append(link);}
  end
end

#google_muck_load_callback_script(feed, content_id, number_of_items = 4, number_of_images = 6, number_of_videos = 6) ⇒ Object



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

def google_muck_load_callback_script(feed, content_id, number_of_items = 4, number_of_images = 6, number_of_videos = 6)
  if feed.service.photo?
    "google_load_images('#{feed.uri}', '#{content_id}', #{number_of_images});"
  elsif feed.service.bookmark?
    "google_load_bookmarks('#{feed.uri}', '#{content_id}', #{number_of_items});"
  elsif feed.service.video?
    "google_load_videos('#{feed.uri}', '#{content_id}', #{number_of_videos});"
  elsif feed.service.music?
    "google_load_entries('#{feed.uri}', '#{content_id}', #{number_of_items});"
  else
    "google_load_entries('#{feed.uri}', '#{content_id}', #{number_of_items});"
  end
end

#google_muck_load_script(feed, content_id = nil, javascript_callback = nil) ⇒ Object

Outputs the appropriate script for handling the google response once the feed is loaded 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.

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).


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/helpers/muck_raker_google_helper.rb', line 86

def google_muck_load_script(feed, content_id = nil, javascript_callback = nil)
  if feed.service.photo?
    google_load_images_script(javascript_callback, feed.uri, content_id)
  elsif feed.service.bookmark?
    google_load_bookmarks_script(javascript_callback, feed.uri, content_id)
  elsif feed.service.video?
    google_load_videos_script(javascript_callback, feed.uri, content_id)
  elsif feed.service.music?
    # TODO need to get music feeds into tag system so that we can search for music feeds and then integrate in a way that can play the tunes.
    google_load_entries_script(javascript_callback, feed.uri, content_id)
  else
    google_load_entries_script(javascript_callback, feed.uri, content_id)
  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


55
56
57
58
59
# File 'app/helpers/muck_raker_google_helper.rb', line 55

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