Cuprum::Cli

A command-line utility powered by Cuprum that provides tools and utilities for defining command-line tools.

Module: Cuprum::Cli::Files::Templates

Parent Namespace
Cuprum::Cli::Files
Defined In
lib/cuprum/cli/files/templates.rb

Table Of Contents

Overview

Namespace for template files and implementations.

Back To Top

Constants

FileTemplate

= Cuprum::Cli::Files::Template.define(:file_path, :file_system) \ do class_methods = Module.new do # Converts a raw file path to a template object. # # @param file_path [String] the input file path. # # @return [FileTemplate] the generated template. def build(file_path) engine = case File.extname(file_path) when '.erb' then Cuprum::Cli::Files::Engines::ERB end

  new(engine:, file_path:)
end   end   const_set(:ClassMethods, class_methods)

def self.included(other) super

other.extend(const_get(:ClassMethods))   end

# @overload initialize(file_path:, engine: nil) # @param engine [Symbol] the engine used to generate the template # contents. # @param file_path [String] the path to the template file. def initialize(file_path:, engine: nil, file_system: nil, **) file_system ||= Cuprum::Cli::Dependencies.provider.get(‘file_system’)

super(engine:, file_path:, file_system:, **)   end

# (see Cuprum::Cli::Files::Template#call) def call success(file_system.read_file(file_path)) rescue Cuprum::Cli::Dependencies::FileSystem::FileNotFoundError error = Cuprum::Cli::Files::Errors::MissingTemplate.new( message: ‘unable to generate file’, template_path: file_path ) failure(error) end end</code></span>

Data class representing a template defined on a file.

StringTemplate

= Cuprum::Cli::Files::Template.define(:raw_template) do class_methods = Module.new do # Converts a raw template string to a template object. # # @param raw_template [String] the unprocessed template string. # # @return [StringTemplate] the generated template. def build(raw_template) = new(engine: nil, raw_template:) end const_set(:ClassMethods, class_methods)

def self.included(other) super

other.extend(const_get(:ClassMethods))   end

# (see Cuprum::Cli::Files::Template#call) def call = success(raw_template) end</code></span>

Data class representing a string literal template.

Back To Top


Back to Documentation | Reference | Cuprum | Cuprum::Cli | Cuprum::Cli::Files