Skip to content

Commit

Permalink
Vanilla shouldn't parse ruby-ish strings as snip references. Basicall…
Browse files Browse the repository at this point in the history
…y, there should be no space between the opening curly bracket and the snip name, and snip name must start with a word character.
  • Loading branch information
lazyatom committed Nov 30, 2009
1 parent 42f3809 commit 33c6e7a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/vanilla/renderers/base.rb
Expand Up @@ -27,7 +27,7 @@ def soup
end

def self.snip_regexp
%r{(\{[^\}.]+\})}
%r{(\{[\w\-_\d]+(\s+[^\}.]+)?\})}
end

# Default behaviour to include a snip's content
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions test/snip_reference_test.rb
@@ -0,0 +1,47 @@
require File.join(File.dirname(__FILE__), *%w[test_helper])

class SnipReferenceTest < Vanilla::TestCase
def setup
super
create_snip :name => "test", :content => "snip content"
end

should "match simple snips" do
assert_equal "rendering snip content", render("rendering {test}")
end

should "match snips with an argument" do
assert_equal "rendering snip content", render("rendering {test arg1}")
end

should "match snips with several arguments" do
assert_equal "rendering snip content", render("rendering {test arg1, arg2}")
end

should "match snips with hyphens" do
create_snip :name => "test-snip", :content => "snip content"
assert_equal "rendering snip content", render("rendering {test-snip}")
end

should "match snips with underscores" do
create_snip :name => "test_snip", :content => "snip content"
assert_equal "rendering snip content", render("rendering {test_snip}")
end

should "match snips with numbers" do
create_snip :name => "test1", :content => "snip content"
assert_equal "rendering snip content", render("rendering {test1}")
end

should "ignore references that are rubyish" do
assert_equal "10.times { |x| puts x }", render("10.times { |x| puts x }")
assert_equal "10.times {|x| puts x }", render("10.times {|x| puts x }")
end

private

def render(content)
snip = create_snip :name => "test-content", :content => content
Vanilla::Renderers::Base.new(@app).render(snip)
end
end
4 changes: 2 additions & 2 deletions vanilla.gemspec
Expand Up @@ -6,12 +6,12 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Adam"]
s.date = %q{2009-11-24}
s.date = %q{2009-11-30}
s.default_executable = %q{vanilla}
s.email = %q{james@lazyatom.com.com}
s.executables = ["vanilla"]
s.extra_rdoc_files = ["README"]
s.files = ["config.example.yml", "config.ru", "Rakefile", "README", "README_FOR_APP", "test/base_renderer_test.rb", "test/dynasnip_test.rb", "test/erb_renderer_test.rb", "test/markdown_renderer_test.rb", "test/raw_renderer_test.rb", "test/ruby_renderer_test.rb", "test/snip_parser_test.rb", "test/test_helper.rb", "test/tmp", "test/tmp/config.yml", "test/tmp/soup", "test/tmp/soup/current_snip.yml", "test/tmp/soup/system.yml", "test/vanilla_app_test.rb", "test/vanilla_presenting_test.rb", "test/vanilla_request_test.rb", "test/vanilla_soup_test.rb", "lib/defensio.rb", "lib/tasks", "lib/tasks/vanilla.rake", "lib/vanilla", "lib/vanilla/app.rb", "lib/vanilla/authentication", "lib/vanilla/authentication/warden.rb", "lib/vanilla/authentication.rb", "lib/vanilla/console.rb", "lib/vanilla/dynasnip.rb", "lib/vanilla/dynasnips", "lib/vanilla/dynasnips/comments.rb", "lib/vanilla/dynasnips/current_snip.rb", "lib/vanilla/dynasnips/debug.rb", "lib/vanilla/dynasnips/edit.rb", "lib/vanilla/dynasnips/edit_link.rb", "lib/vanilla/dynasnips/index.rb", "lib/vanilla/dynasnips/kind.rb", "lib/vanilla/dynasnips/link_to.rb", "lib/vanilla/dynasnips/link_to_current_snip.rb", "lib/vanilla/dynasnips/logout.rb", "lib/vanilla/dynasnips/new.rb", "lib/vanilla/dynasnips/notes.rb", "lib/vanilla/dynasnips/pre.rb", "lib/vanilla/dynasnips/rand.rb", "lib/vanilla/dynasnips/raw.rb", "lib/vanilla/dynasnips/url_to.rb", "lib/vanilla/renderers", "lib/vanilla/renderers/base.rb", "lib/vanilla/renderers/bold.rb", "lib/vanilla/renderers/erb.rb", "lib/vanilla/renderers/markdown.rb", "lib/vanilla/renderers/raw.rb", "lib/vanilla/renderers/ruby.rb", "lib/vanilla/renderers/textile.rb", "lib/vanilla/request.rb", "lib/vanilla/routes.rb", "lib/vanilla/snip_reference.rb", "lib/vanilla/snip_reference.treetop", "lib/vanilla/snip_reference_parser.rb", "lib/vanilla/snips", "lib/vanilla/snips/start.rb", "lib/vanilla/snips/system.rb", "lib/vanilla/snips/tutorial.rb", "lib/vanilla/soup_with_timestamps.rb", "lib/vanilla.rb", "bin/vanilla", "public/hatch.png", "public/javascripts", "public/javascripts/jquery.autogrow-textarea.js", "public/javascripts/jquery.js", "public/javascripts/vanilla.js"]
s.files = ["config.example.yml", "config.ru", "Rakefile", "README", "README_FOR_APP", "test/base_renderer_test.rb", "test/dynasnip_test.rb", "test/erb_renderer_test.rb", "test/markdown_renderer_test.rb", "test/raw_renderer_test.rb", "test/ruby_renderer_test.rb", "test/snip_reference_parser_test.rb", "test/snip_reference_test.rb", "test/test_helper.rb", "test/tmp", "test/tmp/config.yml", "test/tmp/soup", "test/tmp/soup/current_snip.yml", "test/tmp/soup/system.yml", "test/vanilla_app_test.rb", "test/vanilla_presenting_test.rb", "test/vanilla_request_test.rb", "test/vanilla_soup_test.rb", "lib/defensio.rb", "lib/tasks", "lib/tasks/vanilla.rake", "lib/vanilla", "lib/vanilla/app.rb", "lib/vanilla/authentication", "lib/vanilla/authentication/warden.rb", "lib/vanilla/authentication.rb", "lib/vanilla/console.rb", "lib/vanilla/dynasnip.rb", "lib/vanilla/dynasnips", "lib/vanilla/dynasnips/comments.rb", "lib/vanilla/dynasnips/current_snip.rb", "lib/vanilla/dynasnips/debug.rb", "lib/vanilla/dynasnips/edit.rb", "lib/vanilla/dynasnips/edit_link.rb", "lib/vanilla/dynasnips/index.rb", "lib/vanilla/dynasnips/kind.rb", "lib/vanilla/dynasnips/link_to.rb", "lib/vanilla/dynasnips/link_to_current_snip.rb", "lib/vanilla/dynasnips/logout.rb", "lib/vanilla/dynasnips/new.rb", "lib/vanilla/dynasnips/notes.rb", "lib/vanilla/dynasnips/pre.rb", "lib/vanilla/dynasnips/rand.rb", "lib/vanilla/dynasnips/raw.rb", "lib/vanilla/dynasnips/url_to.rb", "lib/vanilla/renderers", "lib/vanilla/renderers/base.rb", "lib/vanilla/renderers/bold.rb", "lib/vanilla/renderers/erb.rb", "lib/vanilla/renderers/markdown.rb", "lib/vanilla/renderers/raw.rb", "lib/vanilla/renderers/ruby.rb", "lib/vanilla/renderers/textile.rb", "lib/vanilla/request.rb", "lib/vanilla/routes.rb", "lib/vanilla/snip_reference.rb", "lib/vanilla/snip_reference.treetop", "lib/vanilla/snip_reference_parser.rb", "lib/vanilla/snips", "lib/vanilla/snips/start.rb", "lib/vanilla/snips/system.rb", "lib/vanilla/snips/tutorial.rb", "lib/vanilla/soup_with_timestamps.rb", "lib/vanilla.rb", "bin/vanilla", "public/hatch.png", "public/javascripts", "public/javascripts/jquery.autogrow-textarea.js", "public/javascripts/jquery.js", "public/javascripts/vanilla.js"]
s.homepage = %q{http://github.com/lazyatom/vanilla-rb}
s.rdoc_options = ["--main", "README"]
s.require_paths = ["lib"]
Expand Down

0 comments on commit 33c6e7a

Please sign in to comment.