Class: ActionView::Helpers::AssetTagHelper::AssetTag

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Memoizable
Defined in:
lib/action_view/helpers/asset_tag_helper.rb

Direct Known Subclasses

ImageTag, JavaScriptTag, StylesheetTag

Constant Summary collapse

Cache =
{}
CacheGuard =
Mutex.new
ProtocolRegexp =
%r{^[-a-z]+://}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(template, controller, source, include_host = true) ⇒ AssetTag

Returns a new instance of AssetTag.



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 532

def initialize(template, controller, source, include_host = true)
  # NOTE: The template arg is temporarily needed for a legacy plugin
  # hook that is expected to call rewrite_asset_path on the
  # template. This should eventually be removed.
  @template = template
  @controller = controller
  @source = source
  @include_host = include_host
  @cache_key = if controller.respond_to?(:request)
    [self.class.name,controller.request.protocol,
     ActionController::Base.asset_host,
     ActionController::Base.relative_url_root,
     source, include_host]
  else
    [self.class.name,ActionController::Base.asset_host, source, include_host]
  end
end

Instance Method Details

#asset_file_pathObject



555
556
557
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 555

def asset_file_path
  File.join(ASSETS_DIR, public_path.split('?').first)
end

#contentsObject



560
561
562
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 560

def contents
  File.read(asset_file_path)
end

#mtimeObject



564
565
566
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 564

def mtime
  File.mtime(asset_file_path)
end

#public_pathObject



550
551
552
# File 'lib/action_view/helpers/asset_tag_helper.rb', line 550

def public_path
  compute_public_path(@source)
end