
<erl>


box(Str) ->
    {'div',[{class,"box"}],
     {pre,[], yaws_api:htmlize(Str)}}.

tbox(T) ->
    box(lists:flatten(io_lib:format("~p",[T]))).


ssi(File) ->
    {'div',[{class,"box"}],
     {pre,[],
      {ssi, File,[],[]}}}.

ss(A, File) ->
    {ok, B} = file:read_file(
                filename:join([A#arg.docroot, File])),
    box(binary_to_list(B)).



out(A) ->
    [{ssi, "TAB.inc", "%%",[{"haxe_intro", "choosen"}]},
     {ehtml,
      {'div', [{id, "entry"}],

      [{h1, [], "haXe remoting"},

        {p, [],
        ["The yaws_rpc module has a haXe remoting adapter that enables "
         "Yaws to respond to respond to "
         "RPC requests from a client written in ",
         {a, [{href, "http://www.haxe.org"}], "haXe"},
          ". haXe is a versatile open source language that compiles to "
          "Flash, Javascript and NekoVM. ",
          "For more information on haXe, visit ",
          {a, [{href, "http://www.haxe.org/intro"}], "www.haxe.org/intro"}, "."]},
       {p, [],
        ["Implementing the server side of a haXe remoting interaction "
         "in Yaws is very similar to the one described in the ",
        {a, [{href, "json_intro.yaws"}], "Ajax/JSON RPC"}, " page. "
         "Most of the action takes place behind the scenes inside the "
         "the yaws_rpc module. The same types (array, struct, number "
         "and string) work for haXe remoting as for JSON RPC. "
         "There are just a few new things to keep in mind when using "
         "haXe remoting: "
        ]},
        {ol, [],
         [
          {li, [], {p, [], "Class objects and enums work with standard "
           "haXe remoting, but are not supported in Yaws. "
           "You should therefore rely on anonymous objects and "
           "signatures when designing your haXe remoting calls."}},
          {li, [], {p, [], "A Yaws RPC handler can \"throw an exception\" "
           "by returning {exception, Obj}, where Obj is any valid "
           "haXe remoting value."}},
          {li, [], {p, [], "haXe remoting has a few extra "
            "values, expressed by the atoms 'infinity', 'neg_infinity' "
            "and 'nan', corresponding to infinity, negative infinity "
            "and 'not a number.'"}}
         ]
        },
       {p, [], "Following is an example demonstrating the use of haXe "
        "remoting in yaws. The first code segment is the haXe client "
        "code, which invokes the 'echo' method in haxe_sample.yaws "
        "and displays the result:"},
       ss(A,"haxe_sample.html"),
       {p, [], ["On the server side, we have the file haxe_sample.yaws "
        "with the following code: "]},
       ss(A, "haxe_sample.yaws"),

       {p,[], "The two important lines on the server side are:"},
       {ol,[],
        [
         {li,[],
          {pre,[],"yaws_rpc:handler(A1, {haxe_sample, respond})."}},
         {li,[],
          {pre,[],"respond(State, {call, echo, Value} = _Request)"}}]},

       {p,[],
        "The first line tells Yaws to forward all RPC calls (this "
        "includes both haXe remoting and JSON RPC calls -- remember that "
        "the yaws_rpc module handles both RPC mechanisms transparently) "
        "to the \"respond\" function in the \"haxe_sample\" module. "},
        {p, [],
        "The second line tells Yaws to invoke this 'respond' function "
        "when the client requests the method 'echo', while passing "
        "the new state variable as the first argument to 'respond'. "
        "You should duplicate this line for every RPC method you "
        "wish to implement, replacing 'echo' with the method's name."},
       {p, [],
        "yaws_rpc optionally handles sessions for both JSON RPC and "
        "haXe remoting. To use sessions, invoke yaws_rpc:handler_session "
        "as shown in the JSON RPC documentation page."},

       {p, [],
          "If the response is in the form of {exception, Obj}, "
          "where Obj is any valid haXe remoting type, then the haXe client "
          "will invoke the 'onError' handler, with Obj passed as the "
          "parameter."},
        {p, [],
           "As with JSON RPC, both request and response values can be "
           "composed of nested tuples of the form"},
        box("{array, [Obj,...]}"),
        {p, [], "and/or "},
        box("{struct, [{prop, Val}...]}"),
        {p, [], "Now go have fun! :)"}
      ]}},

     {ssi, "END2",[],[]}
    ].




</erl>







