Class: Guider::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/guider/search.rb

Overview

Generates HTML for Google search.

Class Method Summary collapse

Class Method Details

.to_html(id) ⇒ Object

Given the ID of custom google search engine, returns the script for generating the search box. Returns empty string when no ID given.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/guider/search.rb', line 7

def self.to_html(id)
  return "" unless id

  <<-EOHTML
  <script>
  (function() {
    var cx = '#{id}';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
  </script>
  <gcse:searchbox-only></gcse:searchbox-only>
  EOHTML
end