DG MS; move logic out of layout into LayoutsHelper.

This commit is contained in:
danielgrippi 2012-02-15 18:38:36 -08:00 committed by Maxwell Salzberg
parent 7ca423b3f2
commit be363b98e5
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") current_user ? current_user.name : t("application.helper.diaspora_alpha")
end end
def stylesheet(*args) def set_asset_host
content_for(:head) { stylesheet_link_tag(*args) } content_tag(:script) do
<<-JS.html_safe
app.baseImageUrl("#{ENV['ASSET_HOST']}")
JS
end
end end
def javascript(*args) def load_javascript_locales
content_for(:head) { javascript_include_tag(*args) } 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
end end

View file

@ -6,75 +6,26 @@
%html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'} %html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'}
%head %head
%meta{:charset => 'utf-8'} %meta{:charset => 'utf-8'}
%title
= page_title yield(:page_title)
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'} %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 => 'shortcut icon', :href => '/favicon.png'}
%link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'} %link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'}
:css %title
@-webkit-keyframes fade-in { = page_title yield(:page_title)
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'
= include_base_css_framework
= include_stylesheets :login, :media => 'screen' = include_stylesheets :login, :media => 'screen'
= include_stylesheets :default, :media => 'all' = include_stylesheets :default, :media => 'all'
- if rtl? - if rtl?
= include_stylesheets :rtl, :media => 'all' = include_stylesheets :rtl, :media => 'all'
:javascript = old_browser_js_support
// 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
<!--[if IE]> <!--[if IE]>
= include_javascripts :ie = include_javascripts :ie
<![endif]--> <![endif]-->
@ -82,55 +33,28 @@
= jquery_include_tag = jquery_include_tag
- unless @landing_page - unless @landing_page
= include_javascripts :main, :templates = include_javascripts :main, :templates
= load_javascript_locales
:javascript = set_asset_host
Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale).to_json}, "#{I18n.locale}"); = set_current_user_in_javascript
Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}"; = translation_missing_warnings
= current_user_atom_tag
: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?}
})
);
= yield(:head) = yield(:head)
= csrf_meta_tag
-unless Rails.env == "production" %body
:css = flash_messages
.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
- unless current_user - unless current_user
%header %header
= render 'layouts/header' = render 'layouts/header'
.container{:style=> "#{yield(:break_the_mold)}"} .container
- if @aspsect == :getting_started || @page == :logged_out - if @aspsect == :getting_started || @page == :logged_out
= yield = yield
- else - else
.span-24.last{:style=> "#{yield(:break_the_mold)}"} .span-24.last
= yield = yield
- unless @landing_page - unless @landing_page

View file

@ -105,6 +105,7 @@ stylesheets:
- public/stylesheets/login.css - public/stylesheets/login.css
default: default:
- public/stylesheets/application.css - public/stylesheets/application.css
- public/stylesheets/loader.css
- public/stylesheets/ui.css - public/stylesheets/ui.css
- public/stylesheets/lightbox.css - public/stylesheets/lightbox.css
- public/stylesheets/autocomplete.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;
}