cirandas.net

ref: master

app/helpers/layout_helper.rb


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
module LayoutHelper

  protected

  def body_classes
    [
      (logged_in? ? " logged-in" : nil),
      "#{" responsive" if theme_option :responsive}",
      "controller-#{controller.controller_name}",
      "action-#{controller.controller_name}-#{controller.action_name}",
      "template-#{@layout_template || layout_template}",
      (!profile.nil? && profile.is_on_homepage?(request.path,@page) ? "profile-homepage" : nil),
      profile.present? ? profile.kinds_style_classes : nil,
    ].compact.join(' ')
  end

  def html_tag_classes
    [
      body_classes, (
        profile.blank? ? nil : [
          'profile-type-is-' + profile.class.name.downcase,
          'profile-name-is-' + profile.identifier,
        ]
      ), 'theme-' + current_theme,
      @plugins.dispatch(:html_tag_classes).map do |content|
        if content.respond_to?(:call)
          instance_exec(&content)
        else
          content.html_safe
        end
      end
    ].flatten.compact.join(' ')
  end

  def noosfero_javascript
    plugins_javascripts = @plugins.flat_map{ |plugin| Array.wrap(plugin.js_files).map{ |js| plugin.class.public_path(js, true) } }

    output = ''
    output += render 'layouts/javascript'
    unless plugins_javascripts.empty?
      output += javascript_include_tag *plugins_javascripts
    end
    output += theme_javascript_ng.to_s
    output += javascript_tag 'render_all_jquery_ui_widgets()'

    output += template_javascript_ng.to_s

    # This output should be safe!
    output.html_safe
  end

  def noosfero_stylesheets
    plugins_stylesheets = @plugins.select(&:stylesheet?).map { |plugin|
      plugin.class.public_path('style.css', true)
    }
    global_css_pub = "/designs/themes/#{session[:theme] || environment.theme}/global.css"
    global_css_at_fs = Rails.root.join 'public' + global_css_pub

    output = []
    output << stylesheet_link_tag('application')
    output << stylesheet_link_tag(template_stylesheet_path)
    output << stylesheet_link_tag(*icon_theme_stylesheet_path)
    output << stylesheet_link_tag('designs/icons/awesome/scss/font-awesome') if defined? ResponsivePlugin and not theme_responsive?
    output << stylesheet_link_tag(jquery_ui_theme_stylesheet_path)
    unless plugins_stylesheets.empty?
      # FIXME: caching does not work with asset pipeline
      #cacheid = "cache/plugins-#{Digest::MD5.hexdigest plugins_stylesheets.to_s}"
      output << stylesheet_link_tag(*plugins_stylesheets)
    end
    if File.exists? global_css_at_fs
      output << stylesheet_link_tag(global_css_pub)
    end
    output << stylesheet_link_tag(theme_stylesheet_path)

    # This output should be safe!
    output.join("\n").html_safe
  end

  def noosfero_layout_features
    render :file => 'shared/noosfero_layout_features'
  end

  def template_stylesheet_path
    File.join template_path, "/stylesheets/style.css"
  end


  def icon_theme_stylesheet_path
    theme_icon_themes = theme_option(:icon_theme) || []
    theme_icon_themes.map{ |it| "designs/icons/#{it}/style.css" }
  end

  def jquery_ui_theme_stylesheet_path
    "https://code.jquery.com/ui/1.10.4/themes/#{jquery_theme}/jquery-ui.css"
  end

  def theme_stylesheet_path
    "#{theme_path}/style.css".gsub(%r{^/}, '')
  end

  def layout_template
    if profile then profile.layout_template else environment.layout_template end
  end

  def addthis_javascript
    return unless NOOSFERO_CONF['addthis_enabled']
    javascript_include_tag "//s7.addthis.com/js/300/addthis_widget.js#pubid=#{NOOSFERO_CONF['addthis_pub']}"
  end

end