Class: Precious::Views::Overview

Inherits:
Layout
  • Object
show all
Defined in:
lib/gollum/views/overview.rb

Constant Summary collapse

HIDDEN_PATHS =
['.gitkeep']

Constants included from RouteHelpers

RouteHelpers::ROUTES

Constants included from LocaleHelpers

LocaleHelpers::NO_METHOD_MESSAGE, LocaleHelpers::YAML_VARIABLE_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Layout

#name, #path

Instance Method Summary collapse

Methods inherited from Layout

#base_url, #critic_markup, #css, #custom_css, #custom_js, #custom_path, #escaped_name, #has_path, #history, #js, #mathjax_config_path, #mathjax_js, #overview, #partial, #per_page_uploads, #search, #show_local_time

Methods included from TemplateCascade

#first_path_available, #template_file, #template_priority_path, #template_priority_path=

Methods included from OcticonHelpers

included, #octicon, #rocticon, #rocticon_css

Methods included from RouteHelpers

#clean_url, included, #page_route, parse_routes

Methods included from SprocketsHelpers

included, #sprockets_asset_path, #sprockets_image_path, #sprockets_javascript_tag, #sprockets_stylesheet_tag

Methods included from LocaleHelpers

#t

Methods included from AppHelpers

#extract_page_dir

Instance Attribute Details

#allow_editingObject (readonly)

Returns the value of attribute allow_editing.



6
7
8
# File 'lib/gollum/views/overview.rb', line 6

def allow_editing
  @allow_editing
end

#newableObject (readonly)

Returns the value of attribute newable.



6
7
8
# File 'lib/gollum/views/overview.rb', line 6

def newable
  @newable
end

#refObject (readonly)

Returns the value of attribute ref.



6
7
8
# File 'lib/gollum/views/overview.rb', line 6

def ref
  @ref
end

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/gollum/views/overview.rb', line 6

def results
  @results
end

Instance Method Details



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gollum/views/overview.rb', line 21

def breadcrumb
  if @path
    path       = Pathname.new(@path)
    breadcrumb = [%{<nav aria-label="Breadcrumb"><ol><li class="breadcrumb-item"><a href="#{overview_path}">Home</a></li>}]
    path.descend do |crumb|
      title = crumb.basename

      if title == path.basename
        breadcrumb << %{<li class="breadcrumb-item" aria-current="page">#{CGI.escapeHTML(title.to_s)}</li>}
      else
        breadcrumb << %{<li class="breadcrumb-item"><a href="#{overview_path}/#{crumb}/">#{CGI.escapeHTML(title.to_s)}</a></li>}
      end
    end
    breadcrumb << %{</ol></nav>}
    breadcrumb.join("\n")
  else
    'Home'
  end
end

#current_pathObject

def editable

false

end



17
18
19
# File 'lib/gollum/views/overview.rb', line 17

def current_path
  @path ? @path : '/'
end

#files_foldersObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gollum/views/overview.rb', line 42

def files_folders
  if has_results
    files_and_folders = []
    
    @results.each do |result|
      result_path = result.url_path
      result_path = result_path.sub(/^#{Regexp.escape(@path)}\//, '') unless @path.nil?            
      if result_path.include?('/')
        # result contains a folder
        folder_name = result_path.split('/').first
        folder_path = @path ? "#{@path}/#{folder_name}" : folder_name
        folder_url  = "#{overview_path}/#{folder_path}/"
        files_and_folders << {name: folder_name, icon: rocticon('file-directory'), type: 'dir', url: folder_url, is_file: false}
      elsif !HIDDEN_PATHS.include?(result_path) 
        file_url = page_route(result.escaped_url_path)
        files_and_folders << {name: result.filename, icon: rocticon('file'), type: 'file', url: file_url, file_path: result.escaped_url_path, is_file: true}
      end
    end
    # 1012: Overview should list folders first, followed by files and pages sorted alphabetically
    files_and_folders.uniq{|f| f[:name]}.sort_by!{|f| [f[:type], f[:name]]}
  end
end

#has_resultsObject



66
67
68
# File 'lib/gollum/views/overview.rb', line 66

def has_results
  !@results.empty?
end

#latest_changesObject



74
75
76
# File 'lib/gollum/views/overview.rb', line 74

def latest_changes
  true
end

#no_resultsObject



70
71
72
# File 'lib/gollum/views/overview.rb', line 70

def no_results
  @results.empty?
end

#titleObject



9
10
11
# File 'lib/gollum/views/overview.rb', line 9

def title
  "Overview of #{@ref}"
end