Skip to content
Browse files

Merge pull request #14 from jonathanstowe/provider

Make a Provider role
  • Loading branch information...
2 parents 45343af + 16a7e27 commit 2708331b1eed4691b80b2ac2512d770318cecb2d @supernovus committed Apr 7, 2016
Showing with 33 additions and 21 deletions.
  1. +2 −1 .gitignore
  2. +2 −1 META.info
  3. +1 −1 lib/Template6/Context.pm6
  4. +26 −0 lib/Template6/Provider.pm6
  5. +2 −18 lib/Template6/Provider/File.pm6
View
3 .gitignore
@@ -1,3 +1,4 @@
*.swp
Makefile
-blib/
+blib/
+.precomp
View
3 META.info
@@ -8,8 +8,9 @@
"Template6::Service" : "lib/Template6/Service.pm6",
"Template6::Context" : "lib/Template6/Context.pm6",
"Template6::Stash" : "lib/Template6/Stash.pm6",
+ "Template6::Provider" : "lib/Template6/Provider.pm6",
"Template6::Provider::File" : "lib/Template6/Provider/File.pm6"
},
"depends" : [ ],
"source-url" : "git://github.com/supernovus/template6.git"
-}
+}
View
2 lib/Template6/Context.pm6
@@ -42,7 +42,7 @@ submethod BUILD (*%args) {
%!providers<file> = Template6::Provider::File.new(|%args);
}
-method add-provider ($name, $object) {
+method add-provider ($name, Template6::Provider $object) {
%!providers{$name} = $object;
}
View
26 lib/Template6/Provider.pm6
@@ -0,0 +1,26 @@
+use v6;
+
+unit role Template6::Provider;
+
+has @.include-path;
+has %.templates;
+has $.ext is rw = '.tt';
+
+submethod BUILD (:@path, *%args) {
+ if @path {
+ @!include-path.splice(@!include-path.elems, 0, @path);
+ }
+}
+
+method add-path ($path) {
+ @.include-path.push: $path;
+}
+
+method fetch ($name) {
+ ...
+}
+
+method store ($name, $template) {
+ %.templates{$name} = $template;
+}
+
View
20 lib/Template6/Provider/File.pm6
@@ -1,24 +1,12 @@
use v6;
-unit class Template6::Provider::File;
+use Template6::Provider;
-has @.include-path;
-has %.templates;
-has $.ext is rw = '.tt';
+unit class Template6::Provider::File does Template6::Provider;
## TODO: Implement 'absolute', 'relative', etc. options.
## TODO: Pre-compiled templates?
-submethod BUILD (:@path, *%args) {
- if @path {
- @!include-path.splice(@!include-path.elems, 0, @path);
- }
-}
-
-method add-path ($path) {
- @.include-path.push: $path;
-}
-
method fetch ($name) {
if %.templates{$name} :exists {
return %.templates{$name};
@@ -34,7 +22,3 @@ method fetch ($name) {
return;
}
-method store ($name, $template) {
- %.templates{$name} = $template;
-}
-

0 comments on commit 2708331

Please sign in to comment.
Something went wrong with that request. Please try again.