| 1 |
|
-- |
| 2 |
|
-- This file is part of FactorCSS |
| 3 |
|
-- Licensed under the MIT License, |
| 4 |
|
-- http://www.opensource.org/licenses/mit-license |
| 5 |
|
-- Copyright 2005 James Bursa <james@semichrome.net> |
| 6 |
|
-- |
| 7 |
|
|
| 8 |
-- Datatypes for CSS |
-- Datatypes for CSS |
| 9 |
|
|
| 10 |
module CSS where |
module CSS where |
| 11 |
import List |
import List |
| 12 |
|
import Numeric |
| 13 |
|
|
| 14 |
data Stylesheet |
data Stylesheet |
| 15 |
= Stylesheet |
= Stylesheet |
| 70 |
deriving Show |
deriving Show |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
is_ruleset :: Statement -> Bool |
| 74 |
|
is_ruleset (Ruleset sels decls) = True |
| 75 |
|
is_ruleset _ = False |
| 76 |
|
|
| 77 |
|
is_media :: Statement -> Bool |
| 78 |
|
is_media (Media media stmts) = True |
| 79 |
|
is_media _ = False |
| 80 |
|
|
| 81 |
|
is_page :: Statement -> Bool |
| 82 |
|
is_page (Page page decls) = True |
| 83 |
|
is_page _ = False |
| 84 |
|
|
| 85 |
|
|
| 86 |
show_stylesheet :: Stylesheet -> [String] |
show_stylesheet :: Stylesheet -> [String] |
| 87 |
show_stylesheet (Stylesheet c is ss) = show_charset c ++ |
show_stylesheet (Stylesheet c is ss) = show_charset c ++ |
| 88 |
map show_import (reverse is) ++ |
map show_import (reverse is) ++ |
| 98 |
|
|
| 99 |
show_statement :: Statement -> String |
show_statement :: Statement -> String |
| 100 |
show_statement (Ruleset ss ds) = |
show_statement (Ruleset ss ds) = |
| 101 |
(concat . intersperse ", " . map show_selector) ss ++ |
show_selectors ss ++ |
| 102 |
" { " ++ |
" { " ++ |
| 103 |
(concat . intersperse "; " . map show_declaration) ds ++ |
(concat . intersperse "; " . map show_declaration) ds ++ |
| 104 |
" }" |
" }" |
| 105 |
|
show_statement (Media media stmts) = |
| 106 |
|
"@media " ++ (concat . intersperse ", ") media ++ |
| 107 |
|
" {\n" ++ |
| 108 |
|
(unlines . map ('\t':) . map show_statement) stmts ++ |
| 109 |
|
"}" |
| 110 |
show_statement z = "(statement)" |
show_statement z = "(statement)" |
| 111 |
|
|
| 112 |
|
show_selectors :: [Selector] -> String |
| 113 |
|
show_selectors = concat . intersperse ", " . map show_selector |
| 114 |
|
|
| 115 |
show_selector :: Selector -> String |
show_selector :: Selector -> String |
| 116 |
show_selector [] = "" |
show_selector [] = "" |
| 117 |
show_selector ((ss, c):zs) = show_simple_selector ss ++ |
show_selector ((ss, c):zs) = show_simple_selector ss ++ |
| 120 |
|
|
| 121 |
show_simple_selector :: SimpleSelector -> String |
show_simple_selector :: SimpleSelector -> String |
| 122 |
show_simple_selector (Just s, ds) = s ++ (concat . map show_detail) ds |
show_simple_selector (Just s, ds) = s ++ (concat . map show_detail) ds |
| 123 |
|
show_simple_selector (Nothing, []) = "*" |
| 124 |
show_simple_selector (Nothing, ds) = (concat . map show_detail) ds |
show_simple_selector (Nothing, ds) = (concat . map show_detail) ds |
| 125 |
|
|
| 126 |
show_detail :: Detail -> String |
show_detail :: Detail -> String |
| 147 |
show_values = concat . intersperse " " . map show_value |
show_values = concat . intersperse " " . map show_value |
| 148 |
|
|
| 149 |
show_value :: Value -> String |
show_value :: Value -> String |
| 150 |
show_value (Number n) = show n |
show_value (Number n) = showFFloat Nothing n "" |
| 151 |
show_value (Percentage p) = show p ++ "%" |
show_value (Percentage p) = showFFloat Nothing p "%" |
| 152 |
show_value (Length l) = l |
show_value (Length l) = l |
| 153 |
show_value (Ems e) = show e ++ "em" |
show_value (Ems e) = showFFloat Nothing e "em" |
| 154 |
show_value (Exs x) = show x ++ "ex" |
show_value (Exs x) = showFFloat Nothing x "ex" |
| 155 |
show_value (Angle a) = a |
show_value (Angle a) = a |
| 156 |
show_value (Time t) = t |
show_value (Time t) = t |
| 157 |
show_value (Freq f) = f |
show_value (Freq f) = f |