~alcinnz/haskell-stylist

ref: 2881aec48224a437d9a258a44637b7b0746057ae haskell-stylist/src/Stylish/Style/Selector.hs -rw-r--r-- 931 bytes
2881aec4 — Adrian Cochrane Implement simple facade over the rule stores. 5 years ago
                                                                                
7d540c43 Adrian Cochrane
2881aec4 Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
2881aec4 Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
7d540c43 Adrian Cochrane
d47030fd Adrian Cochrane
2881aec4 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Stylish.Style.Selector(
        QueryableStyleSheet(..), queryableStyleSheet,
        queryRules
    ) where

import Stylish.Style.Selector.Index
import Stylish.Style.Selector.Interpret
import Stylish.Style.Selector.Specificity
import Stylish.Style.Selector.Importance
import Stylish.Style.Selector.Common

import Stylish.Parse (StyleSheet(..))

ruleStore = ImportanceSplitter $ OrderedRuleStore (InterpretedRuleStore styleIndex) 0

data QueryableStyleSheet store = QueryableStyleSheet {
    store :: store,
    priority :: Int -- author vs user agent vs user styles
}

queryableStyleSheet = QueryableStyleSheet {store = ruleStore, priority = 0}

instance RuleStore s => StyleSheet (QueryableStyleSheet s) where
    addRule self@(QueryableStyleSheet store priority) rule = self {
            store = addStyleRule store priority $ styleRule' rule
        }

queryRules (QueryableStyleSheet store _) el = lookupRules store el