Documentation
¶
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func ClearFontCache()
- func ConvertColorToRGBA(cssString string) (*color.RGBA, error)
- func ConvertUnitToPx(fontsize int, percentbasis int, cssString string) (int, error)
- func IsBorderStyle(s string) bool
- func IsColor(c string) bool
- func IsLength(l string) bool
- func IsPercentage(p string) bool
- func IsURL(u string) bool
- func MustAsset(name string) []byte
- func ParseBlock(val string) map[StyleAttribute]StyleValue
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type CSSSelector
- type FontFamily
- type State
- type StyleAttribute
- type StyleRule
- type StyleSource
- type StyleValue
- type StyledElement
- func (e *StyledElement) AddStyle(s StyleRule)
- func (e *StyledElement) ClearStyles()
- func (e *StyledElement) DisplayProp() string
- func (e *StyledElement) GetAttribute(attr string) StyleValue
- func (e StyledElement) GetBackgroundImage() (string, error)
- func (e StyledElement) GetColor(defaultColour color.Color) (color.Color, error)
- func (e StyledElement) GetFontFace(fsize int, fontFamily FontFamily, weight font.Weight, style font.Style) font.Face
- func (e StyledElement) GetFontSize() (int, error)
- func (e StyledElement) MergeStyles(other ...*StyledElement) StyledElement
- func (e *StyledElement) SetFontSize(size int)
- func (e *StyledElement) SortStyles() error
- func (e StyledElement) String() string
- type Stylesheet
- Bugs
Constants ¶
const DefaultCSS = `` /* 2776-byte string literal not displayed */
Variables ¶
var ( NoStyles = errors.New("No styles to apply") InheritValue = errors.New("Value should be inherited") )
var DefaultFontSize int
var PixelsPerPt float64
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/
foo.txt
img/
a.png
b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func ClearFontCache ¶
func ClearFontCache()
func ConvertUnitToPx ¶
func IsBorderStyle ¶
func IsPercentage ¶
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func ParseBlock ¶
func ParseBlock(val string) map[StyleAttribute]StyleValue
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type CSSSelector ¶
func (CSSSelector) NumberAttrs ¶
func (s CSSSelector) NumberAttrs() int
func (CSSSelector) NumberClasses ¶
func (s CSSSelector) NumberClasses() int
func (CSSSelector) NumberElements ¶
func (s CSSSelector) NumberElements() int
func (CSSSelector) NumberIDs ¶
func (s CSSSelector) NumberIDs() int
func (CSSSelector) NumberPseudo ¶
func (s CSSSelector) NumberPseudo() int
func (CSSSelector) String ¶
func (c CSSSelector) String() string
type FontFamily ¶
type FontFamily string
type StyleAttribute ¶
type StyleAttribute string
type StyleRule ¶
type StyleRule struct {
Selector CSSSelector
Name StyleAttribute
Value StyleValue
Src StyleSource
}
type StyleSource ¶
type StyleSource uint8
const ( UnknownSrc StyleSource = iota UserAgentSrc UserSrc AuthorSrc InlineStyleSrc )
func (StyleSource) String ¶
func (s StyleSource) String() string
type StyleValue ¶
func NewPxValue ¶
func NewPxValue(x int) StyleValue
func NewValue ¶
func NewValue(val string) StyleValue
func (StyleValue) String ¶
func (sv StyleValue) String() string
type StyledElement ¶
type StyledElement struct {
// CSS Level 1 attributes
// Shorthand attributes are commented out, because
// there's not any time in code you would want them
// instead of the expanded versions..
FontFamily StyleValue
FontStyle StyleValue
FontVariant StyleValue
FontWeight StyleValue
FontSize StyleValue
Color StyleValue
BackgroundColor StyleValue
BackgroundImage StyleValue
BackgroundRepeat StyleValue
BackgroundAttachment StyleValue
BackgroundPosition StyleValue
WordSpacing StyleValue
LetterSpacing StyleValue
TextDecoration StyleValue
VerticalAlign StyleValue
TextTransform StyleValue
TextAlign StyleValue
TextIndent StyleValue
LineHeight StyleValue
MarginTop StyleValue
MarginRight StyleValue
MarginBottom StyleValue
MarginLeft StyleValue
PaddingTop StyleValue
PaddingRight StyleValue
PaddingBottom StyleValue
PaddingLeft StyleValue
BorderTopWidth StyleValue
BorderTopColor StyleValue
BorderTopStyle StyleValue
BorderBottomWidth StyleValue
BorderBottomColor StyleValue
BorderBottomStyle StyleValue
BorderLeftWidth StyleValue
BorderLeftColor StyleValue
BorderLeftStyle StyleValue
BorderRightWidth StyleValue
BorderRightColor StyleValue
BorderRightStyle StyleValue
Width StyleValue
Height StyleValue
Float StyleValue
Clear StyleValue
Display StyleValue
WhiteSpace StyleValue
ListStyleType StyleValue
ListStyleImage StyleValue
ListStylePosition StyleValue
// New CSS Level 2 Attributes
// Table related properties
TableLayout StyleValue
BorderCollapse StyleValue
BorderSpacing StyleValue
EmptyCells StyleValue
CaptionSide StyleValue
// Visual Formatting related properties
Position StyleValue
Top StyleValue
Bottom StyleValue
Left StyleValue
Right StyleValue
Overflow StyleValue
Visibility StyleValue
Clip StyleValue
ZIndex StyleValue
MinHeight StyleValue
MaxHeight StyleValue
MinWidth StyleValue
MaxWidth StyleValue
// Generated content related properties
Content StyleValue
CounterIncrement StyleValue
CounterReset StyleValue
Quotes StyleValue
// UI Related properties
Cursor StyleValue
// Other
Direction StyleValue
UnicodeBidi StyleValue
// contains filtered or unexported fields
}
A StyleElement is anything that has CSS rules applied to it.
func (*StyledElement) AddStyle ¶
func (e *StyledElement) AddStyle(s StyleRule)
func (*StyledElement) ClearStyles ¶
func (e *StyledElement) ClearStyles()
func (*StyledElement) DisplayProp ¶
func (e *StyledElement) DisplayProp() string
func (*StyledElement) GetAttribute ¶
func (e *StyledElement) GetAttribute(attr string) StyleValue
func (StyledElement) GetBackgroundImage ¶
func (e StyledElement) GetBackgroundImage() (string, error)
Returns the URL as a string, and an error. Retrieving the URL is left as an exercise for the caller, since the CSS package doesn't know the host/path to resolve relative URLs
func (StyledElement) GetFontFace ¶
func (e StyledElement) GetFontFace(fsize int, fontFamily FontFamily, weight font.Weight, style font.Style) font.Face
func (StyledElement) GetFontSize ¶
func (e StyledElement) GetFontSize() (int, error)
func (StyledElement) MergeStyles ¶
func (e StyledElement) MergeStyles(other ...*StyledElement) StyledElement
func (*StyledElement) SetFontSize ¶
func (e *StyledElement) SetFontSize(size int)
func (*StyledElement) SortStyles ¶
func (e *StyledElement) SortStyles() error
SortStyles will sort the rules on this element according to the CSS spec, which states
1. Find all declarations that apply too element/property (already done when this is called) 2. Sort according to importance (normal or important) and origin (author, user, or user agent). In ascending order of precedence:
- user agent declarations (defaults)
- user normal declrations (don't exist)
- author normal declarations
- author important declarations
- user important declarations (don't exist)
3. Sort rules with the same importance and origin by specificity of selector: more specific selectors will override more general ones. Pseudo-elements and pseudo-classes are counted as normal elements and classes, respectively. 4. Finally, sort by order specified: if two declarations have the same weight, origin, and specificity, the latter specified wins. Declarations in imported stylesheets are considered to be before any declaration in the style sheet itself BUG(driusan): The final tie break is not implemented
func (StyledElement) String ¶
func (e StyledElement) String() string
type Stylesheet ¶
type Stylesheet []StyleRule
func ExtractStyles ¶
func ExtractStyles(n *html.Node, loader net.URLReader, context *url.URL, orderNo uint) (styles Stylesheet, nextOrderNo uint)
ExtractStyles takes an html Node as input, and extracts the unparsed text from any <style> elements in the HTML, returning the string of the style body.
func ParseStylesheet ¶
func ParseStylesheet(val string, src StyleSource, importLoader net.URLReader, urlContext *url.URL, orderNo uint) (styles Stylesheet, nextOrderNoStart uint)
Notes ¶
Bugs ¶
The final tie break is not implemented