Skip to content

Commit 1b578d7

Browse files
committed
Finished JavaDoc updates, also added fluent API for the transform-minify module
1 parent 913dd50 commit 1b578d7

17 files changed

Lines changed: 135 additions & 101 deletions

File tree

‎security-integration-shiro/src/main/java/org/ocpsoft/rewrite/security/shiro/ShiroRoleRequired.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.annotation.Target;
99

10+
import org.ocpsoft.rewrite.annotation.Rule;
11+
1012
/**
13+
* Specifies that the element annotated with {@link Rule} must be constrained to users that are a member of the given
14+
* role or roles.
15+
*
1116
* @author Christian Kaltepoth
1217
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
1318
*/
@@ -17,5 +22,8 @@
1722
@Retention(RetentionPolicy.RUNTIME)
1823
public @interface ShiroRoleRequired
1924
{
25+
/**
26+
* The role or roles of which the user must be a member.
27+
*/
2028
String[] value();
2129
}

‎transform-less/src/main/java/org/ocpsoft/rewrite/transform/less/Less.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import org.mozilla.javascript.Scriptable;
2424
import org.ocpsoft.common.util.Streams;
2525
import org.ocpsoft.rewrite.transform.StringTransformer;
26+
import org.ocpsoft.rewrite.transform.Transformer;
2627

2728
/**
28-
* This transformer compiles LESS files into CSS. The implementation is based on Mozilla Rhino and LESS 1.3.0.
29+
* A {@link Transformer} that compiles LESS files into CSS. This implementation is based on Mozilla Rhino and LESS
30+
* 1.3.0.
2931
*
3032
* @author Christian Kaltepoth
3133
*/
@@ -34,7 +36,15 @@ public class Less extends StringTransformer
3436

3537
private final String baseScript;
3638

37-
public Less()
39+
/**
40+
* Create a {@link Transformer} that compiles LESS files into CSS.
41+
*/
42+
public static Less compiler()
43+
{
44+
return new Less();
45+
}
46+
47+
private Less()
3848
{
3949
StringBuilder scriptBuilder = new StringBuilder();
4050
scriptBuilder.append("function print(s) {}"); // required by env.rhino

‎transform-less/src/test/java/org/ocpsoft/rewrite/transform/less/LessIntegrationTestProvider.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Configuration getConfiguration(final ServletContext context)
4848

4949
.addRule()
5050
.when(Path.matches("/{something}.css"))
51-
.perform(Forward.to("/{something}.less").and(Transform.with(new Less())));
51+
.perform(Forward.to("/{something}.less").and(Transform.with(Less.compiler())));
5252

5353
}
5454
}

‎transform-less/src/test/java/org/ocpsoft/rewrite/transform/less/LessTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ public class LessTest
2727
public void testCalculation()
2828
{
2929
String input = ".class { width: 1 + 1 }";
30-
String output = new Less().transform(input);
30+
String output = Less.compiler().transform(input);
3131
assertSameCSS(".class { width: 2; }", output);
3232
}
3333

3434
@Test
3535
public void testVariables()
3636
{
3737
String input = "@nice-blue: #5B83AD;\n.myblue{ color: @nice-blue; }";
38-
String output = new Less().transform(input);
38+
String output = Less.compiler().transform(input);
3939
assertSameCSS(".myblue { color: #5B83AD; }", output);
4040
}
4141

4242
@Test
4343
public void testMixins()
4444
{
4545
String input = ".bordered { border: 1px solid red; }\n.navigation { .bordered }\n";
46-
String output = new Less().transform(input);
46+
String output = Less.compiler().transform(input);
4747
assertSameCSS(".bordered{ border: 1px solid red; }\n.navigation{ border: 1px solid red; }\n", output);
4848
}
4949

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @author Christian Kaltepoth
1717
*/
18-
public abstract class JRubyTransformer<T> extends StringTransformer
18+
abstract class JRubyTransformer<T> extends StringTransformer
1919
{
2020

2121
private CompileMode compileMode = null;

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import java.util.List;
2020

2121
import org.jruby.embed.ScriptingContainer;
22+
import org.ocpsoft.rewrite.transform.Transformer;
2223

2324
/**
24-
* Transformer that translates Markdown files into HTML.
25+
* A {@link Transformer} that translates Markdown files into HTML.
2526
*
2627
* @author Christian Kaltepoth
2728
*/
@@ -35,36 +36,27 @@ public class Markdown extends JRubyTransformer<Markdown>
3536
private final boolean fullDocument;
3637

3738
/**
38-
* Creates a {@link Markdown} instance that renders a full HTML document.
39+
* Create a {@link Transformer} instance that renders a full markdown HTML document structure.
3940
*/
40-
public Markdown()
41-
{
42-
this(true);
43-
}
44-
45-
/**
46-
* Creates a {@link Markdown} instance.
47-
*/
48-
public Markdown(boolean fullDocument)
41+
public static Markdown fullDocument()
4942
{
50-
this.fullDocument = fullDocument;
43+
return new Markdown(true);
5144
}
5245

5346
/**
54-
* Creates a {@link Markdown} instance that renders a full HTML document structure.
47+
* Create a {@link Transformer} instance that renders markdown without adding the HTML scaffold like a body or head.
5548
*/
56-
public static Markdown fullDocument()
49+
public static Markdown partialDocument()
5750
{
58-
return new Markdown(true);
51+
return new Markdown(false);
5952
}
6053

6154
/**
62-
* Creates a {@link Markdown} instance that just renders the markdown without adding the HTML scaffold like a body or
63-
* head.
55+
* Creates a {@link Markdown} instance.
6456
*/
65-
public static Markdown partialDocument()
57+
private Markdown(boolean fullDocument)
6658
{
67-
return new Markdown(false);
59+
this.fullDocument = fullDocument;
6860
}
6961

7062
@Override

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import java.util.List;
2020

2121
import org.jruby.embed.ScriptingContainer;
22+
import org.ocpsoft.rewrite.transform.Transformer;
2223

2324
/**
24-
* Transformer that translates SASS files into CSS.
25+
* A {@link Transformer} that translates SASS files into CSS.
2526
*
2627
* @author Christian Kaltepoth
2728
*/
@@ -32,11 +33,17 @@ public class Sass extends JRubyTransformer<Sass>
3233
"engine = Sass::Engine.new(input, :syntax => :scss, :cache => false)\n" +
3334
"engine.render\n";
3435

35-
public static Sass create()
36+
/**
37+
* Create a {@link Transformer} that compiles SASS files into CSS.
38+
*/
39+
public static Sass compiler()
3640
{
3741
return new Sass();
3842
}
3943

44+
private Sass()
45+
{}
46+
4047
@Override
4148
public List<String> getLoadPaths()
4249
{

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
import java.util.List;
2020

2121
import org.jruby.embed.ScriptingContainer;
22+
import org.ocpsoft.rewrite.transform.Transformer;
2223

2324
/**
24-
* Transformer that translates Textile markup into HTML.
25+
* A {@link Transformer} that translates Textile markup into HTML.
2526
*
2627
* @author Christian Kaltepoth
2728
*/
@@ -34,38 +35,26 @@ public class Textile extends JRubyTransformer<Textile>
3435
private final boolean fullDocument;
3536

3637
/**
37-
* Creates a {@link Textile} instance that renders a full HTML document structure.
38-
*/
39-
public Textile()
40-
{
41-
this(true);
42-
}
43-
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.
38+
* Create a {@link Transformer} instance that renders a full HTML document structure.
5439
*/
5540
public static Textile fullDocument()
5641
{
5742
return new Textile(true);
5843
}
5944

6045
/**
61-
* Creates a {@link Textile} instance that just renders the textile without adding the HTML scaffold like a body or
62-
* head.
46+
* Create a {@link Transformer} instance that renders textile without adding HTML scaffold like a body or head.
6347
*/
6448
public static Textile partialDocument()
6549
{
6650
return new Textile(false);
6751
}
6852

53+
private Textile(boolean fullDocument)
54+
{
55+
this.fullDocument = fullDocument;
56+
}
57+
6958
@Override
7059
public List<String> getLoadPaths()
7160
{

‎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.create().transform(sass);
28+
String css = Sass.compiler().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.create().transform(sass);
38+
String css = Sass.compiler().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.create().transform(sass);
48+
String css = Sass.compiler().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.create().transform(sass);
58+
String css = Sass.compiler().transform(sass);
5959

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

‎transform-minify/src/main/java/org/ocpsoft/rewrite/transform/minify/CssMinify.java‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,32 @@
2121
import java.io.OutputStream;
2222
import java.io.OutputStreamWriter;
2323
import java.io.Reader;
24-
import java.nio.charset.Charset;
2524

2625
import org.ocpsoft.rewrite.transform.Transformer;
2726

2827
import com.yahoo.platform.yui.compressor.CssCompressor;
2928

3029
/**
3130
*
32-
* CSS compressor implementation based on yuicompressor
31+
* A {@link Transformer} implementation that compresses CSS using yuicompressor.
3332
*
3433
* @author Christian Kaltepoth
35-
*
3634
*/
37-
public class CssMinify implements Transformer
35+
public class CssMinify extends Minify implements Transformer
3836
{
39-
40-
private final Charset charset;
41-
42-
public CssMinify()
43-
{
44-
this(Charset.forName("UTF8"));
45-
}
46-
47-
public CssMinify(Charset charset)
48-
{
49-
this.charset = charset;
50-
}
37+
CssMinify()
38+
{}
5139

5240
@Override
5341
public void transform(InputStream input, OutputStream output) throws IOException
5442
{
5543

5644
// prepare input reader
57-
Reader reader = new InputStreamReader(input, charset);
45+
Reader reader = new InputStreamReader(input, getCharset());
5846
CssCompressor compressor = new CssCompressor(reader);
5947

6048
// write compressed output
61-
OutputStreamWriter writer = new OutputStreamWriter(output, charset);
49+
OutputStreamWriter writer = new OutputStreamWriter(output, getCharset());
6250
compressor.compress(writer, 0);
6351
writer.flush();
6452

0 commit comments

Comments
 (0)