# # Copyright 2011 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'util' require 'authentication' require 'sinatra/url_for' module Backstage class Application < Sinatra::Base helpers do include Backstage::Authentication include Sinatra::UrlForHelper def json_url_for(fragment, options = { }) options[:format] = 'json' url_for( fragment, :full, options ) end def object_path(object) object_action_or_collection_path(*(object.association_chain << nil)) end def object_action_or_collection_path(*objects) collection_or_action = objects.pop paths = [] objects.each do |object| paths << "#{simple_class_name( object )}/#{Util.encode_name( object.full_name )}" end paths << collection_or_action if collection_or_action '/' + paths.join( '/' ) end alias_method :object_action_path, :object_action_or_collection_path alias_method :collection_path, :object_action_or_collection_path def redirect_to(location) redirect url_for(location, :full) end def link_to(path, text, options = {}) "#{text}" end def data_row(name, value) dom_class = ['value'] dom_class << 'status' << value.downcase if name.to_s.downcase == 'status' # hack "