Sample app, first real sample

This commit is contained in:
Dimitry Ivanov 2020-06-26 18:30:51 +03:00
parent bea6d6aeec
commit dc139319a0
8 changed files with 59 additions and 159 deletions

View File

@ -1,45 +1,14 @@
[
{
"javaClassName": "io.noties.markwon.app.samples.nested.ThirdSample",
"id": "202006177155827",
"title": "Third sample",
"description": "\u003e yo! \n\n```\nfinal int i \u003d 0;\n```",
"artifacts": [
"EDITOR",
"SIMPLE_EXT"
],
"tags": [
"a",
"c",
"test"
]
},
{
"javaClassName": "io.noties.markwon.app.samples.nested.SecondSample",
"id": "202006177155656",
"title": "Second sample",
"description": "# Hey hey hey",
"artifacts": [
"CORE",
"RECYCLER"
],
"tags": [
"a",
"b",
"c",
"test"
]
},
{
"javaClassName": "io.noties.markwon.app.samples.FirstSample",
"id": "202006164150023",
"title": "First Sample",
"description": "This **is** _the first_ sample",
"javaClassName": "io.noties.markwon.app.samples.basics.Simple",
"id": "202006178152255",
"title": "Simple",
"description": "The most primitive and simple way to apply markdown to a `TextView`",
"artifacts": [
"CORE"
],
"tags": [
"test"
"basics"
]
}
]

View File

@ -0,0 +1,5 @@
package io.noties.markwon.app.sample
object Tags {
const val basics = "basics"
}

View File

@ -1,30 +0,0 @@
package io.noties.markwon.app.samples
import io.noties.markwon.Markwon
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample
import io.noties.markwon.sample.annotations.MarkwonArtifact
import io.noties.markwon.sample.annotations.MarkwonSampleInfo
@MarkwonSampleInfo(
id = "202006164150023",
title = "First Sample",
description = "This **is** _the first_ sample",
artifacts = [MarkwonArtifact.CORE],
tags = ["test"]
)
class FirstSample : MarkwonTextViewSample() {
override fun render() {
val md = """
# Hello there!
> How are you?
**bold** and _italic_ and **bold _italic bold_ just bold**
""".trimIndent()
val markwon: Markwon = Markwon.create(context)
markwon.setMarkdown(textView, md)
}
}

View File

@ -0,0 +1,33 @@
package io.noties.markwon.app.samples.basics
import io.noties.markwon.Markwon
import io.noties.markwon.app.sample.Tags
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample
import io.noties.markwon.sample.annotations.MarkwonArtifact
import io.noties.markwon.sample.annotations.MarkwonSampleInfo
@MarkwonSampleInfo(
id = "202006178152255",
title = "Simple",
description = "The most primitive and simple way to apply markdown to a `TextView`",
artifacts = [MarkwonArtifact.CORE],
tags = [Tags.basics]
)
class Simple : MarkwonTextViewSample() {
override fun render() {
// markdown input
val md = """
# Heading
> A quote
**bold _italic_ bold**
""".trimIndent()
// markwon instance
val markwon = Markwon.create(context)
// apply raw markdown (internally parsed and rendered)
markwon.setMarkdown(textView, md)
}
}

View File

@ -1,65 +0,0 @@
package io.noties.markwon.app.samples.nested
import io.noties.markwon.Markwon
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample
import io.noties.markwon.sample.annotations.MarkwonArtifact
import io.noties.markwon.sample.annotations.MarkwonSampleInfo
@MarkwonSampleInfo(
id = "202006177155656",
title = "Second sample",
description = "# Hey hey hey",
artifacts = [MarkwonArtifact.CORE, MarkwonArtifact.RECYCLER],
tags = ["b", "c", "a", "test"]
)
class SecondSample : MarkwonTextViewSample() {
override fun render() {
val md = """
# Hello second
```java
final int i = 0;
```
""".trimIndent()
val markwon = Markwon.create(context)
markwon.setMarkdown(textView, md)
}
val _mock: String
get() = """
a
b
d
s
as
sd
ds
sd
s
sd
sd
ds
sd
sd
sd
sd
sd
sd
ds
sd
sd
s
sd
sd
sd
sd
sd
ds
sd
sd
sd
""".trimIndent()
}

View File

@ -1,22 +0,0 @@
package io.noties.markwon.app.samples.nested;
import io.noties.markwon.Markwon;
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample;
import io.noties.markwon.sample.annotations.MarkwonArtifact;
import io.noties.markwon.sample.annotations.MarkwonSampleInfo;
@MarkwonSampleInfo(
id = "202006177155827",
title = "Third sample",
description = "> yo! \n\n```\nfinal int i = 0;\n```",
artifacts = {MarkwonArtifact.SIMPLE_EXT, MarkwonArtifact.EDITOR},
tags = {"a", "c", "test"}
)
public class ThirdSample extends MarkwonTextViewSample {
@Override
public void render() {
final String md = "# Hello!";
final Markwon markwon = Markwon.create(context);
markwon.setMarkdown(textView, md);
}
}

View File

@ -5,6 +5,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
// NB! if class was just removed if won't be removed from samples.json
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface MarkwonSampleInfo {
@ -22,7 +23,7 @@ public @interface MarkwonSampleInfo {
String title();
String description();
String description() default "";
MarkwonArtifact[] artifacts();

View File

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
@ -87,16 +88,22 @@ public class MarkwonSampleProcessor extends AbstractProcessor {
if (!roundEnvironment.processingOver()) {
final long begin = System.currentTimeMillis();
final Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(MarkwonSampleInfo.class);
if (elements != null) {
// we should not have zero samples
if (elements != null && elements.size() > 0) {
final HashSet<MarkwonSample> markwonSamples = new HashSet<>();
for (Element element : elements) {
process(element);
try {
markwonSamples.add(parse((TypeElement) element));
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
if (samplesUpdated) {
if (!markwonSamples.equals(new HashSet<>(samples))) {
logger.info("samples updated, writing at path: %s", samplesFilePath);
try {
writeSamples(samplesFilePath, samples);
writeSamples(samplesFilePath, markwonSamples);
} catch (Throwable t) {
logger.error(t.getMessage());
throw new RuntimeException(t);
@ -145,7 +152,7 @@ public class MarkwonSampleProcessor extends AbstractProcessor {
}
}
private static void writeSamples(@NonNull String path, @NonNull List<MarkwonSample> samples) throws Throwable {
private static void writeSamples(@NonNull String path, @NonNull Set<MarkwonSample> markwonSamples) throws Throwable {
final File file = new File(path);
@ -159,6 +166,8 @@ public class MarkwonSampleProcessor extends AbstractProcessor {
}
}
final List<MarkwonSample> samples = new ArrayList<>(markwonSamples);
// sort based on id (it is date)
// new items come first (DESC order)
Collections.sort(samples, (lhs, rhs) -> rhs.id.compareTo(lhs.id));