Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding anki card format #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<artifactId>rome</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>ch.ledcom.javalib</groupId>
<artifactId>ankilib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome-modules</artifactId>
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/ch/ledcom/signs/AnkiView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright © 2016 Guillaume Lederrey ([email protected])
*
* 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 ch.ledcom.signs;

import lombok.NonNull;
import ch.ledcom.javalib.AnkiWriter;
import ch.ledcom.javalib.Deck;
import ch.ledcom.javalib.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.View;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Component("search.anki")
public class AnkiView implements View {

@NonNull
private final AnkiWriter ankiWriter = new AnkiWriter();

@Override
public String getContentType() {
return "anki+zip";
}

@Override
public void render(
Map<String, ?> model,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=signs.apkg");

Deck deck = new Deck();

for (Sign sign : (Iterable<Sign>) model.get("signs")) {

String signName = sign.getName();
Svg signImage = sign.getImage();

deck.addCard(signName, new Resource(signImage));
}

ankiWriter.write(deck, response.getOutputStream());
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ admin.metrics=metrics
admin.swagger=swagger
admin.thread.dump=thread dump
admin.trace=trace
anki=Anki
app.title=Signs
atom=Atom (XML)
configuration=Configuration
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ admin.metrics=metrics
admin.swagger=swagger
admin.thread.dump=thread dump
admin.trace=trace
anki=Anki
app.title=Signes
atom=Atom (XML)
configuration=Configuration
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</li>
<li><a th:text="#{atom}" th:href="@{${currentUrlNoFormat}(format=atom)}">Atom (XML)</a></li>
<li><a th:text="#{json}" th:href="@{${currentUrlNoFormat}(format=json)}">JSON</a></li>
<li><a th:text="#{anki}" th:href="@{${currentUrlNoFormat}(format=anki)}">Anki</a></li>
</ul>
</div>
</div>
Expand Down