Class: Servel::IndexView

Inherits:
Object
  • Object
show all
Defined in:
lib/servel/index_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(url_path, fs_path) ⇒ IndexView

Returns a new instance of IndexView.



2
3
4
5
# File 'lib/servel/index_view.rb', line 2

def initialize(url_path, fs_path)
  @url_path = url_path
  @fs_path = fs_path
end

Instance Method Details

#localsObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/servel/index_view.rb', line 11

def locals
  directories, files = @fs_path.children.partition { |child| child.directory? }

  {
    url_path: @url_path,
    fs_path: @fs_path,
    directories: sort_paths(directories),
    files: sort_paths(files),
    show_gallery: files.any? { |file| file.image? }
  }
end

#render(haml_context) ⇒ Object



7
8
9
# File 'lib/servel/index_view.rb', line 7

def render(haml_context)
  haml_context.render('index.haml', locals)
end

#sort_paths(paths) ⇒ Object



23
24
25
# File 'lib/servel/index_view.rb', line 23

def sort_paths(paths)
  Naturalsorter::Sorter.sort(paths.map(&:to_s), true).map { |path| Pathname.new(path) }
end