Skip to content
This repository was archived by the owner on Mar 15, 2021. It is now read-only.

Commit 4ab8c7b

Browse files
committed
#3 Support for Source Maps
- use shorter class names - map Source Map options in LessOptions - extract LineNumbersValue to standalone class - remove nonsense methods from LessCompiler (source map methods always require additional configuration) - extend JavaDocs (always print default value) - upgrade mockito-core to 2.7.18
1 parent 67d4d54 commit 4ab8c7b

15 files changed

+1022
-715
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<dependency>
9696
<groupId>org.mockito</groupId>
9797
<artifactId>mockito-core</artifactId>
98-
<version>2.7.12</version>
98+
<version>2.7.18</version>
9999
<scope>test</scope>
100100
</dependency>
101101
</dependencies>

src/main/java/biz/gabrys/lesscss/compiler2/LessCompiler.java

Lines changed: 43 additions & 139 deletions
Large diffs are not rendered by default.

src/main/java/biz/gabrys/lesscss/compiler2/LessCompilerOptions.java renamed to src/main/java/biz/gabrys/lesscss/compiler2/LessOptions.java

Lines changed: 170 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
* Represents <a href="http://lesscss.org/usage/index.html#command-line-usage-options">Less compiler options</a>
2121
* responsible for controlling the {@link LessCompiler} compilation process.
2222
* @since 2.0.0
23-
* @see LessCompilerOptionsBuilder
23+
* @see LessOptionsBuilder
2424
*/
25-
public class LessCompilerOptions {
25+
public class LessOptions {
2626

2727
private boolean silent;
2828
private boolean strictImports;
@@ -36,11 +36,16 @@ public class LessCompilerOptions {
3636
private boolean strictMath;
3737
private boolean strictUnits;
3838

39+
private String sourceMapRootPath;
40+
private String sourceMapBasePath;
41+
private boolean sourceMapLessInline;
42+
private String sourceMapUrl;
43+
3944
/**
4045
* Constructs a new instance.
4146
* @since 2.0.0
4247
*/
43-
public LessCompilerOptions() {
48+
public LessOptions() {
4449
ieCompatibility = true;
4550
javaScript = true;
4651
includePaths = Collections.emptyList();
@@ -50,10 +55,10 @@ public LessCompilerOptions() {
5055
/**
5156
* Constructs a new instance as a copy of an another options object.
5257
* @param options the another options object (cannot be {@code null}).
53-
* @throws IllegalArgumentException if options is equal to {@code null}.
58+
* @throws IllegalArgumentException if options is {@code null}.
5459
* @since 2.0.0
5560
*/
56-
public LessCompilerOptions(final LessCompilerOptions options) {
61+
public LessOptions(final LessOptions options) {
5762
if (options == null) {
5863
throw new IllegalArgumentException("Options cannot be null");
5964
}
@@ -68,6 +73,11 @@ public LessCompilerOptions(final LessCompilerOptions options) {
6873
relativeUrls = options.relativeUrls;
6974
strictMath = options.strictMath;
7075
strictUnits = options.strictUnits;
76+
77+
sourceMapRootPath = options.sourceMapRootPath;
78+
sourceMapBasePath = options.sourceMapBasePath;
79+
sourceMapLessInline = options.sourceMapLessInline;
80+
sourceMapUrl = options.sourceMapUrl;
7181
}
7282

7383
/**
@@ -134,7 +144,7 @@ public void setCompress(final boolean compress) {
134144
* @return {@code true} whether the CSS code should be compatible with IE browser, otherwise {@code false}.
135145
* @since 2.0.0
136146
*/
137-
public boolean isIeCompatability() {
147+
public boolean isIeCompatibility() {
138148
return ieCompatibility;
139149
}
140150

@@ -169,9 +179,10 @@ public void setJavaScript(final boolean javaScript) {
169179
}
170180

171181
/**
172-
* Returns available include paths (default: empty collection). If the file in an &#64;import rule does not exist at
173-
* that exact location, a compiler will look for it at the location(s) passed to this option. You might use this for
174-
* instance to specify a path to a library which you want to be referenced simply and relatively in the less files.
182+
* Returns available include paths (default: {@code empty collection}). If the file in an &#64;import rule does not
183+
* exist at that exact location, a compiler will look for it at the location(s) passed to this option. You might use
184+
* this for instance to specify a path to a library which you want to be referenced simply and relatively in the
185+
* less files.
175186
* @return the available include paths (never {@code null}).
176187
* @since 2.0.0
177188
*/
@@ -180,10 +191,11 @@ public List<String> getIncludePaths() {
180191
}
181192

182193
/**
183-
* Sets available include paths (default: empty collection). If the file in an &#64;import rule does not exist at
184-
* that exact location, a compiler will look for it at the location(s) passed to this option. You might use this for
185-
* instance to specify a path to a library which you want to be referenced simply and relatively in the less files.
186-
* @param includePaths the available include paths ({@code null} is treated as empty collection).
194+
* Sets available include paths (default: {@code empty collection}). If the file in an &#64;import rule does not
195+
* exist at that exact location, a compiler will look for it at the location(s) passed to this option. You might use
196+
* this for instance to specify a path to a library which you want to be referenced simply and relatively in the
197+
* less files.
198+
* @param includePaths the available include paths ({@code null} is treated as an empty collection).
187199
* @since 2.0.0
188200
*/
189201
public void setIncludePaths(final List<String> includePaths) {
@@ -372,6 +384,7 @@ public void setRelativeUrls(final boolean relativeUrls) {
372384
* @return {@code true} whether the compiler should try and process all maths in the Less code, otherwise
373385
* {@code false}.
374386
* @since 2.0.0
387+
* @see #isStrictUnits()
375388
*/
376389
public boolean isStrictMath() {
377390
return strictMath;
@@ -415,6 +428,7 @@ public boolean isStrictMath() {
415428
* @param strictMath {@code true} whether the compiler should try and process all maths in the Less code, otherwise
416429
* {@code false}.
417430
* @since 2.0.0
431+
* @see #setStrictUnits(boolean)
418432
*/
419433
public void setStrictMath(final boolean strictMath) {
420434
this.strictMath = strictMath;
@@ -438,6 +452,7 @@ public void setStrictMath(final boolean strictMath) {
438452
* @return {@code true} whether the compiler should guess units in the Less code when it does maths, otherwise
439453
* {@code false}.
440454
* @since 2.0.0
455+
* @see #isStrictMath()
441456
*/
442457
public boolean isStrictUnits() {
443458
return strictUnits;
@@ -461,52 +476,159 @@ public boolean isStrictUnits() {
461476
* @param strictUnits {@code true} whether the compiler should guess units in the Less code when it does maths,
462477
* otherwise {@code false}.
463478
* @since 2.0.0
479+
* @see #setStrictMath(boolean)
464480
*/
465481
public void setStrictUnits(final boolean strictUnits) {
466482
this.strictUnits = strictUnits;
467483
}
468484

469485
/**
470-
* Available values of the {@code line numbers} option.
486+
* Returns a path that will be prepended to each of the Less file paths inside the Source Map and also to the path
487+
* to the map file specified in your output CSS.
488+
* <p>
489+
* Use it if for instance you have a CSS file generated in the root on your web server but have your source
490+
* less/css/map files in a different folder.
491+
* </p>
492+
* <p>
493+
* Example: if you have a follow file structure:
494+
* </p>
495+
*
496+
* <pre>
497+
* output.css
498+
* dev-files/output.css.map
499+
* dev-files/output.less
500+
* </pre>
501+
* <p>
502+
* then you should set the Source Map root path to {@code dev-files/}.
503+
* </p>
504+
* <p>
505+
* This option is the opposite of the {@link #getSourceMapBasePath() Source Map base path} option.
506+
* </p>
507+
* @return the path which will be added.
471508
* @since 2.0.0
472-
* @see LessCompilerOptions#setLineNumbers(LineNumbersValue)
509+
* @see #getSourceMapBasePath()
510+
* @see #getSourceMapUrl()
473511
*/
474-
public enum LineNumbersValue {
512+
public String getSourceMapRootPath() {
513+
return sourceMapRootPath;
514+
}
475515

476-
/**
477-
* Line numbers won't be put in CSS code.
478-
* @since 2.0.0
479-
*/
480-
OFF(""),
481-
/**
482-
* Line numbers will be put in CSS comments blocks.
483-
* @since 2.0.0
484-
*/
485-
COMMENTS("comments"),
486-
/**
487-
* Line numbers will be put in &#64;media queries.
488-
* @since 2.0.0
489-
*/
490-
MEDIA_QUERY("mediaquery"),
491-
/**
492-
* Line numbers will be put in CSS comments blocks and &#64;media queries.
493-
* @since 2.0.0
494-
*/
495-
ALL("all");
516+
/**
517+
* Sets a path that will be prepended to each of the Less file paths inside the Source Map and also to the path to
518+
* the map file specified in your output CSS (default: {@code null}).
519+
* <p>
520+
* Use it if for instance you have a CSS file generated in the root on your web server but have your source
521+
* less/css/map files in a different folder.
522+
* </p>
523+
* <p>
524+
* Example: if you have a follow file structure:
525+
* </p>
526+
*
527+
* <pre>
528+
* output.css
529+
* dev-files/output.css.map
530+
* dev-files/output.less
531+
* </pre>
532+
* <p>
533+
* then you should set the Source Map root path to {@code dev-files/}.
534+
* </p>
535+
* <p>
536+
* This option is the opposite of the {@link #setSourceMapBasePath(String) Source Map base path} option.
537+
* </p>
538+
* @param sourceMapRootPath the path which will be added.
539+
* @since 2.0.0
540+
* @see #setSourceMapBasePath(String)
541+
* @see #setSourceMapUrl(String)
542+
*/
543+
public void setSourceMapRootPath(final String sourceMapRootPath) {
544+
this.sourceMapRootPath = sourceMapRootPath;
545+
}
496546

497-
private final String value;
547+
/**
548+
* Returns a path that will be removed from each of the Less file paths inside the Source Map and also from the path
549+
* to the map file specified in your output CSS (default: {@code null}).
550+
* <p>
551+
* It specifies a path which should be removed from the output paths. For instance if you are compiling a file in
552+
* the less-files directory but the source files will be available on your web server in the root or current
553+
* directory, you can specify this to remove the additional less-files part of the path.
554+
* </p>
555+
* <p>
556+
* This option is the opposite of the {@link #getSourceMapRootPath() Source Map root path} option.
557+
* </p>
558+
* @return the path which will be removed.
559+
* @since 2.0.0
560+
* @see #getSourceMapRootPath()
561+
* @see #getSourceMapUrl()
562+
*/
563+
public String getSourceMapBasePath() {
564+
return sourceMapBasePath;
565+
}
498566

499-
LineNumbersValue(final String value) {
500-
this.value = value;
501-
}
567+
/**
568+
* Sets a path that will be removed from each of the Less file paths inside the Source Map and also from the path to
569+
* the map file specified in your output CSS (default: {@code null}).
570+
* <p>
571+
* It specifies a path which should be removed from the output paths. For instance if you are compiling a file in
572+
* the less-files directory but the source files will be available on your web server in the root or current
573+
* directory, you can specify this to remove the additional less-files part of the path.
574+
* </p>
575+
* <p>
576+
* This option is the opposite of the {@link #setSourceMapRootPath(String) Source Map root path} option.
577+
* </p>
578+
* @param sourceMapBasePath the path which will be removed.
579+
* @since 2.0.0
580+
* @see #setSourceMapRootPath(String)
581+
* @see #setSourceMapUrl(String)
582+
*/
583+
public void setSourceMapBasePath(final String sourceMapBasePath) {
584+
this.sourceMapBasePath = sourceMapBasePath;
585+
}
502586

503-
/**
504-
* Returns a value assigned to {@code this} object.
505-
* @return the value assigned to {@code this} object.
506-
* @since 2.0.0
507-
*/
508-
public String getValue() {
509-
return value;
510-
}
587+
/**
588+
* Checks whether a compiler should include all of the Less files in to the Source Map (default: {@code false}).
589+
* This means that you only need your map file to get to your original source.
590+
* @return {@code true} whether the compiler should include all of the Less files in to the Source Map, otherwise
591+
* {@code false}.
592+
* @since 2.0.0
593+
*/
594+
public boolean isSourceMapLessInline() {
595+
return sourceMapLessInline;
596+
}
597+
598+
/**
599+
* Sets whether a compiler should include all of the Less files in to the Source Map (default: {@code false}). This
600+
* means that you only need your map file to get to your original source.
601+
* @param sourceMapLessInline {@code true} whether the compiler should include all of the Less files in to the
602+
* Source Map, otherwise {@code false}.
603+
* @since 2.0.0
604+
*/
605+
public void setSourceMapLessInline(final boolean sourceMapLessInline) {
606+
this.sourceMapLessInline = sourceMapLessInline;
607+
}
608+
609+
/**
610+
* Returns a path which will overwrite the URL in the CSS that points at the Source Map map file (default:
611+
* {@code null}). This is for cases when the {@link #getSourceMapRootPath() root path} and the
612+
* {@link #getSourceMapBasePath() base path} options are not producing exactly what you need.
613+
* @return the Source Map URL.
614+
* @since 2.0.0
615+
* @see #getSourceMapBasePath()
616+
* @see #getSourceMapRootPath()
617+
*/
618+
public String getSourceMapUrl() {
619+
return sourceMapUrl;
620+
}
621+
622+
/**
623+
* Sets a path which will overwrite the URL in the CSS that points at the Source Map map file (default:
624+
* {@code null}). This is for cases when the {@link #setSourceMapRootPath(String) root path} and the
625+
* {@link #setSourceMapBasePath(String) base path} options are not producing exactly what you need.
626+
* @param sourceMapUrl the Source Map URL.
627+
* @since 2.0.0
628+
* @see #setSourceMapBasePath(String)
629+
* @see #setSourceMapRootPath(String)
630+
*/
631+
public void setSourceMapUrl(final String sourceMapUrl) {
632+
this.sourceMapUrl = sourceMapUrl;
511633
}
512634
}

0 commit comments

Comments
 (0)