import net.pterodactylus.sone.template.FilesystemTemplate;
import net.pterodactylus.sone.web.ReloadingPage;
+import net.pterodactylus.util.template.FilesystemTemplateProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Request;
return new ReloadingPage<REQ>(basePath, new File(filesystemPath, prefix).getAbsolutePath(), mimeType);
}
+ @Override
+ public TemplateProvider getTemplateProvider() {
+ return new FilesystemTemplateProvider(new File(filesystemPath, "/templates/").getAbsolutePath());
+ }
+
}
import java.io.Reader;
import java.io.UnsupportedEncodingException;
+import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.util.io.Closer;
+import net.pterodactylus.util.template.ClassPathTemplateProvider;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Request;
import net.pterodactylus.util.web.StaticPage;
return new StaticPage<REQ>(pathPrefix, basePath, mimeType);
}
+ @Override
+ public TemplateProvider getTemplateProvider() {
+ return new ClassPathTemplateProvider(WebInterface.class, "/templates/");
+ }
+
}
package net.pterodactylus.sone.main;
import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Request;
-import net.pterodactylus.util.web.StaticPage;
import com.google.inject.ImplementedBy;
Template loadTemplate(String path);
<REQ extends Request> Page<REQ> loadStaticPage(String basePath, String prefix, String mimeType);
+ TemplateProvider getTemplateProvider();
}
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.notify.TemplateNotification;
-import net.pterodactylus.util.template.ClassPathTemplateProvider;
import net.pterodactylus.util.template.CollectionSortFilter;
import net.pterodactylus.util.template.ContainsFilter;
import net.pterodactylus.util.template.DateFilter;
templateContextFactory.addFilter("mod", new ModFilter());
templateContextFactory.addFilter("paginate", new PaginationFilter());
templateContextFactory.addProvider(TemplateProvider.TEMPLATE_CONTEXT_PROVIDER);
- templateContextFactory.addProvider(new ClassPathTemplateProvider(WebInterface.class, "/templates/"));
+ templateContextFactory.addProvider(loaders.getTemplateProvider());
templateContextFactory.addTemplateObject("webInterface", this);
templateContextFactory.addTemplateObject("formPassword", formPassword);
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.web.Method;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Response;
loaders = new DebugLoaders(templatePath);
File templateFile = new File(templatePath, "template.txt");
Files.write("<%if foo>foo<%else>bar<%/if>", templateFile, Charsets.UTF_8);
+ new File(templatePath, "templates").mkdir();
+ File secondTemplateFile = new File(templatePath, "templates/template.txt");
+ Files.write("<%if foo>foo<%else>bar<%/if>", secondTemplateFile, Charsets.UTF_8);
}
@Test
assertThat(response.getStatusCode(), is(200));
}
+ @Test
+ public void templateProviderLocatesTemplatesInFileSystem() {
+ TemplateProvider templateProvider = loaders.getTemplateProvider();
+ Template template = templateProvider.getTemplate(templateContext, "template.txt");
+ template.render(templateContext, stringWriter);
+ assertThat(stringWriter.toString(), is("bar"));
+ }
+
}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.Mockito.mock;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateProvider;
import net.pterodactylus.util.web.Method;
import net.pterodactylus.util.web.Page;
import net.pterodactylus.util.web.Response;
assertThat(response.getStatusCode(), is(200));
}
+ @Test
+ public void templateIsLocatedInClasspath() {
+ TemplateProvider templateProvider = loaders.getTemplateProvider();
+ Template template = templateProvider.getTemplate(templateContext, "about.html");
+ assertThat(template, notNullValue());
+ }
+
}