-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate twirl-specific data from play #SCL-22065
Twirl sbt plugin can be used independently of Play plugin
- Loading branch information
Showing
7 changed files
with
91 additions
and
32 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
31 changes: 31 additions & 0 deletions
31
extractor/src/main/scala/org/jetbrains/sbt/extractors/TwirlTemplatesDataExtractor.scala
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,31 @@ | ||
package org.jetbrains.sbt.extractors | ||
|
||
import org.jetbrains.sbt.structure._ | ||
import org.jetbrains.sbt.{SbtStateOps, TaskOps} | ||
import sbt._ | ||
|
||
object TwirlTemplatesDataExtractor extends SbtStateOps with TaskOps { | ||
|
||
def taskDef: Def.Initialize[Task[Option[TwirlData]]] = Def.task { | ||
val state = sbt.Keys.state.value | ||
val projectRef = sbt.Keys.thisProjectRef.value | ||
|
||
for { | ||
templateImports <- Keys.templateImports.in(projectRef).find(state) | ||
} yield { | ||
val templateImportsFixed = fixTemplateImports(templateImports) | ||
TwirlData(templateImportsFixed) | ||
} | ||
} | ||
|
||
private def fixTemplateImports(imports: Seq[String]): Seq[String] = imports.map { | ||
case "views.%format%._" => "views.xml._" | ||
case value => value | ||
} | ||
|
||
private object Keys { | ||
// should match play.twirl.sbt.Import.TwirlKeys#templateImports | ||
// (see https://github.com/playframework/twirl/blob/main/sbt-twirl/src/main/scala/play/twirl/sbt/SbtTwirl.scala) | ||
val templateImports: SettingKey[Seq[String]] = SettingKey[Seq[String]]("twirl-template-imports") | ||
} | ||
} |
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