Skip to content

Commit

Permalink
coverage for multi-theme build with layout specific varibles
Browse files Browse the repository at this point in the history
  • Loading branch information
scmorrison committed Aug 26, 2017
1 parent 645f29c commit eb00a60
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ Optional arguments:
--no-livereload - Disable livereload when
running uzu watch.
--clear - Delete build directory before
render when running with build.
--page-filter - Restrict build to pages starting
from this directory
--theme - Limit build / watch to single theme
e.g. uzu --theme=default build
```

Config
Expand Down Expand Up @@ -135,13 +141,10 @@ port: 4040
# default is .
project_root: path/to/project/folder

#
# Non-core variables
#

url: https://github.com/scmorrison/uzu-starter
author: Sam Morrison

# List of page template names to ignore for all themes
exclude_pages:
- about
- blog/fiji-scratch
```
### Config variables
Expand Down
11 changes: 10 additions & 1 deletion lib/Uzu/CLI.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ sub USAGE is export {
--no-livereload - Disable livereload when
running uzu watch.
--clear - Delete build directory before
render when running with build.
--page-filter - Restrict build to pages starting
from this directory
--theme - Limit build / watch to single theme
e.g. uzu --theme=default build
END
}

Expand All @@ -53,12 +59,13 @@ multi MAIN(
'build',
Str :$config = 'config.yml',
Str :$page-filter = '',
Str :$theme,
Bool :$clear = False
) is export {

Uzu::Config::from-file(
config_file => $config.IO,
page_filter => $page-filter,
theme => $theme,
no_livereload => True
).&{
if $clear {
Expand All @@ -82,11 +89,13 @@ multi MAIN(
'watch',
Str :$config = 'config.yml',
Str :$page-filter = '',
Str :$theme,
Bool :$no-livereload = False
) is export {
Uzu::Config::from-file(
config_file => $config.IO,
page_filter => $page-filter,
theme => $theme,
no_livereload => $no-livereload
).&Uzu::Watch::start();
}
Expand Down
14 changes: 10 additions & 4 deletions lib/Uzu/Config.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ sub safe-build-dir-check($dir, :$project_root) {
}

sub themes-config(
Str :$single_theme,
IO::Path :$themes_dir,
Str :$theme,
Array :$themes,
Expand All @@ -83,6 +84,8 @@ sub themes-config(

if $theme_config ~~ Str {

next when $single_theme.defined && $single_theme !~~ $theme_config;

my $theme_port = $working_port;
++$working_port;

Expand All @@ -99,6 +102,8 @@ sub themes-config(
my $theme = %theme.values.head;
my $theme_dir = $themes_dir.IO.child($theme_name);

next when $single_theme.defined && $single_theme !~~ $theme_name;

do {
note "Theme directory [{$theme_name}] does not exist. Skipping.";
next;
Expand Down Expand Up @@ -149,6 +154,7 @@ sub themes-config(
our sub from-file(
IO::Path :$config_file = 'config.yml'.IO,
Str :$page_filter = '',
Str :$theme,
Bool :$no_livereload = False
--> Map
) {
Expand All @@ -171,11 +177,11 @@ our sub from-file(
my IO::Path $themes_dir = $project_root.IO.child('themes');
my IO::Path $assets_dir = $project_root.IO.child('themes').child("{$config<theme>||'default'}").child('assets');
my IO::Path $theme_dir = $project_root.IO.child('themes').child("{$config<theme>||'default'}");
my $themes =
themes-config(
my $themes = themes-config(
:$themes_dir, :$build_dir, :$port, :$exclude_pages, :$project_root,
theme => ($config<theme>||''),
themes => ($config<themes> ~~ Array ?? $config<themes> !! [])).Array;
single_theme => $theme,
theme => ($config<theme>||''),
themes => ($config<themes> ~~ Array ?? $config<themes> !! [])).Array;

my IO::Path $layout_dir = $theme_dir.IO.child('layout');
my IO::Path $pages_watch_dir = $project_root.IO.child('pages').child($page_filter)||$project_root.IO.child('pages');
Expand Down
12 changes: 10 additions & 2 deletions t/02-build.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plan 3;
my $test_root = $*CWD.IO.child('t');

subtest {
plan 13;
plan 14;

my $source_root = $test_root.IO.child('example_project_tt');

Expand Down Expand Up @@ -104,10 +104,14 @@ subtest {
my $t13_expected_html = slurp $test_root.IO.child('expected_tt').child('deepembed.html');
my $t13_generated_html = slurp $tmp_build_path.IO.child('deepembed.html');
is $t13_generated_html, $t13_expected_html, '[Template6] deeply embedded partials can access page vars';

my $t14_expected_html = slurp $test_root.IO.child('expected_tt').child('summer2017').child('layout.html');
my $t14_generated_html = slurp $tmp_root.IO.child('build').child('summer2017').child('layout.html');
is $t14_generated_html, $t14_expected_html, '[Template6] multi-theme build with layout specific varibles';
}, 'Rendering [Defaults]';

subtest {
plan 10;
plan 11;

my $source_root = $test_root.IO.child('example_project_mustache');

Expand Down Expand Up @@ -188,6 +192,10 @@ subtest {
my $t10_expected_html = slurp $test_root.IO.child('expected_mustache').child('deepembed.html');
my $t10_generated_html = slurp $tmp_build_path.IO.child('deepembed.html');
is $t10_generated_html, $t10_expected_html, '[Mustache] deeply embedded partials can access page vars';

my $t11_expected_html = slurp $test_root.IO.child('expected_mustache').child('summer2017').child('layout.html');
my $t11_generated_html = slurp $tmp_root.IO.child('build').child('summer2017').child('layout.html');
is $t11_generated_html, $t11_expected_html, '[Mustache] multi-theme build with layout specific varibles';
}, 'Rendering [Mustache]';

subtest {
Expand Down

0 comments on commit eb00a60

Please sign in to comment.