Skip to content

Commit

Permalink
Add support for preprocessing the entire sass/less/css source with Li…
Browse files Browse the repository at this point in the history
…quid.
  • Loading branch information
envygeeks committed Nov 19, 2015
1 parent fbe30d1 commit 3cb73ac
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions TODO.md
@@ -0,0 +1,3 @@
# 2.1
- [x] Add support for processing text files with Liquid.
- [ ] Process tag arguments with Liquid, not just values.
1 change: 1 addition & 0 deletions jekyll-assets.gemspec
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency("sprockets-helpers", "~> 1.2")
spec.add_runtime_dependency("fastimage", "~> 1.8")
spec.add_runtime_dependency("jekyll", "~> 3.0")
spec.add_runtime_dependency("tilt", "~> 2.0")

spec.add_development_dependency("nokogiri", "~> 1.6")
spec.add_development_dependency("envygeeks-coveralls", "~> 1.0")
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/assets.rb
Expand Up @@ -2,6 +2,7 @@
# Copyright: 2012-2015 - MIT License
# Encoding: utf-8

require "tilt"
require "sprockets"
require "jekyll"

Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/assets/addons.rb
Expand Up @@ -5,6 +5,7 @@
require_relative "addons/compass"
require_relative "addons/bootstrap"
require_relative "addons/autoprefixer"
require_relative "addons/processors/liquid"
require_relative "addons/proxies/magick"
require_relative "addons/font_awesome"
require_relative "addons/js_es6"
36 changes: 36 additions & 0 deletions lib/jekyll/assets/addons/processors/liquid.rb
@@ -0,0 +1,36 @@
module Jekyll
module Assets
module Addons
module Processors
class Liquid < Tilt::Template
ProcessingFor = %W(
text/css text/sass text/less text/scss
text/coffeescript text/javascript
)

def prepare
#
end

# Render the file with the sites current context, anything you
# can do in a normal liquid file with Jekyll, you can do here inc,
# accessing the entirety of your posts and pages, though I don't
# know why you would want to, and I ain't judging you.

def evaluate(scope, locals, jekyll = scope.environment.jekyll, &block)
jekyll.liquid_renderer.file(@file).parse(data).render!(
jekyll.site_payload, :registers => {
:site => jekyll
}
)
end
end
end
end
end
end

# There might be a few missing, if there is please do let me know.
Jekyll::Assets::Addons::Processors::Liquid::ProcessingFor.each do |val|
Sprockets.register_preprocessor val, Jekyll::Assets::Addons::Processors::Liquid
end
3 changes: 3 additions & 0 deletions spec/fixture/_assets/css/liquid.scss
@@ -0,0 +1,3 @@
.background {
background: url(asset_path("{{ site.background_image }}"))
}
1 change: 1 addition & 0 deletions spec/fixture/_config.yml
@@ -0,0 +1 @@
background_image: ruby.png
16 changes: 16 additions & 0 deletions spec/lib/jekyll/assets/addons/processors/liquid_spec.rb
@@ -0,0 +1,16 @@
# Frozen-string-literal: true
# Copyright: 2012-2015 - MIT License
# Encoding: utf-8

require "rspec/helper"
describe Jekyll::Assets::Addons::Processors::Liquid do
let(:env) do
Jekyll::Assets::Env.new(stub_jekyll_site)
end

it "lets the user use Liquid" do
source = env.find_asset("liquid").to_s
expect(source).not_to(match(/\{{2}\s*site\.background_image\s*\}{2}/))
expect(source).to(match(/background:\s*url\("\/assets\/ruby\.png"\)/))
end
end

0 comments on commit 3cb73ac

Please sign in to comment.