Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mincss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
mincss
Commits
24707b18
Commit
24707b18
authored
Oct 01, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added number minification
parent
64d75979
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
stringify.ml
stringify.ml
+18
-7
No files found.
stringify.ml
View file @
24707b18
...
...
@@ -12,15 +12,15 @@ let rec cat sep fn = function
|
[
hd
]
->
fn
hd
|
hd
::
tl
->
fn
hd
^
sep
^
cat
sep
fn
tl
(*
* Pretty-printing
*)
let
string_of_num
n
=
if
float_of_int
(
int_of_float
n
)
=
n
then
string_of_int
(
int_of_float
n
)
else
string_of_float
n
(*
* Pretty-printing
*)
let
rec
string_of_expr
=
function
|
Ident
id
->
id
|
Strlit
str
->
"
\"
"
^
str
^
"
\"
"
...
...
@@ -146,12 +146,23 @@ let string_of_stylesheet = cat "\n\n" string_of_statement
* Minified stringification
*)
let
minify_num
n
=
if
float_of_int
(
int_of_float
n
)
=
n
then
string_of_int
(
int_of_float
n
)
else
if
n
<
1
.
0
&&
n
>
-
1
.
0
then
let
s
=
string_of_float
n
in
String
.
sub
s
1
(
String
.
length
s
-
1
)
else
string_of_float
n
let
rec
minify_expr
=
function
|
Concat
values
->
cat
" "
minify_expr
values
|
Function
(
name
,
arg
)
->
name
^
"("
^
minify_expr
arg
^
")"
|
Unary
(
op
,
opnd
)
->
op
^
minify_expr
opnd
|
Nary
(
","
,
opnds
)
->
cat
","
minify_expr
opnds
|
Nary
(
op
,
opnds
)
->
cat
op
minify_expr
opnds
|
Number
(
n
,
None
)
->
minify_num
n
|
Number
(
n
,
Some
u
)
->
minify_num
n
^
u
|
expr
->
string_of_expr
expr
let
minify_declaration
(
name
,
value
,
important
)
=
...
...
@@ -181,9 +192,9 @@ let rec minify_statement = function
"@media"
^
prefix_space
(
cat
","
minify_media_query
queries
)
^
"{"
^
cat
""
minify_statement
rulesets
^
"}"
|
Import
(
target
,
[]
)
->
"@import "
^
string_of
_expr
target
^
";"
"@import "
^
minify
_expr
target
^
";"
|
Import
(
target
,
queries
)
->
"@import "
^
string_of
_expr
target
^
" "
^
"@import "
^
minify
_expr
target
^
" "
^
cat
","
string_of_media_query
queries
^
";"
|
Page
(
None
,
decls
)
->
"@page{"
^
cat
";"
minify_declaration
decls
^
"}"
...
...
@@ -191,7 +202,7 @@ let rec minify_statement = function
"@page :"
^
pseudo
^
"{"
^
cat
";"
minify_declaration
decls
^
"}"
|
Font_face
decls
->
let
minify_descriptor_declaration
(
name
,
value
)
=
name
^
":"
^
string_of
_expr
value
name
^
":"
^
minify
_expr
value
in
"@font-face{"
^
cat
";"
minify_descriptor_declaration
decls
^
"}"
|
Keyframes
(
prefix
,
id
,
rules
)
->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment