mirror of
https://github.com/vanng822/go-premailer.git
synced 2025-02-11 12:30:48 +00:00
Upgrade css to v1.0.0
This commit is contained in:
parent
0a2f8ee587
commit
5392cc8aa5
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/gorilla/css v1.0.0 // indirect
|
||||
github.com/stretchr/testify v1.6.1
|
||||
github.com/unrolled/render v1.0.3
|
||||
github.com/vanng822/css v0.1.0
|
||||
github.com/vanng822/css v1.0.0
|
||||
github.com/vanng822/r2router v0.0.0-20150523112421-1023140a4f30
|
||||
golang.org/x/net v0.0.0-20200904194848-62affa334b73
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -17,6 +17,8 @@ github.com/unrolled/render v1.0.3 h1:baO+NG1bZSF2WR4zwh+0bMWauWky7DVrTOfvE2w+aFo
|
||||
github.com/unrolled/render v1.0.3/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM=
|
||||
github.com/vanng822/css v0.1.0 h1:lFOaxbqoxqgBv9gTOJavvKRS+5oy4YJ/ZBmW1EeYr3M=
|
||||
github.com/vanng822/css v0.1.0/go.mod h1:tcnB1voG49QhCrwq1W0w5hhGasvOg+VQp9i9H1rCM1w=
|
||||
github.com/vanng822/css v1.0.0 h1:Us/aMlvmSMZMbN0jeR3SotsAmPxopmqw+yGRMy3TB+c=
|
||||
github.com/vanng822/css v1.0.0/go.mod h1:tcnB1voG49QhCrwq1W0w5hhGasvOg+VQp9i9H1rCM1w=
|
||||
github.com/vanng822/r2router v0.0.0-20150523112421-1023140a4f30 h1:fCYIzI798sOjtO9fMZaqF0ldAoYEsMLt2EwX7HdXzu4=
|
||||
github.com/vanng822/r2router v0.0.0-20150523112421-1023140a4f30/go.mod h1:1BVq8p2jVr55Ost2PkZWDrG86PiJ/0lxqcXoAcGxvWU=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -11,9 +11,9 @@ import (
|
||||
type void struct{}
|
||||
|
||||
type elementRules struct {
|
||||
element *goquery.Selection
|
||||
rules []*styleRule
|
||||
cssToAttributes bool
|
||||
element *goquery.Selection
|
||||
rules []*styleRule
|
||||
cssToAttributes bool
|
||||
keepBangImportant bool
|
||||
}
|
||||
|
||||
@ -30,8 +30,8 @@ func (er *elementRules) inline() {
|
||||
for _, rule := range er.rules {
|
||||
for _, s := range rule.styles {
|
||||
prop := s.Property
|
||||
styles[prop] = s.Value
|
||||
if er.keepBangImportant && s.Important == 1 {
|
||||
styles[prop] = s.Value.Text()
|
||||
if er.keepBangImportant && s.Important {
|
||||
styles[prop] += " !important"
|
||||
}
|
||||
orders = append(orders, prop)
|
||||
@ -41,7 +41,7 @@ func (er *elementRules) inline() {
|
||||
if len(inlineStyles) > 0 {
|
||||
for _, s := range inlineStyles {
|
||||
prop := s.Property
|
||||
styles[prop] = s.Value
|
||||
styles[prop] = s.Value.Text()
|
||||
orders = append(orders, prop)
|
||||
}
|
||||
}
|
||||
|
@ -71,14 +71,14 @@ func (pr *premailer) sortRules() {
|
||||
importantStyles := make([]*css.CSSStyleDeclaration, 0)
|
||||
|
||||
for _, s := range rule.Style.Styles {
|
||||
if s.Important == 1 {
|
||||
if s.Important {
|
||||
importantStyles = append(importantStyles, s)
|
||||
} else {
|
||||
normalStyles = append(normalStyles, s)
|
||||
}
|
||||
}
|
||||
|
||||
selectors := strings.Split(rule.Style.SelectorText, ",")
|
||||
selectors := strings.Split(rule.Style.Selector.Text(), ",")
|
||||
for _, selector := range selectors {
|
||||
if unmergableSelector.MatchString(selector) || notSupportedSelector.MatchString(selector) {
|
||||
// cause longer css
|
||||
@ -134,9 +134,9 @@ func (pr *premailer) collectElements() {
|
||||
rules := make([]*styleRule, 0)
|
||||
rules = append(rules, rule)
|
||||
pr.elements[id] = &elementRules{
|
||||
element: s,
|
||||
rules: rules,
|
||||
cssToAttributes: pr.options.CssToAttributes,
|
||||
element: s,
|
||||
rules: rules,
|
||||
cssToAttributes: pr.options.CssToAttributes,
|
||||
keepBangImportant: pr.options.KeepBangImportant,
|
||||
}
|
||||
pr.elementId += 1
|
||||
@ -174,7 +174,7 @@ func (pr *premailer) addLeftover() {
|
||||
}
|
||||
cssData = append(cssData, fmt.Sprintf("%s %s{\n%s\n}\n",
|
||||
rule.Type.Text(),
|
||||
rule.Style.SelectorText,
|
||||
rule.Style.Selector.Text(),
|
||||
strings.Join(mcssData, "\n")))
|
||||
} else {
|
||||
cssData = append(cssData, makeRuleImportant(rule))
|
||||
|
@ -8,9 +8,9 @@ func copyRule(selector string, rule *css.CSSRule) *css.CSSRule {
|
||||
// copy rule for each selector
|
||||
styles := make([]*css.CSSStyleDeclaration, 0)
|
||||
for _, s := range rule.Style.Styles {
|
||||
styles = append(styles, css.NewCSSStyleDeclaration(s.Property, s.Value, s.Important))
|
||||
styles = append(styles, css.NewCSSStyleDeclaration(s.Property, s.Value.Text(), s.Important))
|
||||
}
|
||||
copiedStyle := css.CSSStyleRule{SelectorText: selector, Styles: styles}
|
||||
copiedStyle := css.CSSStyleRule{Selector: css.NewCSSValueString(selector), Styles: styles}
|
||||
copiedRule := &css.CSSRule{Type: rule.Type, Style: copiedStyle}
|
||||
return copiedRule
|
||||
}
|
||||
@ -18,7 +18,7 @@ func copyRule(selector string, rule *css.CSSRule) *css.CSSRule {
|
||||
func makeRuleImportant(rule *css.CSSRule) string {
|
||||
// this for using Text() which has nice sorted props
|
||||
for _, s := range rule.Style.Styles {
|
||||
s.Important = 1
|
||||
s.Important = true
|
||||
}
|
||||
return rule.Style.Text()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user