summaryrefslogtreecommitdiff
path: root/app/helpers/tree_helper.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-10-03 18:40:56 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-10-03 19:39:27 -0400
commit388d72e6bf9c3e72113b8c16d1cc266b41870eb9 (patch)
tree99ba9ba92d807d091a90ff1c8df2841687fec13a /app/helpers/tree_helper.rb
parenta8fad4ff9c1ae5adbe55989a44dad56a6a9b56e6 (diff)
downloadgitlab-ce-388d72e6bf9c3e72113b8c16d1cc266b41870eb9.tar.gz
Add render_tree helper; simplify (speed up) tree_icon
Diffstat (limited to 'app/helpers/tree_helper.rb')
-rw-r--r--app/helpers/tree_helper.rb47
1 files changed, 29 insertions, 18 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index 81a16989405..65c2379917c 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -1,29 +1,40 @@
module TreeHelper
- def tree_icon(content)
- if content.is_a?(Grit::Blob)
- if content.text?
- image_tag "file_txt.png"
- elsif content.image?
- image_tag "file_img.png"
+ # Sorts a repository's tree so that folders are before files and renders
+ # their corresponding partials
+ #
+ # contents - A Grit::Tree object for the current tree
+ def render_tree(contents)
+ # Render Folders before Files/Submodules
+ folders, files = contents.partition { |v| v.kind_of?(Grit::Tree) }
+
+ tree = ""
+
+ # Render folders if we have any
+ tree += render partial: 'tree/tree_item', collection: folders, locals: {type: 'folder'} if folders.present?
+
+ files.each do |f|
+ if f.respond_to?(:url)
+ # Object is a Submodule
+ tree += render partial: 'tree/submodule_item', object: f
else
- image_tag "file_bin.png"
+ # Object is a Blob
+ tree += render partial: 'tree/tree_item', object: f, locals: {type: 'file'}
end
- else
- image_tag "file_dir.png"
end
+
+ tree.html_safe
end
- def tree_hex_class(content)
- "file_#{hexdigest(content.name)}"
+ # Return an image icon depending on the file type
+ #
+ # type - String type of the tree item; either 'folder' or 'file'
+ def tree_icon(type)
+ image = type == 'folder' ? 'file_dir.png' : 'file_txt.png'
+ image_tag(image, size: '16x16')
end
- def tree_full_path(content)
- content.name.force_encoding('utf-8')
- if params[:path]
- File.join(params[:path], content.name)
- else
- content.name
- end
+ def tree_hex_class(content)
+ "file_#{hexdigest(content.name)}"
end
# Public: Determines if a given filename is compatible with GitHub::Markup.