Improve and test support for customized templates
Change-Id: I7209c247b01dc06078d84c18e0a7beed80c6a62c
diff --git a/.gitignore b/.gitignore
index c954958..aa3cfbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,6 +17,7 @@
.sass-cache
dev/css
templates/announcement.html.ep
+templates/custom
log
blib
script*
diff --git a/README.md b/README.md
index 5ea5725..6fe7c2b 100644
--- a/README.md
+++ b/README.md
@@ -62,7 +62,10 @@
$ cpanm git://github.com/Akron/Mojolicious-Plugin-Localize.git
```
-Then install the dependencies as always and run the test suite.
+Then install the dependencies using
+[App::cpanminus](http://search.cpan.org/~miyagawa/App-cpanminus/)
+(there is no need to install Kalamar)
+and run the test suite.
```
$ cd Kalamar
@@ -95,7 +98,7 @@
introduced, that will be consulted during the build process, loading
optional components using a ```require(...)``` directive.
-### Localization
+### Localization and Customization
To create a localized version of Kalamar, start the ```localize``` command
with the target locale as its argument, e.g. ```pl``` for polish.
@@ -114,9 +117,7 @@
```
To localize example queries according to a special corpus environment,
-define a name of the example corpus in the configuration,
-and create a translation file based on ```kalamar.queries.dict```
-as a blueprint.
+define a name of the example corpus in the configuration.
```
Kalamar => {
@@ -125,6 +126,14 @@
```
+Then create a translation file based on ```kalamar.queries.dict```
+as a blueprint and add it to the ```Localize``` resource list.
+
+Templates can be localized and customized by overriding
+the ```Template``` dictionary entries.
+This is especially useful for the landing page in
+```Template_intro```.
+
Currently the JavaScript translations are separated and stored in ```dev/js/src/loc```.
To generate assets relying on different locales, add the locale to ```Gruntfile.js```.
@@ -143,7 +152,6 @@
See ```dev/js/src/hint/foundries``` for
more optional foundries.
-
## COPYRIGHT AND LICENSE
### Bundled Software
diff --git a/lib/Kalamar/Controller/Search.pm b/lib/Kalamar/Controller/Search.pm
index 3045bb5..cdd8851 100644
--- a/lib/Kalamar/Controller/Search.pm
+++ b/lib/Kalamar/Controller/Search.pm
@@ -23,7 +23,7 @@
# No query
unless ($query) {
- return $c->render(template => $c->loc('Template_intro', 'intro'));
+ return $c->render($c->loc('Template_intro', 'intro'));
};
# Base parameters for remote access
diff --git a/t/basic.t b/t/basic.t
index 2bdd9cf..0bbc09e 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -1,7 +1,7 @@
use Mojo::Base -strict;
-use lib '../lib', 'lib';
use Test::More;
use Test::Mojo;
+use Mojo::File qw/path/;
my $t = Test::Mojo->new('Kalamar');
@@ -10,7 +10,28 @@
$t->get_ok('/')
->status_is(200)
->text_is('title', 'KorAP - Corpus Analysis Platform')
- ->text_is('h1 span', 'KorAP - Corpus Analysis Platform');
+ ->text_is('h1 span', 'KorAP - Corpus Analysis Platform')
+ ->element_exists('div.intro')
+ ->text_is('div.intro > p > strong', 'KorAP')
+ ;
+
+push @{$t->app->renderer->paths}, path(path(__FILE__)->dirname);
+
+$t->app->plugin(Localize => {
+ dict => {
+ Template => {
+ intro => 'custom/intro'
+ }
+ },
+ override => 1
+});
+
+$t->get_ok('/')
+ ->status_is(200)
+ ->text_is('title', 'KorAP - Corpus Analysis Platform')
+ ->text_is('h1 span', 'KorAP - Corpus Analysis Platform')
+ ->element_exists('div.intro')
+ ->text_is('div.intro h2', 'This is a custom intro page!');
$t->get_ok('/huhuhuhuhu')
->status_is(404)
diff --git a/t/custom/intro.html.ep b/t/custom/intro.html.ep
new file mode 100644
index 0000000..0a29e55
--- /dev/null
+++ b/t/custom/intro.html.ep
@@ -0,0 +1,6 @@
+% layout 'main', sidebar_active => 1;
+
+
+<div class="intro">
+ <h2>This is a custom intro page!</h2>
+</div>
diff --git a/templates/intro.html.ep b/templates/intro.html.ep
index 3052a3e..8e37688 100644
--- a/templates/intro.html.ep
+++ b/templates/intro.html.ep
@@ -1,6 +1,4 @@
-% layout 'main';
-
-% stash(sidebar_active => 1);
+% layout 'main', sidebar_active => 1;
<div class="intro">