diff --git a/Gemfile b/Gemfile index f1f17912..459a8b41 100644 --- a/Gemfile +++ b/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" diff --git a/Gemfile.lock b/Gemfile.lock index a0d9d664..04c7764b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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! diff --git a/app/assets/javascripts/projects.js b/app/assets/javascripts/projects.js index b58cf277..4ffbd140 100644 --- a/app/assets/javascripts/projects.js +++ b/app/assets/javascripts/projects.js @@ -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; } }); diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 9098c194..4c20273e 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -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 */ - - diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 95d94035..b37deafd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index 0da429b8..a694115f 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -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 diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb new file mode 100644 index 00000000..8c35cae9 --- /dev/null +++ b/app/decorators/application_decorator.rb @@ -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 diff --git a/app/decorators/commit_decorator.rb b/app/decorators/commit_decorator.rb new file mode 100644 index 00000000..e4dc027a --- /dev/null +++ b/app/decorators/commit_decorator.rb @@ -0,0 +1,7 @@ +class CommitDecorator < ApplicationDecorator + decorates :commit + + def breadcrumbs + + end +end diff --git a/app/decorators/tree_decorator.rb b/app/decorators/tree_decorator.rb new file mode 100644 index 00000000..8379006c --- /dev/null +++ b/app/decorators/tree_decorator.rb @@ -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 diff --git a/app/models/commit.rb b/app/models/commit.rb new file mode 100644 index 00000000..09030cab --- /dev/null +++ b/app/models/commit.rb @@ -0,0 +1,2 @@ +class Commit +end diff --git a/app/models/tree.rb b/app/models/tree.rb new file mode 100644 index 00000000..032290a0 --- /dev/null +++ b/app/models/tree.rb @@ -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 diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index 5dd55ee4..498acbde 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -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