Module: SnippetCli::GlobalVarsFormatter

Defined in:
lib/snippet_cli/global_vars_formatter.rb

Overview

Pure formatting logic for the global_vars section of an Espanso match file. Operates entirely on strings — no file I/O.

Class Method Summary collapse

Class Method Details

.build_content(existing, var_entries) ⇒ Object

Returns updated file content with var_entries appended under global_vars. Creates the global_vars key if absent. Never overwrites existing vars. existing is the current file content (or empty string). var_entries is the pre-indented YAML string for the new vars.



13
14
15
16
17
18
# File 'lib/snippet_cli/global_vars_formatter.rb', line 13

def self.build_content(existing, var_entries)
  return new_global_vars(var_entries) if existing.strip.empty?
  return insert_into_block(existing, var_entries) if existing.match?(/^global_vars:\s*$/m)

  append_global_vars(existing, var_entries)
end