module LuckyTemplate

Overview

Public interface

Extended Modules

Defined in:

lucky_template.cr
lucky_template/error.cr
lucky_template/file.cr
lucky_template/file_system.cr
lucky_template/folder.cr
lucky_template/version.cr
spec.cr

Constant Summary

VERSION = {{ (`shards version /home/runner/work/lucky_template/lucky_template/src/lucky_template`).chomp.stringify }}

Instance Method Summary

Instance Method Detail

def create_folder(& : Folder -> ) : Folder #

Creates a Folder and yields it, before returning the unlocked Folder

NOTE Folder is locked when being yielded. See Folder#locked?.

Example:

folder = LuckyTemplate.create_folder do |dir|
  dir.locked? # => true
  dir.add_file(".keep")
end
folder.locked? # => false

[View source]
def create_folder : Folder #

Creates an empty Folder

Example:

folder = LuckyTemplate.create_folder
folder.locked? # => false

[View source]
def snapshot(folder : Folder) : Snapshot #

Returns a new Snapshot of all files and folders within this folder

Raises Error if folder is locked

NOTE Does not include file instances in results, only paths

Example:

folder = LuckyTemplate.create_folder do |dir|
  dir.add_file(".keep")
  dir.add_file("README.md")
  dir.add_folder("src") do |src|
    src.add_file("hello.cr")
  end
end
puts LuckyTemplate.snapshot(folder)

Output:

{
  ".keep"        => LuckyTemplate::FileSystem::File,
  "README.md"    => LuckyTemplate::FileSystem::File,
  "src"          => LuckyTemplate::FileSystem::Folder,
  "src/hello.cr" => LuckyTemplate::FileSystem::File,
}

[View source]
def validate!(location : Path, folder : Folder) : Bool #

Returns true if the folder is valid at the given location

valid - files and folders exist within the given location

NOTE Does not check contents of files, only the presence of them in the filesystem

Raises ::File::NotFoundError if either a file or folder does not exist

Raises Error if folder is locked

Example:

begin
  templates_folder = LuckyTemplate.create_folder
  LuckyTemplate.validate!(Path["./templates"], templates_folder) # => true
rescue err : ::File::NotFoundError
  puts err.message
end

[View source]
def validate?(location : Path, folder : Folder) : Bool #

Returns a Bool if the folder is valid at the given location

valid - files and folders exist within the given location

NOTE Does not check contents of files, only the presence of them in the filesystem

Example:

templates_folder = LuckyTemplate.create_folder
LuckyTemplate.validate!(Path["./templates"], templates_folder) # => true

[View source]
def write!(location : Path, folder : Folder) : Nil #

Writes the folder to disk at the given location

Raises Error if folder is locked

Raises ::File::AlreadyExistsError if location is not an existing folder

Example:

templates_folder = LuckyTemplate.create_folder
LuckyTemplate.write!(Path["./templates"], templates_folder)

[View source]
def write!(location : Path, & : Folder -> ) : Folder #

Shorthand for .create_folder and .write!

Example:

folder = LuckyTemplate.write!(Path["./templates"]) do |templates_folder|
  templates_folder.add_file(".keep")
end

[View source]