Browse Source

Merged with new_arc

twitter_facebook_integration
LJ 11 years ago
parent
commit
b7d077f280
  1. 0
      LICENSE
  2. 35
      README.md
  3. 42
      Rakefile
  4. 10
      config.ru
  5. 10
      global.rb
  6. 22
      global_config.rb
  7. 19
      public/js/jquery-1.3.1.min.js
  8. 97
      public/js/jquery.cookie.js
  9. 27
      public/static/css/main.css
  10. 8
      public/static/css/mozilla.css
  11. 12
      public/static/css/webkit.css
  12. 29
      public/static/doc.html
  13. 0
      public/static/img/favicon.ico
  14. 20
      public/static/index.html
  15. 0
      public/static/js/index.js
  16. 0
      public/static/js/rubyzome.js
  17. 43
      public/static/tutorial.html
  18. 10
      rubyzome/controllers.rb
  19. 5
      rubyzome/controllers/RestController.rb
  20. 6
      rubyzome/controllers/ServiceRestController.rb
  21. 62
      rubyzome/controllers/helpers/UserAccountHelper.rb
  22. 6
      rubyzome/lib.rb
  23. 4
      rubyzome/lib/Error.rb
  24. 13
      rubyzome/lib/RestfulDispatcher.rb
  25. 21
      rubyzome/load_local_app.rb
  26. 6
      rubyzome/models.rb
  27. 40
      rubyzome/rubyzome.rb
  28. 14
      rubyzome/scripts/db/db_migrate
  29. 13
      rubyzome/scripts/db/db_upgrade
  30. 21
      rubyzome/scripts/db/delete
  31. 102
      rubyzome/scripts/db/populate
  32. 20
      rubyzome/scripts/db/setup
  33. 105
      rubyzome/scripts/git/rz
  34. BIN
      rubyzome/scripts/logo/rubyzome.png
  35. 219
      rubyzome/scripts/logo/rubyzome.svg
  36. 32
      rubyzome/tasks.rb
  37. 16
      rubyzome/views.rb
  38. 17
      rubyzome/views/HTMLView.rb
  39. 26
      rubyzome/views/JSONView.rb
  40. 4
      rubyzome/views/RestView.rb
  41. 11
      rubyzome/views/XMLView.rb
  42. 9
      rubyzome/views/html/templates/error.erb
  43. 16
      rubyzome/views/html/templates/main.erb
  44. 0
      rubyzome/www/js/rubyzome.js

0
rubyzome/README.markdown → LICENSE

35
README.md

@ -0,0 +1,35 @@
# Rubyzome
Ruby Restful Mobile oriented framework.
- Concentrate on API
- Can create Web interface easily
## Install
1. open a terminal and write
> git clone git@github.com:yogsototh/rubyzome.git rubyzome
> cd rubyzome
> ./rubyzome/scripts/db/db_migrate
> gem install dm-core dm-sqlite-adapter dm-migrations erubis json nokogiri rack rack-rewrite unicorn
> unicorn
2. ???
3. profit
## Heroku
In order to update the database to heroku, you can simply run
heroku console < rubyzome/scripts/db/db_migrate
## Docs
Documentation is to be done.
For now, just know it has something to do with populating the `/app` directory.
## Status
Orientation and satus of the current project to define.

42
Rakefile

@ -1,32 +1,12 @@
namespace "db" do
task :std_db_action, [:action] do |t,args|
require 'rubygems'
require 'global_config'
require 'dm-core'
require 'dm-migrations'
# Connect to DB
DataMapper.setup(:default, $db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
# Reset tables
DataMapper.finalize
if args.action == 'migrate'
DataMapper.auto_migrate!
puts 'migration finished'
elsif args.action == 'upgrade'
DataMapper.auto_upgrade!
puts 'upgrade finished'
else
puts 'std_db_action [migrate|upgrade]'
end
end
task :migrate do
Rake.application.invoke_task("db:std_db_action[migrate]")
end
task :upgrade do
Rake.application.invoke_task("db:std_db_action[upgrade]")
end
# We recommand do use the app/tasks.rb file to add your
# custom rake tasks.
# The code in this file is part of the Rubyzome framework
# Rubyzome framework belongs to Luc Juggery and Yann Esposito
# ----------------------------------------------------------------
# DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING
# ----------------------------------------------------------------
require 'rubyzome/tasks.rb'
if FileTest.exists?('app/tasks.rb')
require 'app/tasks.rb'
end

10
config.ru

@ -1,17 +1,17 @@
# The code in this file is part of the Rubyzome framework
# Rubyzome framework belongs to Luc Juggery and Yann Esposito
# ----------------------------------------------------------------
# DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING
# ----------------------------------------------------------------
require 'global'
require 'rubygems'
require 'rack'
require 'rack-rewrite'
require 'global_config.rb'
require 'rubyzome/rubyzome.rb'
use Rack::Rewrite do
rewrite '/','/static/index.html'
end
use Rack::Static, :urls => ["/css", "/js", "/img", "/static"], :root => "public"
use Rack::Static, :urls => [$static_files_directory], :root => "public"
run Rubyzome::RestfulDispatcher.new

10
global.rb

@ -0,0 +1,10 @@
# Global configuration file
# write here the list of format you want your application to output
$viewsToLoad=["JSON","XML","HTML"]
$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
# With this it works seemlessly with heroku
$db_url=ENV['DATABASE_URL'] || %{sqlite3://#{Dir.pwd}/datas.db}

22
global_config.rb

@ -1,22 +0,0 @@
# --------------------------
# -- global configuration --
# beware the name will not match one of
# a REST resource of the application
$directory_of_website='/website'
# db configuration
$db_type='sqlite3'
$db_user=nil
$db_password=nil
$db_admin_user=nil
$db_admin_password=nil
$db_host=nil
$db_database="#{Dir.pwd}/datas.db"
constructed_db_url="#{$db_type}://"
constructed_db_url<<="#{$db_user}:" if not $db_user.nil?
constructed_db_url<<="#{$db_password}" if not $db_password.nil?
constructed_db_url<<="@#{$db_host}/" if not $db_host.nil?
constructed_db_url<<="@#{$db_database}" if not $db_database.nil?
$db_url=ENV['DATABASE_URL'] || constructed_db_url

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

27
public/css/main.css → public/static/css/main.css

@ -7,13 +7,9 @@ html, body {
left: 0;
}
body, #info {
background-color: #07c;
color: #fff;
}
#content b,
#content strong,
#content em {
color: #07c;
background-color: #320;
color: #ca8;
font-size: 1.2em;
}
#entete {
background-color: #07c;
@ -32,16 +28,23 @@ body, #info {
}
.flush { clear: both; }
#content {
border-top: 1px solid #ddd;
border-bottom: 1px solid #eee;
background-color: #fff;
color: #333;
#middle {
border-top: 1px solid #db8;
border-bottom: 1px solid #eda;
background-color: #ca8;
color: #320;
text-align: center;
padding-top: 3em;
padding-bottom: 3em;
}
#content {
margin-left: auto;
margin-right: auto;
width: 32em;
text-align: left;
}
#content a,
#content a:link,
#content a:visited {

8
public/static/css/mozilla.css

@ -0,0 +1,8 @@
#entete, #bottom {
background: -moz-radial-gradient(center center, 0, center center, 300, from(#531), to(#320) ) no-repeat;
}
#bottom {
-moz-box-shadow: 0px 10px 10px rgba(6,4,0,.3);
margin-left: 10px;
margin-right: 10px;
}

12
public/static/css/webkit.css

@ -0,0 +1,12 @@
#entete {
background-image: -webkit-gradient(radial, center bottom, 0, center bottom, 300, from(#531), to(#320) );
}
#content {
background-image: -webkit-gradient(radial, center top, 0, center top, 300, from(#fdb), to(#ca8) );
}
#bottom {
background-image: -webkit-gradient(radial, center center, 0, center center, 300, from(#531), to(#320) );
-webkit-box-shadow: 0px 10px 10px rgba(6,4,0,.3);
margin-left: 10px;
margin-right: 10px;
}

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
rubyzome/scripts/logo/rubyzome.ico → public/static/img/favicon.ico

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

20
public/static/index.html

@ -4,6 +4,7 @@
<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" />
<<<<<<< HEAD
<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>
@ -32,6 +33,25 @@
<input name="signin" type="submit" id="signin" value="Sign in" />
</div>
</form>
=======
<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>Congratulations. It's working</h2>
</div>
<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>
>>>>>>> origin/new_arc
</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>

10
rubyzome/controllers.rb

@ -1,10 +0,0 @@
# encoding: utf-8
module Rubyzome
# include Rubyzome default controllers
Dir["rubyzome/controllers/*.rb"].each { |file| require file }
# include Rubyzome helpers
Dir["rubyzome/controllers/helpers/*.rb"].each { |file| require file }
end

5
rubyzome/controllers/RestController.rb

@ -1,8 +1,6 @@
# encoding: utf-8
module Rubyzome
class RestController
class RestController
# ajoute un attribut Request
# contenant les détails des requêtes
attr_accessor :request
@ -45,5 +43,4 @@ module Rubyzome
end
end
end
end
end

6
rubyzome/controllers/ServiceRestController.rb

@ -1,8 +1,7 @@
# encoding: utf-8
module Rubyzome
require 'rubyzome/controllers/RestController.rb'
class ServiceRestController < RestController
require 'rubyzome/controllers/RestController.rb'
class ServiceRestController < RestController
def service_name
@request[ (self.class.to_s.gsub(/Controller/,'').downcase + '_id' ).intern ].intern
@ -40,5 +39,4 @@ module Rubyzome
return {}
end
end
end

62
rubyzome/controllers/helpers/UserAccountHelper.rb

@ -3,16 +3,6 @@ module Rubyzome
### AUTHENTICATION ###
def check_admin_authentication
if @request[:l] != 'adm' then
raise Error, "Only admin is authorized to perform this action"
end
if @request[:p] != 'adm' then
raise Error, "Authentication failed, please check your login and password"
end
end
def check_authentication
user=User.first({:nickname => @request[:l]})
if user.nil?
@ -55,34 +45,6 @@ module Rubyzome
return user
end
### SENSOR STUFF ###
def get_sensor(id=:sensor_id)
sensor_id = @request[id]
if(sensor_id.nil?) then
raise Error, "No sensor provided"
end
sensor = Sensor.first({:sensor_hr => sensor_id})
if(sensor.nil?) then
raise Error,"Sensor #{sensor_id} does not exist"
end
return sensor
end
### MEASURE STUFF ###
def get_measure(id=:measure_id)
measure_id = @request[id]
if(measure_id.nil?) then
raise Error, "No measure provided"
end
measure = Measure.first({:measure_hr => measure_id})
if(measure.nil?) then
raise Error,"Measure #{measure_id} does not exist"
end
return measure
end
### OWNERSHIP ###
def check_ownership_user_account(user,account)
@ -91,20 +53,6 @@ module Rubyzome
end
end
def check_ownership_user_sensor(user,sensor)
if sensor.user != user then
raise Error, "Sensor #{sensor.sensor_hr} does not belong to User #{user.nickname}"
end
end
def check_ownership_sensor_measure(sensor,measure)
if measure.sensor != sensor then
raise Error, "Measure #{measure.measure_hr} does not belong to Sensor #{sensor.sensor_hr}"
end
end
### ONLY USED IN USER PART ###
def check_ownership_requestor_user(requestor,user)
if requestor.nickname != user.nickname
raise Error, "Requestor #{requestor.nickname} and user requested #{user.nickname} do not match"
@ -118,17 +66,7 @@ module Rubyzome
hash.delete(:id)
hash.delete(:user_id)
hash.delete(:account_id)
hash.delete(:sensor_id)
hash
end
### STAT PURPOSES ###
def get_start_date
days_nbr = 1
days_nbr = @request[:days_nbr] if not @request[:days_nbr].nil?
start_date = DateTime.now - days_nbr.to_i
return start_date
end
end
end

6
rubyzome/lib.rb

@ -1,6 +0,0 @@
# encoding: utf-8
module Rubyzome
# include Rubyzome helpers
Dir["rubyzome/lib/*.rb"].each { |file| require file }
end

4
rubyzome/lib/Error.rb

@ -1,7 +1,5 @@
# encoding: utf-8
module Rubyzome
class Error < StandardError
class Error < StandardError
attr_accessor :code
end
end

13
rubyzome/RestfulDispatcher.rb → rubyzome/lib/RestfulDispatcher.rb

@ -3,18 +3,15 @@
# The code in this file is part of the Rubyzome framework
# Rubyzome framework belongs to Luc Juggery and Yann Esposito
module Rubyzome
# The RestfulDispatcher class handle the automatic routing of the
# application using filename and classname.
class RestfulDispatcher
# Classe handling incoming requests
class RestfulDispatcher
@view = nil
# Select the view to be used to render the object
def selectView(model,path)
# If it is a file of a website which is required then use the file load
if path.empty? or path =~ /^#{$directory_of_website}\//
if path.nil? or path.empty?
return nil?
end
@ -84,7 +81,7 @@ module Rubyzome
# Nice html error (404 by default)
def html_error(e, controller_name=nil, function_name=nil)
view=$view['HTMLView'].new
view=$views['HTMLView'].new
[ 404,
$views['HTMLView'].head,
$views['HTMLView'].new.httpContent( { :error => 404, :exception => e })
@ -252,6 +249,4 @@ module Rubyzome
end
return modelname, classname, function_name
end
end
end

21
rubyzome/load_local_app.rb

@ -1,21 +0,0 @@
# encoding: utf-8
module Rubyzome
# TODO: centralize configuration for example: default is app/ directory (should be different)
# Include all controllers
Dir["app/controllers/*.rb"].each { |file| require file }
# Include all specific views (if any)
Dir["app/views/*/*.rb"].each do |file|
require file
viewname=File.basename(file,File.extname(file))
typename=File.basename(File.dirname(file))
$views['/'+typename+'/'+viewname]=Kernel.const_get(viewname)
end
DataMapper.setup(:default,$db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
DataMapper.finalize
end

6
rubyzome/models.rb

@ -1,6 +0,0 @@
# encoding: utf-8
module Rubyzome
# TODO: sanitize models to be super-class
Dir["rubyzome/models/*.rb"].each { |file| require file }
end

40
rubyzome/rubyzome.rb

@ -1,19 +1,39 @@
# encoding: utf-8
# Rubyzome central file which load all submodules
# and subclasses
# Rubyzome central file which load all submodules and subclasses
module Rubyzome
require 'dm-core'
# Include all rubyzome classes
require 'rubyzome/lib.rb'
require 'rubyzome/controllers.rb'
require 'rubyzome/views.rb'
require 'rubyzome/models.rb'
Dir["rubyzome/lib/*.rb"].each { |file| require file }
# load the classes for the defined application
require 'rubyzome/load_local_app.rb'
# Load all rubyzome standard views
$views = {} unless defined? $views
$viewsToLoad.each do |view|
file="rubyzome/views/#{view}View.rb"
viewname=File.basename(file,File.extname(file))
require file
$views[viewname]=Rubyzome.const_get(viewname)
end
# load the class that will handle server requests
require 'rubyzome/RestfulDispatcher.rb'
# Make sure classes are available through Rubyzome namaspace
def self.const_missing(c)
Object.const_get(c)
end
# Include all application specific classes
Dir["app/models/*.rb"].each { |file| require file }
Dir["app/controllers/*.rb"].each { |file| require file }
# Load all application specific views
Dir["app/views/*/*.rb"].each do |file|
require file
viewname=File.basename(file,File.extname(file))
typename=File.basename(File.dirname(file))
$views['/'+typename+'/'+viewname]=Kernel.const_get(viewname)
end
# Set Datamapper stuff
DataMapper.setup(:default,$db_url)
DataMapper.finalize
end

14
rubyzome/scripts/db/db_migrate

@ -1,14 +0,0 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'global_config'
require 'dm-core'
require 'dm-migrations'
# Connect to DB
DataMapper.setup(:default, $db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
# Reset tables
DataMapper.finalize
DataMapper.auto_migrate!

13
rubyzome/scripts/db/db_upgrade

@ -1,13 +0,0 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
# Connect to DB
DataMapper.setup(:default, $db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
# Reset tables
DataMapper.finalize
DataMapper.auto_upgrade!

21
rubyzome/scripts/db/delete

@ -1,21 +0,0 @@
#!/usr/bin/env zsh
for info in $( egrep '\$db_.*=' global_config.rb ); do
print $info[2,-1]
if print $info[2,-1] | egrep '^db_url' >/dev/null; then
continue
fi
eval $info[2,-1]
done
if [[ $db_type != "mysql" ]]; then
print -- "Script for mysql database only" >&2
exit 1
fi
print "Enter your mysql root password"
mysql -u root -p <<END
DROP DATABASE ${db_database};
DROP USER '${db_admin_user}'@'${db_host}';
DROP USER '${db_user}'@'${db_host}';
END

102
rubyzome/scripts/db/populate

@ -1,102 +0,0 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'dm-core'
# require 'date'
require 'time'
require 'faker'
include "global_config.rb"
# inclusion de tous les modèles
DataMapper.setup(:default, $db_url)
Dir["app/models/*.rb"].each { |file| require file }
DataMapper.finalize
# connexion à la base de donnée
require "rubyzome/lib/db.rb"
# Comment that could be added by admin, based on user average consumption
comments = {
0..500 => "Very low consumption",
501..1000 => "Low consumption",
1001..1500 => "Normal consumption",
1501..2000 => "Medium consumption",
2001..2500 => "Consumption quite high",
2501..3000 => "High consumption, please reduce it :-)"
}
# User creation
nb_users=30
(1..nb_users).each do |user_nb|
# Get dummy
# - firstname
# - lastname
# - email
# - nickname
# - country
# - zip code
# - city
# - street
firstname = Faker::Name.first_name
lastname = Faker::Name.last_name
nickname = "#{firstname.downcase}#{lastname.downcase}"
# puts "User #{user_nb}:#{nickname}"
user_hash = { :nickname => "#{nickname}",
:status => "" }
account_hash = {:firstname => "#{firstname}",
:lastname => "#{lastname}",
:email => "#{firstname.downcase}.#{lastname.downcase}@yahoo.com",
:password => "guest",
:country => "US",
:zip => Faker::Address.zip_code,
:city => Faker::Address.city,
:street => Faker::Address.street_address}
# Create user entry
user = User.new(user_hash)
user.save
# Create account entry
account_hash[:user] = user
account=Account.new(account_hash)
account.save
# Create sensors for each users
nb_sensors=3
(1..nb_sensors).each do |sensor_nb|
# puts "Sensor:#{sensor_nb}"
sensor=Sensor.new( :sensor_hr => "#{nickname}_#{sensor_nb}",
:description => "Sensor #{sensor_nb} of #{firstname} #{lastname}",
:address => "Same as user",
:user => user)
sensor.save
# Create measure for each sensor: one measure each 30 minutes for the past 2 days
nb_measures=96
total = 0
(1..nb_measures).each do |measure_nb|
# puts "Measure:#{measure_nb}"
d = Time.now - measure_nb * 5 * 60
measure = Measure.new( :measure_hr => "#{nickname}_#{sensor_nb}_#{measure_nb}",
:date => d,
:consumption => rand(3000),
:sensor => sensor)
measure.save
total = total + measure.consumption.to_f
end
# Get measure average
average = total / nb_measures
# Set comment to user depending upon his average consumption
comment = ""
comments.each do |k,v|
if k.include?(average) then
comment = v
end
end
user.status = comment
user.save
end
end

20
rubyzome/scripts/db/setup

@ -1,20 +0,0 @@
#!/usr/bin/env zsh
for info in $( egrep '\$db_.*=' global_config.rb ); do
print $info[2,-1]
if print $info[2,-1] | egrep '^db_url' >/dev/null; then
continue
fi
eval $info[2,-1]
done
if [[ $db_type == "mysql" ]]; then
print "Enter your mysql root password"
mysql -u root -p <<END
CREATE DATABASE ${db_database};
CREATE USER '${db_admin_user}'@'${db_host}' IDENTIFIED BY '${db_admin_password}';
GRANT ALL on ${db_database}.* TO '${db_admin_user}'@'${db_host}' ;
CREATE USER '${db_user}'@'${db_host}' IDENTIFIED BY '${db_password}';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP on ${db_database}.* TO '${db_user}'@'${db_host}';
END
fi

105
rubyzome/scripts/git/rz

@ -1,105 +0,0 @@
#!/usr/bin/env ruby
# encoding: utf-8
# architecture
#
# master <-> rubyzome
# master -> grid
# grid -> gp | gpadm
#
# merge using two of these branches should be
# restricted to these rules
# merge to one of these branch and an unknown one should
# raise a warning, and may the option to add this new branch
# to the hierarchy
$architecture={
:master => [ :rubyzome, :grid, :todogether ],
:rubyzome => [ :master ],
:grid => [ :gp, :gpadm ] }
def get_current_branch()
(`git branch --no-color | awk '$1 == "*" {print $2}'`).chop.intern
end
if ARGV.length == 0
puts %{Script for rubyzome developper to dodge git merge error"
usage: $0:t [git_command or local_command]
local commands:
allmerges: merge from top to down}
exit 0
end
require 'set'
$known_branches=Set.new
$architecture.each do |k,v|
$known_branches.add(k)
v.each { |b| $known_branches.add(b) }
end
def rec_merge(branch)
if $architecture[branch].nil?
return
end
$architecture[branch].each do |b|
if $flag.has_key?(b.to_s + branch.to_s)
next
end
flagname=branch.to_s + b.to_s
if $flag.has_key?(flagname)
next
end
if system %{rz checkout #{b}}
if get_current_branch != b
puts "Can't checkout to #{b}"
exit 2
end
if system %{rz merge #{branch}}
$flag[flagname]=true
rec_merge(b)
else
exit 1
end
else
exit 1
end
end
end
def do_all_merges
puts 'Will merge from father to sons'
current_branch=get_current_branch
$flag={}
rec_merge(:master)
system %{git co #{current_branch}}
end
def do_merge
current_branch=get_current_branch
src_branch=ARGV[1].intern
puts %{do_merge: #{src_branch} => #{current_branch}}
if $known_branches.include?(current_branch)
if $known_branches.include?(src_branch)
if $architecture.has_key?(src_branch) and
$architecture[src_branch].include?(current_branch)
system %{git merge #{src_branch}}
else
puts %{Forbidden merge: #{src_branch} => #{current_branch}}
end
else
puts %{Warning! #{src_branch} not mentionned in rb configuration}
sleep 2
f system %{git merge #{src_branch}}
puts %{Warning! #{src_branch} not mentionned in rb configuration}
end
end
end
case ARGV[0]
when 'allmerges' then do_all_merges
when 'merge' then do_merge
else system %{git #{ARGV.join(' ')}}
end

BIN
rubyzome/scripts/logo/rubyzome.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

219
rubyzome/scripts/logo/rubyzome.svg

@ -1,219 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="512"
height="512"
id="svg2"
version="1.1"
inkscape:version="0.47pre4 r22446"
sodipodi:docname="rubyzome.svg"
inkscape:export-filename="/home/e640846/Sites/gp/rubyzome/scripts/logo/rubyzome.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4">
<linearGradient
id="linearGradient3653">
<stop
style="stop-color:#ff0606;stop-opacity:1;"
offset="0"
id="stop3655" />
<stop
style="stop-color:#aa0000;stop-opacity:1;"
offset="1"
id="stop3657" />
</linearGradient>
<linearGradient
id="linearGradient3595">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3597" />
<stop
style="stop-color:#7e7e7e;stop-opacity:0;"
offset="1"
id="stop3599" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3595"
id="linearGradient3601"
x1="371.42856"
y1="135.21933"
x2="371.42856"
y2="218.07648"
gradientUnits="userSpaceOnUse" />
<inkscape:perspective
id="perspective3611"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3595-4"
id="linearGradient3601-0"
x1="371.42856"
y1="135.21933"
x2="371.42856"
y2="218.07648"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3595-4">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3597-8" />
<stop
style="stop-color:#7e7e7e;stop-opacity:0;"
offset="1"
id="stop3599-5" />
</linearGradient>
<linearGradient
y2="218.07648"
x2="371.42856"
y1="135.21933"
x1="371.42856"
gradientUnits="userSpaceOnUse"
id="linearGradient3620"
xlink:href="#linearGradient3595-4"
inkscape:collect="always" />
<filter
inkscape:collect="always"
id="filter3649"
color-interpolation-filters="sRGB">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="9.2347821"
id="feGaussianBlur3651" />
</filter>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3653"
id="radialGradient3659"
cx="358.57812"
cy="348.07812"
fx="358.57812"
fy="348.07812"
r="182.42188"
gradientTransform="matrix(1,0,0,1.4071949,0,-141.73562)"
gradientUnits="userSpaceOnUse" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3653"
id="radialGradient3706"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,1.4071949,0,-141.73562)"
cx="358.57812"
cy="348.07812"
fx="358.57812"
fy="348.07812"
r="182.42188" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3595"
id="linearGradient3708"
gradientUnits="userSpaceOnUse"
x1="371.42856"
y1="135.21933"
x2="371.42856"
y2="218.07648" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3595-4"
id="linearGradient3710"
gradientUnits="userSpaceOnUse"
x1="371.42856"
y1="135.21933"
x2="371.42856"
y2="218.07648" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="326.15388"
inkscape:cy="215.981"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1103"
inkscape:window-height="801"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-176.15625,-92.78125)">
<g
id="g3693"
transform="matrix(0.82025383,0,0,0.8270887,134.17352,57.33313)">
<path
id="path3641"
d="m 354.59375,90.4375 c -56.28759,0.808508 -109.82728,35.53482 -133.92294,86.07841 -19.59565,39.53173 -20.68486,87.86494 -2.88956,128.26534 -39.70778,46.57211 -52.94873,113.79694 -34.375,172.125 18.74021,61.96571 72.561,111.39137 135.96875,124.6875 57.14174,12.82193 119.74069,-3.89116 162.53125,-43.46875 42.7452,-38.24349 65.41546,-97.39027 59.15625,-154.59375 -3.66378,-36.14298 -18.35863,-70.94078 -41.71875,-98.71875 22.75256,-51.00504 14.24032,-114.18082 -21.25,-157.21875 -29.39984,-36.89663 -76.15886,-58.718847 -123.5,-57.15625 z"
style="fill:#2b0000;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;filter:url(#filter3649)" />
<g
id="g3682">
<path
style="opacity:0.96000001;fill:url(#radialGradient3706);fill-opacity:1;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 358.5625,92.375 c -83.63169,0 -151.40625,67.77456 -151.40625,151.40625 0,21.83859 4.61687,42.58987 12.9375,61.34375 -26.79967,31.62056 -42.9375,72.55362 -42.9375,117.25 0,100.20023 81.20602,181.40625 181.40625,181.40625 C 458.76273,603.78125 540,522.57523 540,422.375 540,377.68719 523.8217,336.77432 497.03125,305.15625 505.36148,286.39337 510,265.63318 510,243.78125 510,160.14956 442.19419,92.375 358.5625,92.375 z"
id="path2816" />
<path
sodipodi:type="arc"
style="fill:url(#linearGradient3708);fill-opacity:1;stroke:none"
id="path2821"
sodipodi:cx="371.42856"
sodipodi:cy="176.6479"
sodipodi:rx="71.428574"
sodipodi:ry="41.42857"
d="m 442.85713,176.6479 c 0,22.88037 -31.97966,41.42857 -71.42857,41.42857 -39.44891,0 -71.42858,-18.5482 -71.42858,-41.42857 0,-22.88036 31.97967,-41.42857 71.42858,-41.42857 39.44891,0 71.42857,18.54821 71.42857,41.42857 z"
transform="matrix(1.44,0,0,1.4827586,-176.279,-105.2783)" />
<path
sodipodi:type="arc"
style="fill:url(#linearGradient3710);fill-opacity:1;stroke:none"
id="path2821-1"
sodipodi:cx="371.42856"
sodipodi:cy="176.6479"
sodipodi:rx="71.428574"
sodipodi:ry="41.42857"
d="m 442.85713,176.6479 c 0,22.88037 -31.97966,41.42857 -71.42857,41.42857 -39.44891,0 -71.42858,-18.5482 -71.42858,-41.42857 0,-22.88036 31.97967,-41.42857 71.42858,-41.42857 39.44891,0 71.42857,18.54821 71.42857,41.42857 z"
transform="matrix(1.72,0,0,2.1034483,-280.279,-28.06469)" />
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 8.0 KiB

32
rubyzome/tasks.rb

@ -0,0 +1,32 @@
namespace "db" do
task :std_db_action, [:action] do |t,args|
require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'global'
# Connect to DB
DataMapper.setup(:default, $db_url)
# Include all models
Dir["app/models/*.rb"].each { |file| require file }
# Reset tables
DataMapper.finalize
if args.action == 'migrate'
DataMapper.auto_migrate!
puts 'migration finished'
elsif args.action == 'upgrade'
DataMapper.auto_upgrade!
puts 'upgrade finished'
else
puts 'std_db_action [migrate|upgrade]'
end
end
task :migrate do
Rake.application.invoke_task("db:std_db_action[migrate]")
end
task :upgrade do
Rake.application.invoke_task("db:std_db_action[upgrade]")
end
end

16
rubyzome/views.rb

@ -1,16 +0,0 @@
# encoding: utf-8
module Rubyzome
# load all standard views
if not defined? $views
$views={}
end
Dir["rubyzome/views/*.rb"].each do |file|
require file
if file == "/rubyzome/views/RestView.rb"
next
end
viewname=File.basename(file,File.extname(file))
$views[viewname]=Rubyzome.const_get(viewname)
end
end

17
rubyzome/views/HTMLView.rb

@ -1,11 +1,9 @@
# encoding: utf-8
module Rubyzome
# La classe pour renvoyer les valeurs en HTML
require 'erubis'
require 'rubyzome/views/RestView.rb'
class HTMLView < RestView
# La classe pour renvoyer les valeurs en HTML
require 'erubis'
require 'rubyzome/views/RestView.rb'
class HTMLView < RestView
attr_accessor :request
# make @template a class variable and not
@ -145,10 +143,9 @@ module Rubyzome
@object=object
render_error
end
end
end
# TODO: think to create a Rubyzome contant Rubyzome::Views::TemplateDir
HTMLView.template=File.read('rubyzome/views/html/templates/main.erb')
HTMLView.error_template=File.read('rubyzome/views/html/templates/error.erb')
HTMLView.template=File.read('rubyzome/views/html/templates/main.erb')
HTMLView.error_template=File.read('rubyzome/views/html/templates/error.erb')
# TODO: create three standard sub-template: header, content and footer. Most of time, only content should vary.
end

26
rubyzome/views/JSONView.rb

@ -1,19 +1,17 @@
# encoding: utf-8
module Rubyzome
require 'json'
require 'rubyzome/views/RestView.rb'
class JSONView < RestView
def initialize
@head = {'Content-Type' => 'application/json', 'charset' => 'UTF-8' }
end
require 'json'
require 'rubyzome/views/RestView.rb'
class JSONView < RestView
def initialize
@head = {'Content-Type' => 'application/json', 'charset' => 'UTF-8' }
end
def content(object)
JSON object
end
def content(object)
JSON object
end
def error(object)
content(object)
end
end
def error(object)
content(object)
end
end

4
rubyzome/views/RestView.rb

@ -1,7 +1,6 @@
# encoding: utf-8
module Rubyzome
class RestView
class RestView
attr_accessor :head
attr_accessor :code_return
def init_code_return_from_object(object)
@ -23,5 +22,4 @@ module Rubyzome
return self.content(object)
end
end
end
end

11
rubyzome/views/XMLView.rb

@ -1,12 +1,11 @@
# encoding: utf-8
module Rubyzome
require 'nokogiri'
require 'rubyzome/views/RestView.rb'
require 'nokogiri'
require 'rubyzome/views/RestView.rb'
# Class used to send back XML
class XMLView < RestView
# Class used to send back XML
class XMLView < RestView
def initialize
@head = {'Content-Type' => 'text/xml', 'charset' => 'UTF-8' }
end
@ -67,5 +66,5 @@ module Rubyzome
end
xml_item
end
end
end

9
rubyzome/views/html/templates/error.erb

@ -4,11 +4,8 @@
<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" />
<% e=@object[:exception] %>
<title><%= @object[:error].to_s %> - <%= @object[:exception].message %></title>
</head>
@ -18,6 +15,7 @@
<h2><%= @object[:exception].message %></h2>
</div>
<div id="middle">
<div id="content">
<p><%= puts @object %></p>
<table>
@ -31,6 +29,7 @@
<% end %>
</table>
</div>
</div>
<div id="bottom">
<div id="promotion">

16
rubyzome/views/html/templates/main.erb

@ -4,11 +4,8 @@
<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><%= @title %></title>
</head>
<body>
@ -17,18 +14,13 @@
<h2><%= @subtitle %></h2>
</div>
<div id="middle">
<div id="content">
<%= @content %>
</div>
</div>
<div id="bottom">
<<<<<<< HEAD
<div id="gprefs">
2009 GridPocket© SAS All Rights Reserved
</div>
<!--
=======
>>>>>>> origin/rubyzome
<div id="promotion">
Designed by <a href="http://yannesposito.com">Yann Esposito</a> &amp; <a href="http://lucarea.net">Luc Juggery</a>.
</div>

0
rubyzome/api/rubyzome.js → rubyzome/www/js/rubyzome.js

Loading…
Cancel
Save