aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-05-06 15:27:30 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-05-06 15:27:30 -0400
commit6d454de6e5954f0e09adafca3141b5394bbc5140 (patch)
treeae765a83259f804f7dc7a8eeede51faec284ef07 /src
parent85341a176564ac3ce4e0a4ec4612262e2945660a (diff)
New optional suffice for 'rewrite' in .urp files: [-]
Diffstat (limited to 'src')
-rw-r--r--src/compiler.sml13
-rw-r--r--src/settings.sig2
-rw-r--r--src/settings.sml12
3 files changed, 19 insertions, 8 deletions
diff --git a/src/compiler.sml b/src/compiler.sml
index dbc478f0..bd6ef493 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -426,7 +426,8 @@ fun parseUrp' accLibs fname =
jsFuncs = [],
rewrites = [{pkind = Settings.Any,
kind = Settings.Prefix,
- from = capitalize (OS.Path.file fname) ^ "/", to = ""}],
+ from = capitalize (OS.Path.file fname) ^ "/", to = "",
+ hyphenate = false}],
filterUrl = [],
filterMime = [],
filterRequest = [],
@@ -774,17 +775,19 @@ fun parseUrp' accLibs fname =
| "jsFunc" => jsFuncs := ffiM () :: !jsFuncs
| "rewrite" =>
let
- fun doit (pkind, from, to) =
+ fun doit (pkind, from, to, hyph) =
let
val pkind = parsePkind pkind
val (kind, from) = parseFrom from
in
- rewrites := {pkind = pkind, kind = kind, from = from, to = to} :: !rewrites
+ rewrites := {pkind = pkind, kind = kind, from = from, to = to, hyphenate = hyph} :: !rewrites
end
in
case String.tokens Char.isSpace arg of
- [pkind, from, to] => doit (pkind, from, to)
- | [pkind, from] => doit (pkind, from, "")
+ [pkind, from, to, "[-]"] => doit (pkind, from, to, true)
+ | [pkind, from, "[-]"] => doit (pkind, from, "", true)
+ | [pkind, from, to] => doit (pkind, from, to, false)
+ | [pkind, from] => doit (pkind, from, "", false)
| _ => ErrorMsg.error "Bad 'rewrite' syntax"
end
| "allow" =>
diff --git a/src/settings.sig b/src/settings.sig
index 4b1ac8ac..7140c645 100644
--- a/src/settings.sig
+++ b/src/settings.sig
@@ -97,7 +97,7 @@ signature SETTINGS = sig
type rule = { action : action, kind : pattern_kind, pattern : string }
datatype path_kind = Any | Url | Table | Sequence | View | Relation | Cookie | Style
- type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string }
+ type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string, hyphenate : bool }
(* Rules for rewriting URLs from canonical forms *)
val setRewriteRules : rewrite list -> unit
diff --git a/src/settings.sml b/src/settings.sml
index 78b02126..a9c2315c 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -326,7 +326,7 @@ datatype action = Allow | Deny
type rule = { action : action, kind : pattern_kind, pattern : string }
datatype path_kind = Any | Url | Table | Sequence | View | Relation | Cookie | Style
-type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string }
+type rewrite = { pkind : path_kind, kind : pattern_kind, from : string, to : string, hyphenate : bool }
val rewrites = ref ([] : rewrite list)
@@ -357,7 +357,15 @@ fun rewrite pk s =
if subsume (pk, #pkind rewr) then
case match () of
NONE => rew ls
- | SOME suffixStart => #to rewr ^ String.extract (s, suffixStart, NONE)
+ | SOME suffixStart =>
+ let
+ val s = #to rewr ^ String.extract (s, suffixStart, NONE)
+ in
+ if #hyphenate rewr then
+ String.translate (fn #"_" => "-" | ch => str ch) s
+ else
+ s
+ end
else
rew ls
end