Commit 4bf4efe7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

decorators & tree model

parent 6721ef01
...@@ -21,6 +21,7 @@ gem "git" ...@@ -21,6 +21,7 @@ gem "git"
gem "acts_as_list" gem "acts_as_list"
gem 'rdiscount' gem 'rdiscount'
gem 'acts-as-taggable-on', '~> 2.1.0' gem 'acts-as-taggable-on', '~> 2.1.0'
gem 'drapper'
group :assets do group :assets do
gem 'sass-rails', "~> 3.1.0" gem 'sass-rails', "~> 3.1.0"
......
...@@ -86,6 +86,7 @@ GEM ...@@ -86,6 +86,7 @@ GEM
orm_adapter (~> 0.0.3) orm_adapter (~> 0.0.3)
warden (~> 1.1) warden (~> 1.1)
diff-lcs (1.1.3) diff-lcs (1.1.3)
drapper (0.8.4)
erubis (2.7.0) erubis (2.7.0)
eventmachine (0.12.10) eventmachine (0.12.10)
execjs (1.2.9) execjs (1.2.9)
...@@ -254,6 +255,7 @@ DEPENDENCIES ...@@ -254,6 +255,7 @@ DEPENDENCIES
coffee-rails (~> 3.1.0) coffee-rails (~> 3.1.0)
database_cleaner database_cleaner
devise (= 1.5.0) devise (= 1.5.0)
drapper
faker faker
git git
grit! grit!
......
...@@ -6,7 +6,8 @@ $(document).ready(function(){ ...@@ -6,7 +6,8 @@ $(document).ready(function(){
$("#tree-slider tr.tree-item").live('click', function(e){ $("#tree-slider tr.tree-item").live('click', function(e){
if(e.target.nodeName != "A") { if(e.target.nodeName != "A") {
e.stopPropagation(); e.stopPropagation();
$(this).find("td.tree-item-file-name a").click(); link = $(this).find("td.tree-item-file-name a")
link.click();
return false; return false;
} }
}); });
......
...@@ -378,5 +378,3 @@ body.dashboard.project-page .news-feed .project-updates a.project-update span.up ...@@ -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{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;} body.dashboard.project-page .news-feed .project-updates a.project-update span.update-author strong{font-weight: bold; font-style: normal;}
/* eo Dashboard Page */ /* eo Dashboard Page */
...@@ -84,4 +84,10 @@ class ApplicationController < ActionController::Base ...@@ -84,4 +84,10 @@ class ApplicationController < ActionController::Base
nil nil
end end
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 end
...@@ -25,16 +25,14 @@ class RefsController < ApplicationController ...@@ -25,16 +25,14 @@ class RefsController < ApplicationController
@repo = project.repo @repo = project.repo
@commit = @repo.commits(@ref).first @commit = @repo.commits(@ref).first
@tree = @commit.tree @tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = @tree / params[:path] if params[:path] @tree = TreeDecorator.new(@tree)
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html
format.js do format.js do
# diasbale cache to allow back button works # disable cache to allow back button works
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" no_cache_headers
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end end
end end
rescue rescue
......
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
class CommitDecorator < ApplicationDecorator
decorates :commit
def breadcrumbs
end
end
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
class Commit
end
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
-#%a.right.button{:href => "#"} Download
-#-if can? current_user, :admin_project, @project
%a.right.button.blue{:href => "#"} EDIT
#tree-breadcrumbs #tree-breadcrumbs
%h2.icon %h2.icon
%span %span
%d %d
= link_to tree_project_ref_path(@project, @ref, :path => nil), :remote => true do = link_to tree_project_ref_path(@project, @ref, :path => nil), :remote => true do
= @project.name = @project.name
- if params[:path] - tree.breadcrumbs(2) do |link|
- 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 = link
&nbsp; &nbsp;
.right= render :partial => "projects/refs", :locals => { :destination => :tree } .right= render :partial => "projects/refs", :locals => { :destination => :tree }
.clear .clear
#tree-content-holder #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 } = render :partial => "refs/tree_file", :locals => { :name => tree.name, :content => tree.data, :file => tree }
- else - else
- contents = tree.contents - contents = tree.contents
...@@ -30,13 +21,13 @@ ...@@ -30,13 +21,13 @@
%th Last Update %th Last Update
%th %th
Last commit Last commit
= link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "right" = link_to "history", tree.history_path, :class => "right"
- if params[:path]
- file = File.join(params[:path], "..") - if tree.up_dir?
%tr{ :class => "tree-item", :url => tree_file_project_ref_path(@project, @ref, file) } %tr{ :class => "tree-item", :url => tree.up_dir_path }
%td.tree-item-file-name %td.tree-item-file-name
= image_tag "dir.png" = 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
%td %td
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment