Skip to content

Commit

Permalink
added Tomcat and Ring modules to cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Mar 31, 2024
1 parent 22ac896 commit cd6863c
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleMavenSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleParsifalSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleQrRefSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleRingSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleSemverSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleShellSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleTestSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleTimingSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleTomcatSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleTracingSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleXmlSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleZipVaultSection;
Expand Down Expand Up @@ -134,7 +136,7 @@ public DocGenerator(final boolean runExamples) {
"fonts", "qrref", "jsonl", "timing",
"zipvault", "gradlew", "matrix", "ascii-table",
"docker", "cargo", "cargo-arangodb", "cargo-qdrant",
"installer"));
"installer", "tomcat", "ring"));

final IVeniceInterpreter venice = new VeniceInterpreter(new AcceptAllInterceptor());

Expand Down Expand Up @@ -368,6 +370,13 @@ private List<DocSection> getTOC() {
extmod.addSection(new DocSection("Semver", "modules.semver"));
content.add(extmod);

final DocSection web = new DocSection("Web", "web");
web.addSection(new DocSection("Http\u00A0Client", "modules.http-client"));
web.addSection(new DocSection("Http\u00A0Client\u00A0Legacy", "modules.http-client-legacy"));
web.addSection(new DocSection("Tomcat\u00A0WebApp\u00A0Server", "modules.tomcat"));
web.addSection(new DocSection("Ring", "modules.ring"));
content.add(web);

final DocSection docker = new DocSection("Docker", "docker");
docker.addSection(new DocSection("Docker", "modules.docker"));
docker.addSection(new DocSection("Cargo", "modules.cargo"));
Expand Down Expand Up @@ -470,6 +479,8 @@ private List<DocSection> getModulesLeftSections() {
new ModuleCargoSection(diBuilder).section(),
new ModuleCargoArangoDBSection(diBuilder).section(),
new ModuleCargoQdrantDBSection(diBuilder).section(),
new ModuleTomcatSection(diBuilder).section(),
new ModuleRingSection(diBuilder).section(),
new ModuleTracingSection(diBuilder).section(),
new ModuleShellSection(diBuilder).section(),
new ModuleAnsiSection(diBuilder).section(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* __ __ _
* \ \ / /__ _ __ (_) ___ ___
* \ \/ / _ \ '_ \| |/ __/ _ \
* \ / __/ | | | | (_| __/
* \/ \___|_| |_|_|\___\___|
*
*
* Copyright 2017-2024 Venice
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.jlangch.venice.impl.docgen.cheatsheet.modules;

import com.github.jlangch.venice.impl.docgen.cheatsheet.DocItemBuilder;
import com.github.jlangch.venice.impl.docgen.cheatsheet.DocSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.ISectionBuilder;


public class ModuleRingSection implements ISectionBuilder {

public ModuleRingSection(final DocItemBuilder diBuilder) {
this.diBuilder = diBuilder;
}

@Override
public DocSection section() {
final DocSection section = new DocSection("Ring", "modules.ring");

final DocSection all = new DocSection("(load-module :ring)", id());
section.addSection(all);

final DocSection servlet = new DocSection("Servlet", id());
all.addSection(servlet);
servlet.addItem(diBuilder.getDocItem("ring/create-servlet", false));

final DocSection routing = new DocSection("Routing", id());
all.addSection(routing);
routing.addItem(diBuilder.getDocItem("ring/match-routes", false));

final DocSection util = new DocSection("Utils", id());
all.addSection(util);
util.addItem(diBuilder.getDocItem("ring/redirect", false));
util.addItem(diBuilder.getDocItem("ring/not-found-response", false));
util.addItem(diBuilder.getDocItem("ring/get-request-parameters ", false));
util.addItem(diBuilder.getDocItem("ring/get-request-header", false));
util.addItem(diBuilder.getDocItem("ring/get-request-header-accept-mimetypes", false));
util.addItem(diBuilder.getDocItem("ring/debug?", false));
util.addItem(diBuilder.getDocItem("ring/html-request?", false));
util.addItem(diBuilder.getDocItem("ring/json-request?", false));

final DocSection middleware = new DocSection("Middleware", id());
all.addSection(middleware);
middleware.addItem(diBuilder.getDocItem("ring/mw-identity", false));
middleware.addItem(diBuilder.getDocItem("ring/mw-debug", false));
middleware.addItem(diBuilder.getDocItem("ring/mw-print-uri", false));
middleware.addItem(diBuilder.getDocItem("ring/mw-request-counter", false));
middleware.addItem(diBuilder.getDocItem("ring/mw-dump-request", false));
middleware.addItem(diBuilder.getDocItem("ring/mw-dump-response", false));

final DocSection session = new DocSection("Session", id());
all.addSection(session);
session.addItem(diBuilder.getDocItem("ring/session-invalidate", false));
session.addItem(diBuilder.getDocItem("ring/session-clear", false));
session.addItem(diBuilder.getDocItem("ring/session-id", false));
session.addItem(diBuilder.getDocItem("ring/session-get-value", false));
session.addItem(diBuilder.getDocItem("ring/session-remove-value", false));
session.addItem(diBuilder.getDocItem("ring/session-creation-time", false));

return section;
}

private String id() {
return diBuilder.id();
}

private final DocItemBuilder diBuilder;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,24 @@ public DocSection section() {
" :silent false)) \n" +
"```\n";

final DocSection section = new DocSection("Tomcat", "Tomcat WebApp Server", "modules.tomcat", null, footer);
final DocSection section = new DocSection("Tomcat", "Embedded Tomcat WebApp Server", "modules.tomcat", null, footer);

final DocSection all = new DocSection("(load-module :tomcat)", id());
section.addSection(all);

final DocSection wr = new DocSection("Writer", id());
all.addSection(wr);
wr.addItem(diBuilder.getDocItem("excel/writer", false));
final DocSection tomcat = new DocSection("Tomcat", id());
all.addSection(tomcat);
tomcat.addItem(diBuilder.getDocItem("tomcat/start", false));
tomcat.addItem(diBuilder.getDocItem("tomcat/stop", false));
tomcat.addItem(diBuilder.getDocItem("tomcat/destroy", false));
tomcat.addItem(diBuilder.getDocItem("tomcat/shutdown", false));
tomcat.addItem(diBuilder.getDocItem("tomcat/state", false));

final DocSection servlet = new DocSection("Servlet", id());
all.addSection(servlet);
servlet.addItem(diBuilder.getDocItem("tomcat/create-servlet", false));
servlet.addItem(diBuilder.getDocItem("tomcat/hello-world-servlet", false));


return section;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

Args:

| [![width: 20%]] | [![width: 85%]] |
| [![width: 20%]] | [![width: 80%]] |
| cname | A unique container name |
| version | The Qdrant version to use. E.g.: 1.8.3 |
| mapped-rest-port | The published (mapped) Qdrant REST port on the \
Expand Down
69 changes: 41 additions & 28 deletions src/main/resources/com/github/jlangch/venice/ring.venice
Original file line number Diff line number Diff line change
Expand Up @@ -326,38 +326,50 @@
;; Routing
;; -----------------------------------------------------------------------------

;; A route is defined by a HTTP verb, a URI filter and a handle
;; function. If multiple routes match the route with the longest
;; URI filter will be chosen.
;;
;; (def routes [
;; [:get "/**" hello-world-handler]
;; [:get "/test/**" test-handler]
;; [:get "/static/images/*.png" image-handler]
;; ])
;;
;; Routing URI pattern filters:
;; "/**"
;; "/app/**"
;; "/static/images/chart.png"
;; "/static/images/*.png"
;; "/static/**/*.png"
;;
;; Rigging up a Ring WEB App and starting Tomcat:
;; (tc/run-tomcat
;; (ring/create-servlet (-> (ring/match-routes routes) ; >--+
;; ; |
;; (ring/mw-dump-request) ; ^ |
;; (ring/mw-request-counter) ; | |
;; (ring/mw-add-session 3600) ; | |
;; (ring/mw-print-uri) ; | |
;; (ring/mw-debug :on))) ; +--+
;; {:await? false})

(defn
^{ :doc """
Compile the routes and return a function that calls the handler
matching the URI.

A route is defined by a HTTP verb, a URI filter and a handle
function. If multiple routes match the route with the longest
URI filter will be chosen.

```
(def routes [
[:get "/**" hello-world-handler]
[:get "/test/**" test-handler]
[:get "/static/images/*.png" image-handler]

[:get "/employees" get-all-employees]
[:get "/employees/:id" get-employee]
[:post "/employees" create-employee]
[:put "/employees/:id" update-employee]
[:delete "/employees/:id" delete-employee] ])
```

Routing URI pattern filters:

* "/**"
* "/app/**"
* "/static/images/chart.png"
* "/static/images/*.png"
* "/static/**/*.png"

Rigging up a Ring WEB App and starting Tomcat:

```
(tc/run-tomcat
(ring/create-servlet (-> (ring/match-routes routes) ; >--+
; |
(ring/mw-dump-request) ; ^ |
(ring/mw-request-counter) ; | |
(ring/mw-add-session 3600) ; | |
(ring/mw-print-uri) ; | |
(ring/mw-debug :on))) ; +--+
{:await? false})
```
""" }

match-routes [routes]
Expand Down Expand Up @@ -433,7 +445,8 @@
^{ :doc """
Gets the character encoding of a Ring response.

E.g.: Content-Type: text/html; charset=utf-8
E.g.: Returns `utf-8` for a content tye header like:
`Content-Type: text/html; charset=utf-8`
""" }

get-charset [res]
Expand Down
Loading

0 comments on commit cd6863c

Please sign in to comment.