Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added docs for lib/asset_hat.rb

  • Loading branch information...
commit 72ee298473db32f5030f2f77f40e629c59125658 1 parent a5b4829
@rondevera rondevera authored
Showing with 42 additions and 15 deletions.
  1. +42 −15 lib/asset_hat.rb
View
57 lib/asset_hat.rb
@@ -12,9 +12,10 @@ module AssetHat
CONFIG_FILEPATH = File.join(RAILS_ROOT, RELATIVE_CONFIG_FILEPATH)
class << self
- attr_accessor :config, :asset_exists, :html_cache
+ attr_accessor :config, :asset_exists, :html_cache #:nodoc:
end
+ # Nested-hash version of <tt>config/assets.yml</tt>.
def self.config
if !cache? || @config.blank?
@config = YAML.load(File.open(CONFIG_FILEPATH, 'r'))
@@ -22,6 +23,9 @@ def self.config
@config
end
+ # Argument: <tt>:css</tt> or <tt>:js</tt>
+ #
+ # Returns the path to the directory where CSS or JS files are stored.
def self.assets_dir(type)
case type.to_sym
when :css ; STYLESHEETS_DIR
@@ -30,6 +34,17 @@ def self.assets_dir(type)
end
end
+ # Returns true if the specified asset exists in the file system:
+ #
+ # AssetHat.asset_exists?('application', :css)
+ # # => <tt>true</tt> if <tt>/public/stylesheets/application.css</tt>
+ # exists
+ # AssetHat.asset_exists?('some-plugin', :js)
+ # # => <tt>true</tt> if <tt>/public/javascripts/some-plugin.js</tt>
+ # exists
+ #
+ # See also <tt>AssetHat::STYLESHEETS_DIR</tt> and
+ # <tt>AssetHat::JAVASCRIPTS_DIR</tt>.
def self.asset_exists?(filename, type)
# Process arguments
type = type.to_sym
@@ -48,20 +63,31 @@ def self.asset_exists?(filename, type)
@asset_exists[type][filename]
end
+ # Returns +true+ if bundles should be included as single minified files
+ # (e.g., in production), or +false+ if bundles should be included as
+ # separate, unminified files (e.g., in development). To modify this value,
+ # set <tt>config.action_controller.perform_caching = true</tt> in your
+ # environment.
def self.cache? ; ActionController::Base.perform_caching ; end
+ # Returns the expected path for the minified version of an asset:
+ #
+ # AssetHat.min_filepath('public/stylesheets/bundles/application.css')
+ # # => 'public/stylesheets/bundles/application.min.css'
+ #
+ # See also <tt>AssetHat::CSS.min_filepath</tt> and
+ # <tt>AssetHat::JS.min_filepath</tt>.
def self.min_filepath(filepath, extension)
filepath.sub(/([^\.]*).#{extension}$/, "\\1.min.#{extension}")
end
+ # Returns the extension-less names of files in the given bundle:
+ #
+ # AssetHat.bundle_filenames('application', :css)
+ # # => ['reset', 'application', 'clearfix']
+ # AssetHat.bundle_filenames('non-existent-file', :css)
+ # # => nil
def self.bundle_filenames(bundle, type)
- # Usage:
- #
- # AssetHat.bundle_filenames('application', :css)
- # # => ['reset', 'application', 'clearfix']
- # AssetHat.bundle_filenames('non-existent-file', :css)
- # # => nil
-
# Process arguments
unless TYPES.include?(type.to_sym)
raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
@@ -71,14 +97,15 @@ def self.bundle_filenames(bundle, type)
self.config[type.to_s]['bundles'][bundle] rescue nil
end
+ # Returns the full paths of files in the given bundle:
+ #
+ # AssetHat.bundle_filenames('application', :css)
+ # # => ['/path/to/app/public/stylesheets/reset.css',
+ # '/path/to/app/public/stylesheets/application.css',
+ # '/path/to/app/public/stylesheets/clearfix.css']
+ # AssetHat.bundle_filenames('non-existent-file', :css)
+ # # => nil
def self.bundle_filepaths(bundle, type)
- # Usage:
- #
- # AssetHat.bundle_filenames('application', :css)
- # # => ['reset', 'application', 'clearfix']
- # AssetHat.bundle_filenames('non-existent-file', :css)
- # # => nil
-
# Process arguments
unless TYPES.include?(type.to_sym)
raise "Unknown type \"#{type}\"; should be one of: #{TYPES.join(', ')}."
Please sign in to comment.
Something went wrong with that request. Please try again.