Skip to content

Commit

Permalink
[enhance] xhtml.opa: added a function to update an xhtml attribute by…
Browse files Browse the repository at this point in the history
… appending a new value to it (usefull for updating class attribute especially)
  • Loading branch information
Frederic Ye committed Oct 18, 2011
1 parent b6f4e6c commit 1ad0ca5
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions stdlib/core/xhtml/xhtml.opa
Expand Up @@ -1155,6 +1155,25 @@ Xhtml =
end
aux(x)
/**
* Update (by appending) an attribute to an xhtml node, add it if not already present
*/
update_attribute(name: string, value: string, x:xhtml):xhtml =
rec aux(x)=
match x : xhtml
{fragment=[x]} -> aux(x)
{~args namespace=_ tag=_ content=_ specific_attributes=_} as x->
args = match find_attr(name,args) with
{some=val} ->
value = "{val} {value}"
l = remove_attr(name,args)
[{~name namespace="" ~value}|l]
{none} -> [{~name namespace="" ~value}|args]
@opensums({x with ~args})
_ -> x
end
aux(x)
/**
* Set an attribute to an xhtml node. Replace if already_exists
*/
Expand Down

0 comments on commit 1ad0ca5

Please sign in to comment.