module

LuckyTemplate

Public interface

Constants

VERSION = {{ (`shards version /tmp/tmp.nBaHNp/src/src/lucky_template`).chomp.stringify }}

Instance methods

create_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
Source
create_folder

Creates an empty Folder

Example:

folder = LuckyTemplate.create_folder
folder.locked? # => false
Source
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,
}
Source
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
Source
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
Source
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)
Source
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
Source

Nested types