DG MS; move logic out of layout into LayoutsHelper.

This commit is contained in:
danielgrippi 2012-02-15 18:38:36 -08:00
parent 5f83abe418
commit 62c0ad13b7
4 changed files with 129 additions and 98 deletions

View file

@ -17,11 +17,84 @@ module LayoutHelper
current_user ? current_user.name : t("application.helper.diaspora_alpha")
end
def stylesheet(*args)
content_for(:head) { stylesheet_link_tag(*args) }
def set_asset_host
content_tag(:script) do
<<-JS.html_safe
app.baseImageUrl("#{ENV['ASSET_HOST']}")
JS
end
end
def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
def load_javascript_locales
content_tag(:script) do
<<-JS.html_safe
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
JS
end
end
def set_current_user_in_javascript
return unless current_user
content_tag(:script) do
<<-JS.html_safe
app.user(
_.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
notifications_count : #{notification_count},
unread_messages_count : #{unread_message_count},
admin : #{current_user.admin?}
})
);
JS
end
end
def current_user_atom_tag
return unless @person.present?
content_tag(:link, '', :rel => 'alternate', :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => t('.public_feed', :name => @person.name))
end
def translation_missing_warnings
return if Rails.env == "production"
content_tag(:style) do
<<-CSS
.translation_missing { color: purple; background-color: red; }
CSS
end
end
def include_base_css_framework
if @aspect == :getting_started || @page == :logged_out
include_stylesheets :bootstrap
else
include_stylesheets :blueprint, :media => 'screen'
end
end
def old_browser_js_support
content_tag(:script) do
<<-JS.html_safe
if(Array.isArray === undefined) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
};
}
if ((window.history) && (window.history.pushState === undefined)) {
window.history.pushState = function() { };
}
JS
end
end
def flash_messages
return if @page == :logged_out
flash.map do |name, msg|
content_tag(:div, :id => "flash_#{name}") do
content_tag(:div, msg, :class => 'message')
end
end.join(' ').html_safe
end
end

View file

@ -6,75 +6,26 @@
%html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'}
%head
%meta{:charset => 'utf-8'}
%title
= page_title yield(:page_title)
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
%meta{:name => "description", :content => "Diaspora*"}
%meta{:name => "author", :content => "Diaspora, Inc."}
%link{:rel => 'shortcut icon', :href => '/favicon.png'}
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
:css
@-webkit-keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@-moz-keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
}
@-moz-keyframes spin {
0% { -moz-transform: rotate(0deg); }
100% { -moz-transform: rotate(360deg); }
}
.loaded {
-webkit-animation: fade-in 0.16s linear;
-moz-animation: fade-in 0.16s linear;
}
.loader {
-webkit-animation: spin 1s infinite ease-in-out,
fade-in 0.2s ease-in;
-moz-animation: spin 1s infinite ease-in-out,
fade-in 0.2s ease-in;
}
/ bootstrap/blueprint switch
- if @aspect == :getting_started || @page == :logged_out
= include_stylesheets :bootstrap
- else
= include_stylesheets :blueprint, :media => 'screen'
%title
= page_title yield(:page_title)
= include_base_css_framework
= include_stylesheets :login, :media => 'screen'
= include_stylesheets :default, :media => 'all'
- if rtl?
= include_stylesheets :rtl, :media => 'all'
:javascript
// Support for older browsers
if(Array.isArray === undefined) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
};
}
if ((window.history) && (window.history.pushState === undefined)) {
window.history.pushState = function() { };
}
= csrf_meta_tag
= old_browser_js_support
<!--[if IE]>
= include_javascripts :ie
<![endif]-->
@ -82,55 +33,28 @@
= jquery_include_tag
- unless @landing_page
= include_javascripts :main, :templates
:javascript
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}");
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
= load_javascript_locales
:javascript
app.baseImageUrl("#{ENV['ASSET_HOST']}")
- if current_user
:javascript
app.user(
_.extend(#{current_user.person.as_api_response(:backbone).to_json}, {
notifications_count : #{notification_count},
unread_messages_count : #{unread_message_count},
admin : #{current_user.admin?}
})
);
= set_asset_host
= set_current_user_in_javascript
= translation_missing_warnings
= current_user_atom_tag
= yield(:head)
= csrf_meta_tag
-unless Rails.env == "production"
:css
.translation_missing {
color: purple;
background-color: red;
}
- if @person
%link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"}
%body{:class => "#{yield(:body_class)}"}
- unless @page == :logged_out
- flash.each do |name, msg|
%div{:id => "flash_#{name}"}
.message
= msg
#notifications
%body
= flash_messages
- unless current_user
%header
= render 'layouts/header'
.container{:style=> "#{yield(:break_the_mold)}"}
.container
- if @aspsect == :getting_started || @page == :logged_out
= yield
- else
.span-24.last{:style=> "#{yield(:break_the_mold)}"}
.span-24.last
= yield
- unless @landing_page

View file

@ -105,6 +105,7 @@ stylesheets:
- public/stylesheets/login.css
default:
- public/stylesheets/application.css
- public/stylesheets/loader.css
- public/stylesheets/ui.css
- public/stylesheets/lightbox.css
- public/stylesheets/autocomplete.css

View file

@ -0,0 +1,33 @@
@-webkit-keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
}
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@-moz-keyframes fade-in {
0% { opacity: 0; }
100% { opacity: 1; }
}
@-moz-keyframes spin {
0% { -moz-transform: rotate(0deg); }
100% { -moz-transform: rotate(360deg); }
}
.loaded {
-webkit-animation: fade-in 0.16s linear;
-moz-animation: fade-in 0.16s linear;
}
.loader {
-webkit-animation: spin 1s infinite ease-in-out,
fade-in 0.2s ease-in;
-moz-animation: spin 1s infinite ease-in-out,
fade-in 0.2s ease-in;
}