use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class ThemeServiceTest method setUp.
@BeforeEach
public void setUp() {
themes = new HashSet<>();
theme1 = mock(Theme1.class);
theme2 = mock(Theme2.class);
when(theme1.getKey()).thenReturn("theme1");
when(theme2.getKey()).thenReturn("theme2");
when(theme1.toString()).thenReturn("theme1.toString()");
when(theme2.toString()).thenReturn("theme2.toString()");
themes.add(theme1);
adminThemes = new HashSet<>();
adminTheme1 = mock(AdminTheme1.class);
adminTheme2 = mock(AdminTheme2.class);
when(adminTheme1.getKey()).thenReturn("adminTheme1");
when(adminTheme2.getKey()).thenReturn("adminTheme2");
when(adminTheme1.toString()).thenReturn("adminTheme1.toString()");
when(adminTheme2.toString()).thenReturn("adminTheme2.toString()");
adminThemes.add(adminTheme1);
assetManager = mock(AssetManager.class);
themeContextOptions = new JSONObject();
theme2ContextOptions = new JSONObject();
adminThemeContextOptions = new JSONObject();
adminTheme2ContextOptions = new JSONObject();
// Mock Injector
// Mock Context
context = mock(OrchidContext.class);
when(context.query("theme")).thenReturn(new JSONElement(themeContextOptions));
when(context.query("theme2")).thenReturn(new JSONElement(theme2ContextOptions));
when(context.query("adminTheme")).thenReturn(new JSONElement(adminThemeContextOptions));
when(context.query("adminTheme2")).thenReturn(new JSONElement(adminTheme2ContextOptions));
when(context.resolve((Class<Theme>) theme1.getClass())).thenReturn(theme1);
when(context.resolve((Class<Theme>) theme2.getClass())).thenReturn(theme2);
when(context.resolve((Class<AdminTheme>) adminTheme1.getClass())).thenReturn(adminTheme1);
when(context.resolve((Class<AdminTheme>) adminTheme2.getClass())).thenReturn(adminTheme2);
// Create instance of Service Implementation
ThemeServiceImpl service = new ThemeServiceImpl(assetManager, () -> themes, "theme1", () -> adminThemes, "adminTheme1");
service.initialize(context);
// Create wrapper around the Implementation to verify it works in composition
underTest = new ThemeService() {
public void initialize(OrchidContext context) {
}
public <T extends OrchidService> T getService(Class<T> serviceClass) {
return (T) service;
}
};
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class ContentTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
TemplateTag freshTag = orchidContext.resolve(tagClass);
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
String bodyContent = StringUtils.toString(tagBodyExpression.evaluate(self, context)).trim();
TemplateTag.Tab tab = new TemplateTag.SimpleTab(null, null, bodyContent);
freshTag.setContent(tab);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class SimpleTagParser method render.
@Override
public void render(PebbleTemplateImpl self, Writer writer, EvaluationContextImpl context) throws IOException {
OrchidContext orchidContext = contextProvider.get();
TemplateTag freshTag = orchidContext.resolve(tagClass);
Map<String, Object> evaluatedParamExpressionMap = evaluateParams(paramExpressionMap, self, context);
Object pageVar = context.getVariable("page");
final OrchidPage actualPage;
if (pageVar instanceof OrchidPage) {
actualPage = (OrchidPage) pageVar;
} else {
actualPage = null;
}
freshTag.extractOptions(orchidContext, evaluatedParamExpressionMap);
freshTag.onRender(orchidContext, actualPage);
if (freshTag.rendersContent()) {
writer.append(freshTag.renderContent(orchidContext, actualPage));
}
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class CompilerServiceTest method setUp.
@BeforeEach
public void setUp() {
// target outputs
mockInput = "input";
compiledOutput = "compiled";
parsedOutput = new HashMap<>();
precompilerOutput = "precompiled";
precompilerElement = new HashMap<>();
precompilerEmbeddedData = new EdenPair<>(precompilerOutput, precompilerElement);
Set<OrchidCompiler> compilers = new HashSet<>();
mockCompiler = mock(OrchidCompiler.class);
compilers.add(mockCompiler);
when(mockCompiler.getSourceExtensions()).thenReturn(new String[] { "md", "markdown" });
when(mockCompiler.getOutputExtension()).thenReturn("html");
// when(mockCompiler.compile("md", mockInput, null)).thenReturn(compiledOutput);
// when(mockCompiler.compile("markdown", mockInput, null)).thenReturn(compiledOutput);
// when(mockCompiler.compile("mkdwn", mockInput, null)).thenReturn(compiledOutput);
doAnswer(invocation -> {
invocation.callRealMethod();
return null;
}).when(mockCompiler).compile(any(), any(), any(), any(), any());
Set<OrchidParser> parsers = new HashSet<>();
mockParser = mock(OrchidParser.class);
parsers.add(mockParser);
when(mockParser.getSourceExtensions()).thenReturn(new String[] { "yml", "yaml" });
when(mockParser.parse("yml", "input")).thenReturn(parsedOutput);
when(mockParser.parse("yaml", "input")).thenReturn(parsedOutput);
mockPrecompiler = mock(OrchidPrecompiler.class);
when(mockPrecompiler.getEmbeddedData("", mockInput)).thenReturn(precompilerEmbeddedData);
// test the service directly
context = mock(OrchidContext.class);
when(context.getSiteData(any())).thenReturn(null);
when(context.resolveSet(OrchidCompiler.class)).thenReturn(compilers);
when(context.resolveSet(OrchidParser.class)).thenReturn(parsers);
when(context.resolve(OrchidPrecompiler.class)).thenReturn(mockPrecompiler);
service = new CompilerServiceImpl();
service.initialize(context);
service.allConfig = new HashMap<>();
// add custom compiler extensions
service.customCompilerExtensions = new JSONObject();
service.customCompilerExtensions.put("mkdwn", "md");
service.onPostExtraction();
// test that the default implementation is identical to the real implementation
underTest = new CompilerService() {
public void initialize(OrchidContext context) {
}
public <T extends OrchidService> T getService(Class<T> serviceClass) {
return (T) service;
}
};
}
use of com.eden.orchid.api.OrchidContext in project Orchid by JavaEden.
the class OrchidModule method bindKnownSet.
private void bindKnownSet(final Class<?> setClass) {
Provider<OrchidContext> contextProvider = getProvider(OrchidContext.class);
if (!knownSets.contains(setClass)) {
Multibinder<AdminList> binder = Multibinder.newSetBinder(binder(), AdminList.class);
binder.addBinding().toInstance(new AdminList() {
@Override
public Class<?> getListClass() {
return setClass;
}
@Override
public String getKey() {
return setClass.getSimpleName();
}
@Override
public Collection<Class<?>> getItems() {
return contextProvider.get().resolveSet(setClass).stream().map(Object::getClass).collect(Collectors.toList());
}
@Override
public boolean isImportantType() {
return setClass.isAnnotationPresent(ImportantModularType.class);
}
});
knownSets.add(setClass);
}
}
Aggregations