home site rendering works; fixed remote rendering (50% done);

This commit is contained in:
Tobias Klika
2011-07-02 04:56:00 +02:00
parent 7bda55c936
commit dac0f9349b
13 changed files with 255 additions and 99 deletions
+21 -13
View File
@@ -1,23 +1,31 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter { |c| @youtube_client = YouTubeIt::Client.new(:dev_key=>"AI39si600H1fRQ6HW1pHG89e-23Uxf44YHu5TsCJMhNf5hFaYWSSSyyrOIEcOX451sFeh_OZdbbA48_g6OInfTv042-Id163tg") }
# create the youtube client to access the API
before_filter { |c|
@youtube_client = YouTubeIt::Client.new(
:dev_key=>"AI39si600H1fRQ6HW1pHG89e-23Uxf44YHu5TsCJMhNf5hFaYWSSSyyrOIEcOX451sFeh_OZdbbA48_g6OInfTv042-Id163tg"
)
}
# REMOTE CALL HELPER
# for accessing/modifying ajax links
def render_remote view
if params[:remote] == "true"
render view, :layout=>false
else
render :nothing=>true, :layout=>true
end
end
def async_redirect_to path
redirect_to "/#!" + path
end
def validate_img_url image, type, size
@attr = (type=="gallery") ? "name" : "size"
image.each do |img|
if img[@attr] == size.to_s
if img["#text"].blank?
return "/images/placeholder/#{type.to_s}.png"
end
return img["#text"]
end
end
def async_link_to body, path, html_options = {}
link_to body, "/#!" + path, html_options
end
end
-4
View File
@@ -22,10 +22,6 @@ class ArtistsController < ApplicationController
}
end
def index
redirect_to :root
end
def more_tracks
prepare params
+3 -3
View File
@@ -1,8 +1,8 @@
class HomeController < ApplicationController
def show
def index
@files = Dir.glob("public/images/startsite/*.jpg")
render :partial=>"index", :locals => {:files => @files}
render_remote :index
end
end
+23 -5
View File
@@ -11,14 +11,36 @@ module ApplicationHelper
return img["#text"]
end
end
end
def get_album_info album, artist
@result = LastFM::Album.getInfo(album, artist)
@result.album
end
# REMOTE CALL HELPER
# for accessing/modifying ajax links
def render_remote view
if params[:remote] == "true"
render view, :layout=>false
else
render :nothing=>true, :layout=>true
end
end
def async_redirect_to path
redirect_to "/#!" + path
end
def async_link_to body, path, html_options = {}
link_to body, "/#!" + path, html_options
end
# STRING HELPER
def trimString str, length
truncate str, :length => length.to_i, :omission => ""
end
@@ -28,8 +50,4 @@ module ApplicationHelper
return phrase
end
def async_link_to body, path, html_options = {}
link_to body, "/#!" + path, html_options
end
end
-11
View File
@@ -1,11 +0,0 @@
%ul#top_artist
- for file in files
%li= image_tag "startsite/"+File.basename(file)
%ul#top_artist_nav
%li= link_to image_tag("startsite/small/beatles.jpg"),"", :class=>"ll dir"
%li= image_tag "startsite/small/katy-perry.jpg", :class=>"cc"
%li= link_to image_tag("startsite/small/coldplay.jpg"),"", :class=>"rr dir"
#search_home
%br.clean
#home_foot
.right
+11
View File
@@ -0,0 +1,11 @@
%ul#top_artist
- for file in @files
%li= image_tag "startsite/"+File.basename(file)
%ul#top_artist_nav
%li= link_to image_tag("startsite/small/beatles.jpg"),"", :class=>"ll dir"
%li= image_tag "startsite/small/katy-perry.jpg", :class=>"cc"
%li= link_to image_tag("startsite/small/coldplay.jpg"),"", :class=>"rr dir"
#search_home
%br.clean
#home_foot
.right
+1
View File
@@ -38,6 +38,7 @@
%li.login= async_link_to image_tag("icons/login.png"), new_user_session_path
%br.clean
#content
= yield
%br.clean
#foot
- date = DateTime.now
+1 -1
View File
@@ -28,7 +28,7 @@ Nineminutes::Application.routes.draw do
resources :users, :only => [ :show, :update, :edit, :create ]
get "/home", :to => "home#show"
get "/home", :to => "home#index"
root :to => "home#index"
end
+5
View File
@@ -43,6 +43,10 @@ function favourite_request(link, params){
}
function load_site_request(link, params){
params = (typeof params == "undefined" || typeof params == "boolean") ? "" : params;
show_flash(false);
if(link != user_path)
cacheResponse = cacheRequest(link+params);
else cacheResponse = false;
@@ -55,6 +59,7 @@ function load_site_request(link, params){
type:"GET",
dataType:"html",
url: link + params,
data:"remote=true",
error: function(){
hide_flash(false);
show_flash(true);
+36 -48
View File
@@ -1,51 +1,39 @@
$(document).ready(function(){
// Artist Show Page
Path.map(hashbang+artist_path+":id").to(function(){
load_site_request(artist_path, this.params['id']);
});
// Artist Show Page
Path.map(hashbang+artist_path+":id").to(function(){
show_flash(false);
load_site_request(artist_path, this.params['id']);
});
// Home Page
Path.map(hashbang+home_path).to(function(){
show_flash(false);
load_site_request(home_path, "");
});
// Charts Page
Path.map(hashbang+charts_path).to(function(){
show_flash(false);
load_site_request(charts_path, "");
});
// Search Page
Path.map(hashbang+search_path+":q").to(function(){
show_flash(false);
load_site_request(search_path, this.params['q']);
});
// Home Page
Path.map(hashbang+home_path).to(function(){
load_site_request(home_path);
});
// Sign Up Page
Path.map(hashbang+register_path).to(function(){
show_flash(false);
load_site_request(register_path, "");
});
// Sign In Page
Path.map(hashbang+login_path).to(function(){
show_flash(false);
load_site_request(login_path, "");
});
// Sign Out Page
Path.map(hashbang+logout_path).to(function(){
show_flash(false);
load_site_request(logout_path, "");
});
// User Show Page
Path.map(hashbang+user_path+":id").to(function(){
show_flash(false);
load_site_request(user_path, this.params['id']);
});
// Charts Page
Path.map(hashbang+charts_path).to(function(){
load_site_request(charts_path);
});
// Search Page
Path.map(hashbang+search_path+":q").to(function(){
load_site_request(search_path, this.params['q']);
});
// Sign Up Page
Path.map(hashbang+register_path).to(function(){
load_site_request(register_path);
});
// Sign In Page
Path.map(hashbang+login_path).to(function(){
load_site_request(login_path);
});
// Sign Out Page
Path.map(hashbang+logout_path).to(function(){
load_site_request(logout_path);
});
// User Show Page
Path.map(hashbang+user_path+":id").to(function(){
load_site_request(user_path, this.params['id']);
});
+5 -2
View File
@@ -15,9 +15,12 @@ var favourite_path = "/favourize";
var search_video_path = "/search_video";
$(document).ready(function(){
// home path
Path.root(hashbang+home_path);
// home site
Path.root("#!/home");
// initialize path listener
Path.listen();
// redirect non existent links
// to the 404 page
Path.rescue(function(){
-1
View File
@@ -1,5 +1,4 @@
$(document).ready(function() {
Path.listen();
initPlaylist();
});
+149 -11
View File
@@ -1,11 +1,149 @@
var Path={'version':"0.6",'map':function(path){if(Path.routes.hasOwnProperty(path)){return Path.routes[path];}else{return new Path.core.route(path);}},'root':function(path){Path.routes.root=path;},'rescue':function(fn){Path.routes.rescue=fn;},'match':function(path,parameterize){var params={};var parse_params=function(str){var results=[],re=/\(([^}]+?)\)/g,text;while(text=re.exec(str)){results.push(text[1]);}
return results;};var route=null;var i=null;for(route in Path.routes){if(route!==null&&route!==undefined){var optional_parts=parse_params(route);var valid_routes=[];valid_routes.push(route.split("(")[0]);for(var j=0;j<optional_parts.length;j++){valid_routes.push(valid_routes[valid_routes.length-1]+optional_parts[j]);}
for(var x=0;x<valid_routes.length;x++){var rroute=valid_routes[x];var compare=path;if(rroute.search(/:/)>0){for(i=0;i<rroute.split("/").length;i++){if((i<compare.split("/").length)&&(rroute.split("/")[i][0]===":")){params[rroute.split('/')[i].replace(/:/,'')]=compare.split("/")[i];compare=compare.replace(compare.split("/")[i],rroute.split("/")[i]);}}}
if(rroute===compare){if(parameterize){Path.routes[route].params=params;}
return Path.routes[route];}}}}
return null;},'dispatch':function(){if(Path.routes.current!==location.hash){Path.routes.previous=Path.routes.current;Path.routes.current=location.hash;var match=Path.match(location.hash,true);if(match!==null){match.run();}else{if(Path.routes.rescue!==null){var previous_route=Path.match(Path.routes.previous);if(previous_route!=null&&previous_route.do_exit!==null){previous_route.do_exit();}
Path.routes.rescue();}}}},'listen':function(){if(location.hash===""){if(Path.routes.root!==null){location.hash=Path.routes.root;}}else{Path.dispatch();}
if("onhashchange"in window){window.onhashchange=Path.dispatch;}else{setInterval(Path.dispatch,50);}},'core':{'route':function(path){this.path=path;this.action=null;this.do_enter=[];this.do_exit=null;this.params={};Path.routes[path]=this;}},'routes':{'current':null,'root':null,'rescue':null,'previous':null}};Path.core.route.prototype={'to':function(fn){this.action=fn;return this;},'enter':function(fns){if(fns instanceof Array){this.do_enter=this.do_enter.concat(fns);}else{this.do_enter.push(fns);}
return this;},'exit':function(fn){this.do_exit=fn;return this;},'run':function(){var halt_execution=false;if(Path.routes.previous){var previous=Path.match(Path.routes.previous,false);if(previous&&previous.do_exit!==null){previous.do_exit();}}
if(Path.routes[this.path].hasOwnProperty("do_enter")){if(Path.routes[this.path].do_enter.length>0){for(var i=0;i<Path.routes[this.path].do_enter.length;i++){result=Path.routes[this.path].do_enter[i]();if(result===false){halt_execution=true;break;}}}}
if(!halt_execution){Path.routes[this.path].action();}}};
var Path = {
'version': "0.6.4",
'map': function (path) {
if (Path.routes.defined.hasOwnProperty(path)) {
return Path.routes.defined[path];
} else {
return new Path.core.route(path);
}
},
'root': function (path) {
Path.routes.root = path;
},
'rescue': function (fn) {
Path.routes.rescue = fn;
},
'match': function (path, parameterize) {
var params = {}, route = null, possible_routes, slice, i, j, compare;
for (route in Path.routes.defined) {
if (route !== null && route !== undefined) {
route = Path.routes.defined[route];
possible_routes = route.partition();
for (j = 0; j < possible_routes.length; j++) {
slice = possible_routes[j];
compare = path;
if (slice.search(/:/) > 0) {
for (i = 0; i < slice.split("/").length; i++) {
if ((i < compare.split("/").length) && (slice.split("/")[i][0] === ":")) {
params[slice.split('/')[i].replace(/:/, '')] = compare.split("/")[i];
compare = compare.replace(compare.split("/")[i], slice.split("/")[i]);
}
}
}
if (slice === compare) {
if (parameterize) {
route.params = params;
}
return route;
}
}
}
}
return null;
},
'dispatch': function () {
var previous_route, matched_route;
if (Path.routes.current !== location.hash) {
Path.routes.previous = Path.routes.current;
Path.routes.current = location.hash;
matched_route = Path.match(location.hash, true);
if (Path.routes.previous) {
previous_route = Path.match(Path.routes.previous);
if (previous_route !== null && previous_route.do_exit !== null) {
previous_route.do_exit();
}
}
if (matched_route !== null) {
matched_route.run();
} else {
if (Path.routes.rescue !== null) {
Path.routes.rescue();
}
}
}
},
'listen': function () {
if (location.hash === "") {
if (Path.routes.root !== null) {
location.hash = Path.routes.root;
// artistandarchitects:
// Added to init response on hashchange
Path.dispatch();
}
} else {
Path.dispatch();
}
if ("onhashchange" in window) {
window.onhashchange = Path.dispatch;
} else {
setInterval(Path.dispatch, 50);
}
},
'core': {
'route': function (path) {
this.path = path;
this.action = null;
this.do_enter = [];
this.do_exit = null;
this.params = {};
Path.routes.defined[path] = this;
}
},
'routes': {
'current': null,
'root': null,
'rescue': null,
'previous': null,
'defined': {}
}
};
Path.core.route.prototype = {
'to': function (fn) {
this.action = fn;
return this;
},
'enter': function (fns) {
if (fns instanceof Array) {
this.do_enter = this.do_enter.concat(fns);
} else {
this.do_enter.push(fns);
}
return this;
},
'exit': function (fn) {
this.do_exit = fn;
return this;
},
'partition': function () {
var parts = [], options = [], re = /\(([^}]+?)\)/g, text, i;
while (text = re.exec(this.path)) {
parts.push(text[1]);
}
options.push(this.path.split("(")[0]);
for (i = 0; i < parts.length; i++) {
options.push(options[options.length - 1] + parts[i]);
}
return options;
},
'run': function () {
var halt_execution = false, i, result, previous;
if (Path.routes.defined[this.path].hasOwnProperty("do_enter")) {
if (Path.routes.defined[this.path].do_enter.length > 0) {
for (i = 0; i < Path.routes.defined[this.path].do_enter.length; i++) {
result = Path.routes.defined[this.path].do_enter[i]();
if (result === false) {
halt_execution = true;
break;
}
}
}
}
if (!halt_execution) {
Path.routes.defined[this.path].action();
}
}
};