class TsAssets::Models::AssetMetaInfo
Constants
- DESCRIPTOR_REGEX
- String
Attributes
asset_path_without_descriptor[R]
@return [String]
descriptor[R]
@return [String]
environment[R]
@return [Sprockets::Environment]
full_path[R]
full_path
is a path from the app root. ex) “app/assets/images/path/to/the/image.png” @return [String]
height[R]
@return [Numeric]
include_path[R]
include_path
is the app asset path root. ex) “app/assets/images” @return [String]
width[R]
@return [Numeric]
Public Class Methods
new(full_path:, include_path:, environment:)
click to toggle source
@param [String] full_path
@param [String] include_path
@param [Sprockets::Environment] environment
# File lib/ts_assets/models/asset_meta_info.rb, line 37 def initialize(full_path:, include_path:, environment:) @full_path = full_path @include_path = include_path @environment = environment @width, @height = FastImage.size(full_path) if has_descriptor? # ex) # dir/blog_feed.png -> #<MatchData "dir/blog_feed." 1:"dir/blog_feed"> # dir/blog_feed@2x.png -> #<MatchData "dir/blog_feed@2x." 1:"dir/blog_feed" 2:"2x"> match_data = asset_path.match(DESCRIPTOR_REGEX) @asset_path_without_descriptor, @descriptor = match_data.captures else @asset_path_without_descriptor = asset_path_without_ext @descriptor = '1x' # 1x as a default descriptor end end
Public Instance Methods
asset()
click to toggle source
# File lib/ts_assets/models/asset_meta_info.rb, line 79 def asset asset = environment.find_asset(asset_path) if !asset raise "No asset in the environment: #{asset_path}" end asset end
asset_path()
click to toggle source
@return [String]
# File lib/ts_assets/models/asset_meta_info.rb, line 65 def asset_path full_path.gsub(%r{^#{include_path}/}, '') end
asset_path_without_ext()
click to toggle source
@return [String]
# File lib/ts_assets/models/asset_meta_info.rb, line 70 def asset_path_without_ext asset_path.chomp(File.extname(asset_path)) end
digest_path()
click to toggle source
@return [String]
# File lib/ts_assets/models/asset_meta_info.rb, line 75 def digest_path asset.digest_path end
has_descriptor?()
click to toggle source
@return [Boolean]
# File lib/ts_assets/models/asset_meta_info.rb, line 60 def has_descriptor? !asset_path.match(DESCRIPTOR_REGEX).nil? end
normalised_path()
click to toggle source
@return [String]
# File lib/ts_assets/models/asset_meta_info.rb, line 88 def normalised_path "PATH_#{asset_path_without_ext.gsub(/[^a-zA-Z0-9_]/, '_').upcase}" end