Skip to content

Commit

Permalink
Reorganize Action (into qualified subdir)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvw committed Jul 31, 2024
1 parent af36a9a commit f9d7a83
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 112 deletions.
4 changes: 2 additions & 2 deletions bin/ring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ let run_build target source log_level =
let source = source
let target = target
end) in
Yocaml_eio.run ~level:log_level (Gem.Action.process_all (module Resolver))
Yocaml_eio.run ~level:log_level (Gem.Action.All.run (module Resolver))

let run_watch target source log_level port =
let module Resolver = Gem.Resolver.Make (struct
let source = source
let target = target
end) in
Yocaml_eio.serve ~target:Resolver.target ~level:log_level ~port
(Gem.Action.process_all (module Resolver))
(Gem.Action.All.run (module Resolver))

open Cmdliner

Expand Down
106 changes: 0 additions & 106 deletions lib/action.ml

This file was deleted.

4 changes: 0 additions & 4 deletions lib/action.mli

This file was deleted.

20 changes: 20 additions & 0 deletions lib/action/all.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let init_message (module R : Sigs.RESOLVER) =
Yocaml.Eff.logf ~level:`Debug "ring.muhokama [source: `%a`, target: `%a`]"
Yocaml.Path.pp R.source Yocaml.Path.pp R.target

let final_message _cache = Yocaml.Eff.log ~level:`Debug "ring.muhokama done"

let run (module R : Sigs.RESOLVER) () =
let open Yocaml.Eff in
let* () = init_message (module R) in
let* cache, chain = Init.run (module R) in
return cache
>>= Cname.run (module R)
>>= Fonts.run (module R)
>>= Css.run (module R)
>>= Images.run (module R)
>>= Opml.run (module R) chain
>>= Chain.run (module R) chain
>>= Index.run (module R) chain
>>= Yocaml.Action.store_cache R.Target.cache
>>= final_message
3 changes: 3 additions & 0 deletions lib/action/all.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** The global process that executes all actions sequentially. *)

val run : (module Sigs.RESOLVER) -> unit -> unit Yocaml.Eff.t
8 changes: 8 additions & 0 deletions lib/action/batch_copy.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let has_extension ext_list path =
List.exists (fun ext -> Yocaml.Path.has_extension ext path) ext_list

let run ?extension ~source ~target cache =
let where = Option.map (fun ext -> has_extension ext) extension in
Yocaml.Action.batch ~only:`Files ?where source
(Yocaml.Action.copy_file ~into:target)
cache
8 changes: 8 additions & 0 deletions lib/action/batch_copy.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(** An action that initiates the copying of files from a source directory to a
target directory. *)

val run :
?extension:string list ->
source:Yocaml.Path.t ->
target:Yocaml.Path.t ->
Yocaml.Action.t
23 changes: 23 additions & 0 deletions lib/action/chain.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let member (module R : Sigs.RESOLVER) pred_or_succ current_member target_member
=
let target =
R.Target.member_redirection
~id:(Model.Member.id current_member)
pred_or_succ
in
Yocaml.Action.write_static_file target
(let open Yocaml.Task in
R.track_common_dependencies
>>> const target_member
>>> empty_body ()
>>> Yocaml_jingoo.Pipeline.as_template
(module Model.Member)
(R.Source.template "redirect.html")
>>> drop_first ())

let run (module R : Sigs.RESOLVER) chain =
let member = member (module R) in
Yocaml.Action.batch_list (Model.Chain.to_list chain)
(fun (curr, (pred, succ)) cache ->
let open Yocaml.Eff in
cache |> member `Pred curr pred >>= member `Succ curr succ)
3 changes: 3 additions & 0 deletions lib/action/chain.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that builds the chain of links for each member. *)

val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t
2 changes: 2 additions & 0 deletions lib/action/cname.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let run (module R : Sigs.RESOLVER) =
Yocaml.Action.copy_file ~into:R.Target.root R.Source.cname
3 changes: 3 additions & 0 deletions lib/action/cname.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that copies the CNAME of the existing webring. *)

val run : (module Sigs.RESOLVER) -> Yocaml.Action.t
2 changes: 2 additions & 0 deletions lib/action/css.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let run (module R : Sigs.RESOLVER) =
Batch_copy.run ~extension:[ "css" ] ~source:R.Source.css ~target:R.Target.css
3 changes: 3 additions & 0 deletions lib/action/css.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that copies all the CSS files from the source to the target. *)

val run : (module Sigs.RESOLVER) -> Yocaml.Action.t
3 changes: 3 additions & 0 deletions lib/action/fonts.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let run (module R : Sigs.RESOLVER) =
Batch_copy.run ~extension:[ "woff2" ] ~source:R.Source.fonts
~target:R.Target.fonts
3 changes: 3 additions & 0 deletions lib/action/fonts.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that copies all the font files from the source to the target. *)

val run : (module Sigs.RESOLVER) -> Yocaml.Action.t
5 changes: 5 additions & 0 deletions lib/action/images.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let run (module R : Sigs.RESOLVER) cache =
(* We pass [cache] in order to add more rules. *)
cache
|> Batch_copy.run ~extension:[ "svg"; "png" ] ~source:R.Source.static_images
~target:R.Target.images
3 changes: 3 additions & 0 deletions lib/action/images.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that copies all the images files from the source to the target. *)

val run : (module Sigs.RESOLVER) -> Yocaml.Action.t
13 changes: 13 additions & 0 deletions lib/action/index.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let run (module R : Sigs.RESOLVER) _chain =
Yocaml.Action.write_static_file R.Target.index
(let open Yocaml.Task in
R.track_common_dependencies
>>> Yocaml.Pipeline.track_file R.Source.members
>>> Yocaml_yaml.Pipeline.read_file_with_metadata
(module Model.Page)
R.Source.index
>>> Yocaml_omd.content_to_html ()
>>> Yocaml_jingoo.Pipeline.as_template
(module Model.Page)
(R.Source.template "layout.html")
>>> drop_first ())
3 changes: 3 additions & 0 deletions lib/action/index.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that builds the webring index. *)

val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t
22 changes: 22 additions & 0 deletions lib/action/init.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let run (module R : Sigs.RESOLVER) =
let open Yocaml.Eff in
let* cache = Yocaml.Action.restore_cache ~on:`Target R.Target.cache in
let* chain =
Yocaml_yaml.Eff.read_file_as_metadata
(module Model.Chain.Metadata)
~on:`Source R.Source.chain
in
let+ cache, members =
Yocaml.Action.fold ~only:`Files
~where:(Yocaml.Path.has_extension "yml")
~state:[] R.Source.members
(fun path state cache ->
let+ member =
Yocaml_yaml.Eff.read_file_as_metadata
(module Model.Member)
~on:`Source path
in
(cache, member :: state))
cache
in
(cache, Model.Chain.init ~chain ~members)
5 changes: 5 additions & 0 deletions lib/action/init.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(** An action (not in the Yocaml sense) which initializes the cache and builds
the chain. *)

val run :
(module Sigs.RESOLVER) -> (Yocaml.Cache.t * Model.Chain.t) Yocaml.Eff.t
7 changes: 7 additions & 0 deletions lib/action/opml.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let run (module R : Sigs.RESOLVER) chain =
Yocaml.Action.write_static_file R.Target.ring_opml
(let open Yocaml.Task in
R.track_common_dependencies
>>> Yocaml.Pipeline.track_file R.Source.members
>>> const chain
>>> Model.Chain.to_opml)
3 changes: 3 additions & 0 deletions lib/action/opml.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(** An action that builds the OPML file for the rss/atom feeds of ring members. *)

val run : (module Sigs.RESOLVER) -> Model.Chain.t -> Yocaml.Action.t

0 comments on commit f9d7a83

Please sign in to comment.