module OASISFileTemplate: sig
.. end
Generate files replacing parts of it
This module allow to generate files using template. Each template files
is split into three parts: an header, a body and a footer. We target at
changing the body part. If target file already exists, we load the header
and the footer from it. We merge the three parts and repalce the target
files.
There are some safety limits:
- embed a digest to check nothing has changed in the body
- if digest of the body has changed, create a backup
- if we cannot find OASIS_START/OASIS_STOP body section, leave the
file untouched
The whole module is not exported.
Author(s): Sylvain Le Gall
Comment definition.
: comment
.ml comments.
: comment
Shell comments.
: comment
Makefile comments.
: comment
OCamlbuild comments.
: comment
.bat file comments.
: comment
META file comments.
Template
type
line = string
type
body =
| |
NoBody |
| |
Body of line list |
| |
BodyWithDigest of Digest.t * line list |
type
template = {
}
val template_make : OASISUnixPath.host_filename ->
comment ->
line list ->
line list ->
line list -> template
template_make fn cmt header body footer
Create a template for which
target file is fn
.
val template_of_string_list : ctxt:OASISContext.t ->
template:bool ->
OASISUnixPath.host_filename ->
comment ->
line list -> template
template_of_string_list ~ctxt ~template fn cmt lst
Split a the list
lst
of
into an header, a body and a footer, using comment
cmt
to determine each
part. Set
~template
if this is an embedded template (i.e. not a file loaded
from disk). See
OASISFileTemplate.template_make
for other options.
val template_of_mlfile : OASISUnixPath.host_filename ->
line list ->
line list ->
line list -> template
template_of_ml_file fn
Create an OCaml file template taking into account
subtleties, like line modifier. See
OASISFileTemplate.template_make
for other options.
File generation
type
file_generate_change =
Describe what has been done to generate a file out of a template.
val file_rollback : ctxt:OASISContext.t -> file_generate_change -> unit
Reset to pristine a generated file.
val file_generate : ctxt:OASISContext.t ->
backup:bool ->
template -> file_generate_change
Generate a file using a template. Only the part between OASIS_START and
OASIS_STOP will be really replaced if the file exists. If the file doesn't
exist use the whole template.
Multiple templates management
exception AlreadyExists of OASISUnixPath.host_filename
Try to add a file that is already in the set
type
templates
Set of templates.
val empty : templates
No generated template files.
val find : OASISUnixPath.host_filename ->
templates -> template
Find a generated template file.
val add : template ->
templates -> templates
Add a generated template file.
val remove : OASISUnixPath.host_filename ->
templates -> templates
Remove a generated template file.
val replace : template ->
templates -> templates
Add or replace a generated template file.
val fold : (template -> 'a -> 'a) ->
templates -> 'a -> 'a
Fold over generated template files.