Class: Redmine::AssetPath::Transition

Inherits:
Struct
  • Object
show all
Defined in:
lib/redmine/asset_path.rb

Instance Method Summary collapse

Instance Method Details

#add_dest(file, logical_path) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/redmine/asset_path.rb', line 65

def add_dest(file, logical_path)
  return if file.extname == '.js' || file.extname == '.map'

  # No parent-child directories are needed in dest.
  dirname = file.dirname
  if child = dest.find{|d| child_path? dirname, d[0]}
    dest.delete child
    dest.add path_pair(file, logical_path)
  elsif !dest.any?{|d| parent_path? dirname, d[0]}
    dest.add path_pair(file, logical_path)
  end
end

#add_src(file, logical_path) ⇒ Object



61
62
63
# File 'lib/redmine/asset_path.rb', line 61

def add_src(file, logical_path)
  src.add  path_pair(file, logical_path) if file.extname == '.css'
end

#child_path?(path, other) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
# File 'lib/redmine/asset_path.rb', line 88

def child_path?(path, other)
  return false if path == other

  other.ascend.any?(path)
end

#parent_path?(path, other) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
86
# File 'lib/redmine/asset_path.rb', line 82

def parent_path?(path, other)
  return false if other == path

  path.ascend.any?(other)
end

#path_pair(file, logical_path) ⇒ Object



78
79
80
# File 'lib/redmine/asset_path.rb', line 78

def path_pair(file, logical_path)
  [file.dirname, Pathname.new("/#{logical_path}").dirname]
end

#update(transition_map) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/redmine/asset_path.rb', line 94

def update(transition_map)
  product = src.to_a.product(dest.to_a).select{|t| t[0] != t[1]}
  maps = product.map do |t|
    AssetPathMap.new(src: t[0][0], dest: t[1][0], logical_src: t[0][1], logical_dest: t[1][1])
  end
  maps.each do |m|
    if m.before != m.after
      transition_map[m.dirname] ||= {}
      transition_map[m.dirname][m.before] = m.after
    end
  end
end