| 1 | package Statocles::App::Basic; | ||||||||||||||
| 2 | 4 | our $VERSION = '0.099'; | |||||||||||||
| 3 | # ABSTRACT: Build Markdown and collateral files | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 4 | ▶ | use Statocles::Base 'Class'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 4 | ▶ | use Statocles::Document; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 4 | ▶ | use Statocles::Util qw( run_editor read_stdin ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 4 | with 'Statocles::App'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | ▶ | sub pages { } | ||||||||||||
|
Subroutine
pages: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | #pod =method command | ||||||||||||||
| 13 | #pod | ||||||||||||||
| 14 | #pod my $exitval = $app->command( $app_name, @args ); | ||||||||||||||
| 15 | #pod | ||||||||||||||
| 16 | #pod Run a command on this app. Commands allow creating, editing, listing, and | ||||||||||||||
| 17 | #pod viewing pages. | ||||||||||||||
| 18 | #pod | ||||||||||||||
| 19 | #pod =cut | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 4 | my $USAGE_INFO = <<'ENDHELP'; | |||||||||||||
| 22 | Usage: | ||||||||||||||
| 23 | $name help -- This help file | ||||||||||||||
| 24 | $name edit <path> -- Edit a page, creating it if necessary | ||||||||||||||
| 25 | ENDHELP | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 1 | ▶ | sub command { | ||||||||||||
|
Subroutine
command: called CC=8 SCAR=37.6
Pod
documented
| |||||||||||||||
| 28 | 1 | my ( $self, $name, @argv ) = @_; | |||||||||||||
| 29 | |||||||||||||||
| 30 | 1 | ▶ | if ( !$argv[0] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | 0 | say STDERR "ERROR: Missing command"; | |||||||||||||
| 32 | 0 | say STDERR eval "qq{$USAGE_INFO}"; | |||||||||||||
| 33 | 0 | return 1; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 1 | ▶ | if ( $argv[0] eq 'help' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 1 | say eval "qq{$USAGE_INFO}"; | |||||||||||||
| 38 | 1 | return 0; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | ▶ | if ( $argv[0] eq 'edit' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 0 | $argv[1] =~ s{^/}{}; | |||||||||||||
| 43 | 0 | ▶ | my $path = Path::Tiny->new( | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | $argv[1] =~ /[.](?:markdown|md)$/ ? $argv[1] : "$argv[1]/index.markdown", | ||||||||||||||
| 45 | ); | ||||||||||||||
| 46 | |||||||||||||||
| 47 | # Read post content on STDIN | ||||||||||||||
| 48 | 0 | ▶ | if ( my $content = read_stdin() ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 49 | 0 | my $doc = Statocles::Document->parse_content( | |||||||||||||
| 50 | path => $path.'', | ||||||||||||||
| 51 | store => $self->site->store, | ||||||||||||||
| 52 | content => $content, | ||||||||||||||
| 53 | ); | ||||||||||||||
| 54 | 0 | $self->site->store->write_file( $path => $doc ); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | elsif ( !$self->site->store->has_file( $path ) ) { | ||||||||||||||
| 57 | 0 | my $doc = Statocles::Document->new( | |||||||||||||
| 58 | content => "Markdown content goes here.\n", | ||||||||||||||
| 59 | ); | ||||||||||||||
| 60 | 0 | $self->site->store->write_file( $path => $doc ); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | my $full_path = $self->site->store->path->child( $path ); | |||||||||||||
| 64 | 0 | ▶ | if ( my $content = run_editor( $full_path ) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 0 | $full_path->spew_utf8( $content ); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | else { | ||||||||||||||
| 68 | 0 | say "New page at: $full_path"; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | } | ||||||||||||||
| 72 | else { | ||||||||||||||
| 73 | 0 | say STDERR qq{ERROR: Unknown command "$argv[0]"}; | |||||||||||||
| 74 | 0 | say STDERR eval "qq{$USAGE_INFO}"; | |||||||||||||
| 75 | 0 | return 1; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | return 0; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 4 | 1; | |||||||||||||
| 82 | |||||||||||||||
| 83 | __END__ | ||||||||||||||