-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from asciidoctor/docs-extension-attributes
Adding docs for accessing named and positional attributes in BlockPro…
- Loading branch information
Showing
69 changed files
with
909 additions
and
1,506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...g/asciidoctor/integrationguide/extension/GistBlockMacroPositionalAttributesProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.asciidoctor.integrationguide.extension; | ||
|
||
//tag::include[] | ||
import org.asciidoctor.ast.StructuralNode; | ||
import org.asciidoctor.extension.BlockMacroProcessor; | ||
import org.asciidoctor.extension.Name; | ||
import org.asciidoctor.extension.PositionalAttributes; | ||
|
||
import java.util.Map; | ||
|
||
@Name("gist") | ||
@PositionalAttributes({"provider", "repo"}) // <1> | ||
public class GistBlockMacroPositionalAttributesProcessor extends BlockMacroProcessor { | ||
|
||
@Override | ||
public Object process(StructuralNode parent, String target, Map<String, Object> attributes) { | ||
|
||
String script; | ||
String provider = (String) attributes.get("provider"); | ||
if (provider == null || "github".equals(provider)) { // <2> | ||
script = String.format("<script src=\"https://gist.github.com/%s.js\"/></script>", target); | ||
} else if ("gitlab".equals(provider)) { | ||
String repo = (String) attributes.get("repo"); | ||
if (repo == null) { | ||
script = String.format("<script src=\"https://gitlab.com/-/snippets/%s.js\"></script>", target); | ||
} else { | ||
script = String.format("<script src=\"https://gitlab.com/%s/-/snippets/%s.js\"></script>", repo, target); | ||
} | ||
} else { | ||
throw new IllegalArgumentException("Unknown provider " + provider); | ||
} | ||
|
||
String content = new StringBuilder() | ||
.append("<div class=\"openblock gist\">") | ||
.append("<div class=\"content\">") | ||
.append(script) | ||
.append("</div>") | ||
.append("</div>").toString(); | ||
|
||
return createBlock(parent, "pass", content); | ||
} | ||
|
||
} | ||
//end::include[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...asciidoctor/integrationguide/extension/IssueInlineMacroPositionalAttributesProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.asciidoctor.integrationguide.extension; | ||
|
||
//tag::include[] | ||
import org.asciidoctor.ast.ContentNode; | ||
import org.asciidoctor.extension.InlineMacroProcessor; | ||
import org.asciidoctor.extension.Name; | ||
import org.asciidoctor.extension.PositionalAttributes; | ||
|
||
//end::include[] | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
//tag::include[] | ||
@Name("issue") | ||
@PositionalAttributes({"repo"}) // <1> | ||
public class IssueInlineMacroPositionalAttributesProcessor extends InlineMacroProcessor { | ||
|
||
@Override | ||
public Object process(ContentNode parent, String target, Map<String, Object> attributes) { | ||
|
||
String href = | ||
new StringBuilder() | ||
.append("https://github.com/") | ||
.append(attributes.containsKey("repo") ? | ||
attributes.get("repo") : | ||
parent.getDocument().getAttribute("repo")) | ||
.append("/issues/") | ||
.append(target).toString(); | ||
|
||
Map<String, Object> options = new HashMap<>(); | ||
options.put("type", ":link"); | ||
options.put("target", href); | ||
return createPhraseNode(parent, "anchor", target, attributes, options); // <4> | ||
} | ||
|
||
} | ||
//end::include[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...est/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorWithAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.asciidoctor.integrationguide.extension; | ||
|
||
import org.asciidoctor.ast.ContentModel; | ||
import org.asciidoctor.ast.StructuralNode; | ||
import org.asciidoctor.extension.BlockProcessor; | ||
import org.asciidoctor.extension.Contexts; | ||
import org.asciidoctor.extension.Name; | ||
import org.asciidoctor.extension.Reader; | ||
|
||
import java.util.Map; | ||
import java.util.stream.IntStream; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
|
||
//tag::include[] | ||
@Name("yell") | ||
@Contexts({Contexts.PARAGRAPH}) | ||
@ContentModel(ContentModel.SIMPLE) | ||
public class YellBlockProcessorWithAttributes extends BlockProcessor { | ||
|
||
@Override | ||
public Object process( | ||
StructuralNode parent, Reader reader, Map<String, Object> attributes) { | ||
|
||
String content = reader.read(); | ||
String yellContent = content.toUpperCase(); | ||
|
||
String loudness = (String) attributes.get("loudness"); // <1> | ||
if (loudness != null) { | ||
yellContent += IntStream.range(0, Integer.parseInt(loudness)) | ||
.mapToObj(i -> "!") | ||
.collect(joining()); | ||
} | ||
|
||
return createBlock(parent, "paragraph", yellContent, attributes); | ||
} | ||
|
||
} | ||
//end::include[] |
37 changes: 37 additions & 0 deletions
37
...rg/asciidoctor/integrationguide/extension/YellBlockProcessorWithPositionalAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.asciidoctor.integrationguide.extension; | ||
|
||
import org.asciidoctor.ast.ContentModel; | ||
import org.asciidoctor.ast.StructuralNode; | ||
import org.asciidoctor.extension.*; | ||
|
||
import java.util.Map; | ||
import java.util.stream.IntStream; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
|
||
//tag::include[] | ||
@Name("yell") | ||
@PositionalAttributes({"loudness"}) // <1> | ||
@Contexts({Contexts.PARAGRAPH}) | ||
@ContentModel(ContentModel.SIMPLE) | ||
public class YellBlockProcessorWithPositionalAttributes extends BlockProcessor { | ||
|
||
@Override | ||
public Object process( | ||
StructuralNode parent, Reader reader, Map<String, Object> attributes) { | ||
|
||
String content = reader.read(); | ||
String yellContent = content.toUpperCase(); | ||
|
||
String loudness = (String) attributes.get("loudness"); // <2> | ||
if (loudness != null) { | ||
yellContent += IntStream.range(0, Integer.parseInt(loudness)) | ||
.mapToObj(i -> "!") | ||
.collect(joining()); | ||
} | ||
|
||
return createBlock(parent, "paragraph", yellContent, attributes); | ||
} | ||
|
||
} | ||
//end::include[] |
9 changes: 9 additions & 0 deletions
9
asciidoctorj-documentation/src/test/resources/gist-macro-attributes.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
== Gists | ||
|
||
gist::myaccount/1234abcd[] | ||
|
||
gist::2228798[gitlab] | ||
|
||
gist::1717978[gitlab,gitlab-org/gitlab-foss] | ||
|
||
gist::1717979[gitlab,repo=gitlab-org/gitlab-foss] |
4 changes: 4 additions & 0 deletions
4
asciidoctorj-documentation/src/test/resources/issue-inline-macro-positional.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= InlineMacroProcessor Test Document | ||
:repo: asciidoctor/asciidoctorj-groovy-dsl | ||
|
||
You might want to take a look at the issue issue:334[asciidoctor/asciidoctorj] and issue:3[]. |
2 changes: 2 additions & 0 deletions
2
asciidoctorj-documentation/src/test/resources/yell-block-attributes.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[yell,loudness=3] | ||
I really mean it |
2 changes: 2 additions & 0 deletions
2
asciidoctorj-documentation/src/test/resources/yell-block-positional.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[yell,5] | ||
I really mean it |
Oops, something went wrong.