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
5003457c
Commit
5003457c
authored
Oct 01, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --sort option
parent
23ce71c2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
main.ml
main.ml
+18
-2
util.ml
util.ml
+16
-0
No files found.
main.ml
View file @
5003457c
...
...
@@ -10,6 +10,7 @@ type args = {
shorthands
:
bool
;
duplicates
:
bool
;
echo
:
bool
;
sort
:
bool
;
}
let
parse_args
()
=
...
...
@@ -31,7 +32,11 @@ let parse_args () =
-d, --duplicates Prune duplicate properties (WARNING: may affect \
cross-browser hacks)
\n
\
-p, --pretty Shorthand for -c -s -d
\n
\
-e, --echo Just parse and pretty-print, no optimizations
\n
"
-e, --echo Just parse and pretty-print, no optimizations
\n
\
\n
\
Formatting options:
--sort Sort declarations in each selector group
\n
\
"
in
let
default_args
=
{
...
...
@@ -43,6 +48,7 @@ let parse_args () =
shorthands
=
false
;
duplicates
=
false
;
echo
=
false
;
sort
=
false
;
}
in
let
rec
handle
args
=
function
...
...
@@ -60,6 +66,8 @@ let parse_args () =
handle
{
args
with
simple
=
true
;
shorthands
=
true
;
duplicates
=
true
}
tl
|
(
"-e"
|
"--echo"
)
::
tl
->
handle
{
args
with
echo
=
true
}
tl
|
"--sort"
::
tl
->
handle
{
args
with
sort
=
true
}
tl
|
(
"-h"
|
"--help"
)
::
tl
->
prerr_string
usage
;
...
...
@@ -83,17 +91,24 @@ let parse_args () =
in
match
handle
default_args
(
List
.
tl
(
Array
.
to_list
Sys
.
argv
))
with
|
{
echo
=
true
;
_
}
as
args
->
{
args
with
whitespace
=
false
;
simple
=
false
;
shorthands
=
false
;
duplicates
=
false
}
|
{
whitespace
=
false
;
simple
=
false
;
shorthands
=
false
;
duplicates
=
false
;
echo
=
false
;
_
}
as
args
->
{
args
with
whitespace
=
true
;
simple
=
true
;
shorthands
=
true
;
duplicates
=
true
}
|
args
->
args
let
parse_files
=
function
...
...
@@ -131,6 +146,7 @@ let handle_args args =
|>
switch
args
.
simple
Simple
.
compress
|>
switch
args
.
duplicates
Duplicates
.
compress
|>
switch
args
.
shorthands
Shorthand
.
compress
|>
switch
args
.
sort
Util
.
sort_stylesheet
in
let
output
=
if
args
.
whitespace
...
...
util.ml
View file @
5003457c
...
...
@@ -231,3 +231,19 @@ let transform_stylesheet f stylesheet =
(* Expression identification *)
let
is_color
=
Color_names
.
is_color
(* Sorting declarations *)
let
sort_stylesheet
=
let
transform_sort_decls
=
function
|
Statement
(
Ruleset
(
selectors
,
decls
))
->
let
pattern
=
Str
.
regexp
"^
\\
([^-]+
\\
)-"
in
let
stem
x
=
if
Str
.
string_match
pattern
x
0
then
Str
.
matched_group
1
x
else
x
in
let
cmp
(
a
,
_
,
_
)
(
b
,
_
,
_
)
=
String
.
compare
(
stem
a
)
(
stem
b
)
in
Statement
(
Ruleset
(
selectors
,
List
.
stable_sort
cmp
decls
))
|
v
->
v
in
transform_stylesheet
transform_sort_decls
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