Class: Benoit::Utils::NormalizesPathToTemplate
- Inherits:
-
Object
- Object
- Benoit::Utils::NormalizesPathToTemplate
- Defined in:
- lib/benoit/utils/normalizes_path_to_template.rb
Instance Attribute Summary collapse
-
#load_paths ⇒ Object
Returns the value of attribute load_paths.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
-
#initialize(template_path, load_paths) ⇒ NormalizesPathToTemplate
constructor
A new instance of NormalizesPathToTemplate.
- #normalize_path ⇒ Object
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_paths ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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 |