decorators & tree model
This commit is contained in:
parent
6721ef01f4
commit
4bf4efe712
12 changed files with 120 additions and 29 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue