postcss-elm-tailwind
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -5,2 +5,3 @@ function elmHeader(elmModuleName, elm_fns) { | ||
tmp.push("classList"); | ||
tmp.sort(); | ||
const l = tmp.join("\n , "); | ||
@@ -16,6 +17,5 @@ | ||
classList : List (Html.Attribute msg, Bool) -> List (Html.Attribute msg) | ||
classList : List ( Html.Attribute msg, Bool ) -> List (Html.Attribute msg) | ||
classList classes = | ||
List.map Tuple.first <| List.filter Tuple.second classes | ||
`; | ||
@@ -34,6 +34,6 @@ } | ||
return ` | ||
${elm} : Html.Attribute msg | ||
${elm} = | ||
A.class "${cls}" | ||
`; | ||
@@ -54,3 +54,3 @@ } | ||
cls = cls.replace( | ||
/:(responsive|group-hover|focus-within|first|last|odd|even|hover|focus|active|visited|disabled)$/, | ||
/:(focus-within|first-child|last-child|odd|even|hover|focus|active|visited|disabled)$/, | ||
"" | ||
@@ -62,6 +62,2 @@ ); | ||
cls = cls.replace(/:nth-child\((even|odd)\)/, ""); | ||
var tmp = cls.toString(); | ||
if (tmp.includes("child")) { | ||
console.log(cls); | ||
} | ||
// | ||
@@ -91,7 +87,7 @@ cls = cls.replace(/\\\//g, "/"); | ||
// handle negative with variant | ||
elm = elm.replace(/:-([a-z])/, "_neg_$1"); | ||
elm = elm.replace(/:-([a-z])/, "__neg_$1"); | ||
// replace dashes now we have sorted the negative stuff | ||
elm = elm.replace(/-/g, "_"); | ||
// replace : | ||
elm = elm.replace(/:/g, "_"); | ||
elm = elm.replace(/:/g, "__"); | ||
// handle fractions | ||
@@ -107,3 +103,3 @@ elm = elm.replace(/\//g, "over"); | ||
if (opts.nameStyle === "camel") { | ||
elm = elm.replace(/(_\w)/g, g => g[1].toUpperCase()); | ||
elm = elm.replace(/(_+\w)/g, g => g.replace(/_/g, "").toUpperCase()); | ||
} | ||
@@ -110,0 +106,0 @@ return elm; |
34
index.js
@@ -15,18 +15,9 @@ const fs = require("fs"); | ||
root.walkRules(rule => { | ||
if (!rule.selector.startsWith(".")) { | ||
// keep only classes | ||
return; | ||
} | ||
let cls = rule.selector; | ||
cls = h.fixClass(cls); | ||
let elm = h.toElmName(cls, opts); | ||
classes.set(cls, h.elmFunction(cls, elm)); | ||
elm_fns.push(elm); | ||
rule.selector | ||
.split(" ") | ||
.forEach(selector => processSelector(selector, opts)); | ||
}); | ||
const elmModule = | ||
h.elmHeader(opts.elmModuleName, elm_fns) + h.elmBody(classes); | ||
const elmModule = h.elmHeader(opts.elmModuleName, elm_fns) + | ||
h.elmBody(classes); | ||
@@ -43,1 +34,16 @@ // writing to disk | ||
}); | ||
function processSelector(selector, opts) { | ||
if (!selector.startsWith(".")) { | ||
// Keep only classes | ||
return; | ||
} | ||
let cls, elm; | ||
cls = h.fixClass(selector); | ||
elm = h.toElmName(cls, opts); | ||
classes.set(cls, h.elmFunction(cls, elm)); | ||
elm_fns.push(elm); | ||
} |
{ | ||
"name": "postcss-elm-tailwind", | ||
"main": "./index.js", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "PostCSS plugin Tailwind classes for Elm", | ||
@@ -22,2 +22,3 @@ "keywords": [ | ||
"elm": "^0.19.1-2", | ||
"elm-format": "0.8.3", | ||
"mocha": "^6.2.2", | ||
@@ -24,0 +25,0 @@ "postcss-cli": "^6.1.3", |
@@ -85,3 +85,3 @@ const h = require("../helpers"); | ||
it("responsive", () => { | ||
assert.equal(h.toElmName(h.fixClass("sm:mx-auto")), "sm_mx_auto"); | ||
assert.equal(h.toElmName(h.fixClass("sm:mx-auto")), "sm__mx_auto"); | ||
}); | ||
@@ -91,3 +91,3 @@ it("responsive and focus", () => { | ||
h.toElmName(h.fixClass(".xl:focus:no-underline:focus")), | ||
"xl_focus_no_underline" | ||
"xl__focus__no_underline" | ||
); | ||
@@ -102,3 +102,3 @@ }); | ||
it("negative with variant .sm:-m-24", () => { | ||
assert.equal(h.toElmName(h.fixClass(".sm:-m-24")), "sm_neg_m_24"); | ||
assert.equal(h.toElmName(h.fixClass(".sm:-m-24")), "sm__neg_m_24"); | ||
}); | ||
@@ -108,3 +108,3 @@ it("negative with variant .sm:-translate-x-1", () => { | ||
h.toElmName(h.fixClass(".sm:-translate-x-1")), | ||
"sm_neg_translate_x_1" | ||
"sm__neg_translate_x_1" | ||
); | ||
@@ -115,3 +115,3 @@ }); | ||
h.toElmName(h.fixClass(".hover:tw-bg-blue-500:hover"), "tw-"), | ||
"hover_tw_bg_blue_500" | ||
"hover__tw_bg_blue_500" | ||
); | ||
@@ -125,3 +125,3 @@ }); | ||
}), | ||
"xl_tw_neg_my_64" | ||
"xl__tw_neg_my_64" | ||
); | ||
@@ -144,3 +144,3 @@ }); | ||
}), | ||
"xl_tw_my_64" | ||
"xl__tw_my_64" | ||
); | ||
@@ -158,13 +158,13 @@ }); | ||
h.toElmName(h.fixClass(".xl\:odd\:tw-bg-pink-700:nth-child(odd)")), | ||
"xl_odd_tw_bg_pink_700" | ||
"xl__odd__tw_bg_pink_700" | ||
); | ||
assert.equal( | ||
h.toElmName(h.fixClass(".lg\:even\:tw-bg-pink-700:nth-child(even)")), | ||
"lg_even_tw_bg_pink_700" | ||
"lg__even__tw_bg_pink_700" | ||
); | ||
assert.equal( | ||
h.toElmName(h.fixClass(".last\:tw-bg-transparent:last-child")), | ||
"last_tw_bg_transparent" | ||
"last__tw_bg_transparent" | ||
); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14201
9
309
5