Author: jfarrell
Date: Thu Aug 30 04:32:21 2012
New Revision: 1378799
URL: http://svn.apache.org/viewvc?rev=1378799&view=rev
Log:
Updating Thrift website to add new tutorial layout and update OS X install.
Added:
thrift/site/layouts/tutorial_intro.md
Modified:
thrift/site/Gemfile
thrift/site/content/docs/install/os_x.md
thrift/site/content/tutorial.md
thrift/site/content/tutorial/js.md
thrift/site/publish/docs/install/os_x/index.html
thrift/site/publish/tutorial/index.html
thrift/site/publish/tutorial/js/index.html
Modified: thrift/site/Gemfile
URL:
http://svn.apache.org/viewvc/thrift/site/Gemfile?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/Gemfile (original)
+++ thrift/site/Gemfile Thu Aug 30 04:32:21 2012
@@ -1,11 +1,12 @@
source "http://rubygems.org"
gem 'rake'
-gem 'nanoc3'
+gem 'nanoc3', '=3.3.0'
gem 'redcarpet'
gem 'coderay'
gem 'adsf'
gem 'nokogiri'
gem 'less'
gem 'mime-types'
+gem 'therubyracer'
Modified: thrift/site/content/docs/install/os_x.md
URL:
http://svn.apache.org/viewvc/thrift/site/content/docs/install/os_x.md?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/content/docs/install/os_x.md (original)
+++ thrift/site/content/docs/install/os_x.md Thu Aug 30 04:32:21 2012
@@ -6,22 +6,22 @@ kind: doc
The following command install all the required tools and libraries to build
and install the Apache Thrift compiler on a OS X based system.
### Install Boost
-Download the boost library and bjam installer from
[boost.org](http://www.boost.org) untar and place bjam in the boost folder and
then compile with
+Download the boost library from [boost.org](http://www.boost.org) untar
compile with
- sudo ./bjam toolset=darwin link=shared threading=multi
runtime-link=shared variant=release address-model=64 stage install
+ ./bootstrap.sh
+ sudo ./b2 threading=multi address-model=64 variant=release stage install
### Install libevent
Download [libevent](http://monkey.org/~provos/libevent/), untar and compile
with
- ./configure --prefix=/usr/local --disable-static
+ ./configure --prefix=/usr/local
make
sudo make install
### Building Apache Thrift
Download the latest version of [Apache Thrift](/download/), untar and compile
with
- ./configure --prefix=/usr/local/ --with-boost=/usr/local
--with-libevent=/usr/local --disable-static
-
+ ./configure --prefix=/usr/local/ --with-boost=/usr/local
--with-libevent=/usr/local
## Additional reading
Modified: thrift/site/content/tutorial.md
URL:
http://svn.apache.org/viewvc/thrift/site/content/tutorial.md?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/content/tutorial.md (original)
+++ thrift/site/content/tutorial.md Thu Aug 30 04:32:21 2012
@@ -4,27 +4,29 @@ title: "Tutorial"
## Apache Thrift Tutorial
----
-* ###Download Apache Thrift
+* ### Download Apache Thrift
To get started, [download](/download/) a copy of Thrift.
-* ###Build and Install the Apache Thrift compiler
+* ### Build and Install the Apache Thrift compiler
You will then need to build the Apache Thrift compiler and install it.
See the [installing Thrift](/docs/install/) guide for any help with this step.
-* ###Writing a .thrift file
- After the Thrift compiler is installed you will need to create a thrift
file. This file is an [interface definition](/docs/idl/) made up of [thrift
types](/docs/types/) and Services. The services you define in this file are
implemented by the server and are called by any clients. The Thrift compiler is
used to generate your Thrift File into source code which is used by the
different client libraries and the server you write. To generate the source
from a thrift file run
+* ### Writing a .thrift file
+ After the Thrift compiler is installed you will need to create a thrift
file. This file is an [interface definition](/docs/idl/) made up of [thrift
types](/docs/types/) and Services. The services you define in this file are
implemented by the server and are called by any clients.
+
+* ### Generate Thrift file to source code
+The Thrift compiler is used to generate your Thrift File into source code
which is used by the different client libraries and the server you write. To
generate the source from a thrift file run
thrift --gen <language> <Thrift filename>
- The sample tutorial.thrift file used for all the client and server
tutorials can be found
[here](http://svn.apache.org/repos/asf/thrift/trunk/tutorial/).
+ The sample
[tutorial.thrift](http://svn.apache.org/repos/asf/thrift/trunk/tutorial/tutorial.thrift)
file defines a basic calculator service. This will be used to demonstrate both
the client and server. To generate the tutorial.thrift file into source code
use the Thrift generator and run
-* ###Examples Clients and Servers
-
- <ul>
- <% @item.children.sort_by { |i| i[:title].downcase }.each do |docs| %>
- <li>
- <a href="<%= docs.path %>"><%= docs[:title] %></a>
- </li>
- <% end %>
- </ul>
+## Examples Clients and Servers
+<ul>
+<% @item.children.sort_by { |i| i[:title].downcase }.each do |docs| %>
+ <li>
+ <a href="<%= docs.path %>"><%= docs[:title] %></a>
+ </li>
+<% end %>
+</ul>
Modified: thrift/site/content/tutorial/js.md
URL:
http://svn.apache.org/viewvc/thrift/site/content/tutorial/js.md?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/content/tutorial/js.md (original)
+++ thrift/site/content/tutorial/js.md Thu Aug 30 04:32:21 2012
@@ -1,3 +1,104 @@
---
title: "Javascript"
---
+<%= render 'tutorial_intro' %>
+
+### Prerequisites
+* This tutorial depends on an existing Thrift server. See either the [Java
tutorial](/tutorial/java/) or [C++ tutorial](/tutorial/cpp/) for how to build
and setup one of these servers.
+
+### Client
+
+<pre><code class="language-js">
+function calc() {
+ var transport = new Thrift.Transport("/thrift/service/tutorial/");
+ var protocol = new Thrift.Protocol(transport);
+ var client = new CalculatorClient(protocol);
+
+ var work = new Work()
+ work.num1 = $("#num1").val();
+ work.num2 = $("#num2").val();
+ work.op = $("#op").val();
+
+ try {
+ result = client.calculate(1, work);
+ $('#result').val(result);
+ $('#result').css('color', 'black');
+ } catch(ouch){
+ $('#result').val(ouch.why);
+ $('#result').css('color', 'red');
+ }
+}
+</code></pre>
+
+### Server
+Use either the [Java tutorial](/tutorial/java/) or [C++
tutorial](/tutorial/cpp/) server
+
+
+## Additional Information
+
+### Inspecting the generated Javascript code and HTML code
+Inside the html file is the entry point of using the Thrift.js and compiled
Javascript files. The main section code from the tutorial.html fileis the
Thrift client as shown above.
+
+The first thing for using the Thrift files is setting up your Transport
protocol. At this time, it only supports AJAX and is as follows:
+
+ var transport = new
Thrift.Transport("/thrift/service/tutorial/");
+
+After that the protocol needs setup using the transport object, which for
Javascript is JSON:
+
+ var protocol = new Thrift.Protocol(transport);
+
+Now we are setup for the full Thrift communications, so we can start
instantiating the Thrift objects, which define our Services and Objects.
+
+ var client = new CalculatorClient(protocol);
+
+Now that we have a functional Service Interface object created, we can can
setup the JSON object, which gets is needed by the service routine and gets
passed to it:
+
+ var work = new Work()
+ work.num1 = $("#num1").val();
+ work.num2 = $("#num2").val();
+ work.op = $("#op").val();
+
+ Once the object is created, we can now pass
+
+ try {
+ result = client.calculate(1, work);
+ //etc......
+
+Now, when the calculate button on the html page is clicked, the calc()
function as defined above is called and we get an AJAX call, which blocks and
waits for the response. This then updates the result from the calculation.
+
+### Inspecting the generated tutorial_types.js file
+Each Thrift struct will have properties associated with it. For our tutorial
object, Work, this is as shown above. For example:
+
+ var work = new Work();
+ work.num1 = 1;
+ work.num2 = 2;
+ work.op = ADD;
+
+In addition, there is a read(input) and write(output) function created on the
object as well. For the end user, these are not functions to be used as they
are mainly just used by the Thrift.js file for accessing objects.
+
+### Inspecting the generated Calculator.js file
+The Calculator.js file is the services created and defined in the .thrift
file. The two services defined are:
+
+ i32 add(1:i32 num1, 2:i32 num2),
+ i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation
ouch),
+
+To start using this, the Calculator object has to be created and accessed as
shown above. The Javascript Object, whichi is your interface to the services
created looks like this:
+
+ CalculatorClient = function(input, output){}
+
+Then, to access your defined services, the functions created look like this:
+
+ CalculatorClient.prototype.add = function(num1, num2) {}
+and
+
+ CalculatorClient.prototype.calculate = function(logid, w) {}
+
+Unfortunately, the Javascript object isn't just called Calculator and there
are a lot of other functions defined as well, but how those are used are out of
the scope of this tutorial.
+
+### Inspecting the Thrift.js file
+
+* The Thrift.js library currently uses jQuery.js in it's usage.
+* The main goal of the library is to define the Transport and Protocol layers.
+* The Transport layer only uses AJAX as of right now.
+* The Protocol layer handles the encoding/decoding to JSON format.
+* There are also the Thrift object types and call functions defined here as
well.
\ No newline at end of file
Added: thrift/site/layouts/tutorial_intro.md
URL:
http://svn.apache.org/viewvc/thrift/site/layouts/tutorial_intro.md?rev=1378799&view=auto
==============================================================================
--- thrift/site/layouts/tutorial_intro.md (added)
+++ thrift/site/layouts/tutorial_intro.md Thu Aug 30 04:32:21 2012
@@ -0,0 +1,13 @@
+##<%=h @item[:title] %> Tutorial
+----
+
+### Introduction
+All Apache Thrift tutorials require that you have:
+
+1. Built and installed the Apache Thrift Compiler, see [installing
Thrift](/docs/install/) for more details.
+1. Generated the
[tutorial.thrift](http://svn.apache.org/repos/asf/thrift/trunk/tutorial/tutorial.thrift)
file as [discussed here](/tutorial/)
+
+ thrift --gen js tutorial.thrift
+
+1. Followed all prerequesets listed
+
Modified: thrift/site/publish/docs/install/os_x/index.html
URL:
http://svn.apache.org/viewvc/thrift/site/publish/docs/install/os_x/index.html?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/publish/docs/install/os_x/index.html (original)
+++ thrift/site/publish/docs/install/os_x/index.html Thu Aug 30 04:32:21 2012
@@ -72,16 +72,17 @@
<h3>Install Boost</h3>
-<p>Download the boost library and bjam installer from <a
href="http://www.boost.org">boost.org</a> untar and place bjam in the boost
folder and then compile with</p>
+<p>Download the boost library from <a
href="http://www.boost.org">boost.org</a> untar compile with</p>
-<pre><code>sudo ./bjam toolset=darwin link=shared threading=multi
runtime-link=shared variant=release address-model=64 stage install
+<pre><code>./bootstrap.sh
+sudo ./b2 threading=multi address-model=64 variant=release stage install
</code></pre>
<h3>Install libevent</h3>
<p>Download <a href="http://monkey.org/%7Eprovos/libevent/">libevent</a>,
untar and compile with</p>
-<pre><code>./configure --prefix=/usr/local --disable-static
+<pre><code>./configure --prefix=/usr/local
make
sudo make install
</code></pre>
@@ -90,7 +91,7 @@ sudo make install
<p>Download the latest version of <a href="/download/">Apache Thrift</a>,
untar and compile with</p>
-<pre><code>./configure --prefix=/usr/local/ --with-boost=/usr/local
--with-libevent=/usr/local --disable-static
+<pre><code>./configure --prefix=/usr/local/ --with-boost=/usr/local
--with-libevent=/usr/local
</code></pre>
<h2>Additional reading</h2>
Modified: thrift/site/publish/tutorial/index.html
URL:
http://svn.apache.org/viewvc/thrift/site/publish/tutorial/index.html?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/publish/tutorial/index.html (original)
+++ thrift/site/publish/tutorial/index.html Thu Aug 30 04:32:21 2012
@@ -82,15 +82,19 @@
<li>
<h3>Writing a .thrift file</h3>
-<p>After the Thrift compiler is installed you will need to create a thrift
file. This file is an <a href="/docs/idl/">interface definition</a> made up of
<a href="/docs/types/">thrift types</a> and Services. The services you define
in this file are implemented by the server and are called by any clients. The
Thrift compiler is used to generate your Thrift File into source code which is
used by the different client libraries and the server you write. To generate
the source from a thrift file run</p>
+<p>After the Thrift compiler is installed you will need to create a thrift
file. This file is an <a href="/docs/idl/">interface definition</a> made up of
<a href="/docs/types/">thrift types</a> and Services. The services you define
in this file are implemented by the server and are called by any clients. </p>
+</li>
+<li>
+<h3>Generate Thrift file to source code</h3>
+
+<p>The Thrift compiler is used to generate your Thrift File into source code
which is used by the different client libraries and the server you write. To
generate the source from a thrift file run</p>
<pre><code>thrift --gen <language> <Thrift filename>
</code></pre>
-<p>The sample tutorial.thrift file used for all the client and server
tutorials can be found <a
href="http://svn.apache.org/repos/asf/thrift/trunk/tutorial/">here</a>. </p>
+<p>The sample <a
href="http://svn.apache.org/repos/asf/thrift/trunk/tutorial/tutorial.thrift">tutorial.thrift</a>
file defines a basic calculator service. This will be used to demonstrate both
the client and server. To generate the tutorial.thrift file into source code
use the Thrift generator and run </p>
</li>
-<li>
-<h3>Examples Clients and Servers</h3>
+</ul><h2>Examples Clients and Servers</h2>
<ul>
<li>
@@ -174,8 +178,6 @@
</li>
</ul>
-</li>
-</ul>
</div>
<div class="container">
<hr>
Modified: thrift/site/publish/tutorial/js/index.html
URL:
http://svn.apache.org/viewvc/thrift/site/publish/tutorial/js/index.html?rev=1378799&r1=1378798&r2=1378799&view=diff
==============================================================================
--- thrift/site/publish/tutorial/js/index.html (original)
+++ thrift/site/publish/tutorial/js/index.html Thu Aug 30 04:32:21 2012
@@ -66,7 +66,135 @@
</div>
<div class="container">
-
+ <h2>Javascript Tutorial</h2>
+
+<hr><h3>Introduction</h3>
+
+<p>All Apache Thrift tutorials require that you have:</p>
+
+<ol>
+<li>Built and installed the Apache Thrift Compiler, see <a
href="/docs/install/">installing Thrift</a> for more details. </li>
+<li>
+<p>Generated the <a
href="http://svn.apache.org/repos/asf/thrift/trunk/tutorial/tutorial.thrift">tutorial.thrift</a>
file as <a href="/tutorial/">discussed here</a></p>
+
+<pre><code>thrift --gen js tutorial.thrift
+</code></pre>
+</li>
+<li><p>Followed all prerequesets listed </p></li>
+</ol><h3>Prerequisites</h3>
+
+<ul>
+<li>This tutorial depends on an existing Thrift server. See either the <a
href="/tutorial/java/">Java tutorial</a> or <a href="/tutorial/cpp/">C++
tutorial</a> for how to build and setup one of these servers.</li>
+</ul><h3>Client</h3>
+
+<pre><code class="language-js"><span
style="color:#080;font-weight:bold">function</span> <span
style="color:#06B;font-weight:bold">calc</span>() {
+ <span style="color:#080;font-weight:bold">var</span> transport = <span
style="color:#080;font-weight:bold">new</span> Thrift.Transport(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">"</span><span
style="color:#D20">/thrift/service/tutorial/</span><span
style="color:#710">"</span></span>);
+ <span style="color:#080;font-weight:bold">var</span> protocol = <span
style="color:#080;font-weight:bold">new</span> Thrift.Protocol(transport);
+ <span style="color:#080;font-weight:bold">var</span> client = <span
style="color:#080;font-weight:bold">new</span> CalculatorClient(protocol);
+
+ <span style="color:#080;font-weight:bold">var</span> work = <span
style="color:#080;font-weight:bold">new</span> Work()
+ work.num1 = <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">"</span><span style="color:#D20">#num1</span><span
style="color:#710">"</span></span>).val();
+ work.num2 = <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">"</span><span style="color:#D20">#num2</span><span
style="color:#710">"</span></span>).val();
+ work.op = <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">"</span><span style="color:#D20">#op</span><span
style="color:#710">"</span></span>).val();
+
+ <span style="color:#080;font-weight:bold">try</span> {
+ result = client.calculate(<span style="color:#00D">1</span>, work);
+ <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">#result</span><span
style="color:#710">'</span></span>).val(result);
+ <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">#result</span><span
style="color:#710">'</span></span>).css(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">color</span><span
style="color:#710">'</span></span>, <span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">black</span><span
style="color:#710">'</span></span>);
+ } <span style="color:#080;font-weight:bold">catch</span>(ouch){
+ <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">#result</span><span
style="color:#710">'</span></span>).val(ouch.why);
+ <span style="color:#369;font-weight:bold">$</span>(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">#result</span><span
style="color:#710">'</span></span>).css(<span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">color</span><span
style="color:#710">'</span></span>, <span
style="background-color:hsla(0,100%,50%,0.05)"><span
style="color:#710">'</span><span style="color:#D20">red</span><span
style="color:#710">'</span></span>);
+ }
+}</code></pre>
+
+<h3>Server</h3>
+
+<p>Use either the <a href="/tutorial/java/">Java tutorial</a> or <a
href="/tutorial/cpp/">C++ tutorial</a> server </p>
+
+<h2>Additional Information</h2>
+
+<h3>Inspecting the generated Javascript code and HTML code</h3>
+
+<p>Inside the html file is the entry point of using the Thrift.js and compiled
Javascript files. The main section code from the tutorial.html fileis the
Thrift client as shown above.</p>
+
+<p>The first thing for using the Thrift files is setting up your Transport
protocol. At this time, it only supports AJAX and is as follows:</p>
+
+<pre><code> var transport = new
Thrift.Transport("/thrift/service/tutorial/");
+</code></pre>
+
+<p>After that the protocol needs setup using the transport object, which for
Javascript is JSON:</p>
+
+<pre><code> var protocol = new Thrift.Protocol(transport);
+</code></pre>
+
+<p>Now we are setup for the full Thrift communications, so we can start
instantiating the Thrift objects, which define our Services and Objects.</p>
+
+<pre><code> var client = new CalculatorClient(protocol);
+</code></pre>
+
+<p>Now that we have a functional Service Interface object created, we can can
setup the JSON object, which gets is needed by the service routine and gets
passed to it:</p>
+
+<pre><code> var work = new Work()
+ work.num1 = $("#num1").val();
+ work.num2 = $("#num2").val();
+ work.op = $("#op").val();
+
+Once the object is created, we can now pass
+
+ try {
+ result = client.calculate(1, work);
+ //etc......
+</code></pre>
+
+<p>Now, when the calculate button on the html page is clicked, the calc()
function as defined above is called and we get an AJAX call, which blocks and
waits for the response. This then updates the result from the calculation.</p>
+
+<h3>Inspecting the generated tutorial_types.js file</h3>
+
+<p>Each Thrift struct will have properties associated with it. For our
tutorial object, Work, this is as shown above. For example:</p>
+
+<pre><code> var work = new Work();
+ work.num1 = 1;
+ work.num2 = 2;
+ work.op = ADD;
+</code></pre>
+
+<p>In addition, there is a read(input) and write(output) function created on
the object as well. For the end user, these are not functions to be used as
they are mainly just used by the Thrift.js file for accessing objects.</p>
+
+<h3>Inspecting the generated Calculator.js file</h3>
+
+<p>The Calculator.js file is the services created and defined in the .thrift
file. The two services defined are:</p>
+
+<pre><code> i32 add(1:i32 num1, 2:i32 num2),
+ i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),
+</code></pre>
+
+<p>To start using this, the Calculator object has to be created and accessed
as shown above. The Javascript Object, whichi is your interface to the services
created looks like this:</p>
+
+<pre><code> CalculatorClient = function(input, output){}
+</code></pre>
+
+<p>Then, to access your defined services, the functions created look like
this:</p>
+
+<pre><code> CalculatorClient.prototype.add = function(num1, num2) {}
+</code></pre>
+
+<p>and</p>
+
+<pre><code> CalculatorClient.prototype.calculate = function(logid, w) {}
+</code></pre>
+
+<p>Unfortunately, the Javascript object isn't just called Calculator and there
are a lot of other functions defined as well, but how those are used are out of
the scope of this tutorial. </p>
+
+<h3>Inspecting the Thrift.js file</h3>
+
+<ul>
+<li>The Thrift.js library currently uses jQuery.js in it's usage.</li>
+<li>The main goal of the library is to define the Transport and Protocol
layers.</li>
+<li>The Transport layer only uses AJAX as of right now.<br>
+</li>
+<li>The Protocol layer handles the encoding/decoding to JSON format.</li>
+<li>There are also the Thrift object types and call functions defined here as
well.</li>
+</ul>
</div>
<div class="container">
<hr>