Class: Redmine::AssetLoadPath

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, compilers) ⇒ AssetLoadPath

Returns a new instance of AssetLoadPath.



135
136
137
138
139
# File 'lib/redmine/asset_path.rb', line 135

def initialize(config, compilers)
  @extension_paths    = config.redmine_extension_paths
  @default_asset_path = config.redmine_default_asset_path
  super(config.paths, compilers: compilers, version: config.version)
end

Instance Attribute Details

#default_asset_pathObject (readonly)

Returns the value of attribute default_asset_path.



133
134
135
# File 'lib/redmine/asset_path.rb', line 133

def default_asset_path
  @default_asset_path
end

#extension_pathsObject (readonly)

Returns the value of attribute extension_paths.



133
134
135
# File 'lib/redmine/asset_path.rb', line 133

def extension_paths
  @extension_paths
end

#transition_mapObject (readonly)

Returns the value of attribute transition_map.



133
134
135
# File 'lib/redmine/asset_path.rb', line 133

def transition_map
  @transition_map
end

Instance Method Details

#all_pathsObject



181
182
183
# File 'lib/redmine/asset_path.rb', line 181

def all_paths
  [paths, default_asset_path.paths, extension_paths.map{|path| path.paths}].flatten.compact
end

#asset_filesObject



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/redmine/asset_path.rb', line 141

def asset_files
  Enumerator.new do |y|
    Rails.logger.info all_paths
    all_paths.each do |path|
      next unless path.exist?

      without_dotfiles(all_files_from_tree(path)).each do |file|
        y << file
      end
    end
  end
end

#assets_by_pathObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/redmine/asset_path.rb', line 154

def assets_by_path
  merge_required = @cached_assets_by_path.nil?
  super
  if merge_required
    @transition_map = {}
    default_asset_path.update(assets: @cached_assets_by_path, transition_map: transition_map, load_path: self)
    extension_paths.each do |asset_path|
      # Support link from extension assets to assets in the application
      default_asset_path.each_file do |file, intermediate_path, logical_path|
        asset_path.instance_eval { @transition.add_dest intermediate_path, logical_path }
      end
      asset_path.update(assets: @cached_assets_by_path, transition_map: transition_map, load_path: self)
    end
  end
  @cached_assets_by_path
end

#cache_sweeperObject



171
172
173
174
175
176
177
178
179
# File 'lib/redmine/asset_path.rb', line 171

def cache_sweeper
  @cache_sweeper ||= begin
    exts_to_watch  = Mime::EXTENSION_LOOKUP.map(&:first)
    files_to_watch = Array(all_paths).to_h { |dir| [dir.to_s, exts_to_watch] }
    Rails.application.config.file_watcher.new([], files_to_watch) do
      clear_cache
    end
  end
end

#clear_cacheObject



185
186
187
188
# File 'lib/redmine/asset_path.rb', line 185

def clear_cache
  @transition_map = nil
  super
end