Module: Ore::Template::Interpolations
- Included in:
- Generator
- Defined in:
- lib/ore/template/interpolations.rb
Overview
Handles the expansion of paths and substitution of path keywords. The following keywords are supported:
[name]
- The name of the project.[project_dir]
- The directory base-name derived from the project name.[namespace_path]
- The full directory path derived from the project name.[namespace_dir]
- The last directory name derived from the project name.
Constant Summary collapse
- @@keywords =
The accepted interpolation keywords that may be used in paths
%w[ name version project_dir namespace_path namespace_dir markup date year month day ]
Instance Method Summary collapse
-
#interpolate(path) ⇒ String
protected
Expands the given path by substituting the interpolation keywords for the related instance variables.
Instance Method Details
#interpolate(path) ⇒ String (protected)
Expands the given path by substituting the interpolation keywords for the related instance variables.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ore/template/interpolations.rb', line 50 def interpolate(path) dirs = path.split(File::SEPARATOR) dirs.each do |dir| dir.gsub!(/(\[[a-z_]+\])/) do |capture| keyword = capture[1..-2] if @@keywords.include?(keyword) instance_variable_get("@#{keyword}") else capture end end end return File.join(dirs.reject { |dir| dir.empty? }) end |