Skip to content

Instantly share code, notes, and snippets.

@sunnyone
Created October 8, 2023 13:27
Show Gist options
  • Save sunnyone/161f93b3b8b19adc6cb0f181b85bab54 to your computer and use it in GitHub Desktop.
Save sunnyone/161f93b3b8b19adc6cb0f181b85bab54 to your computer and use it in GitHub Desktop.
replace-css.rb
#!/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