Class: Benoit::Utils::NormalizesPathToTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/benoit/utils/normalizes_path_to_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_path, load_paths) ⇒ NormalizesPathToTemplate

Returns a new instance of NormalizesPathToTemplate.



19
20
21
22
# File 'lib/benoit/utils/normalizes_path_to_template.rb', line 19

def initialize(template_path, load_paths)
    @template_path = template_path
    @load_paths = load_paths
end

Instance Attribute Details

#load_pathsObject

Returns the value of attribute load_paths.



17
18
19
# File 'lib/benoit/utils/normalizes_path_to_template.rb', line 17

def load_paths
  @load_paths
end

#template_pathObject

Returns the value of attribute template_path.



17
18
19
# File 'lib/benoit/utils/normalizes_path_to_template.rb', line 17

def template_path
  @template_path
end

Instance Method Details

#normalize_pathObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/benoit/utils/normalizes_path_to_template.rb', line 24

def normalize_path
    return template_path if File.exist?(template_path) # Already normalized, just return it
    load_paths.inject(template_path) do |actual_path,load_path|
        path_to_try = actual_path
        if not File.basename(path_to_try).start_with? "_"
          path_to_try = File.join(File.dirname(path_to_try), "_#{File.basename(path_to_try)}")
        end
        path_to_try += ".html" unless File.extname(path_to_try) == ".html"
        return path_to_try if File.exist?(path_to_try)
        path_to_try = File.join(load_path, path_to_try)
        if File.exist?(path_to_try)
            path_to_try
        else
            actual_path
        end
    end
end