Sha256: 4452df54c17baea5824f8828662f4575cda39bcf9de8546ff52cd4a6de2e83d9
Contents?: true
Size: 1.86 KB
Versions: 2
Compression:
Stored size: 1.86 KB
Contents
# encoding: utf-8 # this class represents a project and handles generators and ressources class EasyHtmlGenerator::ProjectPathResolver def initialize(project) @project = project @path_prefix_replace_map = { 'src' => project.src_path, 'dist' => project.dist_path, 'src.scripts' => project.src_path_to(:scripts), 'src.styles' => project.src_path_to(:styles), 'src.images' => project.src_path_to(:images), 'src.public' => project.src_path_to(:public), 'src.views' => project.src_path_to(:views), 'dist.scripts' => project.dist_path_to(:scripts), 'dist.styles' => project.dist_path_to(:styles), 'dist.images' => project.dist_path_to(:images), 'dist.public' => project.dist_path_to(:public), 'dist.views' => project.dist_path_to(:views), 'workspace.root' => EasyHtmlGenerator::WORKSPACE_PATH, 'ehg.root' => EasyHtmlGenerator::EHG_SRC_PATH } end def resolve_config(config) resolve_hash(config) end private def resolve_hash(myHash) myHash.each do |key, value| value.is_a?(Hash) ? resolve_hash(value) : (value.is_a?(Array) ? (myHash[key] = resolve_array(value)) : (myHash[key] = resolve_path(value))) end end def resolve_array(myArray) myArray.map do |value| value.is_a?(Array) ? resolve_array(value) : (value.is_a?(Hash) ? resolve_hash(value) : resolve_path(value)) end end def resolve_path(path) return path unless path.is_a? String return path unless path.include? '://' splitted = path.split('://') unresolved_prefix = splitted.first path_prefix = @path_prefix_replace_map[unresolved_prefix] return path unless @path_prefix_replace_map.key? unresolved_prefix return path_prefix if splitted.length == 1 File.join(path_prefix, splitted.second) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
easy_html_generator-1.0.6 | lib/easy_html_generator/project_path_resolver.rb |
easy_html_generator-1.0.5 | lib/easy_html_generator/project_path_resolver.rb |