-
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.
Fixes #916. Add factory methods to create lists
- Loading branch information
1 parent
56371f3
commit cc18589
Showing
8 changed files
with
212 additions
and
4 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
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
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
29 changes: 29 additions & 0 deletions
29
asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/ListCreatorBlockMacro.groovy
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,29 @@ | ||
package org.asciidoctor.extension | ||
|
||
|
||
import org.asciidoctor.ast.StructuralNode | ||
|
||
@Name('list') | ||
class ListCreatorBlockMacro extends BlockMacroProcessor { | ||
|
||
String context | ||
|
||
ListCreatorBlockMacro(String context) { | ||
this.context = context | ||
} | ||
|
||
@Override | ||
Object process(StructuralNode parent, String target, Map<String, Object> attributes) { | ||
|
||
def attrs = new HashMap<String, Object>() | ||
attrs['start'] = '42' | ||
def opts = new HashMap<Object, Object>() | ||
|
||
org.asciidoctor.ast.List list = createList(parent, context, attrs, opts) | ||
|
||
list.getBlocks().add(createListItem(list, 'First item')) | ||
list.getBlocks().add(createListItem(list, 'Second item')) | ||
|
||
list | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ore/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesAList.groovy
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,73 @@ | ||
package org.asciidoctor.extension | ||
|
||
import org.asciidoctor.Asciidoctor | ||
import org.asciidoctor.OptionsBuilder | ||
import org.asciidoctor.SafeMode | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.jsoup.Jsoup | ||
import org.jsoup.nodes.Document | ||
import org.junit.runner.RunWith | ||
import spock.lang.Specification | ||
|
||
@RunWith(ArquillianSputnik) | ||
class WhenABlockMacroProcessorCreatesAList extends Specification { | ||
|
||
public static final String LISTMACRO_NAME = 'list' | ||
public static final String UTF_8 = 'UTF-8' | ||
public static final String OL = 'ol' | ||
public static final String UL = 'ul' | ||
public static final String LI = 'li' | ||
public static final String FIRST_ITEM = 'First item' | ||
public static final String SECOND_ITEM = 'Second item' | ||
|
||
@ArquillianResource | ||
private Asciidoctor asciidoctor | ||
|
||
private static final String DOCUMENT = ''' | ||
= Section Creation Test | ||
list::HelloWorld[] | ||
''' | ||
|
||
def "the ordered list should appear in the resulting document"() { | ||
|
||
given: | ||
asciidoctor.javaExtensionRegistry().blockMacro(LISTMACRO_NAME, new ListCreatorBlockMacro('olist')) | ||
|
||
when: | ||
String result = asciidoctor.convert(DOCUMENT, OptionsBuilder.options().safe(SafeMode.SAFE).toFile(false).headerFooter(false)) | ||
|
||
then: | ||
noExceptionThrown() | ||
Document htmlDocument = Jsoup.parse(result, UTF_8) | ||
|
||
htmlDocument.select(OL).size() == 1 | ||
def ol = htmlDocument.select(OL).first() | ||
ol.attr('start') == '42' | ||
def items = ol.select(LI) | ||
items.size() == 2 | ||
items.get(0).text() == FIRST_ITEM | ||
items.get(1).text() == SECOND_ITEM | ||
} | ||
|
||
def "the unordered list should appear in the resulting document"() { | ||
|
||
given: | ||
asciidoctor.javaExtensionRegistry().blockMacro(LISTMACRO_NAME, new ListCreatorBlockMacro('ulist')) | ||
|
||
when: | ||
String result = asciidoctor.convert(DOCUMENT, OptionsBuilder.options().safe(SafeMode.SAFE).toFile(false).headerFooter(false)) | ||
|
||
then: | ||
noExceptionThrown() | ||
Document htmlDocument = Jsoup.parse(result, UTF_8) | ||
|
||
htmlDocument.select(UL).size() == 1 | ||
def ul = htmlDocument.select(UL).first() | ||
def items = ul.select(LI) | ||
items.size() == 2 | ||
items.get(0).text() == FIRST_ITEM | ||
items.get(1).text() == SECOND_ITEM | ||
} | ||
} |
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