-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding docs for Block Macro Processor positional attributes
- Loading branch information
1 parent
3e6523a
commit d7551b8
Showing
10 changed files
with
180 additions
and
6 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
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
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] |
5 changes: 3 additions & 2 deletions
5
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
= InlineMacroProcessor Test Document | ||
= 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[asciidoctor/asciidoctorj-groovy-dsl]. | ||
You might want to take a look at the issue issue:334[asciidoctor/asciidoctorj] and issue:3[]. |
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] |
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
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