Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wycats/rake-pipeline-web-filters
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: 12spokes/rake-pipeline-web-filters
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Apr 15, 2013

  1. adding support for slim

    elyngved committed Apr 15, 2013
    Copy the full SHA
    6cef216 View commit details
1 change: 1 addition & 0 deletions lib/rake-pipeline-web-filters.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ module Filters
require "rake-pipeline-web-filters/stylus_filter"
require "rake-pipeline-web-filters/jade_filter"
require "rake-pipeline-web-filters/tilt_filter"
require "rake-pipeline-web-filters/slim_filter"
require "rake-pipeline-web-filters/coffee_script_filter"
require "rake-pipeline-web-filters/yui_javascript_filter"
require "rake-pipeline-web-filters/yui_css_filter"
6 changes: 6 additions & 0 deletions lib/rake-pipeline-web-filters/helpers.rb
Original file line number Diff line number Diff line change
@@ -51,6 +51,12 @@ def tilt(*args, &block)
filter(Rake::Pipeline::Web::Filters::TiltFilter, *args, &block)
end

# Add a new {SlimFilter} to the pipeline.
# @see SlimFilter#initialize
def slim(*args, &block)
filter(Rake::Pipeline::Web::Filters::SlimFilter, *args, &block)
end

# Add a new {MarkdownFilter} to the pipeline.
# @see MarkdownFilter#initialize
def markdown(*args, &block)
12 changes: 12 additions & 0 deletions lib/rake-pipeline-web-filters/slim_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rake-pipeline-web-filters/filter_with_dependencies'

module Rake::Pipeline::Web::Filters

class SlimFilter < TiltFilter

def external_dependencies
[ 'slim' ]
end

end
end
1 change: 1 addition & 0 deletions rake-pipeline-web-filters.gemspec
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|

gem.add_development_dependency "rspec"
gem.add_development_dependency "tilt"
gem.add_development_dependency "slim"
gem.add_development_dependency "sass"
gem.add_development_dependency "compass"
gem.add_development_dependency "coffee-script"
105 changes: 105 additions & 0 deletions spec/slim_filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
describe "SlimFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest

let(:slim_input) { <<-SLIM }
doctype html
html
head
title Slim Sample
body
p I love slim!
SLIM

let (:slim_output) do
"<!DOCTYPE html><html><head><title>Slim Sample</title></head><body><p>I love slim!</p></body></html>"
end

let(:slim_rb_input) { <<-SLIM }
- [0,1,2].each do |i|
li= i
SLIM

let(:slim_rb_output) { "<li>0</li><li>1</li><li>2</li>" }

let(:input_files) {
[
MemoryFileWrapper.new("/path/to/input", "foo.slim", "UTF-8", slim_input),
MemoryFileWrapper.new("/path/to/input", "bar.slim", "UTF-8", slim_rb_input)
]
}

let(:output_files) {
[
MemoryFileWrapper.new("/path/to/output", "foo.html", "UTF-8"),
MemoryFileWrapper.new("/path/to/output", "bar.html", "UTF-8")
]
}

def make_filter(*args)
filter = Rake::Pipeline::Web::Filters::SlimFilter.new(*args) do |input|
input.sub(/\.slim$/, '.html')
end
filter.file_wrapper_class = MemoryFileWrapper
filter.manifest = MemoryManifest.new
filter.last_manifest = MemoryManifest.new
filter.input_files = input_files
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
filter
end

it "generates output" do
filter = make_filter

filter.output_files.should == output_files

tasks = filter.generate_rake_tasks
tasks.each(&:invoke)

file = MemoryFileWrapper.files["/path/to/output/foo.html"]
file.body.should == slim_output
file.encoding.should == "UTF-8"

file = MemoryFileWrapper.files["/path/to/output/bar.html"]
file.body.should == slim_rb_output
file.encoding.should == "UTF-8"
end

it "accepts options to pass to the template class" do
# :pretty => true should indent html for pretty debugging
filter = make_filter(:pretty => true)

tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
file = MemoryFileWrapper.files["/path/to/output/foo.html"]
# body should contain line breaks, and stripping out line breaks & indents
# should produce the original output
file.body.should include "\n "
file.body.gsub(/\n\s*/, '').should == slim_output
end

describe 'with a rendering context' do

let(:input_files) do
[
MemoryFileWrapper.new("/path/to/input", "foo.slim", "UTF-8", "b= foo"),
]
end

let(:context) do
context = Class.new do
def foo; 'bar'; end
end.new
end

it 'uses the context' do
filter = make_filter({}, context)

tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
file = MemoryFileWrapper.files["/path/to/output/foo.html"]
file.body.should == "<b>bar</b>"
end
end
end