decorators & tree model
This commit is contained in:
parent
6721ef01f4
commit
4bf4efe712
1
Gemfile
1
Gemfile
|
@ -21,6 +21,7 @@ gem "git"
|
|||
gem "acts_as_list"
|
||||
gem 'rdiscount'
|
||||
gem 'acts-as-taggable-on', '~> 2.1.0'
|
||||
gem 'drapper'
|
||||
|
||||
group :assets do
|
||||
gem 'sass-rails', "~> 3.1.0"
|
||||
|
|
|
@ -86,6 +86,7 @@ GEM
|
|||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.1)
|
||||
diff-lcs (1.1.3)
|
||||
drapper (0.8.4)
|
||||
erubis (2.7.0)
|
||||
eventmachine (0.12.10)
|
||||
execjs (1.2.9)
|
||||
|
@ -254,6 +255,7 @@ DEPENDENCIES
|
|||
coffee-rails (~> 3.1.0)
|
||||
database_cleaner
|
||||
devise (= 1.5.0)
|
||||
drapper
|
||||
faker
|
||||
git
|
||||
grit!
|
||||
|
|
|
@ -6,7 +6,8 @@ $(document).ready(function(){
|
|||
$("#tree-slider tr.tree-item").live('click', function(e){
|
||||
if(e.target.nodeName != "A") {
|
||||
e.stopPropagation();
|
||||
$(this).find("td.tree-item-file-name a").click();
|
||||
link = $(this).find("td.tree-item-file-name a")
|
||||
link.click();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -378,5 +378,3 @@ body.dashboard.project-page .news-feed .project-updates a.project-update span.up
|
|||
body.dashboard.project-page .news-feed .project-updates a.project-update span.update-author{color: #999; font-weight: normal; font-style: italic;}
|
||||
body.dashboard.project-page .news-feed .project-updates a.project-update span.update-author strong{font-weight: bold; font-style: normal;}
|
||||
/* eo Dashboard Page */
|
||||
|
||||
|
||||
|
|
|
@ -84,4 +84,10 @@ class ApplicationController < ActionController::Base
|
|||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def no_cache_headers
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,16 +25,14 @@ class RefsController < ApplicationController
|
|||
@repo = project.repo
|
||||
|
||||
@commit = @repo.commits(@ref).first
|
||||
@tree = @commit.tree
|
||||
@tree = @tree / params[:path] if params[:path]
|
||||
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
|
||||
@tree = TreeDecorator.new(@tree)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.html
|
||||
format.js do
|
||||
# diasbale cache to allow back button works
|
||||
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
|
||||
# disable cache to allow back button works
|
||||
no_cache_headers
|
||||
end
|
||||
end
|
||||
rescue
|
||||
|
|
28
app/decorators/application_decorator.rb
Normal file
28
app/decorators/application_decorator.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
class ApplicationDecorator < Drapper::Base
|
||||
# Lazy Helpers
|
||||
# PRO: Call Rails helpers without the h. proxy
|
||||
# ex: number_to_currency(model.price)
|
||||
# CON: Add a bazillion methods into your decorator's namespace
|
||||
# and probably sacrifice performance/memory
|
||||
#
|
||||
# Enable them by uncommenting this line:
|
||||
# lazy_helpers
|
||||
|
||||
# Shared Decorations
|
||||
# Consider defining shared methods common to all your models.
|
||||
#
|
||||
# Example: standardize the formatting of timestamps
|
||||
#
|
||||
# def formatted_timestamp(time)
|
||||
# h.content_tag :span, time.strftime("%a %m/%d/%y"),
|
||||
# :class => 'timestamp'
|
||||
# end
|
||||
#
|
||||
# def created_at
|
||||
# formatted_timestamp(model.created_at)
|
||||
# end
|
||||
#
|
||||
# def updated_at
|
||||
# formatted_timestamp(model.updated_at)
|
||||
# end
|
||||
end
|
7
app/decorators/commit_decorator.rb
Normal file
7
app/decorators/commit_decorator.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class CommitDecorator < ApplicationDecorator
|
||||
decorates :commit
|
||||
|
||||
def breadcrumbs
|
||||
|
||||
end
|
||||
end
|
33
app/decorators/tree_decorator.rb
Normal file
33
app/decorators/tree_decorator.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
class TreeDecorator < ApplicationDecorator
|
||||
decorates :tree
|
||||
|
||||
def breadcrumbs(max_links = 2)
|
||||
if path
|
||||
part_path = ""
|
||||
parts = path.split("\/")
|
||||
|
||||
yield(h.link_to("..", "#", :remote => :true)) if parts.count > max_links
|
||||
|
||||
parts.each do |part|
|
||||
part_path = File.join(part_path, part) unless part_path.empty?
|
||||
part_path = part if part_path.empty?
|
||||
|
||||
next unless parts.last(2).include?(part) if parts.count > max_links
|
||||
yield(h.link_to(h.truncate(part, :length => 40), h.tree_file_project_ref_path(project, ref, :path => part_path), :remote => :true))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def up_dir?
|
||||
!!path
|
||||
end
|
||||
|
||||
def up_dir_path
|
||||
file = File.join(path, "..")
|
||||
h.tree_file_project_ref_path(project, ref, file)
|
||||
end
|
||||
|
||||
def history_path
|
||||
h.project_commits_path(project, :path => path, :ref => ref)
|
||||
end
|
||||
end
|
2
app/models/commit.rb
Normal file
2
app/models/commit.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class Commit
|
||||
end
|
24
app/models/tree.rb
Normal file
24
app/models/tree.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class Tree
|
||||
attr_accessor :path, :tree, :project, :ref
|
||||
|
||||
delegate :contents,
|
||||
:basename,
|
||||
:name,
|
||||
:data,
|
||||
:text?,
|
||||
:colorize,
|
||||
:to => :tree
|
||||
|
||||
def initialize(raw_tree, project, ref = nil, path = nil)
|
||||
@project, @ref, @path = project, ref, path,
|
||||
@tree = if path
|
||||
raw_tree / path
|
||||
else
|
||||
raw_tree
|
||||
end
|
||||
end
|
||||
|
||||
def is_blob?
|
||||
tree.is_a?(Grit::Blob)
|
||||
end
|
||||
end
|
|
@ -1,26 +1,17 @@
|
|||
-#%a.right.button{:href => "#"} Download
|
||||
-#-if can? current_user, :admin_project, @project
|
||||
%a.right.button.blue{:href => "#"} EDIT
|
||||
#tree-breadcrumbs
|
||||
%h2.icon
|
||||
%span
|
||||
%d
|
||||
= link_to tree_project_ref_path(@project, @ref, :path => nil), :remote => true do
|
||||
= @project.name
|
||||
- if params[:path]
|
||||
- part_path = ""
|
||||
- params[:path].split("\/").each do |part|
|
||||
- part_path = File.join(part_path, part) unless part_path.empty?
|
||||
- if part_path.empty?
|
||||
- part_path = part
|
||||
\/
|
||||
= link_to truncate(part, :length => 40), tree_file_project_ref_path(@project, @ref, :path => part_path), :remote => :true
|
||||
|
||||
- tree.breadcrumbs(2) do |link|
|
||||
\/
|
||||
= link
|
||||
|
||||
.right= render :partial => "projects/refs", :locals => { :destination => :tree }
|
||||
.clear
|
||||
|
||||
#tree-content-holder
|
||||
- if tree.is_a?(Grit::Blob)
|
||||
- if tree.is_blob?
|
||||
= render :partial => "refs/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree }
|
||||
- else
|
||||
- contents = tree.contents
|
||||
|
@ -30,13 +21,13 @@
|
|||
%th Last Update
|
||||
%th
|
||||
Last commit
|
||||
= link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "right"
|
||||
- if params[:path]
|
||||
- file = File.join(params[:path], "..")
|
||||
%tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) }
|
||||
= link_to "history", tree.history_path, :class => "right"
|
||||
|
||||
- if tree.up_dir?
|
||||
%tr{ :class => "tree-item", :url => tree.up_dir_path }
|
||||
%td.tree-item-file-name
|
||||
= image_tag "dir.png"
|
||||
= link_to "..", tree_file_project_ref_path(@project, @ref, file), :remote => :true
|
||||
= link_to "..", tree.up_dir_path, :remote => :true
|
||||
%td
|
||||
%td
|
||||
|
||||
|
|
Loading…
Reference in a new issue