| 1 | # ABSTRACT: initialize a new site | ||||||||||
| 2 | |||||||||||
| 3 | |||||||||||
| 4 | package HiD::App::Command::init; | ||||||||||
| 5 | 4 | $HiD::App::Command::init::VERSION = '1.5'; | |||||||||
| 6 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | extends 'HiD::App::Command'; | |||||||||
| 8 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 4 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 4 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 4 | ▶ | use warnings qw/ FATAL utf8 /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 4 | ▶ | use open qw/ :std :utf8 /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 4 | ▶ | use charnames qw/ :full /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 4 | ▶ | use feature qw/ unicode_strings /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 4 | ▶ | use YAML::XS qw/ DumpFile /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | 4 | has blog => ( | |||||||||
| 22 | is => 'ro' , | ||||||||||
| 23 | isa => 'Bool' , | ||||||||||
| 24 | traits => [ 'Getopt' ] , | ||||||||||
| 25 | cmd_aliases => 'b' , | ||||||||||
| 26 | documentation => 'include blog-specific features when creating site' , | ||||||||||
| 27 | ); | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | 4 | has github => ( | |||||||||
| 31 | is => 'ro' , | ||||||||||
| 32 | isa => 'Bool' , | ||||||||||
| 33 | traits => [ 'Getopt' ] , | ||||||||||
| 34 | cmd_aliases => 'g' , | ||||||||||
| 35 | documentation => 'create site ready for publishing on GitHub' , | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 4 | has title => ( | |||||||||
| 40 | is => 'ro' , | ||||||||||
| 41 | isa => 'Str' , | ||||||||||
| 42 | traits => [ 'Getopt' ] , | ||||||||||
| 43 | cmd_aliases => 't' , | ||||||||||
| 44 | documentation => 'title for your new site' , | ||||||||||
| 45 | default => 'My Great New Site' , | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | sub _run { | ||||||||||
| 49 | 4 | ▶ | my( $self , $opts , $args ) = @_; | ||||||||
|
Subroutine
_run: called CC=5 SCAR=16.1
| |||||||||||
| 50 | |||||||||||
| 51 | 4 | ▶ | die "TODO: github support" if $self->github; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 3 | for ( qw/ includes layouts site / ) { | |||||||||
| 54 | 9 | ▶ | mkdir "_$_" unless -e "_$_" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 3 | open( my $fh , '>' , '_layouts/default.html' ); | |||||||||
| 58 | 3 | print $fh <<EOF; | |||||||||
| 59 | [% content %] | ||||||||||
| 60 | EOF | ||||||||||
| 61 | 3 | close $fh; | |||||||||
| 62 | |||||||||||
| 63 | 3 | ▶ | $self->_init_blog if $self->blog; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 3 | DumpFile( '_config.yml' , { | |||||||||
| 66 | title => $self->title , | ||||||||||
| 67 | }); | ||||||||||
| 68 | |||||||||||
| 69 | 3 | say "Enjoy your new site!"; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | sub _init_blog { | ||||||||||
| 73 | { | ||||||||||
| 74 | 1 | open( my $fh , '>' , '_layouts/post.html' ); | |||||||||
| 75 | 1 | print $fh <<EOF; | |||||||||
| 76 | --- | ||||||||||
| 77 | layout: default | ||||||||||
| 78 | --- | ||||||||||
| 79 | [% page.title %] | ||||||||||
| 80 | [% content %] | ||||||||||
| 81 | EOF | ||||||||||
| 82 | 1 | close( $fh ); | |||||||||
| 83 | } | ||||||||||
| 84 | { | ||||||||||
| 85 | 1 | ▶ | mkdir "_posts"; | ||||||||
|
Subroutine
_init_blog: called CC=1 SCAR=0.0
| |||||||||||
| 86 | 1 | open( my $fh , '>' , '_posts/1999-09-09-first-post.markdown' ); | |||||||||
| 87 | 1 | print $fh <<EOF; | |||||||||
| 88 | --- | ||||||||||
| 89 | layout: post | ||||||||||
| 90 | title: My First Post | ||||||||||
| 91 | --- | ||||||||||
| 92 | this is the first post in my new blog! | ||||||||||
| 93 | EOF | ||||||||||
| 94 | 1 | close( $fh ); | |||||||||
| 95 | } | ||||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 99 | 4 | 1; | |||||||||
| 100 | |||||||||||
| 101 | __END__ | ||||||||||
| 102 | |||||||||||
| 103 | =pod | ||||||||||
| 104 | |||||||||||
| 105 | =encoding utf-8 | ||||||||||
| 106 | |||||||||||
| 107 | =head1 NAME | ||||||||||
| 108 | |||||||||||
| 109 | HiD::App::Command::init - initialize a new site | ||||||||||
| 110 | |||||||||||
| 111 | =head1 SYNOPSIS | ||||||||||
| 112 | |||||||||||
| 113 | $ ../bin/hid init | ||||||||||
| 114 | Enjoy your new site! | ||||||||||
| 115 | |||||||||||
| 116 | $ ls | ||||||||||
| 117 | _config.yml _includes/ _layouts/ _site/ | ||||||||||
| 118 | |||||||||||
| 119 | $ cat _config.yml | ||||||||||
| 120 | --- | ||||||||||
| 121 | title: My Great New Site | ||||||||||
| 122 | |||||||||||
| 123 | =head1 DESCRIPTION | ||||||||||
| 124 | |||||||||||
| 125 | Generates a directory structure and basic config for a Hid site. | ||||||||||
| 126 | |||||||||||
| 127 | =head1 ATTRIBUTES | ||||||||||
| 128 | |||||||||||
| 129 | =head2 blog | ||||||||||
| 130 | |||||||||||
| 131 | If enabled, this will add in additional site features useful for bloggers. | ||||||||||
| 132 | |||||||||||
| 133 | # FIXME doesn't actually do anything currently. | ||||||||||
| 134 | |||||||||||
| 135 | =head2 github | ||||||||||
| 136 | |||||||||||
| 137 | If enabled, will set the site up to be hosted on and published through GitHub. | ||||||||||
| 138 | |||||||||||
| 139 | # FIXME doesn't actually do anything currently. | ||||||||||
| 140 | |||||||||||
| 141 | =head2 title | ||||||||||
| 142 | |||||||||||
| 143 | Provide a title for the site being created. | ||||||||||
| 144 | |||||||||||
| 145 | =head1 SEE ALSO | ||||||||||
| 146 | |||||||||||
| 147 | See L<HiD::App::Command> for additional command line options supported by all | ||||||||||
| 148 | sub commands. | ||||||||||
| 149 | |||||||||||
| 150 | =head1 VERSION | ||||||||||
| 151 | |||||||||||
| 152 | version 1.5 | ||||||||||
| 153 | |||||||||||
| 154 | =head1 AUTHOR | ||||||||||
| 155 | |||||||||||
| 156 | John SJ Anderson <genehack@genehack.org> | ||||||||||
| 157 | |||||||||||
| 158 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 159 | |||||||||||
| 160 | This software is copyright (c) 2014 by John SJ Anderson. | ||||||||||
| 161 | |||||||||||
| 162 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 163 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 164 | |||||||||||
| 165 | =cut | ||||||||||