Module: ReleaseHx::TemplateOps
- Defined in:
- lib/releasehx/ops/template_ops.rb
Overview
Provides Liquid template rendering services with extended Jekyll integration and configurable template paths.
The TemplateOps module handles the complex setup required for Liquid template processing, including
Jekyll plugin loading, template path resolution, and Sourcerer Jekyll runtime initialization for
advanced template features and includes.
Class Method Summary collapse
-
.render_liquid_string(input, vars, config) ⇒ String
Renders a Liquid template string with provided variables and configuration context.
Class Method Details
.render_liquid_string(input, vars, config) ⇒ String
Renders a Liquid template string with provided variables and configuration context.
Sets up a complete, enhanced Liquid rendering environment with plugin support,
configurable template include paths, and proper site context for advanced template features.
Supports both user-defined and gem-bundled template directories with fallback resolution.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/releasehx/ops/template_ops.rb', line 23 def self.render_liquid_string input, vars, config plugin_dirs = [File.('../../../jekyll_plugins', __dir__)] user_templates_dir = config.dig('paths', 'templates_dir') gem_templates_dir = File.('../rhyml/templates', __dir__) # Build template include path hierarchy: user templates take precedence over gem defaults includes = [] if user_templates_dir unless Pathname.new(user_templates_dir).absolute? user_templates_dir = File.(user_templates_dir, Dir.pwd) end includes << user_templates_dir if File.directory?(user_templates_dir) end includes << gem_templates_dir Sourcerer::Jekyll.initialize_liquid_runtime # Bootstrap an ephemeral Jekyll site context for template processing with full feature support site = Sourcerer::Jekyll::Bootstrapper.fake_site( includes_load_paths: includes, plugin_dirs: plugin_dirs) # Parse template and render with comprehensive register context tpl = ::Liquid::Template.parse(input) rendered = tpl.render( vars, registers: { site: site, file_system: Sourcerer::Jekyll::Liquid::FileSystem.new(includes.first), includes_load_paths: includes, releasehx_debug: true }) raise "Template rendering failed:\n#{rendered}" if rendered.include?('Liquid error') rendered end |