NAME
Yukki::Model::File - the model for loading and saving files in the wiki
VERSION
version 0.140290
SYNOPSIS
my $repository = $app->model('Repository', { repository => 'main' });
my $file = $repository->file({
path => 'foobar',
filetype => 'yukki',
});
DESCRIPTION
Tools for fetching files from the git repository and storing them there.
EXTENDS
ATTRIBUTES
path
This is the path to the file in the repository, but without the file suffix.
filetype
The suffix of the file. Defaults to "yukki".
repository
This is the the Yukki::Model::Repository the file will be fetched from or stored into.
METHODS
BUILDARGS
Allows full_path
to be given instead of path
and filetype
.
full_path
This is the complete path to the file in the repository with the "filetype" tacked onto the end.
file_name
This is the base name of the file.
file_id
This is a SHA-1 of the file name in hex.
object_id
This is the git object ID of the file blob.
title
This is the title for the file. For most files this is the file name. For files with the "yukki" "filetype", the title metadata or first heading found in the file is used.
file_size
This is the size of the file in bytes.
formatted_file_size
This returns a human-readable version of the file size.
media_type
This is the MIME type detected for the file.
store
$file->store({
content => 'text to put in file...',
comment => 'comment describing the change',
});
# OR
$file->store({
filename => 'file.pdf',
comment => 'comment describing the change',
});
This stores a new version of the file, either from the given content string or a named local file.
rename
my $new_file = $file->rename({
full_path => 'renamed/to/path.yukki',
comment => 'renamed the file',
});
Renames the file within the repository. When complete, this method returns a reference to the Yukki::Model::File object representing the new path.
remove
$self->remove({ comment => 'removed the file' });
Removes the file from the repostory. The file is not permanently deleted as it still exists in the version history. However, as of this writing, the API here does not provide any means for getting at a deleted file.
exists
Returns true if the file exists in the repository already.
fetch
my $content = $self->fetch;
my @lines = $self->fetch;
Returns the contents of the file.
has_format
my $yes_or_no = $self->has_format($media_type);
Returns true if the named media type has a format plugin.
fetch_formatted
my $html_content = $self->fetch_formatted($ctx);
Returns the contents of the file. If there are any configured formatter plugins for the media type of the file, those will be used to return the file.
history
my @revisions = $self->history;
Returns a list of revisions. Each revision is a hash with the following keys:
- object_id
-
The object ID of the commit.
-
The name of the commti author.
- date
-
The date the commit was made.
- time_ago
-
A string showing how long ago the edit took place.
- comment
-
The comment the author made about the comment.
- lines_added
-
Number of lines added.
- lines_removed
-
Number of lines removed.
diff
my @chunks = $self->diff('a939fe...', 'b7763d...');
Given two object IDs, returns a list of chunks showing the difference between two revisions of this path. Each chunk is a two element array. The first element is the type of chunk and the second is any detail for that chunk.
The types are:
"+" This chunk was added to the second revision.
"-" This chunk was removed in the second revision.
" " This chunk is the same in both revisions.
file_preview
my $file_preview = $self->file_preview(
content => $content,
);
Takes this file and returns a Yukki::Model::FilePreview object, with the file contents "replaced" by the given content.
list_files
my @files = $self->list_files;
List the files attached to/under this file path.
parent
my $parent = $self->parent;
Return a Yukki::Model::File representing the parent path of the current file within the current repository. For example, if the current path is:
foo/bar/baz.pdf
the parent of it will be:
foo/bar.yukki
This returns undef
if the current file is at the root of the repository.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.