Class: JsAutocompleteBuilder
- Inherits:
-
Object
- Object
- JsAutocompleteBuilder
- Defined in:
- lib/jsautocomplete_builder.rb
Instance Method Summary collapse
-
#initialize(server: {list: '', action: ''}) ⇒ JsAutocompleteBuilder
constructor
list: is the url of the server which returns the list action: is the url of the server to process the search request.
- #to_css ⇒ Object
-
#to_html ⇒ Object
returns just the form part.
- #to_js ⇒ Object
- #to_webpage ⇒ Object
Constructor Details
#initialize(server: {list: '', action: ''}) ⇒ JsAutocompleteBuilder
list: is the url of the server which returns the list action: is the url of the server to process the search request
14 15 16 |
# File 'lib/jsautocomplete_builder.rb', line 14 def initialize(server: {list: '', action: ''}) @server = server end |
Instance Method Details
#to_css ⇒ Object
33 34 35 |
# File 'lib/jsautocomplete_builder.rb', line 33 def to_css() css() end |
#to_html ⇒ Object
returns just the form part
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jsautocomplete_builder.rb', line 19 def to_html() html=<<EOF <form action='#{@server[:action]}' method='get' name='searchForm'> <input tabindex='2' type='text' autofocus='true' onkeyup='updateList(event.keyCode, this)' onfocus='showList()' onblur='hideList()' id='search' autocomplete='off' name='q'/> <input type='submit' value='search'> <ol id='autolist'></ol> </form> EOF end |
#to_js ⇒ Object
37 38 39 40 41 42 |
# File 'lib/jsautocomplete_builder.rb', line 37 def to_js() url = @server[:list] =~ /\?\w+=$/ ? @server[:list] : @server[:list] + '?q=' ("\n var serverList = '%s';\n\n" % url) + js() end |
#to_webpage ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/jsautocomplete_builder.rb', line 44 def to_webpage() doc = Rexle.new(build_html()) doc.root.element('body').add Rexle::Element.new('script').add_text(to_js()) doc.root.element('head').add Rexle::Element.new('style').add_text(to_css()) doc.xml(pretty: true) end |