vanilla 1.16.2 → 1.17

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -36,10 +36,9 @@ if Object.const_defined?(:Gem)
36
36
  s.rdoc_options = %w(--main README)
37
37
 
38
38
  # Add any extra files to include in the gem
39
- s.files = %w(Rakefile README .gemtest) + Dir.glob("{lib,bin,pristine_app}/**/*")
39
+ s.files = %w(Rakefile README .gemtest) + Dir.glob("{test,lib,bin,pristine_app}/**/*")
40
40
  s.executables = ['vanilla']
41
41
  s.require_paths = ["lib"]
42
- s.test_files = Dir.glob("test/**/*")
43
42
 
44
43
  # All the other gems we need.
45
44
  s.add_dependency("rack", ">= 0.9.1")
@@ -47,8 +46,9 @@ if Object.const_defined?(:Gem)
47
46
  s.add_dependency("ratom", ">= 0.3.5")
48
47
  s.add_dependency("RedCloth", ">= 4.1.1")
49
48
  s.add_dependency("BlueCloth", ">= 1.0.0")
50
- s.add_dependency("haml")
49
+ s.add_dependency("haml", ">=3.1")
51
50
  s.add_dependency("parslet", ">= 1.2.0")
51
+ s.add_dependency("rack-test", ">=0.5.7")
52
52
 
53
53
  s.add_development_dependency("kintama", ">= 0.1.6") # add any other gems for testing/development
54
54
  s.add_development_dependency("mocha")
data/bin/vanilla CHANGED
@@ -14,13 +14,19 @@ end
14
14
 
15
15
  def upgrade
16
16
  require 'fileutils'
17
- confirm("Upgrade system snips?") do
18
- pristine_system = File.expand_path("../../pristine_app/soups/system", __FILE__)
19
- copy(pristine_system, File.join(Dir.pwd, "soups"))
20
- end
21
- confirm("Upgrade tutorial snips?") do
22
- pristine_system = File.expand_path("../../pristine_app/soups/tutorial", __FILE__)
23
- copy(pristine_system, File.join(Dir.pwd, "soups"))
17
+ soups_directory = File.join(Dir.pwd, "soups")
18
+ if File.directory(soups_directory)
19
+ confirm("Upgrade system snips?") do
20
+ pristine_system = File.expand_path("../../pristine_app/soups/system", __FILE__)
21
+ copy(pristine_system, system_directory)
22
+ end
23
+ confirm("Upgrade tutorial snips?") do
24
+ pristine_system = File.expand_path("../../pristine_app/soups/tutorial", __FILE__)
25
+ copy(pristine_system, File.join(Dir.pwd, "soups"))
26
+ end
27
+ else
28
+ puts "Your soups must be in a directory called 'soups' to use this upgrade tool."
29
+ exit -1
24
30
  end
25
31
  end
26
32
 
data/lib/vanilla.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Vanilla
2
- VERSION = "1.16.2"
2
+ VERSION = "1.17"
3
3
 
4
4
  autoload :Renderers, "vanilla/renderers"
5
5
  autoload :App, "vanilla/app"
@@ -8,6 +8,7 @@ module Vanilla
8
8
  autoload :Routes, "vanilla/routes"
9
9
  autoload :Static, "vanilla/static"
10
10
  autoload :SnipReferenceParser, "vanilla/snip_reference_parser"
11
+ autoload :TestHelper, "vanilla/test_helper"
11
12
  end
12
13
 
13
14
  # Load all the base dynasnip classes
data/lib/vanilla/app.rb CHANGED
@@ -1,16 +1,45 @@
1
1
  require 'soup'
2
+ require 'ostruct'
2
3
 
3
4
  module Vanilla
4
5
  class App
5
6
  include Vanilla::Routes
6
7
 
8
+ class << self
9
+ attr_reader :config
10
+ def configure(&block)
11
+ reset! unless @config
12
+ yield @config
13
+ self
14
+ end
15
+ def reset!
16
+ @config = OpenStruct.new
17
+ end
18
+ end
19
+
7
20
  attr_reader :request, :response, :config, :soup
8
21
 
22
+ def class_config
23
+ if self.class.config
24
+ {:soup => self.class.config.soup,
25
+ :soups => self.class.config.soups,
26
+ :root => self.class.config.root,
27
+ :root_snip => self.class.config.root_snip,
28
+ :renderers => self.class.config.renderers,
29
+ :default_layout_snip => self.class.config.default_layout_snip,
30
+ :default_renderer => self.class.config.default_renderer}
31
+ else
32
+ {}
33
+ end
34
+ end
35
+
9
36
  # Create a new Vanilla application
10
37
  # Configuration options:
11
38
  #
12
39
  # :soup - provide the path to the soup data
13
40
  # :soups - provide an array of paths to soup data
41
+ # :root - the directory that the soup paths are relative to;
42
+ # defaults to Dir.pwd
14
43
  # :renderers - a hash of names to classes
15
44
  # :default_renderer - the class to use when no renderer is provided;
16
45
  # defaults to 'Vanilla::Renderers::Base'
@@ -18,10 +47,11 @@ module Vanilla
18
47
  # defaults to 'layout'
19
48
  # :root_snip - the snip to load for the root ('/') url;
20
49
  # defaults to 'start'
21
- def initialize(config={})
22
- @config = config
50
+ def initialize(additional_configuration={})
51
+ @config = class_config.merge(additional_configuration)
52
+ @root_directory = @config[:root] || Dir.pwd
23
53
  if @config[:soup].nil? && @config[:soups].nil?
24
- @config.merge!(:soup => File.expand_path("soup"))
54
+ @config[:soup] = File.expand_path("soup", @root_directory)
25
55
  end
26
56
  @soup = prepare_soup(config)
27
57
  prepare_renderers(config[:renderers])
@@ -110,7 +140,7 @@ module Vanilla
110
140
  private
111
141
 
112
142
  def prepare_renderers(additional_renderers={})
113
- @renderers = Hash.new(config[:default_renderer] || Vanilla::Renderers::Base)
143
+ @renderers = Hash.new { config[:default_renderer] || Vanilla::Renderers::Base }
114
144
  @renderers.merge!({
115
145
  "base" => Vanilla::Renderers::Base,
116
146
  "markdown" => Vanilla::Renderers::Markdown,
@@ -145,10 +175,12 @@ module Vanilla
145
175
 
146
176
  def prepare_soup(config)
147
177
  if config[:soups]
148
- backends = [config[:soups]].flatten.map { |path| ::Soup::Backends::FileBackend.new(path) }
178
+ backends = [config[:soups]].flatten.map do |path|
179
+ ::Soup::Backends::FileBackend.new(File.expand_path(path, @root_directory))
180
+ end
149
181
  ::Soup.new(::Soup::Backends::MultiSoup.new(*backends))
150
182
  else
151
- ::Soup.new(::Soup::Backends::FileBackend.new(config[:soup]))
183
+ ::Soup.new(::Soup::Backends::FileBackend.new(File.expand_path(config[:soup], @root_directory)))
152
184
  end
153
185
  end
154
186
  end
@@ -1,23 +1,12 @@
1
- require 'vanilla'
2
-
3
- module Vanilla
4
- class RackShim
5
- def run(app)
6
- app # return it
7
- end
8
- def use(*args)
9
- # ignore
10
- end
11
- def get_binding
12
- binding
13
- end
14
- end
1
+ unless File.exist?("application.rb")
2
+ puts "Your application must reside in application.rb to use this console"
3
+ exit -1
15
4
  end
16
5
 
17
6
  def app(reload=false)
18
7
  if !@__vanilla_console_app || reload
19
- shim_binding = Vanilla::RackShim.new.get_binding
20
- @__vanilla_console_app = eval File.read("config.ru"), shim_binding
8
+ load "application.rb"
9
+ @__vanilla_console_app = Application.new
21
10
  end
22
11
  @__vanilla_console_app
23
12
  end
@@ -0,0 +1,55 @@
1
+ require "vanilla"
2
+ require "rack/test"
3
+ require "tmpdir"
4
+ require "fileutils"
5
+
6
+ module Vanilla
7
+ module TestHelper
8
+ include Rack::Test::Methods
9
+
10
+ def app
11
+ unless @__app
12
+ Application.configure do |config|
13
+ # inject a sandbox soup path first.
14
+ config.soups ||= []
15
+ config.soups.unshift test_soup_path
16
+ # Ensure that the root path is set; this helps with
17
+ # running tests from different directories
18
+ config.root_path = File.expand_path("../.", __FILE__)
19
+ end
20
+ @__app = Application.new
21
+ end
22
+ @__app
23
+ end
24
+
25
+ def vanilla_setup
26
+ FileUtils.mkdir_p(test_soup_path)
27
+ end
28
+
29
+ def assert_response_status(expected, uri)
30
+ get uri
31
+ assert_equal expected, last_response.status
32
+ end
33
+
34
+ def assert_response_body(expected, uri)
35
+ get uri
36
+ assert_equal expected.strip, last_response.body.strip
37
+ end
38
+
39
+ def set_main_template(template_content)
40
+ app.soup << {:name => "layout", :content => template_content}
41
+ end
42
+
43
+ def create_snip(params)
44
+ app.soup << params
45
+ end
46
+
47
+ def test_soup_path
48
+ File.expand_path(File.join(Dir.tmpdir, "soup"))
49
+ end
50
+
51
+ def vanilla_teardown
52
+ FileUtils.rm_rf(test_soup_path)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'vanilla'
5
+
6
+ # This is your application subclass.
7
+ class Application < Vanilla::App
8
+ end
9
+
10
+ Application.configure do |config|
11
+ # The root directory of the application; normally the directory this
12
+ # file is in.
13
+ config.root_path = File.expand_path(__FILE__)
14
+
15
+ # You can partition your snips into subdirectories to keep things tidy.
16
+ # This doesn't affect their URL structure on the site (everything is
17
+ # flat).
18
+ #
19
+ # You should ensure that the system soup is at the bottom of this list
20
+ # unless you really know what you are doing.
21
+ config.soups = [
22
+ "soups/base",
23
+ "soups/system"
24
+ ]
25
+
26
+ # If you don't want the tutorial on your site, remove this and delete the directory
27
+ config.soups << "soups/tutorial"
28
+
29
+ # This is a dumping ground of ideas at the moment
30
+ #
31
+ # config.soups << "soups/extras"
32
+
33
+ # The snip to render on requests to "/". This defaults to "start"
34
+ #
35
+ # config.root_snip = "some-other-snip"
36
+
37
+ # You can register additional renderer classes, to be used with snips
38
+ # with the given extensions or 'render_as' attributes
39
+ #
40
+ # config.renderers = {
41
+ # :awesome => "My::Custom::RendererClass"
42
+ # }
43
+ end
@@ -1,26 +1,6 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- $:.unshift File.join(File.dirname(__FILE__), *%w[lib])
4
-
5
- require 'vanilla'
6
-
7
- # You can partition your snips into subdirectories to keep things tidy. This
8
- # doesn't affect their URL structure on the site (everything is flat).
9
- soups = [
10
- "soups/base",
11
- "soups/system"
12
- ]
13
-
14
- # If you don't want the tutorial on your site, remove this and delete the directory
15
- soups << "soups/tutorial"
16
-
17
- # This is a dumping ground of ideas at the moment
18
- # soups << "soups/extras"
19
-
20
- app = Vanilla::App.new(:soups => soups)
21
-
22
- # If you running your site under a proper webserver, you probably don't need this.
1
+ # If you're running your site under a proper webserver, you probably don't need this.
23
2
  require 'vanilla/static'
24
3
  use Vanilla::Static, File.join(File.dirname(__FILE__), 'public')
25
4
 
26
- run app
5
+ require "application"
6
+ run Application.new
@@ -9,21 +9,21 @@ describe Dynasnip do
9
9
  end
10
10
 
11
11
  should "make the attribute available as an instance method" do
12
- assert_equal "test attribute content", TestDyna.new(@app).test_attribute
12
+ assert_equal "test attribute content", TestDyna.new(app).test_attribute
13
13
  end
14
14
 
15
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
16
+ app.soup << TestDyna.snip_attributes
17
+ assert_equal "test attribute content", app.soup['test_dyna'].test_attribute
18
18
  end
19
19
 
20
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']
21
+ app.soup << TestDyna.snip_attributes
22
+ snip = app.soup['test_dyna']
23
23
  snip.test_attribute = "altered content"
24
24
  snip.save
25
25
 
26
- assert_equal "altered content", TestDyna.new(@app).test_attribute
26
+ assert_equal "altered content", TestDyna.new(app).test_attribute
27
27
  end
28
28
  end
29
29
 
@@ -36,7 +36,7 @@ describe Dynasnip do
36
36
  end
37
37
 
38
38
  should "show the usage defined in the snip" do
39
- assert_equal "This is the usage", ShowUsage.new(@app).handle
39
+ assert_equal "This is the usage", ShowUsage.new(app).handle
40
40
  end
41
41
  end
42
42
  end
@@ -4,7 +4,7 @@ require "link_to_current_snip"
4
4
 
5
5
  context "The link_to_current_snip dynasnip" do
6
6
  setup do
7
- @app.soup << LinkToCurrentSnip.snip_attributes
7
+ app.soup << LinkToCurrentSnip.snip_attributes
8
8
  create_snip :name => "test", :content => "test {link_to_current_snip}"
9
9
  end
10
10
 
@@ -22,6 +22,6 @@ context "The link_to dynasnip" do
22
22
  private
23
23
 
24
24
  def render_dynasnip(klass, *args)
25
- klass.new(@app).handle(*args)
25
+ klass.new(app).handle(*args)
26
26
  end
27
27
  end
@@ -4,7 +4,7 @@ require "page_title"
4
4
 
5
5
  context "The page_title dynasnip" do
6
6
  setup do
7
- @app.soup << PageTitle.snip_attributes
7
+ app.soup << PageTitle.snip_attributes
8
8
  end
9
9
 
10
10
  should "render as the requested snip name if that snip has no title" do
@@ -31,7 +31,7 @@ describe Vanilla::Renderers::Base do
31
31
  should "include other snips using their renderers" do
32
32
  create_snip(:name => "including_snip", :content => "lets include {another_snip}")
33
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+/, ' ')
34
+ assert_response_body "lets include <b>blah</b>", "/including_snip"
35
35
  end
36
36
 
37
37
  context "when trying to include a missing snip" do
@@ -18,7 +18,7 @@ describe Vanilla::Renderers::Erb do
18
18
  end
19
19
 
20
20
  should "expose the app as an instance variable" do
21
- erb_snip(:name => "test", :content => "<%= @app.class.name %>")
21
+ erb_snip(:name => "test", :content => "<%= @app.class.superclass.name %>")
22
22
  assert_response_body "Vanilla::App", "/test"
23
23
  end
24
24
  end
@@ -24,7 +24,7 @@ describe Vanilla::Renderers::Haml do
24
24
  end
25
25
 
26
26
  should "expose the app as an instance variable" do
27
- haml_snip(:name => "test", :content => "= @app.class.name")
27
+ haml_snip(:name => "test", :content => "= @app.class.superclass.name")
28
28
  assert_response_body "Vanilla::App", "/test"
29
29
  end
30
30
  end
@@ -21,7 +21,7 @@ and so lets include {another_snip}
21
21
  Markdown
22
22
  )
23
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+/, ' ')
24
+ assert_response_body "<h1>markdown</h1>\n\n<p>and so lets include <b>blah</b></p>", "/test"
25
25
  end
26
26
  end
27
27
 
@@ -1,4 +1,5 @@
1
1
  require "test_helper"
2
+ require "vanilla/dynasnip"
2
3
 
3
4
  describe Vanilla::Renderers::Ruby do
4
5
  context "when rendering normally" do
@@ -9,7 +10,7 @@ describe Vanilla::Renderers::Ruby do
9
10
  end
10
11
 
11
12
  setup do
12
- @app.soup << TestDyna.snip_attributes
13
+ app.soup << TestDyna.snip_attributes
13
14
  end
14
15
 
15
16
  should "render the result of the handle method" do
@@ -28,7 +29,7 @@ describe Vanilla::Renderers::Ruby do
28
29
  end
29
30
 
30
31
  setup do
31
- @app.soup << RestishDyna.snip_attributes
32
+ app.soup << RestishDyna.snip_attributes
32
33
  end
33
34
 
34
35
  should "render the result of the get method on GET requests" do
@@ -48,7 +49,7 @@ describe Vanilla::Renderers::Ruby do
48
49
  end
49
50
 
50
51
  setup do
51
- @app.soup << Encloser.snip_attributes
52
+ app.soup << Encloser.snip_attributes
52
53
  create_snip(:name => "test", :content => "{encloser}")
53
54
  end
54
55
 
@@ -61,6 +61,6 @@ context "When including snips in other snips" do
61
61
 
62
62
  def render(content)
63
63
  snip = create_snip :name => "test-content", :content => content
64
- Vanilla::Renderers::Base.new(@app).render(snip)
64
+ Vanilla::Renderers::Base.new(app).render(snip)
65
65
  end
66
66
  end
data/test/test_helper.rb CHANGED
@@ -1,71 +1,28 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../lib"), __FILE__)
1
2
  require "kintama"
2
3
  require "kintama/mocha"
3
- require "fileutils"
4
- require "rack/mock"
5
- require "vanilla"
4
+ require "vanilla/test_helper"
6
5
 
7
- module Vanilla
8
- module Test
9
- def setup_clean_environment
10
- clean_environment
11
- @app = Vanilla::App.new(:soup => soup_path)
12
-
13
- require File.expand_path("../../pristine_app/soups/system/current_snip", __FILE__)
14
- @app.soup << CurrentSnip.snip_attributes
15
- create_snip :name => "layout", :content => "{current_snip}"
16
- end
17
-
18
- def response_for(url)
19
- @app.call(mock_env_for_url(url))
20
- end
21
-
22
- def response_body_for(url)
23
- response_for(url)[2].body[0]
24
- end
25
-
26
- def response_code_for(url)
27
- response_for(url)[0]
28
- end
29
-
30
- def assert_response_body(expected, uri)
31
- assert_equal expected.strip, response_body_for(uri).strip
32
- end
33
-
34
- def set_main_template(template_content)
35
- @app.soup << {:name => "layout", :content => template_content}
36
- end
37
-
38
- def create_snip(params)
39
- @app.soup << params
40
- end
41
-
42
- def mock_env_for_url(url)
43
- Rack::MockRequest.env_for(url)
44
- end
45
-
46
- def mock_request(url)
47
- Rack::Request.new(mock_env_for_url(url))
48
- end
49
-
50
- def test_app_directory
51
- File.join(File.dirname(__FILE__), "tmp")
52
- end
53
-
54
- def soup_path
55
- File.expand_path(File.join(test_app_directory, "soup"))
56
- end
6
+ class Application < Vanilla::App
7
+ end
57
8
 
58
- def clean_environment
59
- FileUtils.rm_rf(test_app_directory)
60
- end
9
+ module TestHelper
10
+ include Vanilla::TestHelper
11
+
12
+ def create_simple_layout
13
+ require File.expand_path("../../pristine_app/soups/system/current_snip", __FILE__)
14
+ app.soup << CurrentSnip.snip_attributes
15
+ create_snip :name => "layout", :content => "{current_snip}"
61
16
  end
62
17
  end
63
18
 
64
- Kintama.include Vanilla::Test
19
+ Kintama.include TestHelper
20
+
65
21
  Kintama.setup do
66
- setup_clean_environment
22
+ vanilla_setup
23
+ create_simple_layout
67
24
  end
68
25
 
69
26
  Kintama.teardown do
70
- clean_environment
27
+ vanilla_teardown
71
28
  end
@@ -1,14 +1,14 @@
1
1
  require "test_helper"
2
+ require "tmpdir"
2
3
 
3
4
  describe Vanilla::App do
4
5
  context "when behaving as a Rack application" do
5
- should "return an array of status code, headers and response" do
6
+ should "return a valid rack response" do
6
7
  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 }
8
+ get "/test.text"
9
+ assert_equal 200, last_response.status
10
+ assert_kind_of Hash, last_response.headers
11
+ assert_equal "content", last_response.body
12
12
  end
13
13
  end
14
14
 
@@ -21,19 +21,43 @@ describe Vanilla::App do
21
21
  should "allow a customised root snip" do
22
22
  create_snip :name => "start", :content => "default"
23
23
  create_snip :name => "custom", :content => "custom"
24
- @app = Vanilla::App.new(:soup => soup_path, :root_snip => "custom")
24
+ app.config[:root_snip] = "custom"
25
25
  assert_response_body "custom", "/"
26
26
  end
27
- end
28
27
 
29
- context "when detecting the snip renderer" do
30
- setup do
31
- @app = Vanilla::App.new(:soup => soup_path)
28
+ should "allow specification of the root directory to aide loading external soups" do
29
+ soup_dir = File.join(Dir.tmpdir, "my_soup")
30
+ FileUtils.mkdir_p(soup_dir)
31
+ File.open(File.join(soup_dir, "blah.snip"), "w") { |f| f.write "Hello superfriends" }
32
+
33
+ class TestApp < Vanilla::App
34
+ configure do |c|
35
+ c.root = Dir.tmpdir
36
+ c.soups = ["my_soup"]
37
+ end
38
+ end
39
+
40
+ app =
41
+ assert_equal "Hello superfriends", TestApp.new.soup['blah'].content
42
+ end
43
+
44
+ should "allow configuration against the class" do
45
+ class TestApp < Vanilla::App
46
+ end
47
+
48
+ TestApp.configure do |config|
49
+ config.soups = ["blah", "monkey"]
50
+ config.root = Dir.tmpdir
51
+ end
52
+
53
+ assert_equal ["blah", "monkey"], TestApp.new.config[:soups]
32
54
  end
55
+ end
33
56
 
57
+ context "when detecting the snip renderer" do
34
58
  should "return the constant refered to in the render_as property of the snip" do
35
59
  snip = create_snip(:name => "blah", :render_as => "Raw")
36
- assert_equal Vanilla::Renderers::Raw, @app.renderer_for(snip)
60
+ assert_equal Vanilla::Renderers::Raw, app.renderer_for(snip)
37
61
  end
38
62
 
39
63
  context "using the snip extension" do
@@ -46,25 +70,27 @@ describe Vanilla::App do
46
70
  }.each do |extension, renderer|
47
71
  should "return the renderer #{renderer} when the snip has extension #{extension}" do
48
72
  snip = create_snip(:name => "blah", :extension => extension)
49
- assert_equal renderer, @app.renderer_for(snip)
73
+ assert_equal renderer, app.renderer_for(snip)
50
74
  end
51
75
  end
52
76
  end
53
77
 
54
78
  should "respect snip renderers passed in the config" do
55
- app = Vanilla::App.new(:soup => soup_path, :renderers => {"markdown" => "Vanilla::Renderers::Bold"})
79
+ TestApp.configure do |c|
80
+ c.renderers = {"markdown" => "Vanilla::Renderers::Bold"}
81
+ end
56
82
  snip = create_snip(:name => "blah", :extension => "markdown")
57
- assert_equal Vanilla::Renderers::Bold, app.renderer_for(snip)
83
+ assert_equal Vanilla::Renderers::Bold, TestApp.new.renderer_for(snip)
58
84
  end
59
85
 
60
86
  should "return Vanilla::Renderers::Base if no render_as property exists" do
61
87
  snip = create_snip(:name => "blah")
62
- assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
88
+ assert_equal Vanilla::Renderers::Base, app.renderer_for(snip)
63
89
  end
64
90
 
65
91
  should "return Vanilla::Renderers::Base if the render_as property is blank" do
66
92
  snip = create_snip(:name => "blah", :render_as => '')
67
- assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
93
+ assert_equal Vanilla::Renderers::Base, app.renderer_for(snip)
68
94
  end
69
95
 
70
96
  should "raise an error if the specified renderer doesn't exist" do
@@ -75,9 +101,11 @@ describe Vanilla::App do
75
101
  should "load constants presented as a string" do
76
102
  class ::MyRenderer
77
103
  end
78
- app = Vanilla::App.new(:soup => soup_path, :renderers => {"my_renderer" => "MyRenderer"})
104
+ TestApp.configure do |c|
105
+ c.renderers = {"my_renderer" => "MyRenderer"}
106
+ end
79
107
  snip = create_snip(:name => "blah", :render_as => "my_renderer")
80
- assert_equal MyRenderer, app.renderer_for(snip)
108
+ assert_equal MyRenderer, TestApp.new.renderer_for(snip)
81
109
  end
82
110
  end
83
111
  end
@@ -21,10 +21,10 @@ context "When presenting" do
21
21
  end
22
22
 
23
23
  should "have a response code of 200" do
24
- assert_equal 200, response_code_for("/test")
25
- assert_equal 200, response_code_for("/test.html")
26
- assert_equal 200, response_code_for("/test/part")
27
- assert_equal 200, response_code_for("/test/part.html")
24
+ assert_response_status 200, "/test"
25
+ assert_response_status 200, "/test.html"
26
+ assert_response_status 200, "/test/part"
27
+ assert_response_status 200, "/test/part.html"
28
28
  end
29
29
 
30
30
  should "not allow rendering of the layout to produce infinite recursion" do
@@ -42,8 +42,8 @@ context "When presenting" do
42
42
  end
43
43
 
44
44
  should "have a response code of 200" do
45
- assert_equal 200, response_code_for("/test.text")
46
- assert_equal 200, response_code_for("/test/part.text")
45
+ assert_response_status 200, "/test.text"
46
+ assert_response_status 200, "/test/part.text"
47
47
  end
48
48
  end
49
49
 
@@ -61,8 +61,8 @@ context "When presenting" do
61
61
  end
62
62
 
63
63
  should "have a response code of 200" do
64
- assert_equal 200, response_code_for("/test.raw")
65
- assert_equal 200, response_code_for("/test/part.raw")
64
+ assert_response_status 200, "/test.raw"
65
+ assert_response_status 200, "/test/part.raw"
66
66
  end
67
67
  end
68
68
 
@@ -82,7 +82,7 @@ context "When presenting" do
82
82
 
83
83
  context "a snip using a renderer that specifies a template" do
84
84
  setup do
85
- @app.register_renderer CustomRenderer, "custom"
85
+ app.register_renderer CustomRenderer, "custom"
86
86
  create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
87
87
  end
88
88
 
@@ -100,7 +100,7 @@ context "When presenting" do
100
100
 
101
101
  context "and a custom default renderer has been provided" do
102
102
  should "use that renderer" do
103
- @app = Vanilla::App.new(:soup => soup_path, :default_renderer => ::Vanilla::Renderers::Bold)
103
+ app.config[:default_renderer] = ::Vanilla::Renderers::Bold
104
104
  create_snip :name => "layout", :content => "{test}", :render_as => "base"
105
105
  create_snip :name => "test", :content => "test"
106
106
  assert_response_body "<b>test</b>", "/test"
@@ -113,13 +113,13 @@ context "When presenting" do
113
113
  end
114
114
 
115
115
  should "have a 404 response code" do
116
- assert_equal 404, response_code_for("/missing_snip")
116
+ assert_response_status 404, "/missing_snip"
117
117
  end
118
118
  end
119
119
 
120
120
  context "requesting an unknown format" do
121
121
  should "return a 500 status code" do
122
- assert_equal 500, response_code_for("/test.monkey")
122
+ assert_response_status 500, "/test.monkey"
123
123
  end
124
124
  end
125
125
  end
@@ -2,7 +2,7 @@ require "test_helper"
2
2
 
3
3
  describe Vanilla::Request do
4
4
  context "when requesting the root" do
5
- setup { @request = Vanilla::Request.new(mock_env_for_url("/"), @app) }
5
+ setup { @request = Vanilla::Request.new(mock_env_for_url("/"), app) }
6
6
 
7
7
  should "set snip to 'start' by default" do
8
8
  assert_equal "start", @request.snip_name
@@ -14,14 +14,14 @@ describe Vanilla::Request do
14
14
  end
15
15
 
16
16
  context "when requesting urls" do
17
- setup { @request = Vanilla::Request.new(mock_env_for_url("/snip"), @app) }
17
+ setup { @request = Vanilla::Request.new(mock_env_for_url("/snip"), app) }
18
18
 
19
19
  should "use the first segement as the snip name" do
20
20
  assert_equal "snip", @request.snip_name
21
21
  end
22
22
 
23
23
  should "try to load the snip based on the snip name" do
24
- @app.soup.expects(:[]).with('snip').returns(:snip)
24
+ app.soup.expects(:[]).with('snip').returns(:snip)
25
25
  assert_equal :snip, @request.snip
26
26
  end
27
27
 
@@ -39,7 +39,7 @@ describe Vanilla::Request do
39
39
  end
40
40
 
41
41
  context "when requesting a snip part" do
42
- setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part"), @app) }
42
+ setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part"), app) }
43
43
 
44
44
  should "use the first segment as the snip, and the second segment as the part" do
45
45
  assert_equal "snip", @request.snip_name
@@ -52,7 +52,7 @@ describe Vanilla::Request do
52
52
  end
53
53
 
54
54
  context "when requesting a snip with a format" do
55
- setup { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw"), @app) }
55
+ setup { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw"), app) }
56
56
 
57
57
  should "use the extension as the format" do
58
58
  assert_equal "raw", @request.format
@@ -64,7 +64,7 @@ describe Vanilla::Request do
64
64
  end
65
65
 
66
66
  context "when requesting a snip part with a format" do
67
- setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw"), @app) }
67
+ setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw"), app) }
68
68
 
69
69
  should "use the extension as the format" do
70
70
  assert_equal "raw", @request.format
@@ -81,7 +81,13 @@ describe Vanilla::Request do
81
81
 
82
82
  context "when requested with a _method parameter" do
83
83
  should "return the method using the parameter" do
84
- assert_equal 'put', Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), @app).method
84
+ assert_equal 'put', Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), app).method
85
85
  end
86
86
  end
87
+
88
+ private
89
+
90
+ def mock_env_for_url(url)
91
+ Rack::MockRequest.env_for(url)
92
+ end
87
93
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla
3
3
  version: !ruby/object:Gem::Version
4
- hash: 83
4
+ hash: 45
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 16
9
- - 2
10
- version: 1.16.2
8
+ - 17
9
+ version: "1.17"
11
10
  platform: ruby
12
11
  authors:
13
12
  - James Adam
@@ -15,11 +14,10 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-05-04 00:00:00 +01:00
17
+ date: 2011-05-05 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- name: rack
23
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
@@ -31,11 +29,11 @@ dependencies:
31
29
  - 9
32
30
  - 1
33
31
  version: 0.9.1
32
+ requirement: *id001
34
33
  prerelease: false
34
+ name: rack
35
35
  type: :runtime
36
- requirement: *id001
37
36
  - !ruby/object:Gem::Dependency
38
- name: soup
39
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
@@ -47,11 +45,11 @@ dependencies:
47
45
  - 0
48
46
  - 6
49
47
  version: 1.0.6
48
+ requirement: *id002
50
49
  prerelease: false
50
+ name: soup
51
51
  type: :runtime
52
- requirement: *id002
53
52
  - !ruby/object:Gem::Dependency
54
- name: ratom
55
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
56
54
  none: false
57
55
  requirements:
@@ -63,11 +61,11 @@ dependencies:
63
61
  - 3
64
62
  - 5
65
63
  version: 0.3.5
64
+ requirement: *id003
66
65
  prerelease: false
66
+ name: ratom
67
67
  type: :runtime
68
- requirement: *id003
69
68
  - !ruby/object:Gem::Dependency
70
- name: RedCloth
71
69
  version_requirements: &id004 !ruby/object:Gem::Requirement
72
70
  none: false
73
71
  requirements:
@@ -79,11 +77,11 @@ dependencies:
79
77
  - 1
80
78
  - 1
81
79
  version: 4.1.1
80
+ requirement: *id004
82
81
  prerelease: false
82
+ name: RedCloth
83
83
  type: :runtime
84
- requirement: *id004
85
84
  - !ruby/object:Gem::Dependency
86
- name: BlueCloth
87
85
  version_requirements: &id005 !ruby/object:Gem::Requirement
88
86
  none: false
89
87
  requirements:
@@ -95,25 +93,26 @@ dependencies:
95
93
  - 0
96
94
  - 0
97
95
  version: 1.0.0
96
+ requirement: *id005
98
97
  prerelease: false
98
+ name: BlueCloth
99
99
  type: :runtime
100
- requirement: *id005
101
100
  - !ruby/object:Gem::Dependency
102
- name: haml
103
101
  version_requirements: &id006 !ruby/object:Gem::Requirement
104
102
  none: false
105
103
  requirements:
106
104
  - - ">="
107
105
  - !ruby/object:Gem::Version
108
- hash: 3
106
+ hash: 5
109
107
  segments:
110
- - 0
111
- version: "0"
108
+ - 3
109
+ - 1
110
+ version: "3.1"
111
+ requirement: *id006
112
112
  prerelease: false
113
+ name: haml
113
114
  type: :runtime
114
- requirement: *id006
115
115
  - !ruby/object:Gem::Dependency
116
- name: parslet
117
116
  version_requirements: &id007 !ruby/object:Gem::Requirement
118
117
  none: false
119
118
  requirements:
@@ -125,12 +124,28 @@ dependencies:
125
124
  - 2
126
125
  - 0
127
126
  version: 1.2.0
127
+ requirement: *id007
128
128
  prerelease: false
129
+ name: parslet
129
130
  type: :runtime
130
- requirement: *id007
131
131
  - !ruby/object:Gem::Dependency
132
- name: kintama
133
132
  version_requirements: &id008 !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 5
138
+ segments:
139
+ - 0
140
+ - 5
141
+ - 7
142
+ version: 0.5.7
143
+ requirement: *id008
144
+ prerelease: false
145
+ name: rack-test
146
+ type: :runtime
147
+ - !ruby/object:Gem::Dependency
148
+ version_requirements: &id009 !ruby/object:Gem::Requirement
134
149
  none: false
135
150
  requirements:
136
151
  - - ">="
@@ -141,12 +156,12 @@ dependencies:
141
156
  - 1
142
157
  - 6
143
158
  version: 0.1.6
159
+ requirement: *id009
144
160
  prerelease: false
161
+ name: kintama
145
162
  type: :development
146
- requirement: *id008
147
163
  - !ruby/object:Gem::Dependency
148
- name: mocha
149
- version_requirements: &id009 !ruby/object:Gem::Requirement
164
+ version_requirements: &id010 !ruby/object:Gem::Requirement
150
165
  none: false
151
166
  requirements:
152
167
  - - ">="
@@ -155,9 +170,10 @@ dependencies:
155
170
  segments:
156
171
  - 0
157
172
  version: "0"
173
+ requirement: *id010
158
174
  prerelease: false
175
+ name: mocha
159
176
  type: :development
160
- requirement: *id009
161
177
  description:
162
178
  email: james@lazyatom.com.com
163
179
  executables:
@@ -170,6 +186,22 @@ files:
170
186
  - Rakefile
171
187
  - README
172
188
  - .gemtest
189
+ - test/dynasnip_test.rb
190
+ - test/dynasnips/link_to_current_snip_test.rb
191
+ - test/dynasnips/link_to_test.rb
192
+ - test/dynasnips/page_title_test.rb
193
+ - test/renderers/base_renderer_test.rb
194
+ - test/renderers/erb_renderer_test.rb
195
+ - test/renderers/haml_renderer_test.rb
196
+ - test/renderers/markdown_renderer_test.rb
197
+ - test/renderers/raw_renderer_test.rb
198
+ - test/renderers/ruby_renderer_test.rb
199
+ - test/snip_inclusion_test.rb
200
+ - test/snip_reference_parser_test.rb
201
+ - test/test_helper.rb
202
+ - test/vanilla_app_test.rb
203
+ - test/vanilla_presenting_test.rb
204
+ - test/vanilla_request_test.rb
173
205
  - lib/vanilla/app.rb
174
206
  - lib/vanilla/console.rb
175
207
  - lib/vanilla/dynasnip.rb
@@ -186,11 +218,12 @@ files:
186
218
  - lib/vanilla/routes.rb
187
219
  - lib/vanilla/snip_reference_parser.rb
188
220
  - lib/vanilla/static.rb
221
+ - lib/vanilla/test_helper.rb
189
222
  - lib/vanilla.rb
190
223
  - bin/vanilla
224
+ - pristine_app/application.rb
191
225
  - pristine_app/config.ru
192
226
  - pristine_app/Gemfile
193
- - pristine_app/Gemfile.lock
194
227
  - pristine_app/public/vanilla.css
195
228
  - pristine_app/README
196
229
  - pristine_app/soups/base/layout.snip
@@ -223,23 +256,6 @@ files:
223
256
  - pristine_app/soups/tutorial/tutorial.snip.markdown
224
257
  - pristine_app/soups/tutorial/vanilla-rb.snip
225
258
  - pristine_app/soups/tutorial/vanilla.snip
226
- - pristine_app/tmp/restart.txt
227
- - test/dynasnip_test.rb
228
- - test/dynasnips/link_to_current_snip_test.rb
229
- - test/dynasnips/link_to_test.rb
230
- - test/dynasnips/page_title_test.rb
231
- - test/renderers/base_renderer_test.rb
232
- - test/renderers/erb_renderer_test.rb
233
- - test/renderers/haml_renderer_test.rb
234
- - test/renderers/markdown_renderer_test.rb
235
- - test/renderers/raw_renderer_test.rb
236
- - test/renderers/ruby_renderer_test.rb
237
- - test/snip_inclusion_test.rb
238
- - test/snip_reference_parser_test.rb
239
- - test/test_helper.rb
240
- - test/vanilla_app_test.rb
241
- - test/vanilla_presenting_test.rb
242
- - test/vanilla_request_test.rb
243
259
  has_rdoc: true
244
260
  homepage: http://github.com/lazyatom/vanilla-rb
245
261
  licenses: []
@@ -271,24 +287,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
287
  requirements: []
272
288
 
273
289
  rubyforge_project: vanilla
274
- rubygems_version: 1.5.0
290
+ rubygems_version: 1.4.1
275
291
  signing_key:
276
292
  specification_version: 3
277
293
  summary: A bliki-type web content thing.
278
- test_files:
279
- - test/dynasnip_test.rb
280
- - test/dynasnips/link_to_current_snip_test.rb
281
- - test/dynasnips/link_to_test.rb
282
- - test/dynasnips/page_title_test.rb
283
- - test/renderers/base_renderer_test.rb
284
- - test/renderers/erb_renderer_test.rb
285
- - test/renderers/haml_renderer_test.rb
286
- - test/renderers/markdown_renderer_test.rb
287
- - test/renderers/raw_renderer_test.rb
288
- - test/renderers/ruby_renderer_test.rb
289
- - test/snip_inclusion_test.rb
290
- - test/snip_reference_parser_test.rb
291
- - test/test_helper.rb
292
- - test/vanilla_app_test.rb
293
- - test/vanilla_presenting_test.rb
294
- - test/vanilla_request_test.rb
294
+ test_files: []
295
+
@@ -1,32 +0,0 @@
1
- PATH
2
- remote: /Users/james/Code/lazyatom/vanilla-rb
3
- specs:
4
- vanilla (1.16.1)
5
- BlueCloth (>= 1.0.0)
6
- RedCloth (>= 4.1.1)
7
- haml
8
- parslet (>= 1.2.0)
9
- rack (>= 0.9.1)
10
- ratom (>= 0.3.5)
11
- soup (>= 1.0.6)
12
-
13
- GEM
14
- remote: http://rubygems.org/
15
- specs:
16
- BlueCloth (1.0.1)
17
- RedCloth (4.2.7)
18
- blankslate (2.1.2.4)
19
- haml (3.1.1)
20
- libxml-ruby (2.0.4)
21
- parslet (1.2.0)
22
- blankslate (~> 2.0)
23
- rack (1.2.2)
24
- ratom (0.6.8)
25
- libxml-ruby (>= 1.1.2)
26
- soup (1.0.6)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- vanilla!
File without changes