Browse Source

format

master
zapashcanon 12 months ago
parent
commit
f1c5909508
Signed by: zapashcanon GPG Key ID: 8981C3C62D1D28F1
  1. 61
      .ocamlformat
  2. 6
      src/any.ml
  3. 87
      src/directory.ml
  4. 16
      src/file.ml
  5. 5
      src/hize.ml
  6. 6
      src/html.ml

61
.ocamlformat

@ -0,0 +1,61 @@
version=0.18.0
align-cases=false
align-constructors-decl=false
align-variants-decl=false
assignment-operator=end-line
break-before-in=fit-or-vertical
break-cases=all
break-collection-expressions=fit-or-vertical
break-fun-decl=wrap
break-fun-sig=wrap
break-infix=wrap
break-infix-before-func=false
break-separators=before
break-sequences=true
break-string-literals=auto
break-struct=force
cases-exp-indent=2
cases-matching-exp-indent=normal
disambiguate-non-breaking-match=false
doc-comments=before
doc-comments-padding=2
doc-comments-tag-only=default
dock-collection-brackets=false
exp-grouping=preserve
extension-indent=2
field-space=loose
function-indent=2
function-indent-nested=never
if-then-else=k-r
indent-after-in=0
indicate-multiline-delimiters=space
indicate-nested-or-patterns=unsafe-no
infix-precedence=indent
leading-nested-match-parens=false
let-and=sparse
let-binding-indent=2
let-binding-spacing=compact
let-module=compact
margin=80
match-indent=0
match-indent-nested=never
max-indent=68
module-item-spacing=sparse
nested-match=wrap
ocp-indent-compat=false
parens-ite=false
parens-tuple=always
parens-tuple-patterns=multi-line-only
parse-docstrings=true
sequence-blank-line=preserve-one
sequence-style=terminator
single-case=compact
space-around-arrays=true
space-around-lists=true
space-around-records=true
space-around-variants=true
stritem-extension-indent=0
type-decl=sparse
type-decl-indent=2
wrap-comments=false
wrap-fun-args=true

6
src/any.ml

@ -4,4 +4,8 @@ let gen in_path out_path =
else if Utils.is_directory in_path then
Directory.gen in_path out_path
else
Utils.error (Format.sprintf "path `%s` doesn't exist or it isn't a directory nor a file and I don't know what to do with it" (Fpath.to_string in_path))
Utils.error
(Format.sprintf
"path `%s` doesn't exist or it isn't a directory nor a file and I \
don't know what to do with it"
(Fpath.to_string in_path) )

87
src/directory.ml

@ -1,47 +1,72 @@
let rec gen in_path out_path =
if not @@ Utils.is_directory in_path then
Utils.error (Format.sprintf "directory `%s` doesn't exist" (Fpath.to_string in_path));
Utils.error
(Format.sprintf "directory `%s` doesn't exist" (Fpath.to_string in_path));
let content =
match Bos.OS.Dir.contents ~dotfiles:true ~rel:true in_path with
| Ok content -> content
| Error _e -> Utils.error (Format.sprintf "can't get content of directory `%s`" (Fpath.to_string in_path))
| Error _e ->
Utils.error
(Format.sprintf "can't get content of directory `%s`"
(Fpath.to_string in_path) )
in
begin match Bos.OS.Dir.create ~path:true ~mode:0o755 out_path with
| Ok true -> ()
| Error _ | Ok false ->
Utils.error (Format.sprintf "can't create directory `%s` or it already exists" (Fpath.to_string out_path))
begin
match Bos.OS.Dir.create ~path:true ~mode:0o755 out_path with
| Ok true -> ()
| Error _
| Ok false ->
Utils.error
(Format.sprintf "can't create directory `%s` or it already exists"
(Fpath.to_string out_path) )
end;
let index_f, index_d = List.fold_left (fun (index_f, index_d) filename ->
let in_path = Fpath.append in_path filename in
if Utils.is_directory in_path then begin
gen in_path (Fpath.append out_path in_path);
index_f, ((filename, in_path)::index_d)
end else if Utils.is_file in_path then begin
let file_path = Fpath.v (Fpath.to_string filename ^ ".html") in
File.gen in_path (Fpath.append out_path file_path);
((filename, file_path)::index_f), index_d
end else
Utils.error (Format.sprintf "can't gen `%s`" (Fpath.to_string in_path))
) ([], [])
content
let index_f, index_d =
List.fold_left
(fun (index_f, index_d) filename ->
let in_path = Fpath.append in_path filename in
if Utils.is_directory in_path then begin
gen in_path (Fpath.append out_path in_path);
(index_f, (filename, in_path) :: index_d)
end else if Utils.is_file in_path then begin
let file_path = Fpath.v (Fpath.to_string filename ^ ".html") in
File.gen in_path (Fpath.append out_path file_path);
((filename, file_path) :: index_f, index_d)
end else
Utils.error
(Format.sprintf "can't gen `%s`" (Fpath.to_string in_path)) )
([], []) content
in
let index_f = List.map (fun (filename, path) ->
Format.sprintf {|<li><a href="%s">%s</a></li>|} (Fpath.to_string path) (Fpath.to_string filename)
) index_f in
let index_d = List.map (fun (filename, path) ->
Format.sprintf {|<li><a href="%s/index.html">%s</li>|} (Fpath.to_string path) (Fpath.to_string filename)
) index_d in
let index_f =
List.map
(fun (filename, path) ->
Format.sprintf {|<li><a href="%s">%s</a></li>|} (Fpath.to_string path)
(Fpath.to_string filename) )
index_f
in
let index_d =
List.map
(fun (filename, path) ->
Format.sprintf {|<li><a href="%s/index.html">%s</li>|}
(Fpath.to_string path) (Fpath.to_string filename) )
index_d
in
let pp_list = Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "") Format.pp_print_string in
let content = Format.asprintf "<ul>%a%a</ul>" pp_list index_d pp_list index_f in
let pp_list =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt "")
Format.pp_print_string
in
let content =
Format.asprintf "<ul>%a%a</ul>" pp_list index_d pp_list index_f
in
let content = Format.asprintf "%a" Html.pp content in
let index_path = Fpath.append out_path (Fpath.v "index.html") in
begin match Bos.OS.File.write index_path content with
| Ok () -> ()
| Error _e -> Utils.error (Format.sprintf "can't write to file `%s`" (Fpath.to_string index_path))
end
match Bos.OS.File.write index_path content with
| Ok () -> ()
| Error _e ->
Utils.error
(Format.sprintf "can't write to file `%s`" (Fpath.to_string index_path))

16
src/file.ml

@ -1,12 +1,18 @@
let gen in_path out_path =
if not @@ Utils.is_file in_path then
Utils.error (Format.sprintf "file `%s` doesn't exist" (Fpath.to_string in_path));
Utils.error
(Format.sprintf "file `%s` doesn't exist" (Fpath.to_string in_path));
let content = match Bos.OS.File.read in_path with
| Ok content -> Format.asprintf "%a" Html.pp content
| Error _e -> Utils.error (Format.sprintf "can't read file `%s`" (Fpath.to_string in_path))
let content =
match Bos.OS.File.read in_path with
| Ok content -> Format.asprintf "%a" Html.pp content
| Error _e ->
Utils.error
(Format.sprintf "can't read file `%s`" (Fpath.to_string in_path))
in
match Bos.OS.File.write out_path content with
| Ok () -> ()
| Error _e -> Utils.error (Format.sprintf "can't write to file `%s`" (Fpath.to_string out_path))
| Error _e ->
Utils.error
(Format.sprintf "can't write to file `%s`" (Fpath.to_string out_path))

5
src/hize.ml

@ -1,7 +1,10 @@
open Hize
let () =
if Array.length Sys.argv <> 3 then Utils.error (Format.sprintf "usage: %s <input file or directory> <output>" Sys.argv.(0));
if Array.length Sys.argv <> 3 then
Utils.error
(Format.sprintf "usage: %s <input file or directory> <output>"
Sys.argv.(0) );
let in_path = Fpath.(v Sys.argv.(1)) in
let out_path = Fpath.(v Sys.argv.(2)) in

6
src/html.ml

@ -1,5 +1,6 @@
let pp fmt content =
Format.fprintf fmt {|<!DOCTYPE html>
Format.fprintf fmt
{|<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
@ -11,4 +12,5 @@ let pp fmt content =
<body>
<pre>%s</pre>
</body>
</html>|} content
</html>|}
content

Loading…
Cancel
Save