vanilla 1.2 → 1.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +61 -60
- data/bin/vanilla +6 -35
- data/config.example.yml +6 -0
- data/config.ru +10 -0
- data/lib/defensio.rb +59 -0
- data/lib/tasks/vanilla.rake +173 -0
- data/lib/vanilla.rb +3 -10
- data/lib/vanilla/app.rb +48 -104
- data/lib/vanilla/console.rb +5 -19
- data/lib/vanilla/dynasnips/comments.rb +108 -0
- data/lib/vanilla/dynasnips/current_snip.rb +32 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/debug.rb +3 -5
- data/lib/vanilla/dynasnips/edit.rb +60 -0
- data/lib/vanilla/dynasnips/edit_link.rb +20 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/index.rb +2 -4
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/kind.rb +12 -14
- data/{pristine_app/soups → lib/vanilla}/dynasnips/link_to.rb +0 -2
- data/lib/vanilla/dynasnips/link_to_current_snip.rb +16 -0
- data/lib/vanilla/dynasnips/login.rb +56 -0
- data/lib/vanilla/dynasnips/new.rb +14 -0
- data/lib/vanilla/dynasnips/notes.rb +42 -0
- data/{pristine_app/soups → lib/vanilla}/dynasnips/pre.rb +4 -6
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/rand.rb +0 -2
- data/{pristine_app/soups → lib/vanilla}/dynasnips/raw.rb +5 -8
- data/{pristine_app/soups/extras → lib/vanilla/dynasnips}/url_to.rb +0 -0
- data/lib/vanilla/renderers/base.rb +22 -32
- data/lib/vanilla/renderers/bold.rb +2 -0
- data/lib/vanilla/renderers/erb.rb +2 -0
- data/lib/vanilla/renderers/markdown.rb +2 -0
- data/lib/vanilla/renderers/raw.rb +2 -0
- data/lib/vanilla/renderers/ruby.rb +5 -9
- data/lib/vanilla/renderers/textile.rb +2 -0
- data/lib/vanilla/request.rb +15 -16
- data/lib/vanilla/routes.rb +18 -5
- data/lib/vanilla/snip_reference.rb +534 -0
- data/lib/vanilla/snip_reference.treetop +48 -0
- data/lib/vanilla/snip_reference_parser.rb +99 -82
- data/lib/vanilla/snips/start.rb +28 -0
- data/lib/vanilla/snips/system.rb +77 -0
- data/lib/vanilla/snips/tutorial.rb +244 -0
- data/lib/vanilla/soup_with_timestamps.rb +21 -0
- data/public/hatch.png +0 -0
- data/public/javascripts/jquery.autogrow-textarea.js +54 -0
- data/public/javascripts/jquery.js +4376 -0
- data/public/javascripts/vanilla.js +22 -0
- data/spec/dynasnip_spec.rb +28 -0
- data/spec/renderers/base_renderer_spec.rb +40 -0
- data/spec/renderers/erb_renderer_spec.rb +27 -0
- data/spec/renderers/markdown_renderer_spec.rb +29 -0
- data/spec/renderers/raw_renderer_spec.rb +21 -0
- data/spec/renderers/ruby_renderer_spec.rb +59 -0
- data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +35 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/tmp/config.yml +2 -0
- data/spec/tmp/soup/current_snip.yml +15 -0
- data/spec/tmp/soup/system.yml +5 -0
- data/spec/vanilla_app_spec.rb +38 -0
- data/spec/vanilla_presenting_spec.rb +84 -0
- data/spec/vanilla_request_spec.rb +73 -0
- metadata +79 -170
- data/lib/vanilla/renderers.rb +0 -12
- data/lib/vanilla/renderers/haml.rb +0 -13
- data/lib/vanilla/static.rb +0 -28
- data/pristine_app/Gemfile +0 -3
- data/pristine_app/Gemfile.lock +0 -32
- data/pristine_app/README +0 -47
- data/pristine_app/config.ru +0 -26
- data/pristine_app/public/vanilla.css +0 -15
- data/pristine_app/soups/base/layout.snip +0 -18
- data/pristine_app/soups/base/start.snip +0 -19
- data/pristine_app/soups/dynasnips/current_snip.rb +0 -29
- data/pristine_app/soups/dynasnips/link_to_current_snip.rb +0 -14
- data/pristine_app/soups/dynasnips/page_title.rb +0 -9
- data/pristine_app/soups/extras/comments.rb +0 -78
- data/pristine_app/soups/tutorial/bad_dynasnip.snip +0 -8
- data/pristine_app/soups/tutorial/hello_world.snip +0 -20
- data/pristine_app/soups/tutorial/markdown_example.snip +0 -13
- data/pristine_app/soups/tutorial/snip.snip +0 -9
- data/pristine_app/soups/tutorial/soup.snip +0 -3
- data/pristine_app/soups/tutorial/test.snip +0 -30
- data/pristine_app/soups/tutorial/textile_example.snip +0 -11
- data/pristine_app/soups/tutorial/tutorial-another-snip.snip +0 -1
- data/pristine_app/soups/tutorial/tutorial-basic-snip-inclusion.snip +0 -1
- data/pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown +0 -56
- data/pristine_app/soups/tutorial/tutorial-layout.snip +0 -56
- data/pristine_app/soups/tutorial/tutorial-links.snip +0 -4
- data/pristine_app/soups/tutorial/tutorial-renderers.snip.markdown +0 -77
- data/pristine_app/soups/tutorial/tutorial.snip.markdown +0 -69
- data/pristine_app/soups/tutorial/vanilla-rb.snip +0 -16
- data/pristine_app/soups/tutorial/vanilla.snip +0 -8
- data/test/dynasnip_test.rb +0 -42
- data/test/dynasnips/link_to_current_snip_test.rb +0 -19
- data/test/dynasnips/link_to_test.rb +0 -27
- data/test/dynasnips/page_title_test.rb +0 -19
- data/test/renderers/base_renderer_test.rb +0 -43
- data/test/renderers/erb_renderer_test.rb +0 -29
- data/test/renderers/haml_renderer_test.rb +0 -35
- data/test/renderers/markdown_renderer_test.rb +0 -31
- data/test/renderers/raw_renderer_test.rb +0 -23
- data/test/renderers/ruby_renderer_test.rb +0 -59
- data/test/snip_inclusion_test.rb +0 -56
- data/test/snip_reference_parser_test.rb +0 -123
- data/test/test_helper.rb +0 -75
- data/test/vanilla_app_test.rb +0 -83
- data/test/vanilla_presenting_test.rb +0 -125
- data/test/vanilla_request_test.rb +0 -87
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
describe Vanilla::Renderers::Markdown do
|
|
4
|
-
context "when rendering" do
|
|
5
|
-
should "return the snip contents rendered via Markdown" do
|
|
6
|
-
content = <<Markdown
|
|
7
|
-
# markdown
|
|
8
|
-
|
|
9
|
-
* totally
|
|
10
|
-
* [rocks](http://www.example.com)!
|
|
11
|
-
Markdown
|
|
12
|
-
markdown_snip(:name => "test", :content => content)
|
|
13
|
-
assert_response_body BlueCloth.new(content).to_html, "/test"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
should "include other snips using their renderers" do
|
|
17
|
-
markdown_snip(:name => "test", :content => <<-Markdown
|
|
18
|
-
# markdown
|
|
19
|
-
|
|
20
|
-
and so lets include {another_snip}
|
|
21
|
-
Markdown
|
|
22
|
-
)
|
|
23
|
-
create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
|
|
24
|
-
assert_equal "<h1>markdown</h1> <p>and so lets include <b>blah</b></p>", response_body_for("/test").gsub(/\s+/, ' ')
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def markdown_snip(attributes)
|
|
29
|
-
create_snip(attributes.merge(:render_as => "Markdown"))
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
describe Vanilla::Renderers::Raw do
|
|
4
|
-
context "when rendering" do
|
|
5
|
-
setup do
|
|
6
|
-
@snip = create_snip(:name => "test", :content => "raw content", :part => "raw part")
|
|
7
|
-
set_main_template "<tag>{current_snip}</tag>"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
should "render the contents part of the snip as it is" do
|
|
11
|
-
assert_response_body "raw content", "/test.raw"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
should "render the specified part of the snip" do
|
|
15
|
-
assert_response_body "raw part", "/test/part.raw"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
should "not perform any snip inclusion" do
|
|
19
|
-
create_snip(:name => "snip_with_inclusions", :content => "loading {another_snip}")
|
|
20
|
-
assert_response_body "loading {another_snip}", "/snip_with_inclusions.raw"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
describe Vanilla::Renderers::Ruby do
|
|
4
|
-
context "when rendering normally" do
|
|
5
|
-
class ::TestDyna < Dynasnip
|
|
6
|
-
def handle(*args)
|
|
7
|
-
'handle called'
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
@app.soup << TestDyna.snip_attributes
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
should "render the result of the handle method" do
|
|
16
|
-
assert_response_body 'handle called', "/test_dyna"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context "when responding restfully" do
|
|
21
|
-
class ::RestishDyna < Dynasnip
|
|
22
|
-
def get(*args)
|
|
23
|
-
'get called'
|
|
24
|
-
end
|
|
25
|
-
def post(*args)
|
|
26
|
-
'post called'
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
setup do
|
|
31
|
-
@app.soup << RestishDyna.snip_attributes
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
should "render the result of the get method on GET requests" do
|
|
35
|
-
assert_response_body 'get called', "/restish_dyna"
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
should "render the result of the post method on POST requests" do
|
|
39
|
-
assert_response_body 'post called', "/restish_dyna?_method=post"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when knowing about enclosing snips" do
|
|
44
|
-
class ::Encloser < Dynasnip
|
|
45
|
-
def handle(*args)
|
|
46
|
-
"enclosing snip is #{enclosing_snip.name}"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
setup do
|
|
51
|
-
@app.soup << Encloser.snip_attributes
|
|
52
|
-
create_snip(:name => "test", :content => "{encloser}")
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
should "know about the snip that called this dynasnip" do
|
|
56
|
-
assert_response_body 'enclosing snip is test', "/test"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
data/test/snip_inclusion_test.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
context "When including snips in other snips" do
|
|
4
|
-
setup do
|
|
5
|
-
create_snip :name => "test", :content => "snip content"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
should "match simple snips" do
|
|
9
|
-
assert_equal "rendering snip content", render("rendering {test}")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
should "match snips with an argument" do
|
|
13
|
-
assert_equal "rendering snip content", render("rendering {test arg1}")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
should "match snips with several arguments" do
|
|
17
|
-
assert_equal "rendering snip content", render("rendering {test arg1, arg2}")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
should "match snips with hyphens" do
|
|
21
|
-
create_snip :name => "test-snip", :content => "snip content"
|
|
22
|
-
assert_equal "rendering snip content", render("rendering {test-snip}")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
should "match snips with underscores" do
|
|
26
|
-
create_snip :name => "test_snip", :content => "snip content"
|
|
27
|
-
assert_equal "rendering snip content", render("rendering {test_snip}")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
should "match snips with numbers" do
|
|
31
|
-
create_snip :name => "test1", :content => "snip content"
|
|
32
|
-
assert_equal "rendering snip content", render("rendering {test1}")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
should "match snips with ruby 1.9 style hashes" do
|
|
36
|
-
create_snip :name => "test", :content => %{
|
|
37
|
-
class Blah
|
|
38
|
-
def handle(args)
|
|
39
|
-
args.inspect
|
|
40
|
-
end
|
|
41
|
-
self
|
|
42
|
-
end
|
|
43
|
-
}, :render_as => "Ruby"
|
|
44
|
-
assert_equal %{rendering {:x=>"1"}}, render("rendering {test x:1}")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
should "ignore references that are rubyish" do
|
|
48
|
-
assert_equal "10.times { |x| puts x }", render("10.times { |x| puts x }")
|
|
49
|
-
assert_equal "10.times {|x| puts x }", render("10.times {|x| puts x }")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def render(content)
|
|
53
|
-
snip = create_snip :name => "test-content", :content => content
|
|
54
|
-
Vanilla::Renderers::Base.new(@app).render(snip)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
context "The SnipReference parser" do
|
|
4
|
-
|
|
5
|
-
setup do
|
|
6
|
-
@parser = Vanilla::SnipReferenceParser.new
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
examples = {
|
|
10
|
-
:snip_names => {
|
|
11
|
-
%|{snip}| => {:snip => 'snip', :attribute => nil, :arguments => []},
|
|
12
|
-
%|{Snip}| => {:snip => 'Snip', :attribute => nil, :arguments => []},
|
|
13
|
-
%|{123snip}| => {:snip => '123snip', :attribute => nil, :arguments => []},
|
|
14
|
-
%|{Snip123}| => {:snip => 'Snip123', :attribute => nil, :arguments => []},
|
|
15
|
-
%|{snip-with-dashes}| => {:snip => 'snip-with-dashes', :attribute => nil, :arguments => []},
|
|
16
|
-
%|{snip_with_underscores}| => {:snip => 'snip_with_underscores', :attribute => nil, :arguments => []},
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
:snip_attributes => {
|
|
20
|
-
%|{snip.snip_attribute}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => []},
|
|
21
|
-
%|{snip.snip_attribute arg}| => {:snip => 'snip', :attribute => 'snip_attribute', :arguments => ['arg']},
|
|
22
|
-
%|{snip."spaced attribute"}| => {:snip => 'snip', :attribute => 'spaced attribute', :arguments => []},
|
|
23
|
-
%|{snip.'spaced attribute'}| => {:snip => 'snip', :attribute => 'spaced attribute', :arguments => []}
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
:simple_arguments => {
|
|
27
|
-
%|{snip argument}| => {:snip => 'snip', :attribute => nil, :arguments => ["argument"]},
|
|
28
|
-
%|{snip1 argument}| => {:snip => 'snip1', :attribute => nil, :arguments => ["argument"]},
|
|
29
|
-
%|{snip arg-dashes}| => {:snip => 'snip', :attribute => nil, :arguments => ["arg-dashes"]},
|
|
30
|
-
%|{snip arg_underscores}| => {:snip => 'snip', :attribute => nil, :arguments => ["arg_underscores"]},
|
|
31
|
-
%|{snip arg1,arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
|
32
|
-
%|{snip arg1, arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
|
33
|
-
%|{snip arg1, arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', 'arg2']},
|
|
34
|
-
%|{snip 1ARG, arg_2, arg-3}| => {:snip => 'snip', :attribute => nil, :arguments => ['1ARG', 'arg_2', 'arg-3']}
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
:snip_name_spaces => {
|
|
38
|
-
%|{"snip with spaces"}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => []},
|
|
39
|
-
%|{'snip with spaces'}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => []},
|
|
40
|
-
%|{"snip with spaces" argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
|
41
|
-
%|{'snip with spaces' argument}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['argument']},
|
|
42
|
-
%|{"snip with spaces" a, b}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['a', 'b']},
|
|
43
|
-
%|{'snip with spaces' a, b}| => {:snip => 'snip with spaces', :attribute => nil, :arguments => ['a', 'b']},
|
|
44
|
-
%|{"snip with spaces".attribute}| => {:snip => 'snip with spaces', :attribute => 'attribute', :arguments => []},
|
|
45
|
-
%|{'snip with spaces'.attribute}| => {:snip => 'snip with spaces', :attribute => 'attribute', :arguments => []}
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
:arguments_with_spaces => {
|
|
49
|
-
# %|{snip arg spaces}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg spaces']},
|
|
50
|
-
# %|{snip arg spaces, and this}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg spaces', 'and this']},
|
|
51
|
-
%|{snip "arg spaces"}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg spaces']},
|
|
52
|
-
%|{snip 'arg spaces'}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg spaces']},
|
|
53
|
-
%|{snip "arg spaces", arg2}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg spaces', 'arg2']}
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
:nil_arguments => {
|
|
57
|
-
%|{snip arg1,nil,arg3}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', nil, 'arg3']},
|
|
58
|
-
%|{snip arg1, nil ,arg3}| => {:snip => 'snip', :attribute => nil, :arguments => ['arg1', nil, 'arg3']}
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
:classic_ruby_hash_arguments => {
|
|
62
|
-
%|{s key1=>value1, key2 => value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
63
|
-
%|{s key1 => value1, key2 => value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
64
|
-
%|{s :key1 => value1, :key2 => value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
65
|
-
%|{s key1 => "value with spaces"}| => {:snip => 's', :arguments => {:key1 => "value with spaces"}},
|
|
66
|
-
%|{s.attr key1=>value1}| => {:snip => 's', :attribute => 'attr', :arguments => {:key1 => 'value1'}},
|
|
67
|
-
# %|{s "key with spaces" => value}| => {:snip => 's', :arguments => {:"key with spaces" => "value"}}
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
:named_arguments => {
|
|
71
|
-
%|{s key1:value1,key2:value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
72
|
-
%|{s key1:value1, key2:value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
73
|
-
%|{s key1: value1, key2: value2}| => {:snip => 's', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
|
|
74
|
-
%|{s key1:"value with spaces"}| => {:snip => 's', :arguments => {:key1 => 'value with spaces'}}
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
:quoting_arguments => {
|
|
78
|
-
# %|{s "arg \\" double"}| => {:snip => 's', :attribute => nil, :arguments => ['arg " double']},
|
|
79
|
-
# %|{s 'arg \\' single'}| => {:snip => 's', :attribute => nil, :arguments => ["arg ' single"]},
|
|
80
|
-
%|{s "arg ' single"}| => {:snip => 's', :attribute => nil, :arguments => ["arg ' single"]},
|
|
81
|
-
%|{s 'arg " double'}| => {:snip => 's', :attribute => nil, :arguments => ['arg " double']},
|
|
82
|
-
%|{s "arg, comma"}| => {:snip => 's', :attribute => nil, :arguments => ['arg, comma']},
|
|
83
|
-
%|{s 'arg, comma'}| => {:snip => 's', :attribute => nil, :arguments => ['arg, comma']},
|
|
84
|
-
# %|{s "arg { open"}| => {:snip => 's', :attribute => nil, :arguments => ['arg { open']},
|
|
85
|
-
# %|{s "arg } close"}| => {:snip => 's', :attribute => nil, :arguments => ['arg } close']}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
examples.each do |type, set|
|
|
90
|
-
context type.to_s.gsub("_", " ") do
|
|
91
|
-
set.each do |example, expected|
|
|
92
|
-
should "parse '#{example}' into #{expected.inspect}" do
|
|
93
|
-
reference = @parser.parse(example)
|
|
94
|
-
if reference
|
|
95
|
-
assert_equal expected[:snip], reference.snip
|
|
96
|
-
assert_equal expected[:attribute], reference.attribute
|
|
97
|
-
assert_equal expected[:arguments], reference.arguments
|
|
98
|
-
assert_parsable_by_vanilla example, expected
|
|
99
|
-
else
|
|
100
|
-
flunk "failed to parse: #{example} - #{@parser.failure_reason}"
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
private
|
|
108
|
-
|
|
109
|
-
def assert_parsable_by_vanilla(example, expected)
|
|
110
|
-
create_snip_from_expected expected
|
|
111
|
-
create_snip :name => "test", :content => "alpha #{example} beta"
|
|
112
|
-
assert_response_body "alpha ok beta", "/test"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def create_snip_from_expected(expected)
|
|
116
|
-
simple_dyna = %|class SimpleDyna;def handle(*args); 'ok'; end;self;end|
|
|
117
|
-
attributes = {:name => expected[:snip], :content => simple_dyna, :render_as => "ruby"}
|
|
118
|
-
if expected[:attribute]
|
|
119
|
-
attributes[expected[:attribute]] = simple_dyna
|
|
120
|
-
end
|
|
121
|
-
create_snip(attributes)
|
|
122
|
-
end
|
|
123
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'bundler/setup'
|
|
3
|
-
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
4
|
-
|
|
5
|
-
require "kintama"
|
|
6
|
-
require "kintama/mocha"
|
|
7
|
-
require "fileutils"
|
|
8
|
-
require "rack/mock"
|
|
9
|
-
require "vanilla"
|
|
10
|
-
|
|
11
|
-
module Vanilla
|
|
12
|
-
module Test
|
|
13
|
-
def setup_clean_environment
|
|
14
|
-
clean_environment
|
|
15
|
-
@app = Vanilla::App.new(:soup => soup_path)
|
|
16
|
-
|
|
17
|
-
require File.expand_path("../../pristine_app/soups/dynasnips/current_snip", __FILE__)
|
|
18
|
-
@app.soup << CurrentSnip.snip_attributes
|
|
19
|
-
create_snip :name => "layout", :content => "{current_snip}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def response_for(url)
|
|
23
|
-
@app.call(mock_env_for_url(url))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def response_body_for(url)
|
|
27
|
-
response_for(url)[2].body[0]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def response_code_for(url)
|
|
31
|
-
response_for(url)[0]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def assert_response_body(expected, uri)
|
|
35
|
-
assert_equal expected.strip, response_body_for(uri).strip
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def set_main_template(template_content)
|
|
39
|
-
@app.soup << {:name => "layout", :content => template_content}
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def create_snip(params)
|
|
43
|
-
@app.soup << params
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def mock_env_for_url(url)
|
|
47
|
-
Rack::MockRequest.env_for(url)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def mock_request(url)
|
|
51
|
-
Rack::Request.new(mock_env_for_url(url))
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_app_directory
|
|
55
|
-
File.join(File.dirname(__FILE__), "tmp")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def soup_path
|
|
59
|
-
File.expand_path(File.join(test_app_directory, "soup"))
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def clean_environment
|
|
63
|
-
FileUtils.rm_rf(test_app_directory)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
Kintama.include Vanilla::Test
|
|
69
|
-
Kintama.setup do
|
|
70
|
-
setup_clean_environment
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
Kintama.teardown do
|
|
74
|
-
clean_environment
|
|
75
|
-
end
|
data/test/vanilla_app_test.rb
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
describe Vanilla::App do
|
|
4
|
-
context "when behaving as a Rack application" do
|
|
5
|
-
should "return an array of status code, headers and response" do
|
|
6
|
-
create_snip(:name => "test", :content => "content")
|
|
7
|
-
result = @app.call(mock_env_for_url("/test.text"))
|
|
8
|
-
assert_kind_of Array, result
|
|
9
|
-
assert_equal 200, result[0]
|
|
10
|
-
assert_kind_of Hash, result[1]
|
|
11
|
-
result[2].each{ |output| assert_equal "content", output }
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
context "when being configured" do
|
|
16
|
-
should "default the root snip to 'start'" do
|
|
17
|
-
create_snip :name => "start", :content => "default"
|
|
18
|
-
assert_response_body "default", "/"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
should "allow a customised root snip" do
|
|
22
|
-
create_snip :name => "start", :content => "default"
|
|
23
|
-
create_snip :name => "custom", :content => "custom"
|
|
24
|
-
@app = Vanilla::App.new(:soup => soup_path, :root_snip => "custom")
|
|
25
|
-
assert_response_body "custom", "/"
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when detecting the snip renderer" do
|
|
30
|
-
setup do
|
|
31
|
-
@app = Vanilla::App.new(:soup => soup_path)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
should "return the constant refered to in the render_as property of the snip" do
|
|
35
|
-
snip = create_snip(:name => "blah", :render_as => "Raw")
|
|
36
|
-
assert_equal Vanilla::Renderers::Raw, @app.renderer_for(snip)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "using the snip extension" do
|
|
40
|
-
{
|
|
41
|
-
"markdown" => Vanilla::Renderers::Markdown,
|
|
42
|
-
"textile" => Vanilla::Renderers::Textile,
|
|
43
|
-
"erb" => Vanilla::Renderers::Erb,
|
|
44
|
-
"rb" => Vanilla::Renderers::Ruby,
|
|
45
|
-
"haml" => Vanilla::Renderers::Haml
|
|
46
|
-
}.each do |extension, renderer|
|
|
47
|
-
should "return the renderer #{renderer} when the snip has extension #{extension}" do
|
|
48
|
-
snip = create_snip(:name => "blah", :extension => extension)
|
|
49
|
-
assert_equal renderer, @app.renderer_for(snip)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
should "respect snip renderers passed in the config" do
|
|
55
|
-
app = Vanilla::App.new(:soup => soup_path, :renderers => {"markdown" => "Vanilla::Renderers::Bold"})
|
|
56
|
-
snip = create_snip(:name => "blah", :extension => "markdown")
|
|
57
|
-
assert_equal Vanilla::Renderers::Bold, app.renderer_for(snip)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
should "return Vanilla::Renderers::Base if no render_as property exists" do
|
|
61
|
-
snip = create_snip(:name => "blah")
|
|
62
|
-
assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
should "return Vanilla::Renderers::Base if the render_as property is blank" do
|
|
66
|
-
snip = create_snip(:name => "blah", :render_as => '')
|
|
67
|
-
assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
should "raise an error if the specified renderer doesn't exist" do
|
|
71
|
-
snip = create_snip(:name => "blah", :render_as => "NonExistentClass")
|
|
72
|
-
assert_raises(NameError) { @app.renderer_for(snip) }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
should "load constants presented as a string" do
|
|
76
|
-
class ::MyRenderer
|
|
77
|
-
end
|
|
78
|
-
app = Vanilla::App.new(:soup => soup_path, :renderers => {"my_renderer" => "MyRenderer"})
|
|
79
|
-
snip = create_snip(:name => "blah", :render_as => "my_renderer")
|
|
80
|
-
assert_equal MyRenderer, app.renderer_for(snip)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|