Skip to content

Commit cb0caf3

Browse files
committed
Some minor tweaks of the transform-markup fluent API
1 parent bb6785a commit cb0caf3

5 files changed

Lines changed: 54 additions & 34 deletions

File tree

‎transform-markup/src/main/java/org/ocpsoft/rewrite/transform/markup/Markdown.java‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,39 @@ public class Markdown extends JRubyTransformer<Markdown>
3232
"doc = Maruku.new(input)\n" +
3333
"fullDocument ? doc.to_html_document : doc.to_html\n";
3434

35-
private boolean fullDocument = true;
35+
private final boolean fullDocument;
3636

37+
/**
38+
* Creates a {@link Markdown} instance that renders a full HTML document.
39+
*/
3740
public Markdown()
3841
{
39-
// hide the constructor
42+
this(true);
4043
}
4144

42-
public static Markdown transformer()
45+
/**
46+
* Creates a {@link Markdown} instance.
47+
*/
48+
public Markdown(boolean fullDocument)
4349
{
44-
return new Markdown();
50+
this.fullDocument = fullDocument;
4551
}
4652

47-
public Markdown fullDocument()
53+
/**
54+
* Creates a {@link Markdown} instance that renders a full HTML document structure.
55+
*/
56+
public static Markdown fullDocument()
4857
{
49-
this.fullDocument = true;
50-
return this;
58+
return new Markdown(true);
5159
}
5260

53-
public Markdown partialDocument()
61+
/**
62+
* Creates a {@link Markdown} instance that just renders the markdown without adding the HTML scaffold like a body or
63+
* head.
64+
*/
65+
public static Markdown partialDocument()
5466
{
55-
this.fullDocument = false;
56-
return this;
67+
return new Markdown(false);
5768
}
5869

5970
@Override

‎transform-markup/src/main/java/org/ocpsoft/rewrite/transform/markup/Sass.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ public class Sass extends JRubyTransformer<Sass>
3232
"engine = Sass::Engine.new(input, :syntax => :scss, :cache => false)\n" +
3333
"engine.render\n";
3434

35-
public Sass()
36-
{
37-
// hide constructor
38-
}
39-
40-
public static Sass transformer()
35+
public static Sass create()
4136
{
4237
return new Sass();
4338
}

‎transform-markup/src/main/java/org/ocpsoft/rewrite/transform/markup/Textile.java‎

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,39 @@ public class Textile extends JRubyTransformer<Textile>
3131
private static final String SCRIPT = "require 'redcloth'\n" +
3232
"RedCloth.new(input).to_html\n";
3333

34-
private boolean fullDocument = true;
34+
private final boolean fullDocument;
3535

36+
/**
37+
* Creates a {@link Textile} instance that renders a full HTML document structure.
38+
*/
3639
public Textile()
3740
{
38-
// hide constructor
41+
this(true);
3942
}
4043

44+
/**
45+
* Creates a {@link Textile} instance.
46+
*/
47+
public Textile(boolean fullDocument)
48+
{
49+
this.fullDocument = fullDocument;
50+
}
51+
52+
/**
53+
* Creates a {@link Textile} instance that renders a full HTML document structure.
54+
*/
4155
public static Textile fullDocument()
4256
{
43-
Textile textile = new Textile();
44-
textile.fullDocument = true;
45-
return textile;
57+
return new Textile(true);
4658
}
4759

60+
/**
61+
* Creates a {@link Textile} instance that just renders the textile without adding the HTML scaffold like a body or
62+
* head.
63+
*/
4864
public static Textile partialDocument()
4965
{
50-
Textile textile = new Textile();
51-
textile.fullDocument = false;
52-
return textile;
66+
return new Textile(false);
5367
}
5468

5569
@Override

‎transform-markup/src/test/java/org/ocpsoft/rewrite/transform/markup/MarkdownTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class MarkdownTest {
2626
public void testBoldText() {
2727

2828
String markdown = "This is **bold**!";
29-
String html = Markdown.transformer().partialDocument().transform(markdown);
29+
String html = Markdown.partialDocument().transform(markdown);
3030

3131
assertEquals("<p>This is <strong>bold</strong>!</p>", html);
3232

@@ -36,7 +36,7 @@ public void testBoldText() {
3636
public void testHeaders() {
3737

3838
String markdown = "# Header\n\n##Section\n\nSome text!";
39-
String html = Markdown.transformer().partialDocument().transform(markdown);
39+
String html = Markdown.partialDocument().transform(markdown);
4040

4141
assertEquals("<h1 id='header'>Header</h1><h2 id='section'>Section</h2><p>Some text!</p>", normalize(html));
4242

@@ -46,7 +46,7 @@ public void testHeaders() {
4646
public void testBlockquote() {
4747

4848
String markdown = "> Some quote";
49-
String html = Markdown.transformer().partialDocument().transform(markdown);
49+
String html = Markdown.partialDocument().transform(markdown);
5050

5151
assertEquals("<blockquote><p>Some quote</p></blockquote>", normalize(html));
5252

@@ -56,7 +56,7 @@ public void testBlockquote() {
5656
public void testLists() {
5757

5858
String markdown = "* One\n* Two";
59-
String html = Markdown.transformer().partialDocument().transform(markdown);
59+
String html = Markdown.partialDocument().transform(markdown);
6060

6161
assertEquals("<ul><li>One</li><li>Two</li></ul>", normalize(html));
6262

@@ -66,7 +66,7 @@ public void testLists() {
6666
public void testCode() {
6767

6868
String markdown = " private int n = 0;";
69-
String html = Markdown.transformer().partialDocument().transform(markdown);
69+
String html = Markdown.partialDocument().transform(markdown);
7070

7171
assertEquals("<pre><code>private int n = 0;</code></pre>", normalize(html));
7272

@@ -76,7 +76,7 @@ public void testCode() {
7676
public void testFullHtmlDocument() {
7777

7878
String markdown = "some text";
79-
String html = Markdown.transformer().fullDocument().transform(markdown);
79+
String html = Markdown.fullDocument().transform(markdown);
8080

8181
assertTrue("DOCTYPE is missing", html.contains("<!DOCTYPE html PUBLIC"));
8282
assertTrue("html tag is missing", html.contains("<html"));

‎transform-markup/src/test/java/org/ocpsoft/rewrite/transform/markup/SassTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SassTest {
2525
public void testCalculations() {
2626

2727
String sass = ".class { width: 1+1 }";
28-
String css = Sass.transformer().transform(sass);
28+
String css = Sass.create().transform(sass);
2929

3030
assertEquals(".class { width: 2; }", normalize(css));
3131

@@ -35,7 +35,7 @@ public void testCalculations() {
3535
public void testNesting() {
3636

3737
String sass = ".outer { margin: 2px; .inner { padding: 3px; } }";
38-
String css = Sass.transformer().transform(sass);
38+
String css = Sass.create().transform(sass);
3939

4040
assertEquals(".outer { margin: 2px; } .outer .inner { padding: 3px; }", normalize(css));
4141

@@ -45,7 +45,7 @@ public void testNesting() {
4545
public void testVariables() {
4646

4747
String sass = "$mycolor: #123456; .class { color: $mycolor }";
48-
String css = Sass.transformer().transform(sass);
48+
String css = Sass.create().transform(sass);
4949

5050
assertEquals(".class { color: #123456; }", normalize(css));
5151

@@ -55,7 +55,7 @@ public void testVariables() {
5555
public void testMixins() {
5656

5757
String sass = "@mixin invalid { color: red } .label { @include invalid }";
58-
String css = Sass.transformer().transform(sass);
58+
String css = Sass.create().transform(sass);
5959

6060
assertEquals(".label { color: red; }", normalize(css));
6161

0 commit comments

Comments
 (0)