Module: Jammit
- Defined in:
- lib/jammit.rb,
lib/jammit/helper.rb,
lib/jammit/routes.rb,
lib/jammit/railtie.rb,
lib/jammit/packager.rb,
lib/jammit/controller.rb,
lib/jammit/command_line.rb
Overview
@Jammit@ is the central namespace for all Jammit classes, and provides access to all of the configuration options.
Defined Under Namespace
Modules: Helper, Routes Classes: CommandLine, Controller, DeprecationError, MissingConfiguration, OutputNotWritable, PackageNotFound, Packager, Railtie, Uglifier
Constant Summary collapse
- VERSION =
"0.6.3"
- ROOT =
File.(File.dirname(__FILE__) + '/..')
- ASSET_ROOT =
File.((defined?(Rails) && Rails.root.to_s.length > 0) ? Rails.root : ENV['RAILS_ROOT'] || ".")
- PUBLIC_ROOT =
(Rails) && Rails.public_path.to_s.length > 0) ? Rails.public_path : File.join(ASSET_ROOT, 'public')
- DEFAULT_CONFIG_PATH =
File.join(ASSET_ROOT, 'config', 'assets.yml')
- DEFAULT_PACKAGE_PATH =
"assets"
- DEFAULT_JST_SCRIPT =
File.join(ROOT, 'lib/jammit/jst.js')
- DEFAULT_JST_COMPILER =
"template"
- DEFAULT_JST_NAMESPACE =
"window.JST"
- COMPRESSORS =
[:yui, :closure, :uglifier]
- DEFAULT_COMPRESSOR =
:yui
- JS_EXTENSION =
Extension matchers for JavaScript and JST, which need to be disambiguated.
/\.js\Z/
- DEFAULT_JST_EXTENSION =
"jst"
Class Attribute Summary collapse
-
.allow_debugging ⇒ Object
readonly
Returns the value of attribute allow_debugging.
-
.compress_assets ⇒ Object
readonly
Returns the value of attribute compress_assets.
-
.compressor_options ⇒ Object
readonly
Returns the value of attribute compressor_options.
-
.compressors ⇒ Object
Returns the value of attribute compressors.
-
.config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
.configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
.css_compressor_options ⇒ Object
readonly
Returns the value of attribute css_compressor_options.
-
.embed_assets ⇒ Object
readonly
Returns the value of attribute embed_assets.
-
.gzip_assets ⇒ Object
readonly
Returns the value of attribute gzip_assets.
-
.include_jst_script ⇒ Object
readonly
Returns the value of attribute include_jst_script.
-
.javascript_compressor ⇒ Object
readonly
Returns the value of attribute javascript_compressor.
-
.mhtml_enabled ⇒ Object
readonly
Returns the value of attribute mhtml_enabled.
-
.package_assets ⇒ Object
readonly
Returns the value of attribute package_assets.
-
.package_path ⇒ Object
readonly
Returns the value of attribute package_path.
-
.template_extension ⇒ Object
readonly
Returns the value of attribute template_extension.
-
.template_extension_matcher ⇒ Object
readonly
Returns the value of attribute template_extension_matcher.
-
.template_function ⇒ Object
readonly
Returns the value of attribute template_function.
-
.template_namespace ⇒ Object
readonly
Returns the value of attribute template_namespace.
-
.template_roots ⇒ Object
readonly
Returns the value of attribute template_roots.
Class Method Summary collapse
-
.asset_url(package, extension, suffix = nil, mtime = nil) ⇒ Object
Generates the server-absolute URL to an asset package.
-
.filename(package, extension, suffix = nil) ⇒ Object
Generate the base filename for a version of a given package.
-
.load_configuration(config_path, soft = false) ⇒ Object
Load the complete asset configuration from the specified @config_path@.
-
.package!(options = {}) ⇒ Object
Convenience method for packaging up Jammit, using the default options.
-
.packager ⇒ Object
Keep a global (thread-local) reference to a @Jammit::Packager@, to avoid recomputing asset lists unnecessarily.
-
.reload! ⇒ Object
Force a reload by resetting the Packager and reloading the configuration.
Class Attribute Details
.allow_debugging ⇒ Object (readonly)
Returns the value of attribute allow_debugging.
50 51 52 |
# File 'lib/jammit.rb', line 50 def allow_debugging @allow_debugging end |
.compress_assets ⇒ Object (readonly)
Returns the value of attribute compress_assets.
50 51 52 |
# File 'lib/jammit.rb', line 50 def compress_assets @compress_assets end |
.compressor_options ⇒ Object (readonly)
Returns the value of attribute compressor_options.
50 51 52 |
# File 'lib/jammit.rb', line 50 def @compressor_options end |
.compressors ⇒ Object
Returns the value of attribute compressors.
56 57 58 |
# File 'lib/jammit.rb', line 56 def compressors @compressors end |
.config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
50 51 52 |
# File 'lib/jammit.rb', line 50 def config_path @config_path end |
.configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
50 51 52 |
# File 'lib/jammit.rb', line 50 def configuration @configuration end |
.css_compressor_options ⇒ Object (readonly)
Returns the value of attribute css_compressor_options.
50 51 52 |
# File 'lib/jammit.rb', line 50 def @css_compressor_options end |
.embed_assets ⇒ Object (readonly)
Returns the value of attribute embed_assets.
50 51 52 |
# File 'lib/jammit.rb', line 50 def @embed_assets end |
.gzip_assets ⇒ Object (readonly)
Returns the value of attribute gzip_assets.
50 51 52 |
# File 'lib/jammit.rb', line 50 def gzip_assets @gzip_assets end |
.include_jst_script ⇒ Object (readonly)
Returns the value of attribute include_jst_script.
50 51 52 |
# File 'lib/jammit.rb', line 50 def include_jst_script @include_jst_script end |
.javascript_compressor ⇒ Object (readonly)
Returns the value of attribute javascript_compressor.
50 51 52 |
# File 'lib/jammit.rb', line 50 def javascript_compressor @javascript_compressor end |
.mhtml_enabled ⇒ Object (readonly)
Returns the value of attribute mhtml_enabled.
50 51 52 |
# File 'lib/jammit.rb', line 50 def mhtml_enabled @mhtml_enabled end |
.package_assets ⇒ Object (readonly)
Returns the value of attribute package_assets.
50 51 52 |
# File 'lib/jammit.rb', line 50 def package_assets @package_assets end |
.package_path ⇒ Object (readonly)
Returns the value of attribute package_path.
50 51 52 |
# File 'lib/jammit.rb', line 50 def package_path @package_path end |
.template_extension ⇒ Object (readonly)
Returns the value of attribute template_extension.
50 51 52 |
# File 'lib/jammit.rb', line 50 def template_extension @template_extension end |
.template_extension_matcher ⇒ Object (readonly)
Returns the value of attribute template_extension_matcher.
50 51 52 |
# File 'lib/jammit.rb', line 50 def template_extension_matcher @template_extension_matcher end |
.template_function ⇒ Object (readonly)
Returns the value of attribute template_function.
50 51 52 |
# File 'lib/jammit.rb', line 50 def template_function @template_function end |
.template_namespace ⇒ Object (readonly)
Returns the value of attribute template_namespace.
50 51 52 |
# File 'lib/jammit.rb', line 50 def template_namespace @template_namespace end |
.template_roots ⇒ Object (readonly)
Returns the value of attribute template_roots.
50 51 52 |
# File 'lib/jammit.rb', line 50 def template_roots @template_roots end |
Class Method Details
.asset_url(package, extension, suffix = nil, mtime = nil) ⇒ Object
Generates the server-absolute URL to an asset package.
118 119 120 121 |
# File 'lib/jammit.rb', line 118 def self.asset_url(package, extension, suffix=nil, mtime=nil) = mtime ? "?#{mtime.to_i}" : '' "/#{package_path}/#{filename(package, extension, suffix)}#{}" end |
.filename(package, extension, suffix = nil) ⇒ Object
Generate the base filename for a version of a given package.
112 113 114 115 |
# File 'lib/jammit.rb', line 112 def self.filename(package, extension, suffix=nil) suffix_part = suffix ? "-#{suffix}" : '' "#{package}#{suffix_part}.#{extension}" end |
.load_configuration(config_path, soft = false) ⇒ Object
Load the complete asset configuration from the specified @config_path@. If we’re loading softly, don’t let missing configuration error out.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/jammit.rb', line 66 def self.load_configuration(config_path, soft=false) exists = config_path && File.exists?(config_path) return false if soft && !exists raise MissingConfiguration, "could not find the \"#{config_path}\" configuration file" unless exists conf = YAML.load(ERB.new(File.read(config_path)).result) # Optionally overwrite configuration based on the environment. rails_env = defined?(Rails) ? Rails.env : ENV['RAILS_ENV'] conf.merge! conf.delete rails_env if conf.has_key? rails_env @config_path = config_path @configuration = symbolize_keys(conf) @package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH @embed_assets = conf[:embed_assets] || conf[:embed_images] @compress_assets = !(conf[:compress_assets] == false) @gzip_assets = !(conf[:gzip_assets] == false) @allow_debugging = !(conf[:allow_debugging] == false) @mhtml_enabled = @embed_assets && @embed_assets != "datauri" @compressor_options = symbolize_keys(conf[:compressor_options] || {}) @css_compressor_options = symbolize_keys(conf[:css_compressor_options] || {}) set_javascript_compressor(conf[:javascript_compressor]) set_package_assets(conf[:package_assets]) set_template_function(conf[:template_function]) set_template_namespace(conf[:template_namespace]) set_template_extension(conf[:template_extension]) set_template_roots(conf[:template_roots]) symbolize_keys(conf[:stylesheets]) if conf[:stylesheets] symbolize_keys(conf[:javascripts]) if conf[:javascripts] check_for_deprecations self end |
.package!(options = {}) ⇒ Object
Convenience method for packaging up Jammit, using the default options.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/jammit.rb', line 124 def self.package!(={}) = { :config_path => Jammit::DEFAULT_CONFIG_PATH, :output_folder => nil, :base_url => nil, :force => false }.merge() load_configuration([:config_path]) packager.force = [:force] packager.package_names = [:package_names] packager.precache_all([:output_folder], [:base_url]) end |
.packager ⇒ Object
Keep a global (thread-local) reference to a @Jammit::Packager@, to avoid recomputing asset lists unnecessarily.
107 108 109 |
# File 'lib/jammit.rb', line 107 def self.packager Thread.current[:jammit_packager] ||= Packager.new end |
.reload! ⇒ Object
Force a reload by resetting the Packager and reloading the configuration. In development, this will be called as a before_filter before every request.
100 101 102 103 |
# File 'lib/jammit.rb', line 100 def self.reload! Thread.current[:jammit_packager] = nil load_configuration(@config_path) end |