class Stall::ViewGenerator::ViewTemplate

Attributes

file_path[R]

Public Class Methods

new(file_path) click to toggle source
# File lib/generators/stall/view/view_generator.rb, line 22
def initialize(file_path)
  @file_path = file_path
end

Public Instance Methods

source_path() click to toggle source
# File lib/generators/stall/view/view_generator.rb, line 26
def source_path
  source_file_for(file_path_with_ext)
end
target_path() click to toggle source
# File lib/generators/stall/view/view_generator.rb, line 30
def target_path
  "app/views/#{ file_path_with_ext }"
end

Private Instance Methods

file_path_with_ext() click to toggle source
# File lib/generators/stall/view/view_generator.rb, line 36
def file_path_with_ext
  return @file_path_with_ext if @file_path_with_ext
  @file_path += '.html.haml' unless file_path.match(/\.html\.haml\z/)

  partial_path = [File.dirname(file_path), File.basename(file_path)].join('/_')

  stall_file_path = ['stall', file_path].join('/')
  stall_partial_path = ['stall', partial_path].join('/')

  paths = [file_path, partial_path, stall_file_path, stall_partial_path]

  paths.each do |path|
    if File.exist?(source_path = source_file_for(path))
      @file_path_with_ext = path
      return @file_path_with_ext
    end
  end

  raise ViewNotFound, "No Stall view was found for #{ file_path } !"
end
source_file_for(path) click to toggle source
# File lib/generators/stall/view/view_generator.rb, line 57
def source_file_for(path)
  File.join(Stall::ViewGenerator::VIEWS_DIR, path)
end