1 | package fr.sii.ogham.email.builder; | |
2 | ||
3 | import fr.sii.ogham.core.builder.Builder; | |
4 | import fr.sii.ogham.core.builder.context.BuildContext; | |
5 | import fr.sii.ogham.core.fluent.AbstractParent; | |
6 | import fr.sii.ogham.html.inliner.EveryImageInliner; | |
7 | import fr.sii.ogham.html.inliner.ImageInliner; | |
8 | import fr.sii.ogham.html.inliner.impl.jsoup.JsoupBase64ImageInliner; | |
9 | import fr.sii.ogham.html.inliner.impl.regexp.RegexBase64BackgroundImageInliner; | |
10 | ||
11 | /** | |
12 | * Configures how images defined in the HTML template are inlined (converted to | |
13 | * base64). | |
14 | * | |
15 | * For example, if your template contains the following HTML code: | |
16 | * | |
17 | * <pre> | |
18 | * {@code | |
19 | * <img src="classpath:/foo.png" data-inline-image="base64" /> | |
20 | * } | |
21 | * </pre> | |
22 | * | |
23 | * Then the image will be loaded from the classpath and encoded into a base64 | |
24 | * string. This base64 string is used in the src attribute of the {@code <img>}. | |
25 | * | |
26 | * <p> | |
27 | * In the same way, if your template contains the following code: | |
28 | * | |
29 | * <pre> | |
30 | * <code> | |
31 | * <style> | |
32 | * .some-class { | |
33 | * background: url('classpath:/foo.png'); | |
34 | * --inline-image: base64; | |
35 | * } | |
36 | * </style> | |
37 | * </code> | |
38 | * </pre> | |
39 | * | |
40 | * Or directly on {@code style} attribute: | |
41 | * | |
42 | * <pre> | |
43 | * {@code | |
44 | * <div style="background: url('classpath:/foo.png'); --inline-image: base64;"></div> | |
45 | * } | |
46 | * </pre> | |
47 | * | |
48 | * Then the image will be loaded from the classpath and encoded into a base64 | |
49 | * string. The url is updated with the base64 string. | |
50 | * | |
51 | * | |
52 | * @author Aurélien Baudet | |
53 | * | |
54 | */ | |
55 | public class Base64InliningBuilder extends AbstractParent<ImageInliningBuilder> implements Builder<ImageInliner> { | |
56 | private final BuildContext buildContext; | |
57 | ||
58 | /** | |
59 | * Initializes with the parent (used when calling {@link #and()} method for | |
60 | * fluent chaining). | |
61 | * | |
62 | * @param parent | |
63 | * the parent builder | |
64 | * @param buildContext | |
65 | * for registering instances and property evaluation | |
66 | */ | |
67 | public Base64InliningBuilder(ImageInliningBuilder parent, BuildContext buildContext) { | |
68 | super(parent); | |
69 | this.buildContext = buildContext; | |
70 | } | |
71 | ||
72 | @Override | |
73 | public ImageInliner build() { | |
74 | EveryImageInliner inliner = buildContext.register(new EveryImageInliner()); | |
75 | inliner.addInliner(buildContext.register(new JsoupBase64ImageInliner())); | |
76 | inliner.addInliner(buildContext.register(new RegexBase64BackgroundImageInliner())); | |
77 |
4
1. build : replaced return value with null for fr/sii/ogham/email/builder/Base64InliningBuilder::build → SURVIVED 2. build : replaced return value with null for fr/sii/ogham/email/builder/Base64InliningBuilder::build → NO_COVERAGE 3. build : replaced return value with null for fr/sii/ogham/email/builder/Base64InliningBuilder::build → KILLED 4. build : replaced return value with null for fr/sii/ogham/email/builder/Base64InliningBuilder::build → KILLED |
return inliner; |
78 | } | |
79 | ||
80 | } | |
Mutations | ||
77 |
1.1 2.2 3.3 4.4 |