Class: Stapler::Config
- Inherits:
-
Object
- Object
- Stapler::Config
- Defined in:
- lib/stapler/config.rb
Constant Summary collapse
- PREFIX =
'stapler'
- WHITELIST_DIR =
%w(javascripts stylesheets)
- WHITELIST_RE =
Regexp.union( %r{^/javascripts/.*\.js($|\?)}, %r{^/stylesheets/.*\.css($|\?)} )
- STAPLIZE_RE =
Regexp.union( %r{/javascripts/.*\.js($|\?)}, %r{/stylesheets/.*\.css($|\?)} )
- DEFAULT_ROOT =
defined?(Rails) ? Rails.public_path : 'public'
- DEFAULT_PREFIX =
'stapler'
Instance Attribute Summary collapse
-
#bundle_regex ⇒ Object
Returns the value of attribute bundle_regex.
-
#path_regex ⇒ Object
Returns the value of attribute path_regex.
-
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
-
#perform_compress ⇒ Object
Returns the value of attribute perform_compress.
-
#rack_file ⇒ Object
Returns the value of attribute rack_file.
Class Method Summary collapse
-
.secret ⇒ Object
FIXME: This should not be class variable.
- .stapleable_dir?(dir) ⇒ Boolean
- .stapleable_path?(source) ⇒ Boolean
- .staplize_url(url) ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stapler/config.rb', line 41 def initialize(opts = {}) # The root directory of where all the public files are stored asset_dir = opts[:public_path] || DEFAULT_ROOT # The path prefix and correcsponding RegEx for stapled assets path_prefix = opts[:path_prefix] || DEFAULT_PREFIX @path_regex = %r(^/#{path_prefix}/(.+)$) @bundle_regex = %r(^/#{path_prefix}/bundle/(.+)$) # Rack::File will pull all the source files @rack_file = Rack::File.new(asset_dir) # Should we write stapled results and where? @perform_caching = opts[:cache_assets] || false # Should we compress stapled results @perform_compress = opts[:compress_assets] || false # Bundle URL signature secret @@secret = opts[:secret] || 'nakedemperor' end |
Instance Attribute Details
#bundle_regex ⇒ Object
Returns the value of attribute bundle_regex.
38 39 40 |
# File 'lib/stapler/config.rb', line 38 def bundle_regex @bundle_regex end |
#path_regex ⇒ Object
Returns the value of attribute path_regex.
38 39 40 |
# File 'lib/stapler/config.rb', line 38 def path_regex @path_regex end |
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
38 39 40 |
# File 'lib/stapler/config.rb', line 38 def perform_caching @perform_caching end |
#perform_compress ⇒ Object
Returns the value of attribute perform_compress.
38 39 40 |
# File 'lib/stapler/config.rb', line 38 def perform_compress @perform_compress end |
#rack_file ⇒ Object
Returns the value of attribute rack_file.
38 39 40 |
# File 'lib/stapler/config.rb', line 38 def rack_file @rack_file end |
Class Method Details
.secret ⇒ Object
FIXME: This should not be class variable
64 65 66 |
# File 'lib/stapler/config.rb', line 64 def self.secret @@secret end |
.stapleable_dir?(dir) ⇒ Boolean
26 27 28 |
# File 'lib/stapler/config.rb', line 26 def stapleable_dir?(dir) WHITELIST_DIR.include?(dir) end |
.stapleable_path?(source) ⇒ Boolean
22 23 24 |
# File 'lib/stapler/config.rb', line 22 def stapleable_path?(source) source =~ WHITELIST_RE end |
.staplize_url(url) ⇒ Object
30 31 32 |
# File 'lib/stapler/config.rb', line 30 def staplize_url(url) url.gsub(STAPLIZE_RE, "/#{PREFIX}\\0") end |