diff options
Diffstat (limited to 'vendor/github.com/aymerick/douceur/css/declaration.go')
| -rw-r--r-- | vendor/github.com/aymerick/douceur/css/declaration.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/github.com/aymerick/douceur/css/declaration.go b/vendor/github.com/aymerick/douceur/css/declaration.go new file mode 100644 index 0000000..61d29d3 --- /dev/null +++ b/vendor/github.com/aymerick/douceur/css/declaration.go | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | package css | ||
| 2 | |||
| 3 | import "fmt" | ||
| 4 | |||
| 5 | // Declaration represents a parsed style property | ||
| 6 | type Declaration struct { | ||
| 7 | Property string | ||
| 8 | Value string | ||
| 9 | Important bool | ||
| 10 | } | ||
| 11 | |||
| 12 | // NewDeclaration instanciates a new Declaration | ||
| 13 | func NewDeclaration() *Declaration { | ||
| 14 | return &Declaration{} | ||
| 15 | } | ||
| 16 | |||
| 17 | // Returns string representation of the Declaration | ||
| 18 | func (decl *Declaration) String() string { | ||
| 19 | return decl.StringWithImportant(true) | ||
| 20 | } | ||
| 21 | |||
| 22 | // StringWithImportant returns string representation with optional !important part | ||
| 23 | func (decl *Declaration) StringWithImportant(option bool) string { | ||
| 24 | result := fmt.Sprintf("%s: %s", decl.Property, decl.Value) | ||
| 25 | |||
| 26 | if option && decl.Important { | ||
| 27 | result += " !important" | ||
| 28 | } | ||
| 29 | |||
| 30 | result += ";" | ||
| 31 | |||
| 32 | return result | ||
| 33 | } | ||
| 34 | |||
| 35 | // Equal returns true if both Declarations are equals | ||
| 36 | func (decl *Declaration) Equal(other *Declaration) bool { | ||
| 37 | return (decl.Property == other.Property) && (decl.Value == other.Value) && (decl.Important == other.Important) | ||
| 38 | } | ||
| 39 | |||
| 40 | // | ||
| 41 | // DeclarationsByProperty | ||
| 42 | // | ||
| 43 | |||
| 44 | // DeclarationsByProperty represents sortable style declarations | ||
| 45 | type DeclarationsByProperty []*Declaration | ||
| 46 | |||
| 47 | // Implements sort.Interface | ||
| 48 | func (declarations DeclarationsByProperty) Len() int { | ||
| 49 | return len(declarations) | ||
| 50 | } | ||
| 51 | |||
| 52 | // Implements sort.Interface | ||
| 53 | func (declarations DeclarationsByProperty) Swap(i, j int) { | ||
| 54 | declarations[i], declarations[j] = declarations[j], declarations[i] | ||
| 55 | } | ||
| 56 | |||
| 57 | // Implements sort.Interface | ||
| 58 | func (declarations DeclarationsByProperty) Less(i, j int) bool { | ||
| 59 | return declarations[i].Property < declarations[j].Property | ||
| 60 | } | ||
