Skip to content

Commit

Permalink
It is useful to be able to specify where the root of any relative sou…
Browse files Browse the repository at this point in the history
…p paths is.

This makes it simpler to run tests outside of a site's base directory.
  • Loading branch information
lazyatom committed May 4, 2011
1 parent 5b1d6c4 commit 5feaac3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/vanilla/app.rb
Expand Up @@ -23,6 +23,7 @@ def initialize(config={})
if @config[:soup].nil? && @config[:soups].nil?
@config.merge!(:soup => File.expand_path("soup"))
end
@root_directory = @config[:root] || Dir.pwd
@soup = prepare_soup(config)
prepare_renderers(config[:renderers])
end
Expand Down Expand Up @@ -145,10 +146,12 @@ def rendering(snip)

def prepare_soup(config)
if config[:soups]
backends = [config[:soups]].flatten.map { |path| ::Soup::Backends::FileBackend.new(path) }
backends = [config[:soups]].flatten.map do |path|
::Soup::Backends::FileBackend.new(File.expand_path(path, @root_directory))
end
::Soup.new(::Soup::Backends::MultiSoup.new(*backends))
else
::Soup.new(::Soup::Backends::FileBackend.new(config[:soup]))
::Soup.new(::Soup::Backends::FileBackend.new(File.expand_path(config[:soup], @root_directory)))
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/vanilla_app_test.rb
@@ -1,4 +1,5 @@
require "test_helper"
require "tmpdir"

describe Vanilla::App do
context "when behaving as a Rack application" do
Expand All @@ -24,6 +25,17 @@
@app = Vanilla::App.new(:soup => soup_path, :root_snip => "custom")
assert_response_body "custom", "/"
end

should "allow specification of the root directory to aide loading external soups" do
tmp_dir = Dir.tmpdir
soup_dir = File.join(tmp_dir, "my_soup")
FileUtils.mkdir_p(soup_dir)
File.open(File.join(soup_dir, "blah.snip"), "w") { |f| f.write "Hello superfriends" }

@app = Vanilla::App.new(:soup => "my_soup", :root => tmp_dir)

assert_equal "Hello superfriends", @app.soup['blah'].content
end
end

context "when detecting the snip renderer" do
Expand Down

0 comments on commit 5feaac3

Please sign in to comment.