Skip to content

Commit

Permalink
add display_path option for sites not hosted at domain root
Browse files Browse the repository at this point in the history
  • Loading branch information
matthodan committed Jan 1, 2013
1 parent ed0c9e6 commit e2b6301
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll_asset_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/jekyll_asset_pipeline/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll_asset_pipeline/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand All @@ -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|
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2b6301

Please sign in to comment.