Class: Jekyll::ClientSearch::SearchTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::ClientSearch::SearchTag
- Defined in:
- lib/jekyll/client_search/search_tag.rb
Overview
Liquid tag that renders the search form, status/results containers, and all runtime scripts in one line — config-driven so changing engines in _config.yml requires zero template changes.
{% search_form %}
{% search_form scripts_only %} — just scripts (custom form HTML)
{% search_form no_scripts %} — just form HTML (user loads scripts)
When client_search is disabled the tag renders nothing.
Constant Summary collapse
- SYNTAX =
/\A\s*(scripts_only|no_scripts)?\s*\z/
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ SearchTag
constructor
A new instance of SearchTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ SearchTag
Returns a new instance of SearchTag.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll/client_search/search_tag.rb', line 17 def initialize(tag_name, markup, tokens) super @markup = markup.to_s unless (match = @markup.match(SYNTAX)) raise Liquid::SyntaxError, "search_form: invalid syntax. Use {% search_form %}, " \ "{% search_form scripts_only %}, or {% search_form no_scripts %}" end @mode = match[1] || "full" end |
Instance Method Details
#render(context) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jekyll/client_search/search_tag.rb', line 29 def render(context) site = context.registers[:site] config_hash = site&.config&.fetch("client_search", {}) return "" unless config_hash["enabled"] != false configuration = Configuration.new(site) baseurl = site.config["baseurl"].to_s.gsub(%r{\A/+|/+$}, "") prefix = baseurl.empty? ? "" : "/#{baseurl}" form_html = build_form return form_html if @mode == "no_scripts" scripts = build_scripts(configuration, prefix) return scripts if @mode == "scripts_only" "#{form_html}\n#{scripts}" end |