vanilla 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -41,14 +41,14 @@ if Object.const_defined?(:Gem)
41
41
 
42
42
  # All the other gems we need.
43
43
  s.add_dependency("rack", ">= 0.9.1")
44
- s.add_dependency("soup", ">= 1.0.3")
44
+ s.add_dependency("soup", ">= 1.0.6")
45
45
  s.add_dependency("ratom", ">= 0.3.5")
46
46
  s.add_dependency("RedCloth", ">= 4.1.1")
47
47
  s.add_dependency("BlueCloth", ">= 1.0.0")
48
48
  s.add_dependency("treetop", ">= 1.4.1")
49
49
  s.add_dependency("haml")
50
50
 
51
- s.add_development_dependency("shoulda") # add any other gems for testing/development
51
+ s.add_development_dependency("kintama") # add any other gems for testing/development
52
52
  s.add_development_dependency("mocha")
53
53
 
54
54
  # If you want to publish automatically to rubyforge, you'll may need
@@ -4,7 +4,7 @@ require 'vanilla'
4
4
  namespace :vanilla do
5
5
  desc "Open an irb session preloaded with this library"
6
6
  task :console do
7
- sh "irb -Ilib -rubygems -rvanilla -rvanilla/console"
7
+ sh "irb -Ilib -rubygems -rbundler/setup -rvanilla -rvanilla/console"
8
8
  end
9
9
 
10
10
  desc 'Upgrade dynasnips and system snips'
data/lib/vanilla.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'vanilla/app'
2
2
 
3
3
  module Vanilla
4
- VERSION = "1.13.1"
4
+ VERSION = "1.13.2"
5
5
  end
6
6
 
7
7
  # Load all the other renderer subclasses
data/lib/vanilla/app.rb CHANGED
@@ -75,6 +75,8 @@ module Vanilla
75
75
  def renderer_for(snip)
76
76
  if snip && snip.render_as && !snip.render_as.empty?
77
77
  Vanilla::Renderers.const_get(snip.render_as)
78
+ elsif snip && snip.extension && !snip.extension.empty?
79
+ Vanilla::Renderers.const_get(renderer_for_extension(snip.extension))
78
80
  else
79
81
  Vanilla::Renderers::Base
80
82
  end
@@ -103,6 +105,16 @@ module Vanilla
103
105
 
104
106
  private
105
107
 
108
+ def renderer_for_extension(extension)
109
+ mapping = Hash.new("Base")
110
+ mapping["markdown"] = "Markdown"
111
+ mapping["textile"] = "Textile"
112
+ mapping["erb"] = "Erb"
113
+ mapping["rb"] = "Ruby"
114
+ mapping["haml"] = "Haml"
115
+ mapping[extension]
116
+ end
117
+
106
118
  def prepare_configuration(config_file)
107
119
  config_file ||= "config.yml"
108
120
  @config = YAML.load(File.open(config_file)) rescue {}
@@ -4,7 +4,7 @@ class HelloWorld
4
4
 
5
5
  def handle(name=nil)
6
6
  if name
7
- "Hey \#{name} - Hello World!"
7
+ "Hey #{name} - Hello World!"
8
8
  else
9
9
  "Hello World!"
10
10
  end
@@ -1,34 +1,32 @@
1
1
  require "test_helper"
2
2
 
3
- class BaseRendererTest < Vanilla::TestCase
4
- context "in general" do
5
- setup do
6
- create_snip(:name => "test", :content => "content content", :part => "part content")
7
- end
3
+ describe Vanilla::Renderers::Base do
4
+ setup do
5
+ create_snip(:name => "test", :content => "content content", :part => "part content")
6
+ end
8
7
 
9
- should "render the contents part of the snip as it is" do
10
- assert_response_body "content content", "/test"
11
- end
12
-
13
- should "render the specified part of the snip" do
14
- assert_response_body "part content", "/test/part"
15
- end
16
-
17
- should "include the contents of a referenced snip" do
18
- create_snip(:name => "snip_with_inclusions", :content => "loading {test}")
19
- assert_response_body "loading content content", "/snip_with_inclusions"
20
- end
21
-
22
- should "perform snip inclusion when rendering a part" do
23
- create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
24
- assert_response_body "loading content content", "/snip_with_inclusions/part"
25
- end
26
-
27
- 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
- assert_equal "lets include <b>blah</b>", response_body_for("/including_snip").gsub(/\s+/, ' ')
31
- end
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 "perform snip inclusion when rendering a part" do
22
+ create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
23
+ assert_response_body "loading content content", "/snip_with_inclusions/part"
24
+ end
25
+
26
+ should "include other snips using their renderers" do
27
+ create_snip(:name => "including_snip", :content => "lets include {another_snip}")
28
+ create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
29
+ assert_equal "lets include <b>blah</b>", response_body_for("/including_snip").gsub(/\s+/, ' ')
32
30
  end
33
31
 
34
32
  context "when trying to include a missing snip" do
@@ -1,8 +1,7 @@
1
1
  require "test_helper"
2
2
  require 'vanilla/dynasnip'
3
3
 
4
- class DynasnipTest < Vanilla::TestCase
5
-
4
+ describe Dynasnip do
6
5
  context "when storing attributes" do
7
6
 
8
7
  class ::TestDyna < Dynasnip
@@ -27,5 +26,4 @@ class DynasnipTest < Vanilla::TestCase
27
26
  assert_equal "altered content", TestDyna.new(@app).test_attribute
28
27
  end
29
28
  end
30
-
31
29
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class ErbRendererTest < Vanilla::TestCase
3
+ describe Vanilla::Renderers::Erb do
4
4
  context "when rendering" do
5
5
  should "insert evaluated Erb content into the snip" do
6
6
  erb_snip(:name => "test", :content => "<%= 1 + 2 %>")
@@ -23,8 +23,6 @@ class ErbRendererTest < Vanilla::TestCase
23
23
  end
24
24
  end
25
25
 
26
- private
27
-
28
26
  def erb_snip(params)
29
27
  create_snip(params.merge(:render_as => "Erb"))
30
28
  end
@@ -1,7 +1,7 @@
1
- require 'haml'
2
1
  require 'test_helper'
2
+ require 'haml'
3
3
 
4
- class HamlRendererTest < Vanilla::TestCase
4
+ describe Vanilla::Renderers::Haml do
5
5
  context "when rendering" do
6
6
  should "render Haml into HTML" do
7
7
  haml_snip(:name => "test", :content => "#hello\n stuff")
@@ -29,8 +29,6 @@ class HamlRendererTest < Vanilla::TestCase
29
29
  end
30
30
  end
31
31
 
32
- private
33
-
34
32
  def haml_snip(params)
35
33
  create_snip(params.merge(:render_as => "Haml"))
36
34
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class MarkdownRendererTest < Vanilla::TestCase
3
+ describe Vanilla::Renderers::Markdown do
4
4
  context "when rendering" do
5
5
  should "return the snip contents rendered via Markdown" do
6
6
  content = <<Markdown
@@ -25,8 +25,6 @@ Markdown
25
25
  end
26
26
  end
27
27
 
28
- private
29
-
30
28
  def markdown_snip(attributes)
31
29
  create_snip(attributes.merge(:render_as => "Markdown"))
32
30
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class RawRendererTest < Vanilla::TestCase
3
+ describe Vanilla::Renderers::Raw do
4
4
  context "when rendering" do
5
5
  setup do
6
6
  @snip = create_snip(:name => "test", :content => "raw content", :part => "raw part")
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class RubyRendererTest < Vanilla::TestCase
3
+ describe Vanilla::Renderers::Ruby do
4
4
  context "when rendering normally" do
5
5
  class ::TestDyna < Dynasnip
6
6
  def handle(*args)
@@ -11,7 +11,7 @@ class RubyRendererTest < Vanilla::TestCase
11
11
  setup do
12
12
  @app.soup << TestDyna.snip_attributes
13
13
  end
14
-
14
+
15
15
  should "render the result of the handle method" do
16
16
  assert_response_body 'handle called', "/test_dyna"
17
17
  end
@@ -24,34 +24,34 @@ class RubyRendererTest < Vanilla::TestCase
24
24
  end
25
25
  def post(*args)
26
26
  'post called'
27
- end
27
+ end
28
28
  end
29
-
29
+
30
30
  setup do
31
31
  @app.soup << RestishDyna.snip_attributes
32
32
  end
33
-
33
+
34
34
  should "render the result of the get method on GET requests" do
35
35
  assert_response_body 'get called', "/restish_dyna"
36
36
  end
37
-
37
+
38
38
  should "render the result of the post method on POST requests" do
39
39
  assert_response_body 'post called', "/restish_dyna?_method=post"
40
40
  end
41
41
  end
42
-
42
+
43
43
  context "when knowing about enclosing snips" do
44
44
  class ::Encloser < Dynasnip
45
45
  def handle(*args)
46
46
  "enclosing snip is #{enclosing_snip.name}"
47
47
  end
48
48
  end
49
-
49
+
50
50
  setup do
51
51
  @app.soup << Encloser.snip_attributes
52
52
  create_snip(:name => "test", :content => "{encloser}")
53
53
  end
54
-
54
+
55
55
  should "know about the snip that called this dynasnip" do
56
56
  assert_response_body 'enclosing snip is test', "/test"
57
57
  end
@@ -1,7 +1,11 @@
1
1
  require "test_helper"
2
2
  Treetop.load File.join(File.dirname(__FILE__), *%w[.. lib vanilla snip_reference])
3
3
 
4
- class SnipReferenceParserTest < Test::Unit::TestCase
4
+ context "The SnipReference parser" do
5
+ setup do
6
+ @parser = SnipReferenceParser.new
7
+ end
8
+
5
9
  examples = {
6
10
  %|{snip}| => {:snip => 'snip', :attribute => nil, :arguments => []},
7
11
  %|{snip argument}| => {:snip => 'snip', :attribute => nil, :arguments => ["argument"]},
@@ -35,13 +39,9 @@ class SnipReferenceParserTest < Test::Unit::TestCase
35
39
  %|{snip key1: value1, key2: value2}| => {:snip => 'snip', :arguments => {:key1 => 'value1', :key2 => 'value2'}},
36
40
  %|{snip key1:"value with spaces"}| => {:snip => 'snip', :arguments => {:key1 => 'value with spaces'}}
37
41
  }
38
-
39
- def setup
40
- @parser = SnipReferenceParser.new
41
- end
42
-
42
+
43
43
  examples.each do |example, expected|
44
- define_method :"test_parsing_#{example}" do
44
+ should "parse '#{example}' into #{expected.inspect}" do
45
45
  reference = @parser.parse(example)
46
46
  if reference
47
47
  assert_equal expected[:snip], reference.snip
@@ -1,8 +1,7 @@
1
1
  require "test_helper"
2
2
 
3
- class SnipReferenceTest < Vanilla::TestCase
4
- def setup
5
- super
3
+ context "The SnipReference parser" do
4
+ setup do
6
5
  create_snip :name => "test", :content => "snip content"
7
6
  end
8
7
 
@@ -50,8 +49,6 @@ class SnipReferenceTest < Vanilla::TestCase
50
49
  assert_equal "10.times {|x| puts x }", render("10.times {|x| puts x }")
51
50
  end
52
51
 
53
- private
54
-
55
52
  def render(content)
56
53
  snip = create_snip :name => "test-content", :content => content
57
54
  Vanilla::Renderers::Base.new(@app).render(snip)
data/test/test_helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
4
 
5
- require "shoulda"
5
+ require "kintama"
6
6
  require "mocha"
7
7
  require "fileutils"
8
8
  require "rack/mock"
@@ -12,7 +12,6 @@ module Vanilla
12
12
  module Test
13
13
  def setup_clean_environment
14
14
  FileUtils.mkdir_p(File.dirname(config_file_for_tests))
15
- clear_soup
16
15
  File.open(config_file_for_tests, 'w') { |f| f.write({:soup => soup_path}.to_yaml) }
17
16
  @app = Vanilla::App.new(config_file_for_tests)
18
17
 
@@ -53,8 +52,12 @@ module Vanilla
53
52
  Rack::Request.new(mock_env_for_url(url))
54
53
  end
55
54
 
55
+ def test_app_directory
56
+ File.join(File.dirname(__FILE__), "tmp")
57
+ end
58
+
56
59
  def config_file_for_tests
57
- File.join(File.dirname(__FILE__), "tmp", "config.yml")
60
+ File.join(test_app_directory, "config.yml")
58
61
  end
59
62
 
60
63
  def config_for_tests(options={})
@@ -62,23 +65,27 @@ module Vanilla
62
65
  end
63
66
 
64
67
  def soup_path
65
- File.expand_path(File.join(File.dirname(__FILE__), "tmp", "soup"))
66
- end
67
-
68
- def clear_soup
69
- FileUtils.rm_rf(soup_path)
68
+ File.expand_path(File.join(test_app_directory, "soup"))
70
69
  end
71
70
  end
72
71
  end
73
72
 
74
- class Vanilla::TestCase < Test::Unit::TestCase
75
- include Vanilla::Test
73
+ Kintama.include Vanilla::Test
74
+ Kintama.setup do
75
+ setup_clean_environment
76
+ end
76
77
 
77
- def setup
78
- setup_clean_environment
79
- end
78
+ Kintama.teardown do
79
+ FileUtils.rm_rf(test_app_directory)
80
+ end
80
81
 
81
- def test_nothing
82
- # please, please stop complaining.
82
+ Kintama.include Mocha::API
83
+ Kintama.teardown do
84
+ begin
85
+ mocha_verify
86
+ rescue Mocha::ExpectationError => e
87
+ raise e
88
+ ensure
89
+ mocha_teardown
83
90
  end
84
- end
91
+ end
@@ -1,7 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class VanillaAppTest < Vanilla::TestCase
4
-
3
+ describe Vanilla::App do
5
4
  context "when behaving as a Rack application" do
6
5
  should "return an array of status code, headers and response" do
7
6
  create_snip(:name => "test", :content => "content")
@@ -47,6 +46,21 @@ class VanillaAppTest < Vanilla::TestCase
47
46
  assert_equal Vanilla::Renderers::Raw, @app.renderer_for(snip)
48
47
  end
49
48
 
49
+ context "using the snip extension" do
50
+ {
51
+ "markdown" => Vanilla::Renderers::Markdown,
52
+ "textile" => Vanilla::Renderers::Textile,
53
+ "erb" => Vanilla::Renderers::Erb,
54
+ "rb" => Vanilla::Renderers::Ruby,
55
+ "haml" => Vanilla::Renderers::Haml
56
+ }.each do |extension, renderer|
57
+ should "return the renderer #{renderer} when the snip has extension #{extension}" do
58
+ snip = create_snip(:name => "blah", :extension => extension)
59
+ assert_equal renderer, @app.renderer_for(snip)
60
+ end
61
+ end
62
+ end
63
+
50
64
  should "return Vanilla::Renderers::Base if no render_as property exists" do
51
65
  snip = create_snip(:name => "blah")
52
66
  assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
@@ -70,4 +84,4 @@ class VanillaAppTest < Vanilla::TestCase
70
84
  assert_equal MyRenderer, @app.renderer_for(snip)
71
85
  end
72
86
  end
73
- end
87
+ end
@@ -1,15 +1,14 @@
1
1
  require "test_helper"
2
2
 
3
- class VanillaPresentingTest < Vanilla::TestCase
4
- def setup
5
- super
3
+ context "When presenting" do
4
+ setup do
6
5
  @app.soup << LinkTo.snip_attributes
7
6
  set_main_template "<tag>{current_snip}</tag>"
8
7
  create_snip :name => "test", :content => "blah {other_snip}", :part => 'part content'
9
8
  create_snip :name => "other_snip", :content => "blah!"
10
9
  end
11
10
 
12
- context "when presenting as HTML" do
11
+ context "HTML" do
13
12
  should "render the snip's content in the system template if no format or part is given" do
14
13
  assert_response_body "<tag>blah blah!</tag>", "/test"
15
14
  end
@@ -30,7 +29,7 @@ class VanillaPresentingTest < Vanilla::TestCase
30
29
  end
31
30
  end
32
31
 
33
- context "when presenting content as text" do
32
+ context "as text" do
34
33
  should "render the snip's content outside of the main template with its default renderer" do
35
34
  assert_response_body "blah blah!", "/test.text"
36
35
  end
@@ -45,7 +44,7 @@ class VanillaPresentingTest < Vanilla::TestCase
45
44
  end
46
45
  end
47
46
 
48
- context "when presenting raw content" do
47
+ context "raw content" do
49
48
  should "render the snips contents exactly as they are" do
50
49
  assert_response_body "blah {other_snip}", "/test.raw"
51
50
  end
@@ -64,7 +63,7 @@ class VanillaPresentingTest < Vanilla::TestCase
64
63
  end
65
64
  end
66
65
 
67
- context "when presenting a snip with a custom layout" do
66
+ context "a snip with a custom layout" do
68
67
  should "render the snips contents within that layout" do
69
68
  create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
70
69
  create_snip :name => "test", :content => "this is a test", :layout => "custom-layout"
@@ -78,7 +77,7 @@ class VanillaPresentingTest < Vanilla::TestCase
78
77
  end
79
78
  end
80
79
 
81
- context "when presenting a snip using a renderer that specifies a template" do
80
+ context "a snip using a renderer that specifies a template" do
82
81
  setup do
83
82
  create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
84
83
  end
@@ -95,7 +94,7 @@ class VanillaPresentingTest < Vanilla::TestCase
95
94
  end
96
95
  end
97
96
 
98
- context "when a missing snip is requested" do
97
+ context "and a missing snip is requested" do
99
98
  should "render missing snip content in the main template" do
100
99
  assert_response_body "<tag>Couldn't find snip #{LinkTo.new(@app).handle("missing_snip")}</tag>", "/missing_snip"
101
100
  end
@@ -105,7 +104,7 @@ class VanillaPresentingTest < Vanilla::TestCase
105
104
  end
106
105
  end
107
106
 
108
- context "when requesting an unknown format" do
107
+ context "requesting an unknown format" do
109
108
  should "return a 500 status code" do
110
109
  assert_equal 500, response_code_for("/test.monkey")
111
110
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
 
3
- class VanillaRequestTest < Vanilla::TestCase
3
+ describe Vanilla::Request do
4
4
  context "when requesting the root" do
5
5
  setup { @request = Vanilla::Request.new(mock_env_for_url("/"), @app) }
6
6
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla
3
3
  version: !ruby/object:Gem::Version
4
- hash: 33
4
+ hash: 39
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 13
9
- - 1
10
- version: 1.13.1
9
+ - 2
10
+ version: 1.13.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Adam
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-22 00:00:00 +00:00
18
+ date: 2011-03-01 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 17
45
+ hash: 27
46
46
  segments:
47
47
  - 1
48
48
  - 0
49
- - 3
50
- version: 1.0.3
49
+ - 6
50
+ version: 1.0.6
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -129,7 +129,7 @@ dependencies:
129
129
  type: :runtime
130
130
  version_requirements: *id007
131
131
  - !ruby/object:Gem::Dependency
132
- name: shoulda
132
+ name: kintama
133
133
  prerelease: false
134
134
  requirement: &id008 !ruby/object:Gem::Requirement
135
135
  none: false
@@ -180,9 +180,6 @@ files:
180
180
  - test/snip_reference_parser_test.rb
181
181
  - test/snip_reference_test.rb
182
182
  - test/test_helper.rb
183
- - test/tmp/config.yml
184
- - test/tmp/soup/current_snip.snip
185
- - test/tmp/soup/layout.snip
186
183
  - test/vanilla_app_test.rb
187
184
  - test/vanilla_presenting_test.rb
188
185
  - test/vanilla_request_test.rb
data/test/tmp/config.yml DELETED
@@ -1,2 +0,0 @@
1
- ---
2
- :soup: /Users/james/Code/lazyatom/vanilla-rb/test/tmp/soup
@@ -1,14 +0,0 @@
1
- CurrentSnip
2
-
3
- :usage: |-
4
- The current_snip dyna normally returns the result of rendering the snip named by the
5
- 'snip' value in the parameters. This way, it can be used in templates to place the currently
6
- requested snip, in its rendered form, within the page.
7
-
8
- It can also be used to determine the name of the current snip in a consistent way:
9
-
10
- &#123;current_snip name&#125;
11
-
12
- will output the name of the current snip, or the name of the snip currently being edited.
13
- :name: current_snip
14
- :render_as: Ruby
@@ -1,3 +0,0 @@
1
- {current_snip}
2
-
3
- :name: layout