Class: Giblish::AddSearchForm

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

Constant Summary collapse

FORM_DATA =
<<~FORM_HTML
  <script type="text/javascript">
  window.onload = function () {
    document.getElementById("calingurl_input").value = window.location.href;
  };
  </script>

  <style>
  #gibsearch-form {
    position:fixed;
    top:0.5rem;
    left:70%;
    width:30%;
    height:3rem;
    background:white;
    z-index:2000; 
    }
  </style>

  <div id=gibsearch-form>
  <form class="gibsearch" action="<%=action_path%>">
    <input type="search" placeholder="Search the docs.." name="search-phrase" />
    <button type="submit">Search</button>
    <br>

    <input type="checkbox" id="consider-case" name="consider-case" />
    <label for="consider-case">case sensitive</label>
    &nbsp;&nbsp;
    <input type="checkbox" id="as-regexp" name="as-regexp" />
    <label for="as-regexp">use regexp</label>

    <input type="hidden" name="calling-url" id=calingurl_input />
    <input type="hidden" name="search-assets-top-rel" value="<%=sa_top_rel%>"/>
    <input type="hidden" name="css-path" value="<%=css_path%>"/>
  </form>
  </div>
FORM_HTML

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