Skip to content

Commit

Permalink
fixed margin outlook bug and optmizied output
Browse files Browse the repository at this point in the history
  • Loading branch information
avigoldman committed Oct 26, 2017
1 parent adc66c3 commit 7cdcd9b
Show file tree
Hide file tree
Showing 4 changed files with 279 additions and 3 deletions.
260 changes: 260 additions & 0 deletions packages/heml-styles/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/heml-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"postcss-discard-overridden": "^0.1.1",
"postcss-email-important": "^1.0.0",
"postcss-hex-format": "^1.0.0",
"postcss-merge-longhand": "^3.0.0",
"postcss-merge-rules": "^2.1.2",
"postcss-minify-font-values": "^1.0.5",
"postcss-minify-gradients": "^1.0.5",
Expand Down
11 changes: 8 additions & 3 deletions packages/heml-styles/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import rgbaFallback from 'postcss-color-rgba-fallback'
import formatHexColors from 'postcss-hex-format'

/** email fixes */
import shorthandExpand from './plugins/postcss-expand-shorthand'
import emailImportant from 'postcss-email-important'
import zeroOutMargin from './plugins/postcss-zero-out-margin'

/** custom plugins */
import shorthandExpand from './plugins/postcss-expand-shorthand'
/** custom element expander */
import elementExpander from './plugins/postcss-element-expander'

import mergeLonghand from 'postcss-merge-longhand'

async function hemlstyles (contents, options = {}) {
const {
elements = {},
Expand Down Expand Up @@ -76,10 +79,12 @@ async function hemlstyles (contents, options = {}) {

/** email fixes */
emailImportant(),
shorthandExpand(), // so we can match for margin-top/margin-left etc.
zeroOutMargin(),

/** expanding to match heml elements */
shorthandExpand(), // so we can match for margin-left/margin-right etc.
elementExpander({ elements, aliases }),
mergeLonghand(),
discardEmpty()
])
.process(contents, { parser: safeParser })
Expand Down
10 changes: 10 additions & 0 deletions packages/heml-styles/src/plugins/postcss-zero-out-margin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import postcss from 'postcss'

/**
* convert margin-top/margin-bottom to 0 when they are margin auto
*/
export default postcss.plugin('postcss-zero-out-margin', () => (root) => {
root.walkDecls(/margin-top|margin-bottom/i, (decl) => {
decl.value = decl.value.toLowerCase() === 'auto' ? '0' : decl.value
})
})

0 comments on commit 7cdcd9b

Please sign in to comment.