src/web: render do not require the server reference anymore
[nit.git] / src / web / web_base.nit
index ecf639e..5d7dbde 100644 (file)
@@ -16,8 +16,8 @@
 module web_base
 
 import model::model_views
+import model::model_json
 import nitcorn
-import json
 
 # Nitcorn server runned by `nitweb`.
 #
@@ -73,7 +73,7 @@ class NitAction
        # Render a view as a HttpResponse 200.
        fun render_view(view: NitView): HttpResponse do
                var response = new HttpResponse(200)
-               response.body = view.render(srv).write_to_string
+               response.body = view.render.write_to_string
                return response
        end
 
@@ -92,10 +92,15 @@ class ModelAction
        # Model to use.
        var model: Model
 
+       # Find the MEntity ` with `full_name`.
+       fun find_mentity(model: ModelView, full_name: nullable String): nullable MEntity do
+               if full_name == null then return null
+               return model.mentity_by_full_name(full_name.from_percent_encoding)
+       end
+
        # Init the model view from the `req` uri parameters.
        fun init_model_view(req: HttpRequest): ModelView do
                var view = new ModelView(model)
-
                var show_private = req.bool_arg("private") or else false
                if not show_private then view.min_visibility = protected_visibility
 
@@ -111,7 +116,7 @@ end
 # A NitView is rendered by an action.
 interface NitView
        # Renders this view and returns something that can be written to a HTTP response.
-       fun render(srv: NitServer): Writable is abstract
+       fun render: Writable is abstract
 end
 
 redef class HttpRequest