Permalink
Browse files

add display_path option for sites not hosted at domain root

  • Loading branch information...
1 parent ed0c9e6 commit e2b63015c1d62f26d7cdc3b694c6079b1cd7b819 @matthodan committed Jan 1, 2013
View
@@ -263,6 +263,7 @@ asset_pipeline:
bundle: true # Default = true
compress: true # Default = true
output_path: assets # Default = assets
+ display_path: nil # Default = nil
gzip: false # Default = false
```
@@ -271,6 +272,7 @@ asset_pipeline:
> - The "bundle" setting controls whether Jekyll Asset Pipeline bundles the assets defined in each manifest. If "bundle" is set to false, each asset will be saved individually and individual html tags pointing to each unbundled asset will be produced when you compile your site. It is useful to set this to false while you are debugging your site.
> - The "compress" setting tells Jekyll Asset Pipeline whether or not to compress the bundled assets. It is useful to set this setting to "false" while you are debugging your site.
> - The "output\_path" setting defines where generated bundles should be saved within the "\_site" folder of your project.
+> - The "display\_path" setting overrides the path to assets in generated html tags. This is useful if you are hosting your site at a path other than the root of your domain (e.g. "http://example.com/blog/").
> - The "gzip" setting controls whether Jekyll Asset Pipeline saves gzipped versions of your assets alongside un-gzipped versions.
## Octopress
@@ -39,6 +39,7 @@ module JekyllAssetPipeline
# Strings used for keys to play nice when merging with _config.yml
DEFAULTS = {
'output_path' => 'assets', # Destination for bundle file (within the '_site' directory)
+ 'display_path' => nil, # Optional. Override path to assets for output HTML refs
'bundle' => true, # true = Bundle assets, false = Leave assets unbundled
'compress' => true, # true = Minify assets, false = Leave assets unminified
'gzip' => false # true = Create gzip versions, false = Do not create gzip versions
@@ -202,14 +202,15 @@ def save
# Generate html markup pointing to assets
def markup
- path = @options['output_path']
+ # Use display_path if defined, otherwise use output_path in url
+ display_path = @options['display_path'] || @options['output_path']
@html = @assets.map do |asset|
klass = JekyllAssetPipeline::Template.subclasses.select do |t|
t.filetype == File.extname(asset.filename).downcase
end.sort! { |x, y| x.priority <=> y.priority }.last
- html = klass.new(path, asset.filename).html unless klass.nil?
+ html = klass.new(display_path, asset.filename).html unless klass.nil?
html
end.join
@@ -20,8 +20,8 @@ def self.priority
# HTML output to return
#
# Available instance variables:
- # @path Path to bundle file
- # @filename Name of bundle file
+ # @filename Name of bundle file
+ # @path Path to bundle file
#
# Returns string
def html
View
@@ -4,7 +4,7 @@
# Sensible defaults
let(:manifest) { "- /_assets/foo.css\n- /_assets/bar.css" }
let(:prefix) { 'global' }
- let(:config) { { 'output_path' => 'foobar' } }
+ let(:config) { {} }
let(:tag_name) { 'css_asset_tag' }
let(:extension) { '.css' }
@@ -15,6 +15,7 @@
it "saves assets to output path" do
$stdout.stub(:puts, nil) do
+ config['output_path'] = 'foobar_assets'
pipeline, cached = Pipeline.run(manifest, prefix, source_path, temp_path,
tag_name, extension, config)
pipeline.assets.each do |asset|
@@ -29,7 +30,7 @@
it "outputs processing and saved file status messages" do
hash = Pipeline.hash(source_path, manifest, config)
filename = "#{prefix}-#{hash}#{extension}"
- path = File.join(temp_path, config['output_path'])
+ path = File.join(temp_path, DEFAULTS['output_path'])
expected = "Asset Pipeline: Processing '#{tag_name}' manifest '#{prefix}'\n" +
"Asset Pipeline: Saved '#{filename}' to '#{path}'\n"
@@ -121,6 +122,15 @@ def html
pipeline.html.must_match(/script/i)
end
end
+
+ it "links to display_path if option is set" do
+ $stdout.stub(:puts, nil) do
+ config['display_path'] = 'foo/bar/baz'
+ pipeline, cached = Pipeline.run(manifest, prefix, source_path, temp_path,
+ tag_name, '.js', config)
+ pipeline.html.must_match(/foo\/bar\/baz/)
+ end
+ end
end
context "bundle => true" do

0 comments on commit e2b6301

Please sign in to comment.