-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for multi-line macro inputs. Makes MacroUtils more modul…
- Loading branch information
1 parent
464442c
commit aeb98f2
Showing
10 changed files
with
279 additions
and
111 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
buildSrc/src/main/java/io/micronaut/guides/core/GuidesConfiguration.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package io.micronaut.guides.core; | ||
|
||
import java.util.List; | ||
|
||
public interface GuidesConfiguration { | ||
String getHomePageUrl(); | ||
String getTitle(); | ||
String getLicensePath(); | ||
String getPackageName(); | ||
List<String> getFilesWithHeader(); | ||
} |
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
48 changes: 48 additions & 0 deletions
48
buildSrc/src/main/java/io/micronaut/guides/core/RawTestMacroSubstitution.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,48 @@ | ||
package io.micronaut.guides.core; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import jakarta.inject.Singleton; | ||
import java.util.List; | ||
|
||
import static io.micronaut.guides.core.MacroUtils.*; | ||
import static io.micronaut.guides.core.MacroUtils.addIncludes; | ||
|
||
@Singleton | ||
public class RawTestMacroSubstitution implements MacroSubstitution{ | ||
|
||
private final GuidesConfiguration guidesConfiguration; | ||
private final LicenseLoader licenseLoader; | ||
|
||
public RawTestMacroSubstitution(GuidesConfiguration guidesConfiguration, LicenseLoader licenseLoader) { | ||
this.guidesConfiguration = guidesConfiguration; | ||
this.licenseLoader = licenseLoader; | ||
} | ||
|
||
@Override | ||
public String substitute(String str, String slug, GuidesOption option) { | ||
for(String line : findMacroLines(str, "rawTest")) { | ||
|
||
String name = extractName(line, "rawTest"); | ||
String appName = extractAppName(line); | ||
List<String> tags = extractTags(line); | ||
String indent = extractIndent(line); | ||
String sourcePath = rawTestPath(guidesConfiguration, appName, name, option); | ||
|
||
List<String> lines = addIncludes(option, licenseLoader, guidesConfiguration, slug, sourcePath, option.getTestFramework().toTestFramework().getDefaultLanguage().getExtension(), indent, tags); | ||
|
||
str = str.replace(line,String.join("\n", lines)); | ||
} | ||
return str; | ||
} | ||
|
||
@NonNull | ||
private static String rawTestPath(@NonNull GuidesConfiguration guidesConfiguration, | ||
@NonNull String appName, | ||
@NonNull String name, | ||
@NonNull GuidesOption option) { | ||
String module = appName.isEmpty() ? "" : appName + "/"; | ||
String fileExtension = option.getTestFramework().toTestFramework().getDefaultLanguage().getExtension(); | ||
String langTestFolder = option.getTestFramework().toTestFramework().getDefaultLanguage().getTestSrcDir(); | ||
return module + langTestFolder + "/" + guidesConfiguration.getPackageName().replace(".", "/") + "/" + name + "." + fileExtension; | ||
} | ||
} |
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
Oops, something went wrong.