Browse Source

Isolated static elements part. Added some doc.

new_arc
parent
commit
35a1a38eae
  1. 2
      config.ru
  2. 2
      global.rb
  3. 19
      public/js/jquery-1.3.1.min.js
  4. 97
      public/js/jquery.cookie.js
  5. 10
      public/static/css/main.css
  6. 0
      public/static/css/mozilla.css
  7. 0
      public/static/css/webkit.css
  8. 29
      public/static/doc.html
  9. 0
      public/static/img/favicon.ico
  10. 32
      public/static/index.html
  11. 0
      public/static/js/index.js
  12. 0
      public/static/js/rubyzome.js
  13. 43
      public/static/tutorial.html
  14. 83
      rubyzome/controllers/helpers/glue.rb

2
config.ru

@ -12,6 +12,6 @@ require 'rubyzome/rubyzome.rb'
use Rack::Rewrite do
rewrite '/','/static/index.html'
end
use Rack::Static, :urls => ["/css", "/js", "/img", "/static", $directory_of_website], :root => "public"
use Rack::Static, :urls => [$static_files_directory], :root => "public"
run Rubyzome::RestfulDispatcher.new

2
global.rb

@ -2,7 +2,7 @@
# write here the list of format you want your application to output
$viewsToLoad=["JSON","XML","HTML"]
$directory_of_website='/website'
$static_files_directory='/static'
# the DB URL default is an sqlite db file: datas.db
# if the env variable DATABASE_URL is set it is the one choosen

19
public/js/jquery-1.3.1.min.js

File diff suppressed because one or more lines are too long

97
public/js/jquery.cookie.js

@ -1,97 +0,0 @@
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// NOTE Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};

10
public/css/main.css → public/static/css/main.css

@ -7,6 +7,7 @@ html, body {
body, #info {
background-color: #320;
color: #ca8;
font-size: 1.2em;
}
#entete {
background-color: #320;
@ -16,7 +17,7 @@ body, #info {
text-shadow: 0 0 9px #100;
}
#content {
#middle {
border-top: 1px solid #db8;
border-bottom: 1px solid #eda;
background-color: #ca8;
@ -26,6 +27,13 @@ body, #info {
padding-bottom: 3em;
}
#content {
margin-left: auto;
margin-right: auto;
width: 32em;
text-align: left;
}
#content a,
#content a:link,
#content a:visited {

0
public/css/mozilla.css → public/static/css/mozilla.css

0
public/css/webkit.css → public/static/css/webkit.css

29
public/static/doc.html

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/static/css/main.css" />
<title>Rubyzome</title>
</head>
<body>
<div id="entete">
<h1>Rubyzome's Documentation</h1>
<h2>To be done</h2>
</div>
<div id="middle">
<div id="content">
I'm sorry to say it isn't done for now.
</div>
</div>
<div id="bottom">
<div id="promotion">
Designed by <a href="http://yannesposito.com">Yann Esposito</a> &amp; <a href="http://lucarea.com">Luc Juggery</a>.
</div>
</div>
</body>
</html>

0
public/img/favicon.ico → public/static/img/favicon.ico

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

32
public/static/index.html

@ -4,35 +4,23 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/main.css" />
<script type="text/javascript" src="/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/js/index.js"></script>
<link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/static/css/main.css" />
<title>Rubyzome</title>
</head>
<body>
<div id="entete">
<h1>Rubyzome</h1>
<h2>Sign in</h2>
<h2>Congratulations. It's working</h2>
</div>
<div id="content">
<form action="#" method="GET">
<div id="usernameblock">
<input name="username" type="text" id="username" value="User Name" class="inactive" />
</div>
<div id="passwordblock">
<input name="password" type="password" id="password" value="password" class="inactive" />
</div>
<div id="remember">
<input name="signin" type="checkbox" id="checkbox" value="Sign in" />
<label>Remember me on this computer</label>
</div>
<div id="signinbutton">
<input name="signin" type="submit" id="signin" value="Sign in" />
</div>
</form>
<div id="middle">
<div id="content">
<p>Glad you used Rubyzome!</p>
<p>Now you can begin with the <a href="/static/tutorial.html">tutorial</a></p>
<p>Or with the <a href="/static/doc.html">documentation</a></p>
<p>You can also contact us on github: <a href="http://github.com/yogsototh">yogsototh</a> and <a href="http://github.com/lucj">lucj</a>.
</div>
</div>
<div id="bottom">

0
public/js/index.js → public/static/js/index.js

0
public/js/rubyzome.js → public/static/js/rubyzome.js

43
public/static/tutorial.html

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/static/css/main.css" />
<title>Rubyzome</title>
</head>
<body>
<div id="entete">
<h1>Rubyzome's Tutorial</h1>
</div>
<div id="middle">
<div id="content">
<h3>Back to basis</h3>
<p>To have a working API, just populate the <code>app</code> directory.</p>
<ul>
<li><code>app/models</code> will contains model classes.</li>
<li><code>app/controllers</code> will contains controller classes.</li>
<li><code>app/views</code> will contains custom views.</li>
</ul>
<h3>Usages</h3>
<p>Beware the name of the files <b>MUST</b> follow some rules.</p>
<ul>
<li>Controllers must be named <code><em>Name</em>Controller.rb</code></li>
<li>Views must be named <code><em>Type</em>View.rb</code></li>
<li>Then you can access your controller using the URI: <code>http://host/<em>name</em>s/id.<em>type</em></code>.</li>
</ul>
<p>For example, creating a <code><em>User</em>Controller.rb</code> in <code>app/controllers</code> will provide the URI: <code>http://host/<em>user</em>s/johndoe.<em>json</em></code></p>
<p>More precisely, calling this URI will execute the <code>UserController::show</code> with <code>@request[:user]="johndoe"</code>. Then the returned object is given to the <code>JSONView</code> provided by Rubyzome.</p>
</div>
</div>
<div id="bottom">
<div id="promotion">
Designed by <a href="http://yannesposito.com">Yann Esposito</a> &amp; <a href="http://lucarea.com">Luc Juggery</a>.
</div>
</div>
</body>
</html>

83
rubyzome/controllers/helpers/glue.rb

@ -0,0 +1,83 @@
module ResourcesFromRequest
# get ressource object from name
#
# in general request are in the form:
# MainRessources with params [
# login_param,
# general_param,
# subresource_1_id,
# subresource_2_id,
# ... ,
# subresource_n_id ]
# Most of time the controller need to access the object
# associated to subresource_x_id
# to get it, we need the model associated to the subresource_x_id
# most of time it is the name of the subresource_x_id which provide
# the associated model name.
# For example todolist_id is most of time
# used to match a Todolist object.
# Sometime there could be strange name to access
# get_resource("todolist")
# will return
# resource = Todolist.first({:id => request[:todolist_id]})
#
# For example as Todolist as :uid as primary key, we should have
# reclaimed:
# get_resource({ resource_name=>"todolist",db_key => :uid })
#
# and if we provided the user to send todoidentifier
# instead of todolist_id in the HTTP request we should
# have done
# get_resource({ resource_name =>"todolist",:uid,:todoidentifier)
#
# and if todolist wasn't for Todolist model but for Egg
# we should have written
# get_resource({:db_key => :uid,
# :req_id => :todoidentifier,
# :model_name => "Egg"})
#
# PARAMETERS
# or a simple string (resource_name)
# or a hash containing following key (not all mandatory)
# :resource_name mandatory if :req_id
# and :model_name not given)
# :req_id the name of the HTTP parameter
# used to identify resource
# :model_name the model class name
# :db_key the primary key of the model
def get_resource(params)
# A bit of introspection
if params.is_a?(String)
resource_name=params
elsif params.is_a?(Hash)
resource_name=params[:resource_name]
db_key=params[:db_key]
req_id=params[:req_id]
model_name=params[:model_name]
else
raise Error, "get_resource should take a String or Hash parameter"
end
# set default database id associated with ressource if needed
req_id=%{#{resource_name}_id}.intern if req_id == nil
# set the model name from the ressource name if needed
model_name=resource_name.capitalize if model_name == nil
# set the db primary key if needed
db_key=:id if db_key == nil
# get the given (by parameter) identifier of the ressource
ressource_id = @request[req_id]
# if no parameter is given demand from it
if(ressource_id.nil?) then
raise Error, "I lack the parameter #{req_id}"
end
# get the object from DB using ressource id to identify it
ressource = Kernel.const_get(model_name).first({db_key => ressource_id})
# raise an error if no ressource is found
if(ressource.nil?) then
raise Error, "#{ressource_id} does not exist"
end
return ressource
end
end
Loading…
Cancel
Save