Class: Copy::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/copy/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, views) ⇒ Router

Returns a new instance of Router.



3
4
5
6
# File 'lib/copy/router.rb', line 3

def initialize(path, views)
  @path  = determine_path(path)
  @views = views
end

Instance Method Details

#formatObject



8
9
10
11
12
13
14
# File 'lib/copy/router.rb', line 8

def format
  @format ||= if @path.index('.')
    @path.split('.').last.to_sym
  else
    :html
  end
end

#layoutObject



32
33
34
35
36
37
38
# File 'lib/copy/router.rb', line 32

def layout
  @layout ||= if format == :html && File.exists?(File.join(@views, "layout.html.#{renderer}"))
    :'layout.html'
  else
    false
  end
end

#rendererObject



24
25
26
# File 'lib/copy/router.rb', line 24

def renderer
  @renderer ||= template_file.split('.').last.to_sym
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/copy/router.rb', line 40

def success?
  template_file && renderer && template
end

#templateObject



28
29
30
# File 'lib/copy/router.rb', line 28

def template
  @template ||= template_file.gsub(%r{^#{@views}\/*}, '').gsub(%r{.#{renderer}$}, '').to_sym
end

#template_fileObject



16
17
18
19
20
21
22
# File 'lib/copy/router.rb', line 16

def template_file
  @template_file ||= if file = Dir.glob(File.join(@views, "#{path_with_format}*")).first
    file
  elsif index = Dir.glob(File.join(@views, path_without_format, "index.#{format}*")).first
    index
  end
end