-
Notifications
You must be signed in to change notification settings - Fork 7
Creating a view
Everything you need to get a view working, is to be found in the abstract class com.github.intellectualsites.iserver.api.views.View
. Just extend that, and move from there.
The constructor takes a view pattern, these are further explained here
public ExampleView() {
super ( "(view)/[pattern])", "viewName" );
}
There is one method that allows you to reject a view, and thus control what you accept or not. This code is called if the requested URL matches your specified regex pattern.
@Override
public boolean passes(final Request request) {
// This will only return true if the request was paired with a post
// request, this is good for form specific views and alike.
return request.getPostRequest() != null;
}
This is the method that actually generates the view. You are free to generate whatever content you want, and you can freely choose between sending text or raw bytes.
@Override
public Response generate(final Request r) {
Response response = new Response(this /* Requires a parent view */);
// This will tell the client that we are sending a CSS document
response.getHeader().set("Content-Type", "text/css; charset=utf-8");
// This sets a text content body
response.setContent("body { background-color: green; }");
// Then we return our created response
return response;
}
In order for anyone to use your view (via config/views.yml
), then you've got to register it. It's quite simple:
// The first parameter is the key that will be used to bind
// a view from the views.yml class
Server.getInstance().addViewBinding("example", ExampleView.class);
If you don't want to make your view configurable, or are building a private application, then you can register your view directly into the ViewManager
Server.getInstance().getViewManager().add(new ExampleView());
The default views can be found in com.github.intellectualsites.iserver.api.views
Implement this interface if you want to ignore the Crush syntax:
com.github.intellectualsites.iserver.api.util.IgnoreSyntax
If you want your generated responses to be cached, then implement com.github.intellectualsites.iserver.api.cache.CacheApplicable
. You have to implement one method:
@Override
public boolean isApplicable(final Request r) {
// To allow all request to use the cached
// response, just return true. If you want to
// do additional checks, then return the value
// based on those.
return true;
}
IntellectualServer
Files can be found in .kvantum/config
- Getting Started
- View Patterns
- File Patterns
- server.yml
views.yml- socketFilters.yml
- translations.yml
- SSL
- Getting Started
- Modules
- Hello World
- Plugins
- Events
- Account System
- Authorization
- Application System
- Sessions
- Create a view - OOP based
- Create a view - @Annotation based
- Middleware
- Extending Crush (Templating syntax)
- ViewReturn