module LuckyTemplate
Overview
Public interface
Extended Modules
Defined in:
lucky_template.crlucky_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 /srv/crystaldoc.info/github-luckyframework-lucky_template-v0.2.0/src/lucky_template`).chomp.stringify }}
Instance Method Summary
- #create_folder(& : Folder -> ) : Folder
-
#create_folder : Folder
Creates an empty
Folder
-
#snapshot(folder : Folder) : Snapshot
Returns a new
Snapshot
of all files and folders within this folder -
#validate!(location : Path, folder : Folder) : Bool
Returns
true
if the folder is valid at the given location -
#validate?(location : Path, folder : Folder) : Bool
Returns a
Bool
if the folder is valid at the given location -
#write!(location : Path, folder : Folder) : Nil
Writes the folder to disk at the given location
-
#write!(location : Path, & : Folder -> ) : Folder
Shorthand for
.create_folder
and.write!
Instance Method Detail
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
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,
}
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
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
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)
Shorthand for .create_folder
and .write!
Example:
folder = LuckyTemplate.write!(Path["./templates"]) do |templates_folder|
templates_folder.add_file(".keep")
end