Title / Description
Code class RepositoriesController < ApplicationController layout 'v2' before_filter :require_login def index @repositories = @user.account.repositories + @user.account.git_repositories end def show path = params[:path].join('/') if params[:repo_type].to_s == "svn" expected_class = Repository repo = @overview_repositories.find {|r| r.short_name.nil? == false && r.short_name.downcase == params[:id].to_s.downcase && r.is_a?(expected_class) rescue nil } else expected_class = GitRepository repo = @overview_repositories.find {|r| r.url.nil? == false && r.url.downcase == params[:id].to_s.downcase && r.is_a?(expected_class) rescue nil } end if repo.nil? throw "ACCESS DENIED" end if params[:repo_type].to_s == "svn" entries = repo.scm(@user.user_name, @user.user_password, 0).entries(path) else entries = repo.scm().entries(path, params[:branch]) end # Generate content for a file or a directory if requesting_a_file?(entries) if params[:repo_type].to_s == "svn" @content = render_to_string(:partial => "file", :locals => { :file => h(repo.scm(@user.user_name, @user.user_password, 0).cat(path, rev = nil)), :repo => get_repo_navigation, :filetype => ::CodeRay::FileType.fetch(params[:path].last, :text, true) } ) else @content = render_to_string(:partial => "file", :locals => { :file => h(repo.scm().cat(path, params[:branch])), :repo => get_repo_navigation, :filetype => ::CodeRay::FileType.fetch(params[:path].last, :text, true) } ) end else @content = render_to_string(:partial => "fs", :locals => { :entries => entries, :repo => get_repo_navigation } ) end render :text => @content if params["_pjax"] end private def get_repo_navigation config = {} arrPath = params[:path] if params[:repo_type].to_s == "svn" config[:root_path] = "/svn_repositories/#{params[:id]}" else config[:root_path] = "/git_repositories/#{params[:id]}/#{params[:branch]}" end config[:previous_path] = config[:root_path] + "/" + arrPath[0...-1].join("/") arrBreadcrumb = [{:title => "~", :href => config[:root_path]}] arrPath.each_with_index do |part, i| next if part.blank? # prevents adding an empty breadcrumb; I don't know # why it happens, but it does... so here's my fix. arrBreadcrumb << {:title => part, :href => arrBreadcrumb[arrBreadcrumb.length-1][:href] + "/" + part} end config[:breadcrumb] = arrBreadcrumb config end # Determines if the request is attempting to load a file def requesting_a_file?(entries) begin # If there's more than one entry, it's not a file if entries.count > 1 return false end # If the only entry isn't a file, it's not a file if "file" != entries[0].kind return false; end # If the last to parts of the path aren't the same, it's not a file # ex. TaskList/doc/README_FOR_APP/README_FOR_APP arrPath = entries[0].path.split("/") if arrPath[arrPath.count-2] != arrPath[arrPath.count-1] return false end return true rescue true end end end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code