class BridgetownPlausibleTag::Builder

Public Instance Methods

build() click to toggle source

Builds the tag

@return [Set] <description>

# File lib/bridgetown-plausible-tag/builder.rb, line 8
def build
  liquid_tag "plausible", :render
end
render(_markup, _builder) click to toggle source

Prepares and returns the SVG markup

@param [String] _markup @param [BridgetownInlineSvg::Tag] _builder @return [String] The output HTML.

# File lib/bridgetown-plausible-tag/builder.rb, line 19
def render(_markup, _builder)
  domain = options.dig(:domain)&.strip

  tag = if domain
    script_tag(domain)
  else
    Bridgetown.logger.warn "Plausible Warning:", "Plausible domain not configured."
    script_tag("NOT CONFIGURED")
  end

  return wrap_with_comment(tag) if Bridgetown.environment == "development"

  tag
end

Private Instance Methods

options() click to toggle source

Plugin options specified in Bridgetown config

@return [Hash] configuration options. Ex: {“optimize”=>true}

# File lib/bridgetown-plausible-tag/builder.rb, line 63
def options
  config["plausible"] || {}
end
script_tag(domain) click to toggle source

Builds the script tag with the domain

@param [String] domain

@return [String] The script tag with domain interpolated.

# File lib/bridgetown-plausible-tag/builder.rb, line 43
def script_tag(domain)
  "<script async defer data-domain=\"#{domain}\" src=\"https://plausible.io/js/plausible.js\"></script>"
end
wrap_with_comment(tag) click to toggle source

Wrap the input with an HTML comment

@param [String] tag

@return [String] The tag wrapped in an HTML comment

# File lib/bridgetown-plausible-tag/builder.rb, line 54
def wrap_with_comment(tag)
  "<!-- #{tag} -->"
end