vendor dependencies with dep
This commit is contained in:
parent
93d8310491
commit
1384296a47
2712 changed files with 965742 additions and 0 deletions
3
vendor/github.com/vanng822/css/.gitignore
generated
vendored
Normal file
3
vendor/github.com/vanng822/css/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/src/
|
||||
/pkg/
|
||||
/bin/
|
||||
16
vendor/github.com/vanng822/css/.travis.yml
generated
vendored
Normal file
16
vendor/github.com/vanng822/css/.travis.yml
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
language: golang
|
||||
|
||||
go:
|
||||
- 1.4
|
||||
|
||||
env:
|
||||
global:
|
||||
- GOPATH="$HOME/gopath"
|
||||
- PATH="$HOME/gopath/bin:$HOME/bin:$PATH"
|
||||
|
||||
install:
|
||||
- go get github.com/gorilla/css/scanner
|
||||
- go get github.com/stretchr/testify/assert
|
||||
|
||||
script:
|
||||
- go test -v
|
||||
23
vendor/github.com/vanng822/css/LICENSE
generated
vendored
Normal file
23
vendor/github.com/vanng822/css/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 2015 Nguyen Van Nhu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
23
vendor/github.com/vanng822/css/README.md
generated
vendored
Normal file
23
vendor/github.com/vanng822/css/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# css
|
||||
|
||||
Package css is for parsing css stylesheet.
|
||||
|
||||
# Document
|
||||
|
||||
[](https://godoc.org/github.com/vanng822/css)
|
||||
|
||||
# example
|
||||
|
||||
import (
|
||||
"github.com/vanng822/css"
|
||||
"fmt"
|
||||
)
|
||||
func main() {
|
||||
csstext = "td {width: 100px; height: 100px;}"
|
||||
ss := css.Parse(csstext)
|
||||
rules := ss.GetCSSRuleList()
|
||||
for _, rule := range rules {
|
||||
fmt.Println(rule.Style.SelectorText)
|
||||
fmt.Println(rule.Style.Styles)
|
||||
}
|
||||
}
|
||||
140
vendor/github.com/vanng822/css/block_parser.go
generated
vendored
Normal file
140
vendor/github.com/vanng822/css/block_parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/gorilla/css/scanner"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type blockParserContext struct {
|
||||
State State
|
||||
NowProperty string
|
||||
NowValue string
|
||||
NowImportant int
|
||||
}
|
||||
|
||||
// ParseBlock take a string of a css block,
|
||||
// parses it and returns a map of css style declarations.
|
||||
func ParseBlock(csstext string) map[string]*CSSStyleDeclaration {
|
||||
s := scanner.New(csstext)
|
||||
return parseBlock(s)
|
||||
}
|
||||
|
||||
func parseBlock(s *scanner.Scanner) map[string]*CSSStyleDeclaration {
|
||||
/* block : '{' S* [ any | block | ATKEYWORD S* | ';' S* ]* '}' S*;
|
||||
property : IDENT;
|
||||
value : [ any | block | ATKEYWORD S* ]+;
|
||||
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
|
||||
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
|
||||
| DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
|
||||
| '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
|
||||
] S*;
|
||||
*/
|
||||
decls := make(map[string]*CSSStyleDeclaration)
|
||||
|
||||
context := &blockParserContext{
|
||||
State: STATE_NONE,
|
||||
NowProperty: "",
|
||||
NowValue: "",
|
||||
NowImportant: 0,
|
||||
}
|
||||
|
||||
for {
|
||||
token := s.Next()
|
||||
|
||||
//fmt.Printf("BLOCK(%d): %s:'%s'\n", context.State, token.Type.String(), token.Value)
|
||||
|
||||
if token.Type == scanner.TokenError {
|
||||
break
|
||||
}
|
||||
|
||||
if token.Type == scanner.TokenEOF {
|
||||
if context.State == STATE_VALUE {
|
||||
// we are ending without ; or }
|
||||
// this can happen when we parse only css declaration
|
||||
decl := NewCSSStyleDeclaration(context.NowProperty, strings.TrimSpace(context.NowValue), context.NowImportant)
|
||||
decls[context.NowProperty] = decl
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
switch token.Type {
|
||||
|
||||
case scanner.TokenS:
|
||||
if context.State == STATE_VALUE {
|
||||
context.NowValue += token.Value
|
||||
}
|
||||
case scanner.TokenIdent:
|
||||
if context.State == STATE_NONE {
|
||||
context.State = STATE_PROPERTY
|
||||
context.NowProperty = strings.TrimSpace(token.Value)
|
||||
break
|
||||
}
|
||||
if token.Value == "important" {
|
||||
context.NowImportant = 1
|
||||
} else {
|
||||
context.NowValue += token.Value
|
||||
}
|
||||
case scanner.TokenChar:
|
||||
if context.State == STATE_NONE {
|
||||
if token.Value == "{" {
|
||||
break
|
||||
}
|
||||
}
|
||||
if context.State == STATE_PROPERTY {
|
||||
if token.Value == ":" {
|
||||
context.State = STATE_VALUE
|
||||
}
|
||||
// CHAR and STATE_PROPERTY but not : then weird
|
||||
// break to ignore it
|
||||
break
|
||||
}
|
||||
// should be no state or value
|
||||
if token.Value == ";" {
|
||||
decl := NewCSSStyleDeclaration(context.NowProperty, strings.TrimSpace(context.NowValue), context.NowImportant)
|
||||
decls[context.NowProperty] = decl
|
||||
context.NowProperty = ""
|
||||
context.NowValue = ""
|
||||
context.NowImportant = 0
|
||||
context.State = STATE_NONE
|
||||
} else if token.Value == "}" { // last property in a block can have optional ;
|
||||
if context.State == STATE_VALUE {
|
||||
// only valid if state is still VALUE, could be ;}
|
||||
decl := NewCSSStyleDeclaration(context.NowProperty, strings.TrimSpace(context.NowValue), context.NowImportant)
|
||||
decls[context.NowProperty] = decl
|
||||
}
|
||||
// we are done
|
||||
return decls
|
||||
} else if token.Value != "!" {
|
||||
context.NowValue += token.Value
|
||||
}
|
||||
break
|
||||
|
||||
// any
|
||||
case scanner.TokenNumber:
|
||||
fallthrough
|
||||
case scanner.TokenPercentage:
|
||||
fallthrough
|
||||
case scanner.TokenDimension:
|
||||
fallthrough
|
||||
case scanner.TokenString:
|
||||
fallthrough
|
||||
case scanner.TokenURI:
|
||||
fallthrough
|
||||
case scanner.TokenHash:
|
||||
fallthrough
|
||||
case scanner.TokenUnicodeRange:
|
||||
fallthrough
|
||||
case scanner.TokenIncludes:
|
||||
fallthrough
|
||||
case scanner.TokenDashMatch:
|
||||
fallthrough
|
||||
case scanner.TokenFunction:
|
||||
fallthrough
|
||||
case scanner.TokenSubstringMatch:
|
||||
context.NowValue += token.Value
|
||||
}
|
||||
}
|
||||
|
||||
return decls
|
||||
}
|
||||
50
vendor/github.com/vanng822/css/block_parser_test.go
generated
vendored
Normal file
50
vendor/github.com/vanng822/css/block_parser_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
//"fmt"
|
||||
)
|
||||
|
||||
func TestParseBlock(t *testing.T) {
|
||||
css := ParseBlock(`
|
||||
font-family: "Source Sans Pro", Arial, sans-serif;
|
||||
font-size: 27px;
|
||||
line-height: 35px;`)
|
||||
|
||||
assert.Equal(t, len(css), 3)
|
||||
assert.Equal(t, "35px", css["line-height"].Value)
|
||||
}
|
||||
|
||||
func TestParseBlockOneLine(t *testing.T) {
|
||||
css := ParseBlock("font-family: \"Source Sans Pro\", Arial, sans-serif; font-size: 27px;")
|
||||
|
||||
assert.Equal(t, len(css), 2)
|
||||
assert.Equal(t, "27px", css["font-size"].Value)
|
||||
assert.Equal(t, "\"Source Sans Pro\", Arial, sans-serif", css["font-family"].Value)
|
||||
}
|
||||
|
||||
func TestParseBlockBlankEnd(t *testing.T) {
|
||||
css := ParseBlock("font-size: 27px; width: 10px")
|
||||
|
||||
assert.Equal(t, len(css), 2)
|
||||
assert.Equal(t, "27px", css["font-size"].Value)
|
||||
assert.Equal(t, "10px", css["width"].Value)
|
||||
}
|
||||
|
||||
func TestParseBlockInportant(t *testing.T) {
|
||||
css := ParseBlock("font-size: 27px; width: 10px !important")
|
||||
|
||||
assert.Equal(t, len(css), 2)
|
||||
assert.Equal(t, "27px", css["font-size"].Value)
|
||||
assert.Equal(t, "10px", css["width"].Value)
|
||||
assert.Equal(t, 1, css["width"].Important)
|
||||
}
|
||||
|
||||
func TestParseBlockWithBraces(t *testing.T) {
|
||||
css := ParseBlock("{ font-size: 27px; width: 10px }")
|
||||
|
||||
assert.Equal(t, len(css), 2)
|
||||
assert.Equal(t, "27px", css["font-size"].Value)
|
||||
assert.Equal(t, "10px", css["width"].Value)
|
||||
}
|
||||
51
vendor/github.com/vanng822/css/charset_parser.go
generated
vendored
Normal file
51
vendor/github.com/vanng822/css/charset_parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/gorilla/css/scanner"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func newCharsetRule(statement string) *CSSRule {
|
||||
statement = strings.TrimSpace(statement)
|
||||
if statement != "" {
|
||||
rule := NewRule(CHARSET_RULE)
|
||||
rule.Style.SelectorText = statement
|
||||
return rule
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseCharset(s *scanner.Scanner) *CSSRule {
|
||||
/*
|
||||
|
||||
Syntax:
|
||||
@charset charset;
|
||||
|
||||
Example:
|
||||
@charset "UTF-8";
|
||||
|
||||
*/
|
||||
|
||||
var statement string
|
||||
for {
|
||||
token := s.Next()
|
||||
|
||||
//fmt.Printf("Import: %s:'%s'\n", token.Type.String(), token.Value)
|
||||
|
||||
if token.Type == scanner.TokenEOF || token.Type == scanner.TokenError {
|
||||
return nil
|
||||
}
|
||||
// take everything for now
|
||||
switch token.Type {
|
||||
case scanner.TokenChar:
|
||||
if token.Value == ";" {
|
||||
return newCharsetRule(statement)
|
||||
}
|
||||
statement += token.Value
|
||||
default:
|
||||
statement += token.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/github.com/vanng822/css/charset_parser_test.go
generated
vendored
Normal file
27
vendor/github.com/vanng822/css/charset_parser_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/gorilla/css/scanner"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCharsetDoubleQ(t *testing.T) {
|
||||
css := Parse(`@charset "UTF-8";`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "\"UTF-8\"")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, CHARSET_RULE)
|
||||
}
|
||||
|
||||
func TestCharsetSingleQ(t *testing.T) {
|
||||
css := Parse(`@charset 'iso-8859-15';`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "'iso-8859-15'")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, CHARSET_RULE)
|
||||
}
|
||||
|
||||
func TestCharsetIgnore(t *testing.T) {
|
||||
css := parseCharset(scanner.New(` 'iso-8859-15'`))
|
||||
|
||||
assert.Nil(t, css)
|
||||
}
|
||||
16
vendor/github.com/vanng822/css/doc.go
generated
vendored
Normal file
16
vendor/github.com/vanng822/css/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Package css is for parsing css stylesheet.
|
||||
//
|
||||
// import (
|
||||
// "github.com/vanng822/css"
|
||||
// "fmt"
|
||||
// )
|
||||
// func main() {
|
||||
// csstext = "td {width: 100px; height: 100px;}"
|
||||
// ss := css.Parse(csstext)
|
||||
// rules := ss.GetCSSRuleList()
|
||||
// for _, rule := range rules {
|
||||
// fmt.Println(rule.Style.SelectorText)
|
||||
// fmt.Println(rule.Style.Styles)
|
||||
// }
|
||||
// }
|
||||
package css
|
||||
56
vendor/github.com/vanng822/css/import_parser.go
generated
vendored
Normal file
56
vendor/github.com/vanng822/css/import_parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/gorilla/css/scanner"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func newImportRule(statement string) *CSSRule {
|
||||
statement = strings.TrimSpace(statement)
|
||||
if statement != "" {
|
||||
rule := NewRule(IMPORT_RULE)
|
||||
rule.Style.SelectorText = statement
|
||||
return rule
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseImport(s *scanner.Scanner) *CSSRule {
|
||||
/*
|
||||
Syntax:
|
||||
@import url; or
|
||||
@import url list-of-media-queries;
|
||||
|
||||
Example:
|
||||
@import url("fineprint.css") print;
|
||||
@import url("bluish.css") projection, tv;
|
||||
@import 'custom.css';
|
||||
@import url("chrome://communicator/skin/");
|
||||
@import "common.css" screen, projection;
|
||||
@import url('landscape.css') screen and (orientation:landscape);
|
||||
|
||||
*/
|
||||
|
||||
var statement string
|
||||
for {
|
||||
token := s.Next()
|
||||
|
||||
//fmt.Printf("Import: %s:'%s'\n", token.Type.String(), token.Value)
|
||||
|
||||
if token.Type == scanner.TokenEOF || token.Type == scanner.TokenError {
|
||||
return nil
|
||||
}
|
||||
// take everything for now
|
||||
switch token.Type {
|
||||
case scanner.TokenChar:
|
||||
if token.Value == ";" {
|
||||
return newImportRule(statement)
|
||||
}
|
||||
statement += token.Value
|
||||
default:
|
||||
statement += token.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
35
vendor/github.com/vanng822/css/import_parser_test.go
generated
vendored
Normal file
35
vendor/github.com/vanng822/css/import_parser_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/gorilla/css/scanner"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestImport(t *testing.T) {
|
||||
css := Parse(`@import url("fineprint.css") print;
|
||||
@import url("bluish.css") projection, tv;
|
||||
@import 'custom.css';
|
||||
@import url("chrome://communicator/skin/");
|
||||
@import "common.css" screen, projection;
|
||||
@import url('landscape.css') screen and (orientation:landscape);`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "url(\"fineprint.css\") print")
|
||||
assert.Equal(t, css.CssRuleList[1].Style.SelectorText, "url(\"bluish.css\") projection, tv")
|
||||
assert.Equal(t, css.CssRuleList[2].Style.SelectorText, "'custom.css'")
|
||||
assert.Equal(t, css.CssRuleList[3].Style.SelectorText, "url(\"chrome://communicator/skin/\")")
|
||||
assert.Equal(t, css.CssRuleList[4].Style.SelectorText, "\"common.css\" screen, projection")
|
||||
assert.Equal(t, css.CssRuleList[5].Style.SelectorText, "url('landscape.css') screen and (orientation:landscape)")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Type, IMPORT_RULE)
|
||||
assert.Equal(t, css.CssRuleList[1].Type, IMPORT_RULE)
|
||||
assert.Equal(t, css.CssRuleList[2].Type, IMPORT_RULE)
|
||||
assert.Equal(t, css.CssRuleList[3].Type, IMPORT_RULE)
|
||||
assert.Equal(t, css.CssRuleList[4].Type, IMPORT_RULE)
|
||||
assert.Equal(t, css.CssRuleList[5].Type, IMPORT_RULE)
|
||||
}
|
||||
|
||||
func TestImportIgnore(t *testing.T) {
|
||||
css := parseImport(scanner.New(` url("fineprint.css") print`))
|
||||
assert.Nil(t, css)
|
||||
}
|
||||
154
vendor/github.com/vanng822/css/parser.go
generated
vendored
Normal file
154
vendor/github.com/vanng822/css/parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/css/scanner"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
stylesheet : [ CDO | CDC | S | statement ]*;
|
||||
statement : ruleset | at-rule;
|
||||
at-rule : ATKEYWORD S* any* [ block | ';' S* ];
|
||||
block : '{' S* [ any | block | ATKEYWORD S* | ';' S* ]* '}' S*;
|
||||
ruleset : selector? '{' S* declaration? [ ';' S* declaration? ]* '}' S*;
|
||||
selector : any+;
|
||||
declaration : property S* ':' S* value;
|
||||
property : IDENT;
|
||||
value : [ any | block | ATKEYWORD S* ]+;
|
||||
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
|
||||
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
|
||||
| DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
|
||||
| '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
|
||||
] S*;
|
||||
unused : block | ATKEYWORD S* | ';' S* | CDO S* | CDC S*;
|
||||
*/
|
||||
|
||||
type State int
|
||||
|
||||
const (
|
||||
STATE_NONE State = iota
|
||||
STATE_SELECTOR
|
||||
STATE_PROPERTY
|
||||
STATE_VALUE
|
||||
)
|
||||
|
||||
type parserContext struct {
|
||||
State State
|
||||
NowSelectorText string
|
||||
NowRuleType RuleType
|
||||
CurrentRule *CSSRule
|
||||
CurrentMediaRule *CSSRule
|
||||
}
|
||||
|
||||
func resetContextStyleRule(context *parserContext) {
|
||||
context.CurrentRule = nil
|
||||
context.NowSelectorText = ""
|
||||
context.NowRuleType = STYLE_RULE
|
||||
context.State = STATE_NONE
|
||||
}
|
||||
|
||||
func parseRule(context *parserContext, s *scanner.Scanner, css *CSSStyleSheet) {
|
||||
context.CurrentRule = NewRule(context.NowRuleType)
|
||||
context.NowSelectorText += parseSelector(s)
|
||||
context.CurrentRule.Style.SelectorText = strings.TrimSpace(context.NowSelectorText)
|
||||
context.CurrentRule.Style.Styles = parseBlock(s)
|
||||
if context.CurrentMediaRule != nil {
|
||||
context.CurrentMediaRule.Rules = append(context.CurrentMediaRule.Rules, context.CurrentRule)
|
||||
} else {
|
||||
css.CssRuleList = append(css.CssRuleList, context.CurrentRule)
|
||||
}
|
||||
}
|
||||
|
||||
// Parse takes a string of valid css rules, stylesheet,
|
||||
// and parses it. Be aware this function has poor error handling
|
||||
// so you should have valid syntax in your css
|
||||
func Parse(csstext string) *CSSStyleSheet {
|
||||
context := &parserContext{
|
||||
State: STATE_NONE,
|
||||
NowSelectorText: "",
|
||||
NowRuleType: STYLE_RULE,
|
||||
CurrentMediaRule: nil,
|
||||
}
|
||||
|
||||
css := &CSSStyleSheet{}
|
||||
css.CssRuleList = make([]*CSSRule, 0)
|
||||
s := scanner.New(csstext)
|
||||
|
||||
for {
|
||||
token := s.Next()
|
||||
|
||||
//fmt.Printf("Parse(%d): %s:'%s'\n", context.State, token.Type.String(), token.Value)
|
||||
|
||||
if token.Type == scanner.TokenEOF || token.Type == scanner.TokenError {
|
||||
break
|
||||
}
|
||||
|
||||
switch token.Type {
|
||||
case scanner.TokenCDO:
|
||||
break
|
||||
case scanner.TokenCDC:
|
||||
break
|
||||
case scanner.TokenComment:
|
||||
break
|
||||
case scanner.TokenS:
|
||||
break
|
||||
case scanner.TokenAtKeyword:
|
||||
switch token.Value {
|
||||
case "@media":
|
||||
context.NowRuleType = MEDIA_RULE
|
||||
case "@font-face":
|
||||
// Parse as normal rule, would be nice to parse according to syntax
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face
|
||||
context.NowRuleType = FONT_FACE_RULE
|
||||
parseRule(context, s, css)
|
||||
resetContextStyleRule(context)
|
||||
case "@import":
|
||||
// No validation
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/@import
|
||||
rule := parseImport(s)
|
||||
if rule != nil {
|
||||
css.CssRuleList = append(css.CssRuleList, rule)
|
||||
}
|
||||
resetContextStyleRule(context)
|
||||
case "@charset":
|
||||
// No validation
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/@charset
|
||||
rule := parseCharset(s)
|
||||
if rule != nil {
|
||||
css.CssRuleList = append(css.CssRuleList, rule)
|
||||
}
|
||||
resetContextStyleRule(context)
|
||||
|
||||
case "@page":
|
||||
context.NowRuleType = PAGE_RULE
|
||||
parseRule(context, s, css)
|
||||
resetContextStyleRule(context)
|
||||
default:
|
||||
panic(fmt.Sprintf("At rule '%s' is not supported", token.Value))
|
||||
}
|
||||
default:
|
||||
if context.State == STATE_NONE {
|
||||
if token.Value == "}" && context.CurrentMediaRule != nil {
|
||||
// close media rule
|
||||
css.CssRuleList = append(css.CssRuleList, context.CurrentMediaRule)
|
||||
context.CurrentMediaRule = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if context.NowRuleType == MEDIA_RULE {
|
||||
context.CurrentMediaRule = NewRule(context.NowRuleType)
|
||||
context.CurrentMediaRule.Style.SelectorText = strings.TrimSpace(token.Value + parseSelector(s))
|
||||
resetContextStyleRule(context)
|
||||
break
|
||||
} else {
|
||||
context.NowSelectorText += token.Value
|
||||
parseRule(context, s, css)
|
||||
resetContextStyleRule(context)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return css
|
||||
}
|
||||
103
vendor/github.com/vanng822/css/parser_media_test.go
generated
vendored
Normal file
103
vendor/github.com/vanng822/css/parser_media_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMedia(t *testing.T) {
|
||||
css := Parse(`@media only screen and (max-width: 600px) {
|
||||
table[class="body"] img {
|
||||
width: auto !important;
|
||||
height: auto !important
|
||||
}
|
||||
table[class="body"] center {
|
||||
min-width: 0 !important
|
||||
}
|
||||
table[class="body"] .container {
|
||||
width: 95% !important
|
||||
}
|
||||
table[class="body"] .row {
|
||||
width: 100% !important;
|
||||
display: block !important
|
||||
}
|
||||
}`)
|
||||
|
||||
//fmt.Println(css)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "only screen and (max-width: 600px)")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, MEDIA_RULE)
|
||||
assert.Equal(t, len(css.CssRuleList[0].Rules), 4)
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[0].Style.SelectorText, "table[class=\"body\"] img")
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[0].Style.Styles["height"].Value, "auto")
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[0].Style.Styles["height"].Important, 1)
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[1].Style.SelectorText, "table[class=\"body\"] center")
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[2].Style.SelectorText, "table[class=\"body\"] .container")
|
||||
assert.Equal(t, css.CssRuleList[0].Rules[3].Style.SelectorText, "table[class=\"body\"] .row")
|
||||
|
||||
}
|
||||
|
||||
func TestMediaMulti(t *testing.T) {
|
||||
css := Parse(`
|
||||
table.one {
|
||||
width: 30px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
table[class="body"] img {
|
||||
width: auto !important;
|
||||
height: auto !important
|
||||
}
|
||||
table[class="body"] center {
|
||||
min-width: 0 !important
|
||||
}
|
||||
table[class="body"] .container {
|
||||
width: 95% !important
|
||||
}
|
||||
table[class="body"] .row {
|
||||
width: 100% !important;
|
||||
display: block !important
|
||||
}
|
||||
}
|
||||
@media all and (min-width: 48em) {
|
||||
blockquote {
|
||||
font-size: 34px;
|
||||
line-height: 40px;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 3px;
|
||||
}
|
||||
}
|
||||
table.two {
|
||||
width: 80px;
|
||||
}`)
|
||||
|
||||
assert.Equal(t, len(css.CssRuleList), 4)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "table.one")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, STYLE_RULE)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["width"].Value, "30px")
|
||||
assert.Equal(t, len(css.CssRuleList[0].Rules), 0)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[1].Style.SelectorText, "only screen and (max-width: 600px)")
|
||||
assert.Equal(t, css.CssRuleList[1].Type, MEDIA_RULE)
|
||||
assert.Equal(t, len(css.CssRuleList[1].Rules), 4)
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[0].Style.SelectorText, "table[class=\"body\"] img")
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[0].Style.Styles["height"].Value, "auto")
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[0].Style.Styles["height"].Important, 1)
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[1].Style.SelectorText, "table[class=\"body\"] center")
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[2].Style.SelectorText, "table[class=\"body\"] .container")
|
||||
assert.Equal(t, css.CssRuleList[1].Rules[3].Style.SelectorText, "table[class=\"body\"] .row")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[2].Style.SelectorText, "all and (min-width: 48em)")
|
||||
assert.Equal(t, css.CssRuleList[2].Type, MEDIA_RULE)
|
||||
assert.Equal(t, css.CssRuleList[2].Rules[0].Style.SelectorText, "blockquote")
|
||||
assert.Equal(t, css.CssRuleList[2].Rules[0].Style.Styles["font-size"].Value, "34px")
|
||||
assert.Equal(t, css.CssRuleList[2].Rules[0].Style.Styles["line-height"].Value, "40px")
|
||||
assert.Equal(t, css.CssRuleList[2].Rules[0].Style.Styles["padding-top"].Value, "2px")
|
||||
assert.Equal(t, css.CssRuleList[2].Rules[0].Style.Styles["padding-bottom"].Value, "3px")
|
||||
assert.Equal(t, len(css.CssRuleList[2].Rules), 1)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[3].Style.SelectorText, "table.two")
|
||||
assert.Equal(t, css.CssRuleList[3].Type, STYLE_RULE)
|
||||
assert.Equal(t, css.CssRuleList[3].Style.Styles["width"].Value, "80px")
|
||||
assert.Equal(t, len(css.CssRuleList[3].Rules), 0)
|
||||
}
|
||||
175
vendor/github.com/vanng822/css/parser_selector_test.go
generated
vendored
Normal file
175
vendor/github.com/vanng822/css/parser_selector_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMultipleSelectors(t *testing.T) {
|
||||
css := Parse(`div .a {
|
||||
font-size: 150%;
|
||||
}
|
||||
p .b {
|
||||
font-size: 250%;
|
||||
}`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "div .a")
|
||||
assert.Equal(t, css.CssRuleList[1].Style.SelectorText, "p .b")
|
||||
|
||||
}
|
||||
|
||||
func TestIdSelector(t *testing.T) {
|
||||
css := Parse("#div { color: red;}")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["color"].Value, "red")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "#div")
|
||||
}
|
||||
|
||||
func TestClassSelector(t *testing.T) {
|
||||
css := Parse(".div { color: green;}")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["color"].Value, "green")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, ".div")
|
||||
}
|
||||
|
||||
func TestStarSelector(t *testing.T) {
|
||||
css := Parse("* { text-rendering: optimizelegibility; }")
|
||||
|
||||
assert.Equal(t, "optimizelegibility", css.CssRuleList[0].Style.Styles["text-rendering"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "*")
|
||||
}
|
||||
|
||||
func TestStarSelectorMulti(t *testing.T) {
|
||||
css := Parse(`div .a {
|
||||
font-size: 150%;
|
||||
}
|
||||
* { text-rendering: optimizelegibility; }`)
|
||||
|
||||
assert.Equal(t, "150%", css.CssRuleList[0].Style.Styles["font-size"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "div .a")
|
||||
|
||||
assert.Equal(t, "optimizelegibility", css.CssRuleList[1].Style.Styles["text-rendering"].Value)
|
||||
assert.Equal(t, css.CssRuleList[1].Style.SelectorText, "*")
|
||||
}
|
||||
|
||||
func TestMixedClassSelectors(t *testing.T) {
|
||||
selectors := []string{".footer__content_wrapper--last",
|
||||
"table[class=\"body\"] .footer__content td",
|
||||
"table[class=\"body\"] td.footer__link_wrapper--first",
|
||||
"table[class=\"body\"] td.footer__link_wrapper--last"}
|
||||
|
||||
for _, selector := range selectors {
|
||||
css := Parse(fmt.Sprintf(` %s {
|
||||
border-collapse: separate;
|
||||
padding: 10px 0 0
|
||||
}`, selector))
|
||||
|
||||
assert.Equal(t, "separate", css.CssRuleList[0].Style.Styles["border-collapse"].Value)
|
||||
assert.Equal(t, "10px 0 0", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, selector)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenericSelectors(t *testing.T) {
|
||||
selectors := []string{
|
||||
"p ~ ul",
|
||||
"div > p",
|
||||
"div > p",
|
||||
"div p",
|
||||
"div, p",
|
||||
"[target]",
|
||||
"[target=_blank]",
|
||||
"[title~=flower]",
|
||||
"[lang|=en]",
|
||||
"a[href^=\"https\"]",
|
||||
"a[href$=\".pdf\"]",
|
||||
"a[href*=\"css\"]",
|
||||
".header + .content",
|
||||
"#firstname",
|
||||
"table[class=\"body\"] .footer__content td",
|
||||
"table[class=\"body\"] td.footer__link_wrapper--first"}
|
||||
|
||||
for _, selector := range selectors {
|
||||
css := Parse(fmt.Sprintf(` %s {
|
||||
border-collapse: separate;
|
||||
padding: 10px 0 0
|
||||
}`, selector))
|
||||
|
||||
assert.Equal(t, "separate", css.CssRuleList[0].Style.Styles["border-collapse"].Value)
|
||||
assert.Equal(t, "10px 0 0", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, selector)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterSelectors(t *testing.T) {
|
||||
selectors := []string{
|
||||
"a:active",
|
||||
"p::after",
|
||||
"p::before",
|
||||
"input:checked",
|
||||
"input:disabled",
|
||||
"input:in-range",
|
||||
"input:invalid",
|
||||
"input:optional",
|
||||
"input:read-only",
|
||||
"input:enabled",
|
||||
"p:empty",
|
||||
"p:first-child",
|
||||
"p::first-letter",
|
||||
"p::first-line",
|
||||
"p:first-of-type",
|
||||
"input:focus",
|
||||
"a:hover",
|
||||
"p:lang(it)",
|
||||
"p:last-child",
|
||||
"p:last-of-type",
|
||||
"a:link",
|
||||
":not(p)",
|
||||
"p:nth-child(2)",
|
||||
"p:nth-last-child(2)",
|
||||
"p:only-of-type",
|
||||
"p:only-child",
|
||||
"p:nth-last-of-type(2)",
|
||||
"div:not(:nth-child(1))",
|
||||
"div:not(:not(:first-child))",
|
||||
":root",
|
||||
"::selection",
|
||||
"#news:target"}
|
||||
|
||||
for _, selector := range selectors {
|
||||
css := Parse(fmt.Sprintf(` %s {
|
||||
border-collapse: separate;
|
||||
padding: 10px 0 0
|
||||
}`, selector))
|
||||
|
||||
assert.Equal(t, "separate", css.CssRuleList[0].Style.Styles["border-collapse"].Value)
|
||||
assert.Equal(t, "10px 0 0", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, selector)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFontFace(t *testing.T) {
|
||||
css := Parse(`@font-face {
|
||||
font-family: "Bitstream Vera Serif Bold";
|
||||
src: url("https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf");
|
||||
}
|
||||
|
||||
body { font-family: "Bitstream Vera Serif Bold", serif }`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-family"].Value, "\"Bitstream Vera Serif Bold\"")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["src"].Value, "url(\"https://mdn.mozillademos.org/files/2468/VeraSeBd.ttf\")")
|
||||
assert.Equal(t, css.CssRuleList[1].Style.Styles["font-family"].Value, "\"Bitstream Vera Serif Bold\", serif")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, FONT_FACE_RULE)
|
||||
}
|
||||
|
||||
func TestPage(t *testing.T) {
|
||||
css := Parse(`@page :first {
|
||||
margin: 2in 3in;
|
||||
}`)
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, ":first")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["margin"].Value, "2in 3in")
|
||||
assert.Equal(t, css.CssRuleList[0].Type, PAGE_RULE)
|
||||
}
|
||||
148
vendor/github.com/vanng822/css/parser_test.go
generated
vendored
Normal file
148
vendor/github.com/vanng822/css/parser_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWithoutImpotant(t *testing.T) {
|
||||
css := Parse(`div .a { font-size: 150%;}`)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Value, "150%")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Property, "font-size")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Important, 0)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "div .a")
|
||||
|
||||
}
|
||||
|
||||
func TestWithImpotant(t *testing.T) {
|
||||
css := Parse("div .a { font-size: 150% !important;}")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Value, "150%")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Property, "font-size")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Important, 1)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "div .a")
|
||||
}
|
||||
|
||||
func TestMultipleDeclarations(t *testing.T) {
|
||||
css := Parse(`div .a {
|
||||
font-size: 150%;
|
||||
width: 100%
|
||||
}`)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Value, "150%")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Property, "font-size")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Important, 0)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["width"].Value, "100%")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["width"].Property, "width")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["width"].Important, 0)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "div .a")
|
||||
}
|
||||
|
||||
func TestValuePx(t *testing.T) {
|
||||
css := Parse("div .a { font-size: 45px;}")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Value, "45px")
|
||||
}
|
||||
|
||||
func TestValueEm(t *testing.T) {
|
||||
css := Parse("div .a { font-size: 45em;}")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["font-size"].Value, "45em")
|
||||
}
|
||||
|
||||
func TestValueHex(t *testing.T) {
|
||||
css := Parse("div .a { color: #123456;}")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["color"].Value, "#123456")
|
||||
}
|
||||
|
||||
func TestValueRGBFunction(t *testing.T) {
|
||||
css := Parse(".color{ color: rgb(1,2,3);}")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["color"].Value, "rgb(1,2,3)")
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, ".color")
|
||||
}
|
||||
|
||||
func TestValueString(t *testing.T) {
|
||||
css := Parse("div .center { text-align: center; }")
|
||||
|
||||
assert.Equal(t, css.CssRuleList[0].Style.Styles["text-align"].Value, "center")
|
||||
}
|
||||
|
||||
func TestValueWhiteSpace(t *testing.T) {
|
||||
css := Parse(".div { padding: 10px 0 0 10px}")
|
||||
|
||||
assert.Equal(t, "10px 0 0 10px", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, ".div")
|
||||
}
|
||||
|
||||
func TestValueMixed(t *testing.T) {
|
||||
css := Parse(`td {
|
||||
padding: 0 12px 0 10px;
|
||||
border-right: 1px solid white
|
||||
}`)
|
||||
|
||||
assert.Equal(t, "0 12px 0 10px", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, "1px solid white", css.CssRuleList[0].Style.Styles["border-right"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "td")
|
||||
}
|
||||
|
||||
func TestQuoteValue(t *testing.T) {
|
||||
css := Parse(`blockquote {
|
||||
font-family: "Source Sans Pro", Arial, sans-serif;
|
||||
font-size: 27px;
|
||||
line-height: 35px;}`)
|
||||
|
||||
assert.Equal(t, "\"Source Sans Pro\", Arial, sans-serif", css.CssRuleList[0].Style.Styles["font-family"].Value)
|
||||
assert.Equal(t, "27px", css.CssRuleList[0].Style.Styles["font-size"].Value)
|
||||
assert.Equal(t, "35px", css.CssRuleList[0].Style.Styles["line-height"].Value)
|
||||
assert.Equal(t, css.CssRuleList[0].Style.SelectorText, "blockquote")
|
||||
}
|
||||
|
||||
func TestDashClassname(t *testing.T) {
|
||||
css := Parse(`.content {
|
||||
padding: 0px;
|
||||
}
|
||||
.content-wrap {
|
||||
padding: 2px;
|
||||
}`)
|
||||
|
||||
assert.Equal(t, ".content", css.CssRuleList[0].Style.SelectorText)
|
||||
assert.Equal(t, ".content-wrap", css.CssRuleList[1].Style.SelectorText)
|
||||
assert.Equal(t, "0px", css.CssRuleList[0].Style.Styles["padding"].Value)
|
||||
assert.Equal(t, "2px", css.CssRuleList[1].Style.Styles["padding"].Value)
|
||||
}
|
||||
|
||||
func TestNotSupportedAtRule(t *testing.T) {
|
||||
rules := []string{
|
||||
`@keyframes mymove {
|
||||
0% {top: 0px;}
|
||||
25% {top: 200px;}
|
||||
50% {top: 100px;}
|
||||
75% {top: 200px;}
|
||||
100% {top: 0px;}
|
||||
}`,
|
||||
`@-webkit-keyframes mymove {
|
||||
0% {top: 0px;}
|
||||
25% {top: 200px;}
|
||||
50% {top: 100px;}
|
||||
75% {top: 200px;}
|
||||
100% {top: 0px;}
|
||||
} `,
|
||||
`@counter-style winners-list {
|
||||
system: fixed;
|
||||
symbols: url(gold-medal.svg) url(silver-medal.svg) url(bronze-medal.svg);
|
||||
suffix: " ";
|
||||
}`,
|
||||
`@namespace url(http://www.w3.org/1999/xhtml);`,
|
||||
`@document url(http://www.w3.org/),
|
||||
url-prefix(http://www.w3.org/Style/),
|
||||
domain(mozilla.org),
|
||||
regexp("https:.*")
|
||||
{
|
||||
|
||||
body { color: purple; background: yellow; }
|
||||
}`,
|
||||
}
|
||||
for _, rule := range rules {
|
||||
assert.Panics(t, func() {
|
||||
Parse(rule)
|
||||
})
|
||||
}
|
||||
}
|
||||
43
vendor/github.com/vanng822/css/rule.go
generated
vendored
Normal file
43
vendor/github.com/vanng822/css/rule.go
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package css
|
||||
|
||||
import ()
|
||||
|
||||
type RuleType int
|
||||
|
||||
const (
|
||||
STYLE_RULE RuleType = iota
|
||||
CHARSET_RULE
|
||||
IMPORT_RULE
|
||||
MEDIA_RULE
|
||||
FONT_FACE_RULE
|
||||
PAGE_RULE
|
||||
|
||||
)
|
||||
|
||||
var ruleTypeNames = map[RuleType]string{
|
||||
STYLE_RULE: "",
|
||||
MEDIA_RULE: "@media",
|
||||
CHARSET_RULE: "@charset",
|
||||
IMPORT_RULE: "@import",
|
||||
FONT_FACE_RULE: "@font-face",
|
||||
PAGE_RULE: "@page",
|
||||
}
|
||||
|
||||
func (rt RuleType) Text() string {
|
||||
return ruleTypeNames[rt]
|
||||
}
|
||||
|
||||
type CSSRule struct {
|
||||
Type RuleType
|
||||
Style CSSStyleRule
|
||||
Rules []*CSSRule
|
||||
}
|
||||
|
||||
func NewRule(ruleType RuleType) *CSSRule {
|
||||
r := &CSSRule{
|
||||
Type: ruleType,
|
||||
}
|
||||
r.Style.Styles = make(map[string]*CSSStyleDeclaration)
|
||||
r.Rules = make([]*CSSRule, 0)
|
||||
return r
|
||||
}
|
||||
16
vendor/github.com/vanng822/css/rule_test.go
generated
vendored
Normal file
16
vendor/github.com/vanng822/css/rule_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRuleTypeString(t *testing.T) {
|
||||
assert.Equal(t, STYLE_RULE.Text(), "")
|
||||
assert.Equal(t, CHARSET_RULE.Text(), "@charset")
|
||||
assert.Equal(t, IMPORT_RULE.Text(), "@import")
|
||||
assert.Equal(t, MEDIA_RULE.Text(), "@media")
|
||||
assert.Equal(t, FONT_FACE_RULE.Text(), "@font-face")
|
||||
assert.Equal(t, PAGE_RULE.Text(), "@page")
|
||||
}
|
||||
|
||||
69
vendor/github.com/vanng822/css/selector_parser.go
generated
vendored
Normal file
69
vendor/github.com/vanng822/css/selector_parser.go
generated
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"github.com/gorilla/css/scanner"
|
||||
)
|
||||
|
||||
func parseSelector(s *scanner.Scanner) string {
|
||||
/*
|
||||
selector : any+;
|
||||
any : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
|
||||
| DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
|
||||
| DASHMATCH | ':' | FUNCTION S* [any|unused]* ')'
|
||||
| '(' S* [any|unused]* ')' | '[' S* [any|unused]* ']'
|
||||
] S*;
|
||||
*/
|
||||
|
||||
selector := ""
|
||||
|
||||
for {
|
||||
token := s.Next()
|
||||
|
||||
//fmt.Printf("SELECTOR: %s:'%s'\n", token.Type.String(), token.Value)
|
||||
|
||||
if token.Type == scanner.TokenError || token.Type == scanner.TokenEOF {
|
||||
break
|
||||
}
|
||||
|
||||
switch token.Type {
|
||||
case scanner.TokenChar:
|
||||
if token.Value == "{" {
|
||||
return selector
|
||||
}
|
||||
fallthrough
|
||||
case scanner.TokenIdent:
|
||||
fallthrough
|
||||
case scanner.TokenS:
|
||||
fallthrough
|
||||
case scanner.TokenNumber:
|
||||
fallthrough
|
||||
case scanner.TokenPercentage:
|
||||
fallthrough
|
||||
case scanner.TokenDimension:
|
||||
fallthrough
|
||||
case scanner.TokenString:
|
||||
fallthrough
|
||||
case scanner.TokenURI:
|
||||
fallthrough
|
||||
case scanner.TokenHash:
|
||||
fallthrough
|
||||
case scanner.TokenUnicodeRange:
|
||||
fallthrough
|
||||
case scanner.TokenIncludes:
|
||||
fallthrough
|
||||
case scanner.TokenDashMatch:
|
||||
fallthrough
|
||||
case scanner.TokenFunction:
|
||||
fallthrough
|
||||
case scanner.TokenSuffixMatch:
|
||||
fallthrough
|
||||
case scanner.TokenPrefixMatch:
|
||||
fallthrough
|
||||
case scanner.TokenSubstringMatch:
|
||||
selector += token.Value
|
||||
}
|
||||
}
|
||||
|
||||
return selector
|
||||
}
|
||||
26
vendor/github.com/vanng822/css/styledeclaration.go
generated
vendored
Normal file
26
vendor/github.com/vanng822/css/styledeclaration.go
generated
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CSSStyleDeclaration struct {
|
||||
Property string
|
||||
Value string
|
||||
Important int
|
||||
}
|
||||
|
||||
func NewCSSStyleDeclaration(property, value string, important int) *CSSStyleDeclaration {
|
||||
return &CSSStyleDeclaration{
|
||||
Property: property,
|
||||
Value: value,
|
||||
Important: important,
|
||||
}
|
||||
}
|
||||
|
||||
func (decl *CSSStyleDeclaration) Text() string {
|
||||
if decl.Important == 1 {
|
||||
return fmt.Sprintf("%s: %s !important", decl.Property, decl.Value)
|
||||
}
|
||||
return fmt.Sprintf("%s: %s", decl.Property, decl.Value)
|
||||
}
|
||||
16
vendor/github.com/vanng822/css/styledeclaration_test.go
generated
vendored
Normal file
16
vendor/github.com/vanng822/css/styledeclaration_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeclWithImportan(t *testing.T) {
|
||||
decl := NewCSSStyleDeclaration("width", "100%", 1)
|
||||
assert.Equal(t, decl.Text(), "width: 100% !important")
|
||||
}
|
||||
|
||||
func TestDeclWithoutImportan(t *testing.T) {
|
||||
decl := NewCSSStyleDeclaration("width", "100%", 0)
|
||||
assert.Equal(t, decl.Text(), "width: 100%")
|
||||
}
|
||||
24
vendor/github.com/vanng822/css/stylerule.go
generated
vendored
Normal file
24
vendor/github.com/vanng822/css/stylerule.go
generated
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CSSStyleRule struct {
|
||||
SelectorText string
|
||||
Styles map[string]*CSSStyleDeclaration
|
||||
}
|
||||
|
||||
func (sr *CSSStyleRule) Text() string {
|
||||
decls := make([]string, 0, len(sr.Styles))
|
||||
|
||||
for _, s := range sr.Styles {
|
||||
decls = append(decls, s.Text())
|
||||
}
|
||||
|
||||
sort.Strings(decls)
|
||||
|
||||
return fmt.Sprintf("%s {\n%s\n}", sr.SelectorText, strings.Join(decls, ";\n"))
|
||||
}
|
||||
16
vendor/github.com/vanng822/css/stylerule_test.go
generated
vendored
Normal file
16
vendor/github.com/vanng822/css/stylerule_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package css
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStyleRuleText(t *testing.T) {
|
||||
sr := CSSStyleRule{}
|
||||
sr.SelectorText = ".box"
|
||||
sr.Styles = make(map[string]*CSSStyleDeclaration)
|
||||
sr.Styles["width"] = NewCSSStyleDeclaration("width", "10px", 0)
|
||||
sr.Styles["height"] = NewCSSStyleDeclaration("height", "100px", 0)
|
||||
|
||||
assert.Equal(t, sr.Text(), ".box {\nheight: 100px;\nwidth: 10px\n}")
|
||||
}
|
||||
13
vendor/github.com/vanng822/css/stylesheet.go
generated
vendored
Normal file
13
vendor/github.com/vanng822/css/stylesheet.go
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package css
|
||||
|
||||
import ()
|
||||
|
||||
type CSSStyleSheet struct {
|
||||
Type string
|
||||
Media string
|
||||
CssRuleList []*CSSRule
|
||||
}
|
||||
|
||||
func (ss *CSSStyleSheet) GetCSSRuleList() []*CSSRule {
|
||||
return ss.CssRuleList
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue