Class: Redmine::AssetPath

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

Defined Under Namespace

Classes: AssetPathMap, Transition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, paths, prefix = nil) ⇒ AssetPath

Returns a new instance of AssetPath.



24
25
26
27
28
29
30
# File 'lib/redmine/asset_path.rb', line 24

def initialize(base_dir, paths, prefix=nil)
  @base_dir = base_dir
  @paths  = paths
  @prefix = prefix
  @transition = Transition.new(src: Set.new, dest: Set.new)
  @version = Rails.application.config.assets.version
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



22
23
24
# File 'lib/redmine/asset_path.rb', line 22

def paths
  @paths
end

#prefixObject (readonly)

Returns the value of attribute prefix.



22
23
24
# File 'lib/redmine/asset_path.rb', line 22

def prefix
  @prefix
end

#versionObject (readonly)

Returns the value of attribute version.



22
23
24
# File 'lib/redmine/asset_path.rb', line 22

def version
  @version
end

Instance Method Details

#each_fileObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/redmine/asset_path.rb', line 47

def each_file
  paths.each do |path|
    without_dotfiles(all_files_from_tree(path)).each do |file|
      relative_path = file.relative_path_from(path).to_s
      logical_path  = prefix ? File.join(prefix, relative_path) : relative_path
      intermediate_path = Pathname.new("/#{prefix}").join(file.relative_path_from(@base_dir))
      yield file, intermediate_path, logical_path
    end
  end
end

#update(transition_map:, assets:, load_path:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/redmine/asset_path.rb', line 32

def update(transition_map:, assets:, load_path:)
  each_file do |file, intermediate_path, logical_path|
    @transition.add_src  intermediate_path, logical_path
    @transition.add_dest intermediate_path, logical_path
    asset = if file.extname == '.css'
              Redmine::Asset.new(file,   logical_path: logical_path, load_path: load_path, transition_map: transition_map)
            else
              Propshaft::Asset.new(file, logical_path: logical_path, load_path: load_path)
            end
    assets[asset.logical_path.to_s] ||= asset
  end
  @transition.update(transition_map)
  nil
end