Skip to content

Commit

Permalink
Write assets upon site regeneration (with --auto)
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
ixti committed Feb 18, 2013
1 parent 38c1070 commit cc5c35f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
26 changes: 24 additions & 2 deletions lib/jekyll/assets_plugin/site_patch.rb
Expand Up @@ -11,6 +11,14 @@ module Jekyll
module AssetsPlugin
module SitePatch

def self.included base
base.class_eval do
alias_method :write_without_assets, :write
alias_method :write, :write_with_assets
end
end


def assets_config
@assets_config ||= Configuration.new(self.config["assets"] || {})
end
Expand All @@ -21,6 +29,11 @@ def assets
end


def asset_files
@asset_files ||= []
end


def asset_path *args
asset = assets[*args]
baseurl = "#{assets_config.baseurl}/"
Expand All @@ -36,11 +49,20 @@ def asset_path *args


def bundle_asset! asset
if not static_files.include? asset
static_files << AssetFile.new(self, asset)
if not asset_files.include? asset
file = AssetFile.new self, asset

asset_files << file
static_files << file
end
end


def write_with_assets
static_files.push(*asset_files).uniq!
write_without_assets
end

end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/lib/jekyll/assets_plugin/site_patch_spec.rb
Expand Up @@ -45,7 +45,7 @@ def source
site.assets["app.css"].to_s.should match(noise_img_re)
end

it "should be appended to the static files list" do
it "should be appended to the static_files list" do
asset = site.assets["app.css"] # make sure main asset was compiled
asset = site.assets["noise.png"]

Expand Down Expand Up @@ -88,6 +88,7 @@ def source
end
end


context "#assets_config" do
subject { site.assets_config }
it { should be_an_instance_of Configuration }
Expand All @@ -98,6 +99,15 @@ def source
end
end


it "should regenerate assets upon multiple #process" do
@site.assets_config.cachebust = :none
2.times { @site.process }

@dest.join("assets", "app.css").exist?.should be_true
end


it "should be included into Jekyll::Site" do
Jekyll::Site.included_modules.should include SitePatch
end
Expand Down

0 comments on commit cc5c35f

Please sign in to comment.