Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 127 lines (99 sloc) 4.458 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

<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>







Something went wrong with that request. Please try again.