| 1 | package Mojolicious::Command::generate::bootstrap_app; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mojo::Base 'Mojolicious::Command'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Mojo::Util qw(class_to_path class_to_file); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use String::Random qw(random_string); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use MIME::Base64; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = 0.07; | |||||||||
| 11 | |||||||||||
| 12 | 1 | has description => "Generate Mojolicious application directory structure including Twitter Bootstrap assets and DBIC authentication.\n"; | |||||||||
| 13 | 1 | has usage => "usage: $0 generate bootstrap_app [NAME]\n"; | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub render_base64_data { | ||||||||
|
Subroutine
render_base64_data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 16 | 0 | my ($self, $name) = (shift, shift); | |||||||||
| 17 | 0 | decode_base64( | |||||||||
| 18 | Mojo::Template->new->name("template $name from DATA section") | ||||||||||
| 19 | ->render(Mojo::Loader->new->data(ref $self, $name), @_) | ||||||||||
| 20 | ); | ||||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | sub render_base64_to_file { | ||||||||
|
Subroutine
render_base64_to_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 24 | 0 | my ($self, $data, $path) = (shift, shift, shift); | |||||||||
| 25 | 0 | return $self->write_file($path, $self->render_base64_data($data, @_)); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub render_base64_to_rel_file { | ||||||||
|
Subroutine
render_base64_to_rel_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 29 | 0 | my $self = shift; | |||||||||
| 30 | 0 | $self->render_base64_to_file(shift, $self->rel_dir(shift), @_); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 34 | 0 | my ($self, $class) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | if (not $class =~ /^[A-Z](?:\w|::)+$/){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | die 'Your application name has to be a well formed (camel case) Perl module name like MyApp::Bootstrap.'; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | # get paths to create in ./lib | ||||||||||
| 41 | 0 | my $model_namespace = "${class}::DB"; | |||||||||
| 42 | 0 | my $controller_namespace = "${class}::Controller"; | |||||||||
| 43 | |||||||||||
| 44 | # get app lib path from class name | ||||||||||
| 45 | 0 | my $name = class_to_file $class; | |||||||||
| 46 | 0 | my $app = class_to_path $class; | |||||||||
| 47 | |||||||||||
| 48 | # script | ||||||||||
| 49 | 0 | $self->render_to_rel_file('script', "$name/script/$name", $class); | |||||||||
| 50 | 0 | $self->chmod_file("$name/script/$name", 0744); | |||||||||
| 51 | |||||||||||
| 52 | # templates, static and assets | ||||||||||
| 53 | 0 | $self->render_base64_to_rel_file('glyphicons_halflings_regular_eot', "$name/public/bootstrap-3.0.3/fonts/glyphicons-halflings-regular.eot"); | |||||||||
| 54 | 0 | $self->render_base64_to_rel_file('glyphicons_halflings_regular_svg', "$name/public/bootstrap-3.0.3/fonts/glyphicons-halflings-regular.svg"); | |||||||||
| 55 | 0 | $self->render_base64_to_rel_file('glyphicons_halflings_regular_ttf', "$name/public/bootstrap-3.0.3/fonts/glyphicons-halflings-regular.ttf"); | |||||||||
| 56 | 0 | $self->render_base64_to_rel_file('glyphicons_halflings_regular_woff', "$name/public/bootstrap-3.0.3/fonts/glyphicons-halflings-regular.woff"); | |||||||||
| 57 | 0 | $self->render_base64_to_rel_file('bootstrap_min_js', "$name/public/bootstrap-3.0.3/js/bootstrap.min.js"); | |||||||||
| 58 | 0 | $self->render_base64_to_rel_file('bootstrap_min_css', "$name/public/bootstrap-3.0.3/css/bootstrap.min.css"); | |||||||||
| 59 | 0 | $self->render_base64_to_rel_file('bootstrap_theme_min_css', "$name/public/bootstrap-3.0.3/css/bootstrap-theme.min.css"); | |||||||||
| 60 | 0 | $self->render_base64_to_rel_file('jquery_1_10_2_min_js', "$name/public/bootstrap-3.0.3/js/jquery-1.10.2.min.js"); | |||||||||
| 61 | |||||||||||
| 62 | 0 | $self->render_to_rel_file('static', "$name/public/index.html"); | |||||||||
| 63 | 0 | $self->render_to_rel_file('style', "$name/public/style.css"); | |||||||||
| 64 | |||||||||||
| 65 | 0 | $self->render_to_rel_file('layout', "$name/templates/layouts/bootstrap.html.ep"); | |||||||||
| 66 | 0 | $self->render_to_rel_file('topnav', "$name/templates/elements/topnav.html.ep"); | |||||||||
| 67 | 0 | $self->render_to_rel_file('footer', "$name/templates/elements/footer.html.ep"); | |||||||||
| 68 | 0 | $self->render_to_rel_file('flash', "$name/templates/elements/flash.html.ep"); | |||||||||
| 69 | |||||||||||
| 70 | 0 | $self->render_to_rel_file('login_form', "$name/templates/auth/login.html.ep"); | |||||||||
| 71 | 0 | $self->render_to_rel_file('user_list_template', "$name/templates/users/list.html.ep"); | |||||||||
| 72 | 0 | $self->render_to_rel_file('user_add_template', "$name/templates/users/add.html.ep"); | |||||||||
| 73 | 0 | $self->render_to_rel_file('user_edit_template', "$name/templates/users/edit.html.ep"); | |||||||||
| 74 | |||||||||||
| 75 | 0 | $self->render_to_rel_file('welcome_template', "$name/templates/example/welcome.html.ep"); | |||||||||
| 76 | |||||||||||
| 77 | # application class | ||||||||||
| 78 | 0 | my $model_name = class_to_file $model_namespace; | |||||||||
| 79 | 0 | $self->render_to_rel_file('appclass', "$name/lib/$app", $class, $controller_namespace, $model_namespace, $model_name, random_string('s' x 64)); | |||||||||
| 80 | |||||||||||
| 81 | # controllers | ||||||||||
| 82 | 0 | my $app_controller = class_to_path $controller_namespace; | |||||||||
| 83 | 0 | my $example_controller = class_to_path "${controller_namespace}::Example"; | |||||||||
| 84 | 0 | my $auth_controller = class_to_path "${controller_namespace}::Auth"; | |||||||||
| 85 | 0 | my $users_controller = class_to_path "${controller_namespace}::Users"; | |||||||||
| 86 | 0 | $self->render_to_rel_file('app_controller', "$name/lib/$app_controller", ${controller_namespace}); | |||||||||
| 87 | 0 | $self->render_to_rel_file('example_controller', "$name/lib/$example_controller", ${controller_namespace}, "Example"); | |||||||||
| 88 | 0 | $self->render_to_rel_file('auth_controller', "$name/lib/$auth_controller", ${controller_namespace}, "Auth"); | |||||||||
| 89 | 0 | $self->render_to_rel_file('users_controller', "$name/lib/$users_controller", ${controller_namespace}, "Users"); | |||||||||
| 90 | |||||||||||
| 91 | # models | ||||||||||
| 92 | 0 | my $schema = class_to_path $model_namespace; | |||||||||
| 93 | 0 | $self->render_to_rel_file('schema', "$name/lib/$schema", $model_namespace); | |||||||||
| 94 | 0 | my $usermodel = class_to_path "${model_namespace}::Result::User"; | |||||||||
| 95 | 0 | $self->render_to_rel_file('users_model', "$name/lib/$usermodel", $model_namespace); | |||||||||
| 96 | |||||||||||
| 97 | # db_deploy_script | ||||||||||
| 98 | 0 | $self->render_to_rel_file('migrate', "$name/script/migrate", $model_namespace, $model_name); | |||||||||
| 99 | 0 | $self->chmod_file("$name/script/migrate", 0744); | |||||||||
| 100 | |||||||||||
| 101 | # fixtures | ||||||||||
| 102 | 0 | for my $mode (qw(production development testing)) { | |||||||||
| 103 | 0 | $self->render_to_rel_file('fixture', "$name/share/$mode/fixtures/1/all_tables/users/1.fix"); | |||||||||
| 104 | 0 | $self->render_to_rel_file('fixture_config', "$name/share/$mode/fixtures/1/conf/all_tables.json"); | |||||||||
| 105 | }; | ||||||||||
| 106 | |||||||||||
| 107 | # tests | ||||||||||
| 108 | 0 | $self->render_to_rel_file('test', "$name/t/basic.t", $class ); | |||||||||
| 109 | |||||||||||
| 110 | # config | ||||||||||
| 111 | 0 | $self->render_to_rel_file('config', "$name/config.yml", $model_name); | |||||||||
| 112 | |||||||||||
| 113 | # db (to play with DBIx::Class::Migration nicely | ||||||||||
| 114 | 0 | $self->create_rel_dir("$name/db"); | |||||||||
| 115 | |||||||||||
| 116 | 0 | return 1; | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 1 | 1; | |||||||||
| 120 | |||||||||||
| 121 | __DATA__ | ||||||||||