Skip to content

Commit

Permalink
added :multipart module to cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Apr 1, 2024
1 parent 5057a18 commit 2ebc1d8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleMatrixSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleMavenSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleMimetypesSection;
import com.github.jlangch.venice.impl.docgen.cheatsheet.modules.ModuleMultipartSection;
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;
Expand Down Expand Up @@ -137,7 +138,8 @@ public DocGenerator(final boolean runExamples) {
"fonts", "qrref", "jsonl", "timing",
"zipvault", "gradlew", "matrix", "ascii-table",
"docker", "cargo", "cargo-arangodb", "cargo-qdrant",
"installer", "tomcat", "ring", "mimetypes"));
"installer", "tomcat", "ring",
"mimetypes", "multipart"));

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

Expand Down Expand Up @@ -382,6 +384,7 @@ private List<DocSection> getTOC() {
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"));
web.addSection(new DocSection("Multipart", "modules.multipart"));
content.add(web);

final DocSection docker = new DocSection("Docker", "docker");
Expand Down Expand Up @@ -511,6 +514,7 @@ private List<DocSection> getModulesRightSections() {
new ModuleMatrixSection(diBuilder).section(),
new ModuleAnsiSection(diBuilder).section(),
new ModuleMimetypesSection(diBuilder).section(),
new ModuleMultipartSection(diBuilder).section(),
new ModuleInstallerSection(diBuilder).section());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* __ __ _
* \ \ / /__ _ __ (_) ___ ___
* \ \/ / _ \ '_ \| |/ __/ _ \
* \ / __/ | | | | (_| __/
* \/ \___|_| |_|_|\___\___|
*
*
* 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 ModuleMultipartSection implements ISectionBuilder {

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

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

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

final DocSection part = new DocSection("Multipart", id());
all.addSection(part);
part.addItem(diBuilder.getDocItem("multipart/render", false));

return section;
}

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

private final DocItemBuilder diBuilder;
}
12 changes: 6 additions & 6 deletions src/main/resources/com/github/jlangch/venice/multipart.venice
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
The part name must be a string and the part data may be of type:
* string
* string ("file:/user/foo/image.png" to reference a file)
* map (describing a part as :name, :mimetype, and :data)
* map (describing a part as :name, :mimetype, and :data (string or bytebuf)) elements)
* io/file
* all other part data types are converted with `(str data)` to a string

Expand All @@ -79,9 +79,7 @@
"Part-3" (io/file "/user/foo/image.png")
"Part-4" {:name "data.xml"
:mimetype "application/xml"
:data (bytebuf-from-string
"<user><name>foo</name></user>"
:utf-8)}})
:data "<user><name>foo</name></user>"}})
""" ) }

render [data]
Expand Down Expand Up @@ -138,15 +136,17 @@
(defn- render-file-data-part [name v-file-name v-file-mimetype v-file-data os]
(assert (string? v-file-name))
(assert (string? v-file-mimetype))
(assert (bytebuf? v-file-data))
(assert (or (string? v-file-data) (bytebuf? v-file-data)))

(io/spit-stream os (bytebuf-from-string (str dash boundary-value nl)))
(io/spit-stream os (bytebuf-from-string disposition))

(io/spit-stream os (bytebuf-from-string (str field-name dq name dq file-name dq v-file-name dq nl)))
(io/spit-stream os (bytebuf-from-string (str content-type v-file-mimetype nl)))
(io/spit-stream os (bytebuf-from-string nl))
(io/spit-stream os v-file-data)
(io/spit-stream os (if (string? v-file-data)
(bytebuf-from-string v-file-data)
v-file-data))
(io/spit-stream os (bytebuf-from-string nl))

(io/spit-stream os (bytebuf-from-string (str dash boundary-value dash nl))))
Expand Down

0 comments on commit 2ebc1d8

Please sign in to comment.