layout_helper.rb 2.53 KB
Newer Older
danielgrippi's avatar
danielgrippi committed
1
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
Raphael's avatar
Raphael committed
2
#   licensed under the Affero General Public License version 3 or later.  See
Raphael's avatar
Raphael committed
3
#   the COPYRIGHT file.
4

5 6 7 8 9
# These helper methods can be called in your template to set variables to be used in the layout
# This module should be included in all views globally,
# to do so you may need to add this line to your ApplicationController
#   helper :layout
module LayoutHelper
10 11
  include ApplicationHelper

12 13 14 15
  def title(page_title, show_title = true)
    content_for(:title) { page_title.to_s }
    @show_title = show_title
  end
16

17 18
  def page_title(text=nil)
    return text unless text.blank?
19
    pod_name
20 21
  end

22
  def set_asset_host
23
    path = AppConfig.environment.assets.host.to_s + '/assets/'
24 25
    content_tag(:script) do
      <<-JS.html_safe
26
        if(window.app) app.baseImageUrl("#{path}")
27 28
      JS
    end
29
  end
30

31
  def load_javascript_locales(section = 'javascripts')
32 33
    content_tag(:script) do
      <<-JS.html_safe
34
        Diaspora.I18n.loadLocale(#{get_javascript_strings_for(I18n.locale, section).to_json}, "#{I18n.locale}");
35 36 37 38 39
        Diaspora.Page = "#{params[:controller].camelcase}#{params[:action].camelcase}";
      JS
    end
  end

40
  def current_user_atom_tag
danielgrippi's avatar
danielgrippi committed
41 42
    return #temp hax

43 44 45 46 47 48 49 50 51 52 53 54 55 56
    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

57
  def include_base_css_framework(use_bootstrap=false)
58
    if use_bootstrap || @aspect == :getting_started
Jonne Haß's avatar
Jonne Haß committed
59
      stylesheet_link_tag('bootstrap-complete')
60
    else
61
      stylesheet_link_tag 'blueprint', :media => 'screen'
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    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
    flash.map do |name, msg|
      content_tag(:div, :id => "flash_#{name}") do
        content_tag(:div, msg, :class => 'message')
      end
    end.join(' ').html_safe
86
  end
87

88 89 90
  def bootstrap?
    @css_framework == :bootstrap
  end
91
end