Class: CabezaDeTermo::AssetsPublisher::OneFilePerAssetBuilder

Inherits:
CompilationJobsBuilder show all
Defined in:
lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb

Instance Method Summary collapse

Methods inherited from CompilationJobsBuilder

#asset_to_publish, #asset_type, #compiled_assets_folder, #compiled_uri, #configuration, #initialize, jobs_for

Constructor Details

This class inherits a constructor from CabezaDeTermo::AssetsPublisher::CompilationJobsBuilder

Instance Method Details

#add_timestamps?Boolean

Answer if we must append a timestamp to the relative assets or not

Returns:

  • (Boolean)


54
55
56
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 54

def add_timestamps?()
	configuration.add_timestamps_to_published_assets?
end

#assetObject

Answer the current asset



19
20
21
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 19

def asset()
	@asset
end

#asset_to_compile_toObject

Answer the asset that will hold the compiled assets.



35
36
37
38
39
40
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 35

def asset_to_compile_to()
	return asset if asset.location.is_absolute?

	asset_to_publish
		.set_uri_parameters(timestamp_string)
end

#assets_to_compileObject

Answer the asset to compile. If the asset has an absolute location we won’t compile it



25
26
27
28
29
30
31
32
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 25

def assets_to_compile()
	if asset.location.is_absolute?
		asset.validate_real_path
		return [] 
	end

	[asset]
end

#compiled_filenameObject



42
43
44
45
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 42

def compiled_filename
	return asset.uri if ['.css', '.js'].include?(asset.uri.extname)
	Pathname.new(remove_last_extension_from_uri)
end

#jobs_for(assets) ⇒ Object

Answer a collection of CompilationJob to send to a Compiler.



8
9
10
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 8

def jobs_for(assets)
	assets.collect { |asset| new_compilation_job_for asset }
end

#new_compilation_job_for(asset) ⇒ Object

Answer a new CompilationJob for a single asset to send to a Compiler



13
14
15
16
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 13

def new_compilation_job_for(asset)
	@asset = asset
	CompilationJob.new(assets: assets_to_compile, destination: asset_to_compile_to)
end

#remove_last_extension_from_uriObject



47
48
49
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 47

def remove_last_extension_from_uri
	asset.uri.to_s.split('.')[0..-2].join('.')
end

#timestamp_stringObject

Answer the timestamp string to add to this asset.



59
60
61
62
63
# File 'lib/cabeza-de-termo/assets-publisher/compilation-jobs/one-file-per-asset-builder.rb', line 59

def timestamp_string()
	return nil unless add_timestamps?

	Time.now.to_s
end