From 8cf69faf32c7fb6606cbf09bf64a08080e583c7a Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Sun, 27 Nov 2011 12:41:28 +0400 Subject: [PATCH] Organizing misc pages --- app/assets/javascripts/beathaven.coffee | 4 ++- app/assets/javascripts/vkontakte.coffee | 1 + app/controllers/application_controller.rb | 27 +++++++------------ app/controllers/page_controller.rb | 21 +++++++++++++++ .../{application => page}/_about.en.html.haml | 0 .../{application => page}/_about.ru.html.haml | 0 .../_greetings.en.html.haml | 0 .../_greetings.ru.html.haml | 0 .../{application => page}/_stat.en.html.haml | 0 .../{application => page}/_stat.ru.html.haml | 0 .../{application => page}/index.html.haml | 0 config/routes.rb | 10 +++---- 12 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 app/controllers/page_controller.rb rename app/views/{application => page}/_about.en.html.haml (100%) rename app/views/{application => page}/_about.ru.html.haml (100%) rename app/views/{application => page}/_greetings.en.html.haml (100%) rename app/views/{application => page}/_greetings.ru.html.haml (100%) rename app/views/{application => page}/_stat.en.html.haml (100%) rename app/views/{application => page}/_stat.ru.html.haml (100%) rename app/views/{application => page}/index.html.haml (100%) diff --git a/app/assets/javascripts/beathaven.coffee b/app/assets/javascripts/beathaven.coffee index 7d879d0..a44cefa 100644 --- a/app/assets/javascripts/beathaven.coffee +++ b/app/assets/javascripts/beathaven.coffee @@ -30,9 +30,11 @@ class window.BeatHaven lang: 'ru' init: -> + log "Initiatin BeatHaven ..." + window._vkontakte = new Vkontakte(2335068) window._vkontakte.init() - window._vk_music = new VkontakteMusic + window._vk_music = new VkontakteMusic() window._ajax = new Ajax() diff --git a/app/assets/javascripts/vkontakte.coffee b/app/assets/javascripts/vkontakte.coffee index 7193cb5..83c35bd 100644 --- a/app/assets/javascripts/vkontakte.coffee +++ b/app/assets/javascripts/vkontakte.coffee @@ -8,6 +8,7 @@ class window.Vkontakte @api_id init: -> + log "Initiatin Vkontakte API ..." window.vkAsyncInit = -> VK.init apiId: _vkontakte.getApiId() VK.Auth.getLoginStatus (response) -> diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2c0c82f..1698837 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,28 +5,19 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale - def index; end - - def greetings - render partial: 'greetings' - end - - def about - render partial: 'about' - end - - def stat - @artists = Artist.count - @albums = Album.count - @tracks = Track.count - @users = User.count - render partial: 'stat' - end - def cache_for time response.headers['Cache-Control'] = 'public, max-age=' + time.seconds.to_s end + def compile_page params + @data = params[:data] + render json: { + status: (params[:status] unless params[:status].nil?), + data: @data, + html: render_compact_partial(params[:partial]) + }, include: (params[:include] unless params[:include].nil?) + end + protected def authorize diff --git a/app/controllers/page_controller.rb b/app/controllers/page_controller.rb new file mode 100644 index 0000000..93713b3 --- /dev/null +++ b/app/controllers/page_controller.rb @@ -0,0 +1,21 @@ +class PageController < ApplicationController + def index + # Something + end + + def greetings + render partial: 'greetings' + end + + def about + render partial: 'about' + end + + def stat + @artists = Artist.count + @albums = Album.count + @tracks = Track.count + @users = User.count + render partial: 'stat' + end +end diff --git a/app/views/application/_about.en.html.haml b/app/views/page/_about.en.html.haml similarity index 100% rename from app/views/application/_about.en.html.haml rename to app/views/page/_about.en.html.haml diff --git a/app/views/application/_about.ru.html.haml b/app/views/page/_about.ru.html.haml similarity index 100% rename from app/views/application/_about.ru.html.haml rename to app/views/page/_about.ru.html.haml diff --git a/app/views/application/_greetings.en.html.haml b/app/views/page/_greetings.en.html.haml similarity index 100% rename from app/views/application/_greetings.en.html.haml rename to app/views/page/_greetings.en.html.haml diff --git a/app/views/application/_greetings.ru.html.haml b/app/views/page/_greetings.ru.html.haml similarity index 100% rename from app/views/application/_greetings.ru.html.haml rename to app/views/page/_greetings.ru.html.haml diff --git a/app/views/application/_stat.en.html.haml b/app/views/page/_stat.en.html.haml similarity index 100% rename from app/views/application/_stat.en.html.haml rename to app/views/page/_stat.en.html.haml diff --git a/app/views/application/_stat.ru.html.haml b/app/views/page/_stat.ru.html.haml similarity index 100% rename from app/views/application/_stat.ru.html.haml rename to app/views/page/_stat.ru.html.haml diff --git a/app/views/application/index.html.haml b/app/views/page/index.html.haml similarity index 100% rename from app/views/application/index.html.haml rename to app/views/page/index.html.haml diff --git a/config/routes.rb b/config/routes.rb index 8666641..7feddef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,8 @@ Beathaven::Application.routes.draw do - match '/' => 'application#index' - match '/greetings/' => 'application#greetings' - match '/about/' => 'application#about' - match '/stat/' => 'application#stat' + match '/' => 'page#index' + match '/greetings/' => 'page#greetings' + match '/about/' => 'page#about' + match '/stat/' => 'page#stat' match 'user/auth' => 'user#auth' match 'user/update' => 'user#update' @@ -21,5 +21,5 @@ Beathaven::Application.routes.draw do match 'settings' => 'user#settings' match 'artist/autocomplete' => 'last_fm#autocomplete' - match 'artist/(:name)' => 'artist#data', :constraints => { :name => /.*/ } + match 'artist/(:name)' => 'artist#data', constraints: { name: /.*/ } end