vanilla 1.0.2 → 1.2

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.
Files changed (105) hide show
  1. data/Rakefile +112 -109
  2. data/bin/vanilla +35 -6
  3. data/lib/vanilla.rb +10 -14
  4. data/lib/vanilla/app.rb +109 -41
  5. data/lib/vanilla/console.rb +22 -2
  6. data/lib/vanilla/dynasnip.rb +4 -36
  7. data/lib/vanilla/renderers.rb +12 -0
  8. data/lib/vanilla/renderers/base.rb +58 -34
  9. data/lib/vanilla/renderers/bold.rb +0 -2
  10. data/lib/vanilla/renderers/erb.rb +1 -3
  11. data/lib/vanilla/renderers/haml.rb +13 -0
  12. data/lib/vanilla/renderers/markdown.rb +0 -2
  13. data/lib/vanilla/renderers/raw.rb +0 -2
  14. data/lib/vanilla/renderers/ruby.rb +12 -6
  15. data/lib/vanilla/renderers/textile.rb +0 -2
  16. data/lib/vanilla/request.rb +19 -17
  17. data/lib/vanilla/routes.rb +9 -20
  18. data/lib/vanilla/snip_reference_parser.rb +94 -0
  19. data/lib/vanilla/static.rb +28 -0
  20. data/pristine_app/Gemfile +3 -0
  21. data/pristine_app/Gemfile.lock +32 -0
  22. data/pristine_app/README +47 -0
  23. data/pristine_app/config.ru +26 -0
  24. data/pristine_app/public/vanilla.css +15 -0
  25. data/pristine_app/soups/base/layout.snip +18 -0
  26. data/pristine_app/soups/base/start.snip +19 -0
  27. data/pristine_app/soups/dynasnips/current_snip.rb +29 -0
  28. data/{lib/vanilla → pristine_app/soups}/dynasnips/debug.rb +5 -3
  29. data/pristine_app/soups/dynasnips/index.rb +12 -0
  30. data/{lib/vanilla → pristine_app/soups}/dynasnips/link_to.rb +4 -2
  31. data/pristine_app/soups/dynasnips/link_to_current_snip.rb +14 -0
  32. data/pristine_app/soups/dynasnips/page_title.rb +9 -0
  33. data/{lib/vanilla → pristine_app/soups}/dynasnips/pre.rb +7 -5
  34. data/{lib/vanilla → pristine_app/soups}/dynasnips/raw.rb +8 -5
  35. data/pristine_app/soups/extras/comments.rb +78 -0
  36. data/{lib/vanilla/dynasnips → pristine_app/soups/extras}/kind.rb +19 -17
  37. data/{lib/vanilla/dynasnips → pristine_app/soups/extras}/rand.rb +2 -0
  38. data/pristine_app/soups/extras/url_to.rb +7 -0
  39. data/pristine_app/soups/tutorial/bad_dynasnip.snip +8 -0
  40. data/pristine_app/soups/tutorial/hello_world.snip +20 -0
  41. data/pristine_app/soups/tutorial/markdown_example.snip +13 -0
  42. data/pristine_app/soups/tutorial/snip.snip +9 -0
  43. data/pristine_app/soups/tutorial/soup.snip +3 -0
  44. data/pristine_app/soups/tutorial/test.snip +30 -0
  45. data/pristine_app/soups/tutorial/textile_example.snip +11 -0
  46. data/pristine_app/soups/tutorial/tutorial-another-snip.snip +1 -0
  47. data/pristine_app/soups/tutorial/tutorial-basic-snip-inclusion.snip +1 -0
  48. data/pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown +56 -0
  49. data/pristine_app/soups/tutorial/tutorial-layout.snip +56 -0
  50. data/pristine_app/soups/tutorial/tutorial-links.snip +4 -0
  51. data/pristine_app/soups/tutorial/tutorial-renderers.snip.markdown +77 -0
  52. data/pristine_app/soups/tutorial/tutorial.snip.markdown +69 -0
  53. data/pristine_app/soups/tutorial/vanilla-rb.snip +16 -0
  54. data/pristine_app/soups/tutorial/vanilla.snip +8 -0
  55. data/test/dynasnip_test.rb +42 -0
  56. data/test/dynasnips/link_to_current_snip_test.rb +19 -0
  57. data/test/dynasnips/link_to_test.rb +27 -0
  58. data/test/dynasnips/page_title_test.rb +19 -0
  59. data/test/renderers/base_renderer_test.rb +43 -0
  60. data/test/renderers/erb_renderer_test.rb +29 -0
  61. data/test/renderers/haml_renderer_test.rb +35 -0
  62. data/test/renderers/markdown_renderer_test.rb +31 -0
  63. data/test/renderers/raw_renderer_test.rb +23 -0
  64. data/test/renderers/ruby_renderer_test.rb +59 -0
  65. data/test/snip_inclusion_test.rb +56 -0
  66. data/test/snip_reference_parser_test.rb +123 -0
  67. data/test/test_helper.rb +75 -0
  68. data/test/vanilla_app_test.rb +83 -0
  69. data/test/vanilla_presenting_test.rb +125 -0
  70. data/test/vanilla_request_test.rb +87 -0
  71. metadata +179 -78
  72. data/config.example.yml +0 -5
  73. data/config.ru +0 -9
  74. data/lib/defensio.rb +0 -59
  75. data/lib/tasks/vanilla.rake +0 -177
  76. data/lib/vanilla/dynasnips/comments.rb +0 -108
  77. data/lib/vanilla/dynasnips/current_snip.rb +0 -32
  78. data/lib/vanilla/dynasnips/edit.rb +0 -63
  79. data/lib/vanilla/dynasnips/edit_link.rb +0 -24
  80. data/lib/vanilla/dynasnips/index.rb +0 -11
  81. data/lib/vanilla/dynasnips/link_to_current_snip.rb +0 -16
  82. data/lib/vanilla/dynasnips/login.rb +0 -56
  83. data/lib/vanilla/dynasnips/new.rb +0 -14
  84. data/lib/vanilla/dynasnips/notes.rb +0 -42
  85. data/lib/vanilla/dynasnips/url_to.rb +0 -7
  86. data/lib/vanilla/snip_handling.rb +0 -33
  87. data/lib/vanilla/snips/start.rb +0 -27
  88. data/lib/vanilla/snips/system.rb +0 -76
  89. data/lib/vanilla/snips/tutorial.rb +0 -157
  90. data/lib/vanilla/test_snips.rb +0 -85
  91. data/public/hatch.png +0 -0
  92. data/public/javascripts/jquery.js +0 -3549
  93. data/public/javascripts/vanilla.js +0 -21
  94. data/spec/dynasnip_spec.rb +0 -31
  95. data/spec/renderers/base_renderer_spec.rb +0 -40
  96. data/spec/renderers/erb_renderer_spec.rb +0 -27
  97. data/spec/renderers/markdown_renderer_spec.rb +0 -29
  98. data/spec/renderers/raw_renderer_spec.rb +0 -21
  99. data/spec/renderers/ruby_renderer_spec.rb +0 -42
  100. data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +0 -35
  101. data/spec/spec_helper.rb +0 -64
  102. data/spec/vanilla_app_spec.rb +0 -38
  103. data/spec/vanilla_presenting_spec.rb +0 -84
  104. data/spec/vanilla_request_spec.rb +0 -73
  105. data/spec/vanilla_snip_finding_spec.rb +0 -28
@@ -0,0 +1,69 @@
1
+ {tutorial-links}
2
+
3
+ Snips - the basic concept
4
+ ------------
5
+
6
+ Firstly, open the raw contents of this snip - either in your editor (search for `vanilla-rb-tutorial.snip`), or by opening <a href="{current_snip name}.raw">this snip in raw format</a> in a new window or tab. Ready? OK.
7
+
8
+ Every piece of information displayed here is stored as a {link_to snip}. Snips, within their contents, can also reference other snips. When you request a snip, it will render into a page (or another kind of response), and also render any snips that it internally references.
9
+
10
+ For example, consider the snip {link_to tutorial-basic-snip-inclusion}:
11
+
12
+ {raw tutorial-basic-snip-inclusion}
13
+
14
+ When this snip is rendered, it appears like this:
15
+
16
+ > {tutorial-basic-snip-inclusion}
17
+
18
+ Notice the use of curly brackets to reference one snip from inside another. {link_to vanilla-rb} finds these references to snips, then renders that snip and replaces it in the first snip. Neat!
19
+
20
+ Renderers
21
+ --------
22
+
23
+ The way that a snip is rendered depends on whether or not it has an extension, or a `render_as` attribute set. For instance, the extention of this snip is `{current_snip extension}`, and the `render_as` property of `markdown_example` is `Markdown`. Scroll to the bottom of the raw markdown_example snip in your editor, and you'll see this being declared.
24
+
25
+ This means that the `content` of this snip will be passed through `Vanilla::Renderers::Markdown` before it is then rendered to the page. There are several different renders provided by Vanilla.rb at the moment:
26
+
27
+ * Markdown - as described above
28
+ * Textile - which performs similarly for Textile. This means that you can mix how you write the content of snips!
29
+ * Raw - which simply returns the content of the snip, as-is. If you attach a `.raw` extension to this url, you'll see it in action
30
+ * Bold - simply wraps the content in bold. It's a demo, essentially.
31
+ * Erb - passes the snip contents through Ruby's `Erb` library. It also makes some information available for use by ruby code within the snip's contents
32
+ * Ruby - parses the snips content as Ruby itself.
33
+
34
+ You can see a lot of these renderers being exercised in the {link_to test} snip.
35
+
36
+ It's using this last renderer that a second concept of Vanilla is implemented - dynasnips.
37
+
38
+
39
+ Dynasnips
40
+ --------
41
+
42
+ Because the curly braces simply cause a snip to be rendered, we can use this in conjunction with the Ruby renderer to run actual code. For instance, in the snip above:
43
+
44
+ {raw tutorial-basic-snip-inclusion}
45
+
46
+ we can see a reference to the `link_to` snip - <tt>&#123;link\_to snip&#125;</tt>.
47
+
48
+ Lets look at the raw content of `link_to`:
49
+
50
+ {raw link_to}
51
+
52
+ As you can see, it simply refers to the Ruby class `LinkTo`, which is contained within the vanilla-rb codebase. When the Ruby renderer is called, expects the given code to evaulate to a Ruby class. It then instantiates the class, and calls a `handle` method on the instance, passing it any other arguments from the snip inclusion. So, in the case of <tt>&#123;link\_to snip&#125;</tt>, the only argument is `snip`.
53
+
54
+ ### Included Dynasnips
55
+
56
+ Vanilla.rb includes a number of dynasnips by default. Here are a couple:
57
+
58
+ * `link_to`, to produce a link to another snip
59
+ * `raw`, which displays the raw contents of a snip
60
+ * `index`, which shows all of the available snips: {link_to index}
61
+ * ... and several others.
62
+
63
+
64
+ Anyway - that should be enough to get you started.
65
+
66
+ {tutorial-links}
67
+
68
+
69
+ :updated_at: 2011-04-28 16:21:00 +01:00
@@ -0,0 +1,16 @@
1
+ Vanilla.rb is the software powering this site. It's a sort-of wiki/bliki thing, based on {link_to vanilla}.
2
+
3
+ Here's the [introductory blog post][3].
4
+
5
+ It's developed on [github][1], and has a [lighthouse bug tracker][2]. At the moment it's not very well documented, since I'm exploring how the concept might work and the internals are subject to change. However, please do play around with it.
6
+
7
+ Here's the tutorial (helpfully included from {link_to tutorial}).
8
+
9
+ {tutorial}
10
+
11
+
12
+ [1]: http://github.com/lazyatom/vanilla
13
+ [2]: http://lazyatom.lighthouseapp.com/projects/11797-vanilla/tickets
14
+ [3]: http://interblah.net/introducing-vanilla-rb
15
+
16
+ :render_as: Markdown
@@ -0,0 +1,8 @@
1
+ The bliki upon which {link_to vanilla-rb} is based, written by [Christian Langreiter][1]
2
+
3
+ [Official Web HQ][2]
4
+
5
+ [1]: http://www.langreiter.com
6
+ [2]: http://www.vanillasite.at
7
+
8
+ :render_as: Markdown
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+ require 'vanilla/dynasnip'
3
+
4
+ describe Dynasnip do
5
+ context "when storing attributes" do
6
+
7
+ class ::TestDyna < Dynasnip
8
+ attribute :test_attribute, "test attribute content"
9
+ end
10
+
11
+ should "make the attribute available as an instance method" do
12
+ assert_equal "test attribute content", TestDyna.new(@app).test_attribute
13
+ end
14
+
15
+ should "store the attribute in the soup" do
16
+ @app.soup << TestDyna.snip_attributes
17
+ assert_equal "test attribute content", @app.soup['test_dyna'].test_attribute
18
+ end
19
+
20
+ should "allow the attribute to be overriden by the soup contents" do
21
+ @app.soup << TestDyna.snip_attributes
22
+ snip = @app.soup['test_dyna']
23
+ snip.test_attribute = "altered content"
24
+ snip.save
25
+
26
+ assert_equal "altered content", TestDyna.new(@app).test_attribute
27
+ end
28
+ end
29
+
30
+ context "when rendering usage" do
31
+ class ::ShowUsage < Dynasnip
32
+ usage "This is the usage"
33
+ def handle
34
+ usage
35
+ end
36
+ end
37
+
38
+ should "show the usage defined in the snip" do
39
+ assert_equal "This is the usage", ShowUsage.new(@app).handle
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+ $LOAD_PATH.unshift File.expand_path("../../../pristine_app/soups/dynasnips", __FILE__)
3
+ require "link_to_current_snip"
4
+
5
+ context "The link_to_current_snip dynasnip" do
6
+ setup do
7
+ @app.soup << LinkToCurrentSnip.snip_attributes
8
+ create_snip :name => "test", :content => "test {link_to_current_snip}"
9
+ end
10
+
11
+ should "render a link to the snip that was requested" do
12
+ assert_response_body %{test <a href="/test">test</a>}, "/test"
13
+ end
14
+
15
+ should "render a link to the snip that was requested even if it isn't the snip that included the dyna" do
16
+ create_snip :name => "othertest", :content => "othertest {test}"
17
+ assert_response_body %{othertest test <a href="/othertest">othertest</a>}, "/othertest"
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+ $LOAD_PATH.unshift File.expand_path("../../../pristine_app/soups/dynasnips", __FILE__)
3
+ require "link_to"
4
+
5
+ context "The link_to dynasnip" do
6
+ setup do
7
+ create_snip :name => "start", :content => "hello"
8
+ end
9
+
10
+ should "render a link to a snip that exists" do
11
+ assert_equal %{<a href="/start">start</a>}, render_dynasnip(LinkTo, "start")
12
+ end
13
+
14
+ should "allow specification of the link text" do
15
+ assert_equal %{<a href="/start">the start snip</a>}, render_dynasnip(LinkTo, "start", "the start snip")
16
+ end
17
+
18
+ should "mark snips that are missing with a class" do
19
+ assert_equal %{<a class="missing" href="/missing">missing</a>}, render_dynasnip(LinkTo, "missing")
20
+ end
21
+
22
+ private
23
+
24
+ def render_dynasnip(klass, *args)
25
+ klass.new(@app).handle(*args)
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require "test_helper"
2
+ $LOAD_PATH.unshift File.expand_path("../../../pristine_app/soups/dynasnips", __FILE__)
3
+ require "page_title"
4
+
5
+ context "The page_title dynasnip" do
6
+ setup do
7
+ @app.soup << PageTitle.snip_attributes
8
+ end
9
+
10
+ should "render as the requested snip name if that snip has no title" do
11
+ create_snip :name => "test", :content => "{page_title}"
12
+ assert_response_body %{test}, "/test"
13
+ end
14
+
15
+ should "render as the requested snip's page_title when that attribute is present" do
16
+ create_snip :name => "test", :content => "{page_title}", :page_title => "This is a test"
17
+ assert_response_body %{This is a test}, "/test"
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ describe Vanilla::Renderers::Base do
4
+ setup do
5
+ create_snip(:name => "test", :content => "content content", :part => "part content")
6
+ end
7
+
8
+ should "render the contents part of the snip as it is" do
9
+ assert_response_body "content content", "/test"
10
+ end
11
+
12
+ should "render the specified part of the snip" do
13
+ assert_response_body "part content", "/test/part"
14
+ end
15
+
16
+ should "include the contents of a referenced snip" do
17
+ create_snip(:name => "snip_with_inclusions", :content => "loading {test}")
18
+ assert_response_body "loading content content", "/snip_with_inclusions"
19
+ end
20
+
21
+ should "be able to render a snip attribute" do
22
+ create_snip(:name => "snip_with_inclusions", :content => "loading {test.part}")
23
+ assert_response_body "loading part content", "/snip_with_inclusions"
24
+ end
25
+
26
+ should "perform snip inclusion when rendering a part" do
27
+ create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
28
+ assert_response_body "loading content content", "/snip_with_inclusions/part"
29
+ end
30
+
31
+ should "include other snips using their renderers" do
32
+ create_snip(:name => "including_snip", :content => "lets include {another_snip}")
33
+ create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
34
+ assert_equal "lets include <b>blah</b>", response_body_for("/including_snip").gsub(/\s+/, ' ')
35
+ end
36
+
37
+ context "when trying to include a missing snip" do
38
+ should "return a string describing the missing snip" do
39
+ create_snip(:name => 'blah', :content => 'include a {missing_snip}')
40
+ assert_response_body "include a [snip 'missing_snip' cannot be found]", "/blah"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ describe Vanilla::Renderers::Erb do
4
+ context "when rendering" do
5
+ should "insert evaluated Erb content into the snip" do
6
+ erb_snip(:name => "test", :content => "<%= 1 + 2 %>")
7
+ assert_response_body "3", "/test"
8
+ end
9
+
10
+ should "evaluate Erb content in the snip" do
11
+ erb_snip(:name => "test", :content => "<% if false %>monkey<% else %>donkey<% end %>")
12
+ assert_response_body "donkey", "/test"
13
+ end
14
+
15
+ should "expose the snip as an instance variable" do
16
+ erb_snip(:name => "test", :content => "<%= @snip.name %>")
17
+ assert_response_body "test", "/test"
18
+ end
19
+
20
+ should "expose the app as an instance variable" do
21
+ erb_snip(:name => "test", :content => "<%= @app.class.name %>")
22
+ assert_response_body "Vanilla::App", "/test"
23
+ end
24
+ end
25
+
26
+ def erb_snip(params)
27
+ create_snip(params.merge(:render_as => "Erb"))
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'haml'
3
+
4
+ describe Vanilla::Renderers::Haml do
5
+ context "when rendering" do
6
+ should "render Haml into HTML" do
7
+ haml_snip(:name => "test", :content => "#hello\n stuff")
8
+ assert_response_body %{<div id='hello'>\n stuff\n</div>}, "/test"
9
+ end
10
+
11
+ should "insert evaluated Haml content into the snip" do
12
+ haml_snip(:name => "test", :content => "= 1 + 2")
13
+ assert_response_body "3", "/test"
14
+ end
15
+
16
+ should "evaluate Erb content in the snip" do
17
+ haml_snip(:name => "test", :content => "- if false\n monkey\n- else\n donkey")
18
+ assert_response_body "donkey", "/test"
19
+ end
20
+
21
+ should "expose the snip as an instance variable" do
22
+ haml_snip(:name => "test", :content => "= @snip.name")
23
+ assert_response_body "test", "/test"
24
+ end
25
+
26
+ should "expose the app as an instance variable" do
27
+ haml_snip(:name => "test", :content => "= @app.class.name")
28
+ assert_response_body "Vanilla::App", "/test"
29
+ end
30
+ end
31
+
32
+ def haml_snip(params)
33
+ create_snip(params.merge(:render_as => "Haml"))
34
+ end
35
+ end
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,56 @@
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