mirror of
https://github.com/laosb/SwiftTailwind.git
synced 2025-11-28 22:01:38 +00:00
Improve glob handling for source paths and update docs
- Simplify glob handling in TailwindCSSBuildPlugin to support ** patterns - Update README and Tailwind.css example to clarify glob usage - Add Template.swift example using Tailwind classes - Extend tests to verify class extraction from globbed Swift files
This commit is contained in:
parent
7c848062ec
commit
e23147768d
5 changed files with 15 additions and 3 deletions
|
|
@ -65,8 +65,10 @@ struct TailwindCSSBuildPlugin: BuildToolPlugin {
|
||||||
.matches(of: sourceDeclarationRegex)
|
.matches(of: sourceDeclarationRegex)
|
||||||
.compactMap { String($0.output.1) }
|
.compactMap { String($0.output.1) }
|
||||||
let sourceURLs: [URL] = sourcePaths.map { path in
|
let sourceURLs: [URL] = sourcePaths.map { path in
|
||||||
target.directoryURL
|
// Simplified handling: If ** is used, we just include everything in the directory.
|
||||||
.appending(component: path, directoryHint: .inferFromPath)
|
let globlessPath = path.replacing(/\*\*.*/, with: "")
|
||||||
|
return target.directoryURL
|
||||||
|
.appending(component: globlessPath, directoryHint: .inferFromPath)
|
||||||
.resolvingSymlinksInPath()
|
.resolvingSymlinksInPath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ Place your Tailwind CSS entrypoint file at `Tailwind.css` in your target. To int
|
||||||
|
|
||||||
```css
|
```css
|
||||||
@import "tailwindcss" source(none);
|
@import "tailwindcss" source(none);
|
||||||
@source "./Views";
|
/* Note that as of writing, Tailwind doesn't scan .swift files by default, so you need to specify a glob pattern including the extension. */
|
||||||
|
@source "./Views/**/*.swift";
|
||||||
@source "./Template.swift";
|
@source "./Template.swift";
|
||||||
@source "./Static";
|
@source "./Static";
|
||||||
```
|
```
|
||||||
|
|
|
||||||
4
Sources/SwiftTailwindExample/Folder/Template.swift
Normal file
4
Sources/SwiftTailwindExample/Folder/Template.swift
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
let template =
|
||||||
|
"""
|
||||||
|
<div class="bg-red-100">Test</div>
|
||||||
|
"""
|
||||||
|
|
@ -5,3 +5,4 @@
|
||||||
@import "tailwindcss" source(none);
|
@import "tailwindcss" source(none);
|
||||||
@source "./Example.swift";
|
@source "./Example.swift";
|
||||||
@source "./Folder";
|
@source "./Folder";
|
||||||
|
@source "./Folder/**/*.swift";
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ struct SwiftTailwindExampleTests {
|
||||||
generatedCSS?.contains("text-\\[\\#f05138\\]") == true,
|
generatedCSS?.contains("text-\\[\\#f05138\\]") == true,
|
||||||
"Arbitary value class used in Test.html is generated."
|
"Arbitary value class used in Test.html is generated."
|
||||||
)
|
)
|
||||||
|
#expect(
|
||||||
|
generatedCSS?.contains("bg-red-100") == true,
|
||||||
|
"Arbitary value class used in Folder/Template.swift is generated."
|
||||||
|
)
|
||||||
#expect(
|
#expect(
|
||||||
generatedCSS?.contains("bg-blue-500") == false,
|
generatedCSS?.contains("bg-blue-500") == false,
|
||||||
"Class not used is not generated."
|
"Class not used is not generated."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue