Sha256: c0756fc34fc85dae5fa04e40480544741847bd16455771f9a3652799e9d49e11

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

class Lolita::InfoController < ApplicationController
  @@properties = []
  include Lolita::Controllers::AuthenticationHelpers

  def index
    if Lolita.mappings.any?
      if available_mapping = Lolita.mappings.detect{ |name,mapping| authorization_proxy.authorize!(:read, mapping.to) }
        mapping = available_mapping.last
        return redirect_to(lolita_resources_path(mapping))
      end
    end
    render :layout => false
  end

  def properties
    if request.local?
      render :inline => to_html
    else
      render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
    end
  end

  def is_lolita_resource?
    true
  end

  private

  def self.property(name, value = nil)
    value ||= yield
    @@properties << [name, value] if value
    rescue Exception
  end

  def to_html
    (table = '<table>').tap do
      @@properties.each do |(name, value)|
        table << %(<tr><td class="name">#{CGI.escapeHTML(name.to_s)}</td>)
        formatted_value = if value.kind_of?(Array)
              "<ul>" + value.map { |v| "<li>#{CGI.escapeHTML(v.to_s)}</li>" }.join + "</ul>"
            else
              CGI.escapeHTML(value.to_s)
            end
        table << %(<td class="value">#{formatted_value}</td></tr>)
      end
      table << '</table>'
    end
  end
    
  property 'Lolita version', "#{Lolita::Version}"

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lolita-3.3.9 app/controllers/lolita/info_controller.rb
lolita-3.3.8 app/controllers/lolita/info_controller.rb
lolita-3.3.7 app/controllers/lolita/info_controller.rb
lolita-3.3.6 app/controllers/lolita/info_controller.rb