vanilla 1.0.2 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,21 +0,0 @@
1
- function vanillaPrepareEditor() {
2
- $('input.attribute_name').change(function() {
3
- var dl_children = $('dl.attributes').children();
4
- var dt_index = dl_children.index(this.parentNode) + 1;
5
- var textarea_for_this = dl_children[dt_index].childNodes[0];
6
- textarea_for_this.name = this.value;
7
- });
8
- }
9
-
10
- $(document).ready(function() {
11
-
12
- $('a#add').click(function() {
13
- $('dl.attributes').append('<dt><input class="attribute_name" type="text"></input></dt><dd><textarea></textarea></dd>');
14
- vanillaPrepareEditor();
15
- return false;
16
- });
17
-
18
- vanillaPrepareEditor();
19
-
20
- });
21
-
@@ -1,31 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper")
2
- require 'vanilla/dynasnip'
3
-
4
- describe Dynasnip, "when storing attributes" do
5
- class TestDyna < Dynasnip
6
- attribute :test_attribute, "test attribute content"
7
- end
8
-
9
- before(:each) do
10
- @fake_app = nil
11
- end
12
-
13
- it "should make the attribute available as an instance method" do
14
- TestDyna.new(@fake_app).test_attribute.should == "test attribute content"
15
- end
16
-
17
- it "should store the attribute in the soup" do
18
- TestDyna.persist!
19
- Soup['test_dyna'].test_attribute.should == "test attribute content"
20
- end
21
-
22
- it "should allow the attribute to be overriden by the soup contents" do
23
- TestDyna.persist!
24
- snip = Soup['test_dyna']
25
- snip.test_attribute = "altered content"
26
- snip.save
27
-
28
- TestDyna.new(@fake_app).test_attribute.should == "altered content"
29
- end
30
-
31
- end
@@ -1,40 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe Vanilla::Renderers::Base do
4
- describe "in general" do
5
- before(:each) do
6
- create_snip(:name => "test", :content => "content content", :part => "part content")
7
- end
8
-
9
- it "should render the contents part of the snip as it is" do
10
- response_body_for("/test").should == "content content"
11
- end
12
-
13
- it "should render the specified part of the snip" do
14
- response_body_for("/test/part").should == "part content"
15
- end
16
-
17
- it "should include the contents of a referenced snip" do
18
- create_snip(:name => "snip_with_inclusions", :content => "loading {test}")
19
- response_body_for("/snip_with_inclusions").should == "loading content content"
20
- end
21
-
22
- it "should perform snip inclusion when rendering a part" do
23
- create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
24
- response_body_for("/snip_with_inclusions/part").should == "loading content content"
25
- end
26
-
27
- it "should include other snips using their renderers" do
28
- create_snip(:name => "including_snip", :content => "lets include {another_snip}")
29
- create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
30
- response_body_for("/including_snip").gsub(/\s+/, ' ').should == "lets include <b>blah</b>"
31
- end
32
- end
33
-
34
- describe "when trying to include a missing snip" do
35
- it "should return a string describing the missing snip" do
36
- create_snip(:name => 'blah', :content => 'include a {missing_snip}')
37
- response_body_for("/blah").should == "include a [snip 'missing_snip' cannot be found]"
38
- end
39
- end
40
- end
@@ -1,27 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe Vanilla::Renderers::Erb, "when rendering" do
4
- def erb_snip(params)
5
- create_snip(params.merge(:render_as => "Erb"))
6
- end
7
-
8
- it "should insert evaluated Erb content into the snip" do
9
- erb_snip(:name => "test", :content => "<%= 1 + 2 %>")
10
- response_body_for("/test").should == "3"
11
- end
12
-
13
- it "should evaluate Erb content in the snip" do
14
- erb_snip(:name => "test", :content => "<% if false %>monkey<% else %>donkey<% end %>")
15
- response_body_for("/test").should == "donkey"
16
- end
17
-
18
- it "should expose the snip as an instance variable" do
19
- erb_snip(:name => "test", :content => "<%= @snip.name %>")
20
- response_body_for("/test").should == "test"
21
- end
22
-
23
- it "shoudl expose the app as an instance variable" do
24
- erb_snip(:name => "test", :content => "<%= @app.class.name %>")
25
- response_body_for("/test").should == "Vanilla::App"
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe Vanilla::Renderers::Markdown, "when rendering" do
4
- def markdown_snip(attributes)
5
- create_snip(attributes.merge(:render_as => "Markdown"))
6
- end
7
-
8
- it "should return the snip contents rendered via Markdown" do
9
- content = <<Markdown
10
- # markdown
11
-
12
- * totally
13
- * [rocks](http://www.example.com)!
14
- Markdown
15
- markdown_snip(:name => "test", :content => content)
16
- response_body_for("/test").should == BlueCloth.new(content).to_html
17
- end
18
-
19
- it "should include other snips using their renderers" do
20
- markdown_snip(:name => "test", :content => <<-Markdown
21
- # markdown
22
-
23
- and so lets include {another_snip}
24
- Markdown
25
- )
26
- create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
27
- response_body_for("/test").gsub(/\s+/, ' ').should == "<h1>markdown</h1> <p>and so lets include <b>blah</b> </p>"
28
- end
29
- end
@@ -1,21 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe Vanilla::Renderers::Raw, "when rendering" do
4
- before(:each) do
5
- @snip = create_snip(:name => "test", :content => "raw content", :part => "raw part")
6
- set_main_template "<tag>{current_snip}</tag>"
7
- end
8
-
9
- it "should render the contents part of the snip as it is" do
10
- response_body_for("/test.raw").should == "raw content"
11
- end
12
-
13
- it "should render the specified part of the snip" do
14
- response_body_for("/test/part.raw").should == "raw part"
15
- end
16
-
17
- it "should not perform any snip inclusion" do
18
- create_snip(:name => "snip_with_inclusions", :content => "loading {another_snip}")
19
- response_body_for("/snip_with_inclusions.raw").should == "loading {another_snip}"
20
- end
21
- end
@@ -1,42 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe Vanilla::Renderers::Ruby do
4
- describe "when rendering normally" do
5
- class TestDyna < Dynasnip
6
- def handle(*args)
7
- 'handle called'
8
- end
9
- end
10
-
11
- before(:each) do
12
- @test_dyna = TestDyna.persist!
13
- end
14
-
15
- it "should render the result of the handle method" do
16
- Vanilla::Test.response_body_for("/test_dyna").should == 'handle called'
17
- end
18
- end
19
-
20
- describe "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
- before(:each) do
31
- @dyna = RestishDyna.persist!
32
- end
33
-
34
- it "should render the result of the get method on GET requests" do
35
- Vanilla::Test.response_body_for("/restish_dyna").should == 'get called'
36
- end
37
-
38
- it "should render the result of the post method on POST requests" do
39
- Vanilla::Test.response_body_for("/restish_dyna?_method=post") == 'post called'
40
- end
41
- end
42
- end
@@ -1,35 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "spec_helper")
2
-
3
- describe "when detecting the snip renderer" do
4
- before(:each) do
5
- @app = Vanilla::App.new
6
- end
7
-
8
- it "should return the constant refered to in the render_as property of the snip" do
9
- snip = create_snip(:render_as => "Raw")
10
- @app.renderer_for(snip).should == Vanilla::Renderers::Raw
11
- end
12
-
13
- it "should return Vanilla::Renderers::Base if no render_as property exists" do
14
- snip = create_snip(:name => "blah")
15
- @app.renderer_for(snip).should == Vanilla::Renderers::Base
16
- end
17
-
18
- it "should return Vanilla::Renderers::Base if the render_as property is blank" do
19
- snip = create_snip(:name => "blah", :render_as => '')
20
- @app.renderer_for(snip).should == Vanilla::Renderers::Base
21
- end
22
-
23
- it "should raise an error if the specified renderer doesn't exist" do
24
- snip = create_snip(:render_as => "NonExistentClass")
25
- lambda { @app.renderer_for(snip) }.should raise_error
26
- end
27
-
28
- it "should load constants outside of the Vanilla::Renderers module" do
29
- class ::MyRenderer
30
- end
31
-
32
- snip = create_snip(:render_as => "MyRenderer")
33
- @app.renderer_for(snip).should == MyRenderer
34
- end
35
- end
@@ -1,64 +0,0 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
- require "vanilla"
3
- require "spec"
4
- require "fileutils"
5
- require "rack/mock"
6
-
7
- module Vanilla
8
- module Test
9
- def setup_clean_environment
10
- test_soup_config = { :database => File.join(File.dirname(__FILE__), "soup_test.db")}
11
- FileUtils.rm(test_soup_config[:database]) if File.exist?(test_soup_config[:database])
12
- Soup.base = test_soup_config
13
-
14
- # TODO: this is hard-coded for the AR implementation
15
- require "active_record"
16
- ActiveRecord::Migration.verbose = false
17
-
18
- Soup.prepare
19
- require "vanilla/dynasnips/current_snip"
20
- CurrentSnip.persist!
21
- create_snip :name => "system", :main_template => "{current_snip}"
22
- end
23
-
24
- def response_for(url)
25
- Vanilla::App.new.call(mock_env_for_url(url))
26
- end
27
-
28
- def response_body_for(url)
29
- response_for(url)[2].body[0]
30
- end
31
-
32
- def response_code_for(url)
33
- response_for(url)[0]
34
- end
35
-
36
- def set_main_template(template_content)
37
- system = Vanilla.snip("system") || Snip.new(:name => "system")
38
- system.main_template = template_content
39
- system.save
40
- end
41
-
42
- def create_snip(params)
43
- s = Snip.new(params)
44
- s.save
45
- s
46
- end
47
-
48
- def mock_env_for_url(url)
49
- Rack::MockRequest.env_for(url)
50
- end
51
-
52
- def mock_request(url)
53
- Rack::Request.new(mock_env_for_url(url))
54
- end
55
-
56
- extend self
57
- end
58
- end
59
-
60
- Spec::Runner.configure do |config|
61
- config.include(Vanilla::Test)
62
- config.before { Vanilla::Test.setup_clean_environment }
63
- end
64
-
@@ -1,38 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'spec_helper')
2
-
3
- describe Vanilla::App do
4
- describe "when behaving as a Rack application" do
5
- it "should return an array of status code, headers and response" do
6
- create_snip(:name => "test", :content => "content")
7
- result = Vanilla::App.new.call(mock_env_for_url("/test.text"))
8
- result.should be_a_kind_of(Array)
9
- result[0].should == 200
10
- result[1].should be_a_kind_of(Hash)
11
- result[2].each{ |output| output.should == "content" }
12
- end
13
- end
14
-
15
- describe "when being configured" do
16
- it "should load a config file from the current working directory by default" do
17
- File.should_receive(:open).with("config.yml").and_return(StringIO.new({}.to_yaml))
18
- Vanilla::App.new
19
- end
20
-
21
- it "should load a config file given" do
22
- File.open("/tmp/vanilla_config.yml", "w") { |f| f.write({:hello => true}.to_yaml) }
23
- app = Vanilla::App.new("/tmp/vanilla_config.yml")
24
- app.config[:hello].should be_true
25
- end
26
-
27
- it "should allow saving of configuration to the same file it was loaded from" do
28
- config_file = "/tmp/vanilla_config.yml"
29
- File.open(config_file, "w") { |f| f.write({:hello => true}.to_yaml) }
30
- app = Vanilla::App.new(config_file)
31
- app.config[:saved] = true
32
- app.config.save!
33
-
34
- config = YAML.load(File.open(config_file))
35
- config[:saved].should be_true
36
- end
37
- end
38
- end
@@ -1,84 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "spec_helper")
2
-
3
- describe Vanilla::App do
4
- before(:each) do
5
- LinkTo.persist!
6
- set_main_template "<tag>{current_snip}</tag>"
7
- create_snip :name => "test", :content => "blah {other_snip}", :part => 'part content'
8
- create_snip :name => "other_snip", :content => "blah!"
9
- end
10
-
11
- describe "when presenting as HTML" do
12
- it "should render the snip's content in the system template if no format or part is given" do
13
- response_body_for("/test").should == "<tag>blah blah!</tag>"
14
- end
15
-
16
- it "should render the snip's content in the system template if the HTML format is given" do
17
- response_body_for("/test.html").should == "<tag>blah blah!</tag>"
18
- end
19
-
20
- it "should render the requested part within the main template when a part is given" do
21
- response_body_for("/test/part").should == "<tag>part content</tag>"
22
- end
23
-
24
- it "should have a response code of 200" do
25
- response_code_for("/test").should == 200
26
- response_code_for("/test.html").should == 200
27
- response_code_for("/test/part").should == 200
28
- response_code_for("/test/part.html").should == 200
29
- end
30
- end
31
-
32
- describe "when presenting content as text" do
33
- it "should render the snip's content outside of the main template with its default renderer" do
34
- response_body_for("/test.text").should == "blah blah!"
35
- end
36
-
37
- it "should render the snip part outside the main template when a format is given" do
38
- response_body_for("/test/part.text").should == "part content"
39
- end
40
-
41
- it "should have a response code of 200" do
42
- response_code_for("/test.text").should == 200
43
- response_code_for("/test/part.text").should == 200
44
- end
45
- end
46
-
47
-
48
- describe "when presenting raw content" do
49
- it "should render the snips contents exactly as they are" do
50
- response_body_for("/test.raw").should == "blah {other_snip}"
51
- end
52
-
53
- it "should render the snip content exactly even if a render_as attribute exists" do
54
- response_body_for("/current_snip.raw").should == "CurrentSnip"
55
- end
56
-
57
- it "should render a snips part if requested" do
58
- response_body_for("/test/part.raw").should == "part content"
59
- end
60
-
61
- it "should have a response code of 200" do
62
- response_code_for("/test.raw").should == 200
63
- response_code_for("/test/part.raw").should == 200
64
- end
65
- end
66
-
67
-
68
- describe "when a missing snip is requested" do
69
- it "should render missing snip content in the main template" do
70
- response_body_for("/missing_snip").should == "<tag>Couldn't find snip #{LinkTo.new(nil).handle("missing_snip")}</tag>"
71
- end
72
-
73
- it "should have a 404 response code" do
74
- response_code_for("/missing_snip").should == 404
75
- end
76
- end
77
-
78
-
79
- describe "when requesting an unknown format" do
80
- it "should return a 500 status code" do
81
- response_code_for("/test.monkey").should == 500
82
- end
83
- end
84
- end