Created
October 8, 2023 13:27
-
-
Save sunnyone/161f93b3b8b19adc6cb0f181b85bab54 to your computer and use it in GitHub Desktop.
replace-css.rb
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
#!/usr/bin/ruby | |
# Replace linaria css`` to panda css({}) | |
text = DATA.read | |
text.gsub!(%r|css`(.*?)`|m) do | |
css = $1 | |
list = css.split(/;/).map do |s| | |
pair = s.split(/:/) | |
pair[0].gsub!(%r|-([a-z])|) { $1.upcase } | |
pair[1].gsub!(%r|^(\s*)(.*?)(\s*)$|, '\1"\2"\3') if pair[1] | |
pair.join(":") | |
end | |
"css({" + list.join(",") + "})" | |
end | |
puts text | |
__END__ | |
const topMenuDivStyle = css` | |
position: relative; | |
`; | |
const topMenuUlStyle = css` | |
margin: 0; | |
padding: 0; | |
display: flex; | |
border-bottom: 1px solid ${borderColor}; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment