Skip to content

Commit

Permalink
it seems we could implement it much easier
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed May 10, 2017
1 parent 3836ac5 commit ec3eaef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Once the plugin has been installed, it may be you can make your "Stylus" run `xx

1. `1px` will be ignored for experience, you can override it with define your number named `px2rem_ignore_limit`.

2. If you want to preserve px value in some case(html element for example), use `font-size '16px!'`, and also you can override `preserve_px` to '_px'(then `font-size '16_px'`) or something else.
2. If you want to preserve px value in some case(html element for example), use quote like `font-size '16px'`.

## Input/Output

Expand Down
9 changes: 2 additions & 7 deletions lib/stylus-px2rem/mixins.styl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ html-font-size ?= 16px;
style-names ?= "min-height" "max-height" "min-width" "max-width" "width" "height" "border" "margin" "margin-top" "margin-bottom" "margin-left" "margin-right" "padding" "padding-left" "padding-right" "padding-bottom" "padding-top" "line-height"
// value less then ignore_limit will be ignored and return the original value
px2rem_ignore_limit ?= 1
// if you want to preserve px value in some case(html element for example), use `font-size '16px!'`, and also you can override `preserve_px` to '_px'(then `font-size '16_px'`) or something else
preserve_px ?= 'px!'

px2rem(prop,values){
values-px = null;
values-rem = null;
need_normalize = !prop in style-names
for value in values {
Expand All @@ -28,10 +25,8 @@ px2rem(prop,values){
value-rem = unit(value ,'rem');
}
push(values-rem,value-rem)
} else if(match(preserve_px+'$',''+value)) {
push(values-rem,unquote(replace(preserve_px,px,value)))
} else {
push(values-rem,value)
} else {
push(values-rem,match('px$',''+value) ? unquote(value) : value)
}
}
{prop} : values-rem;
Expand Down

0 comments on commit ec3eaef

Please sign in to comment.