vanilla 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/README +52 -0
  2. data/Rakefile +118 -0
  3. data/bin/vanilla +9 -0
  4. data/config.example.yml +5 -0
  5. data/config.ru +9 -0
  6. data/lib/defensio.rb +59 -0
  7. data/lib/tasks/vanilla.rake +178 -0
  8. data/lib/vanilla/app.rb +87 -0
  9. data/lib/vanilla/console.rb +3 -0
  10. data/lib/vanilla/dynasnip.rb +110 -0
  11. data/lib/vanilla/dynasnips/comments.rb +108 -0
  12. data/lib/vanilla/dynasnips/current_snip.rb +32 -0
  13. data/lib/vanilla/dynasnips/debug.rb +13 -0
  14. data/lib/vanilla/dynasnips/edit.rb +63 -0
  15. data/lib/vanilla/dynasnips/edit_link.rb +24 -0
  16. data/lib/vanilla/dynasnips/index.rb +11 -0
  17. data/lib/vanilla/dynasnips/kind.rb +70 -0
  18. data/lib/vanilla/dynasnips/link_to.rb +14 -0
  19. data/lib/vanilla/dynasnips/link_to_current_snip.rb +16 -0
  20. data/lib/vanilla/dynasnips/login.rb +56 -0
  21. data/lib/vanilla/dynasnips/new.rb +14 -0
  22. data/lib/vanilla/dynasnips/notes.rb +42 -0
  23. data/lib/vanilla/dynasnips/pre.rb +19 -0
  24. data/lib/vanilla/dynasnips/rand.rb +27 -0
  25. data/lib/vanilla/dynasnips/raw.rb +19 -0
  26. data/lib/vanilla/dynasnips/url_to.rb +7 -0
  27. data/lib/vanilla/renderers/base.rb +78 -0
  28. data/lib/vanilla/renderers/bold.rb +9 -0
  29. data/lib/vanilla/renderers/erb.rb +16 -0
  30. data/lib/vanilla/renderers/markdown.rb +13 -0
  31. data/lib/vanilla/renderers/raw.rb +9 -0
  32. data/lib/vanilla/renderers/ruby.rb +35 -0
  33. data/lib/vanilla/renderers/textile.rb +13 -0
  34. data/lib/vanilla/request.rb +68 -0
  35. data/lib/vanilla/routes.rb +29 -0
  36. data/lib/vanilla/snip_handling.rb +33 -0
  37. data/lib/vanilla/snips/start.rb +18 -0
  38. data/lib/vanilla/snips/system.rb +76 -0
  39. data/lib/vanilla/snips/tutorial.rb +158 -0
  40. data/lib/vanilla/test_snips.rb +85 -0
  41. data/lib/vanilla.rb +20 -0
  42. data/spec/dynasnip_spec.rb +31 -0
  43. data/spec/renderers/base_renderer_spec.rb +40 -0
  44. data/spec/renderers/erb_renderer_spec.rb +27 -0
  45. data/spec/renderers/markdown_renderer_spec.rb +29 -0
  46. data/spec/renderers/raw_renderer_spec.rb +21 -0
  47. data/spec/renderers/ruby_renderer_spec.rb +42 -0
  48. data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +35 -0
  49. data/spec/soup_test.db +0 -0
  50. data/spec/spec_helper.rb +64 -0
  51. data/spec/vanilla_app_spec.rb +38 -0
  52. data/spec/vanilla_presenting_spec.rb +84 -0
  53. data/spec/vanilla_request_spec.rb +73 -0
  54. data/spec/vanilla_snip_finding_spec.rb +28 -0
  55. metadata +122 -0
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,35 @@
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
data/spec/soup_test.db ADDED
Binary file
@@ -0,0 +1,64 @@
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
+
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,84 @@
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
@@ -0,0 +1,73 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Vanilla::Request, "when requesting urls" do
4
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip")) }
5
+
6
+ it "should use the first segement as the snip name" do
7
+ @request.snip_name.should == "snip"
8
+ end
9
+
10
+ it "should try to load the snip based on the snip name" do
11
+ Vanilla.should_receive(:snip).with('snip').and_return(:snip)
12
+ @request.snip.should == :snip
13
+ end
14
+
15
+ it "should have no part if the url contains only a single segment" do
16
+ @request.part.should == nil
17
+ end
18
+
19
+ it "should have a default format of html" do
20
+ @request.format.should == 'html'
21
+ end
22
+
23
+ it "should determine the request method" do
24
+ @request.method.should == 'get'
25
+ end
26
+ end
27
+
28
+ describe Vanilla::Request, "when requesting a snip part" do
29
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part")) }
30
+
31
+ it "should use the first segment as the snip, and the second segment as the part" do
32
+ @request.snip_name.should == "snip"
33
+ @request.part.should == "part"
34
+ end
35
+
36
+ it "should have a default format of html" do
37
+ @request.format.should == "html"
38
+ end
39
+ end
40
+
41
+ describe Vanilla::Request, "when requesting a snip with a format" do
42
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw")) }
43
+
44
+ it "should use the extension as the format" do
45
+ @request.format.should == "raw"
46
+ end
47
+
48
+ it "should retain the filename part of the path as the snip" do
49
+ @request.snip_name.should == "snip"
50
+ end
51
+ end
52
+
53
+ describe Vanilla::Request, "when requesting a snip part with a format" do
54
+ before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw")) }
55
+
56
+ it "should use the extension as the format" do
57
+ @request.format.should == "raw"
58
+ end
59
+
60
+ it "should retain the first segment of the path as the snip" do
61
+ @request.snip_name.should == "snip"
62
+ end
63
+
64
+ it "should use the filename part of the second segment as the snip part" do
65
+ @request.part.should == "part"
66
+ end
67
+ end
68
+
69
+ describe Vanilla::Request, "when requested with a _method paramter" do
70
+ it "should return the method using the parameter" do
71
+ Vanilla::Request.new(mock_env_for_url("/snip?_method=put")).method.should == 'put'
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Vanilla, "when loading a snip" do
4
+ it "should delegate to Soup" do
5
+ snip = :snip
6
+ Soup.should_receive(:[]).with('name').and_return(snip)
7
+ Vanilla.snip('name').should == :snip
8
+ end
9
+
10
+ it "should return nil if the snip cannot be found" do
11
+ Vanilla.snip('missing').should be_nil
12
+ end
13
+
14
+ it "should raise an exception if the snip cannot be when calling snip!" do
15
+ lambda { Vanilla.snip!('missing') }.should raise_error(Vanilla::MissingSnipException)
16
+ end
17
+ end
18
+
19
+ describe Vanilla, "when checking a snip exists" do
20
+ it "should return true if the snip exists" do
21
+ create_snip(:name => 'blah')
22
+ Vanilla.snip_exists?('blah').should be_true
23
+ end
24
+
25
+ it "should return false if the snip does not exist" do
26
+ Vanilla.snip_exists?('missing').should be_false
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vanilla
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Adam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-09 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: james@lazyatom.com.com
27
+ executables:
28
+ - vanilla
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README
33
+ files:
34
+ - config.example.yml
35
+ - config.ru
36
+ - Rakefile
37
+ - README
38
+ - spec/dynasnip_spec.rb
39
+ - spec/renderers
40
+ - spec/renderers/base_renderer_spec.rb
41
+ - spec/renderers/erb_renderer_spec.rb
42
+ - spec/renderers/markdown_renderer_spec.rb
43
+ - spec/renderers/raw_renderer_spec.rb
44
+ - spec/renderers/ruby_renderer_spec.rb
45
+ - spec/renderers/vanilla_app_detecting_renderer_spec.rb
46
+ - spec/soup_test.db
47
+ - spec/spec_helper.rb
48
+ - spec/vanilla_app_spec.rb
49
+ - spec/vanilla_presenting_spec.rb
50
+ - spec/vanilla_request_spec.rb
51
+ - spec/vanilla_snip_finding_spec.rb
52
+ - lib/defensio.rb
53
+ - lib/tasks
54
+ - lib/tasks/vanilla.rake
55
+ - lib/vanilla
56
+ - lib/vanilla/app.rb
57
+ - lib/vanilla/console.rb
58
+ - lib/vanilla/dynasnip.rb
59
+ - lib/vanilla/dynasnips
60
+ - lib/vanilla/dynasnips/comments.rb
61
+ - lib/vanilla/dynasnips/current_snip.rb
62
+ - lib/vanilla/dynasnips/debug.rb
63
+ - lib/vanilla/dynasnips/edit.rb
64
+ - lib/vanilla/dynasnips/edit_link.rb
65
+ - lib/vanilla/dynasnips/index.rb
66
+ - lib/vanilla/dynasnips/kind.rb
67
+ - lib/vanilla/dynasnips/link_to.rb
68
+ - lib/vanilla/dynasnips/link_to_current_snip.rb
69
+ - lib/vanilla/dynasnips/login.rb
70
+ - lib/vanilla/dynasnips/new.rb
71
+ - lib/vanilla/dynasnips/notes.rb
72
+ - lib/vanilla/dynasnips/pre.rb
73
+ - lib/vanilla/dynasnips/rand.rb
74
+ - lib/vanilla/dynasnips/raw.rb
75
+ - lib/vanilla/dynasnips/url_to.rb
76
+ - lib/vanilla/renderers
77
+ - lib/vanilla/renderers/base.rb
78
+ - lib/vanilla/renderers/bold.rb
79
+ - lib/vanilla/renderers/erb.rb
80
+ - lib/vanilla/renderers/markdown.rb
81
+ - lib/vanilla/renderers/raw.rb
82
+ - lib/vanilla/renderers/ruby.rb
83
+ - lib/vanilla/renderers/textile.rb
84
+ - lib/vanilla/request.rb
85
+ - lib/vanilla/routes.rb
86
+ - lib/vanilla/snip_handling.rb
87
+ - lib/vanilla/snips
88
+ - lib/vanilla/snips/start.rb
89
+ - lib/vanilla/snips/system.rb
90
+ - lib/vanilla/snips/tutorial.rb
91
+ - lib/vanilla/test_snips.rb
92
+ - lib/vanilla.rb
93
+ - bin/vanilla
94
+ has_rdoc: true
95
+ homepage: http://github.com/lazyatom/vanilla-rb
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --main
99
+ - README
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: "0"
113
+ version:
114
+ requirements: []
115
+
116
+ rubyforge_project: vanilla
117
+ rubygems_version: 1.3.1
118
+ signing_key:
119
+ specification_version: 2
120
+ summary: A bliki-type web content thing.
121
+ test_files: []
122
+