Class: Giblish::AddSearchForm

Inherits:
Asciidoctor::Extensions::DocinfoProcessor
  • Object
show all
Defined in:
lib/giblish/search/headingindexer.rb

Constant Summary collapse

FORM_DATA =
"<script type=\"text/javascript\">\nwindow.onload = function () {\n  document.getElementById(\"calingurl_input\").value = window.location.href;\n};\n</script>\n\n<style>\n#gibsearch-form {\n  position:fixed;\n  top:0.5rem;\n  left:70%;\n  width:30%;\n  height:3rem;\n  background:white;\n  z-index:2000; \n  }\n</style>\n\n<div id=gibsearch-form>\n<form class=\"gibsearch\" action=\"<%=action_path%>\">\n  <input type=\"search\" placeholder=\"Search the docs..\" name=\"search-phrase\" />\n  <button type=\"submit\">Search</button>\n  <br>\n\n  <input type=\"checkbox\" id=\"consider-case\" name=\"consider-case\" />\n  <label for=\"consider-case\">case sensitive</label>\n  &nbsp;&nbsp;\n  <input type=\"checkbox\" id=\"as-regexp\" name=\"as-regexp\" />\n  <label for=\"as-regexp\">use regexp</label>\n\n  <input type=\"hidden\" name=\"calling-url\" id=calingurl_input />\n  <input type=\"hidden\" name=\"search-assets-top-rel\" value=\"<%=sa_top_rel%>\"/>\n  <input type=\"hidden\" name=\"css-path\" value=\"<%=css_path%>\"/>\n</form>\n</div>\n"

Instance Method Summary collapse

Constructor Details

#initialize(action_path = nil, opts = {}) ⇒ AddSearchForm

Returns a new instance of AddSearchForm.



288
289
290
291
# File 'lib/giblish/search/headingindexer.rb', line 288

def initialize(action_path = nil, opts = {})
  @action_path = action_path
  super(opts)
end

Instance Method Details

#process(document) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/giblish/search/headingindexer.rb', line 293

def process(document)
  attrs = document.attributes
  src_node = attrs["giblish-info"][:src_node]
  dst_node = attrs["giblish-info"][:dst_node]
  dst_top = attrs["giblish-info"][:dst_top]

  to_top_rel = dst_top.relative_path_from(dst_node.parent)
  sa_top_rel = to_top_rel.join("gibsearch_assets").cleanpath
  action_path = @action_path || to_top_rel.join("gibsearch.cgi").cleanpath

  # only include css_path if it is given in the document's attributes
  doc_attrs = src_node.data.document_attributes(src_node, dst_node, dst_top)
  css_path = if %w[stylesdir stylesheet].all? { |k| doc_attrs.key?(k) }
    doc_attrs["stylesdir"] + "/" + doc_attrs["stylesheet"]
  end

  ERB.new(FORM_DATA).result(binding)
end