Skip to content

Commit

Permalink
[feature] WFormBuilder: Skeleton for the FormBuilder's Template engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
akoprow committed Jul 25, 2011
1 parent 812b329 commit c3d3ebe
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/web/template/template.opa
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* functions and implement parse (conversion from xml to content) and export functions.
* {[
* my_namespace = "http://response.xsd"
*
*
* my_engine = { Template.empty with
* // Parse function. It takes the xmlns, and a xmlns parse which is able to process xmlns into Template.content.
* // If the current engine is able to process the current, it should create a Template.content. Otherwise, it should fail.
Expand Down
74 changes: 74 additions & 0 deletions stdlib/widgets/formbuilder/formbuilder_template_engine.opa
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/

package widgets.formbuilder

import stdlib.*
import widgets.core

/**
* @author Adam Koprowski
* @category widget
* @stability experimental [WIP]
*
*
* {1 About this module}
*
* This module defines a Template engine, allowing to easily build forms
* with templating machinery.
**/

type FormBuilderTemplate.tag = { form }

FormBuilderTemplate =

my_ns : Uri.uri =
Uri.of_string("http://opalang.org/template/FormBuilder")
|> Option.get

FB = WFormBuilder

{{

@private
parse(_conf, {~ns; ~tag; args=_; children=_})
: outcome(Template.content(either(FormBuilderTemplate.tag, 'b)), Template.failure) =
if ns != my_ns then
{ failure = { namespace_not_supported_by_engine = "Got {ns}, expected {my_ns}" }}
else
match tag with
| "form" -> { success = Template.to_extension({form}) }
| _ -> { failure = { unsupported_tag; ~ns; ~tag } }

@private
export(content, _) =
match Template.from_extension(content) with
| {none} -> { failure = { unknown_tag = "Expected extension" } }
| {some=fb_tag} ->
match fb_tag with
| {form} ->
fields = []
spec = FB.create_specification(fields)
form = FB.create_form(spec)
{success = form}

engine : Template.engine =
{ Template.empty with ~parse ~export }

}}

0 comments on commit c3d3ebe

Please sign in to comment.