vanilla 1.13.3 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/config.ru +1 -1
- data/lib/vanilla.rb +8 -6
- data/lib/vanilla/app.rb +57 -39
- data/lib/vanilla/console.rb +5 -2
- data/lib/vanilla/renderers.rb +12 -0
- data/lib/vanilla/renderers/base.rb +1 -2
- data/lib/vanilla/renderers/bold.rb +0 -2
- data/lib/vanilla/renderers/erb.rb +0 -2
- data/lib/vanilla/renderers/haml.rb +0 -2
- data/lib/vanilla/renderers/markdown.rb +0 -2
- data/lib/vanilla/renderers/raw.rb +0 -2
- data/lib/vanilla/renderers/ruby.rb +0 -2
- data/lib/vanilla/renderers/textile.rb +0 -2
- data/test/base_renderer_test.rb +5 -0
- data/test/vanilla_app_test.rb +6 -6
- data/test/vanilla_presenting_test.rb +5 -4
- metadata +6 -5
data/config.ru
CHANGED
@@ -5,7 +5,7 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[lib])
|
|
5
5
|
require 'vanilla'
|
6
6
|
require 'vanilla/static'
|
7
7
|
|
8
|
-
config = YAML.parse_file(ENV['VANILLA_CONFIG'])
|
8
|
+
config = YAML.parse_file(ENV['VANILLA_CONFIG']) rescue {}
|
9
9
|
app = Vanilla::App.new(config)
|
10
10
|
use Vanilla::Static, File.join(File.dirname(__FILE__), 'public')
|
11
11
|
run app
|
data/lib/vanilla.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
require 'vanilla/app'
|
2
|
-
|
3
1
|
module Vanilla
|
4
|
-
VERSION = "1.
|
5
|
-
end
|
2
|
+
VERSION = "1.14.1"
|
6
3
|
|
7
|
-
|
8
|
-
|
4
|
+
autoload :Renderers, "vanilla/renderers"
|
5
|
+
autoload :App, "vanilla/app"
|
6
|
+
autoload :Dynasnip, "vanilla/dynasnip"
|
7
|
+
autoload :Request, "vanilla/request"
|
8
|
+
autoload :Routes, "vanilla/routes"
|
9
|
+
autoload :Static, "vanilla/static"
|
10
|
+
end
|
9
11
|
|
10
12
|
# Load all the base dynasnip classes
|
11
13
|
Dir[File.join(File.dirname(__FILE__), 'vanilla', 'dynasnips', '*.rb')].each do |dynasnip|
|
data/lib/vanilla/app.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
require 'soup'
|
2
|
-
require 'vanilla/request'
|
3
|
-
require 'vanilla/routes'
|
4
|
-
|
5
|
-
# Require the base set of renderers
|
6
|
-
require 'vanilla/renderers/base'
|
7
|
-
require 'vanilla/renderers/raw'
|
8
|
-
require 'vanilla/renderers/erb'
|
9
2
|
|
10
3
|
module Vanilla
|
11
4
|
class App
|
12
|
-
include Routes
|
5
|
+
include Vanilla::Routes
|
13
6
|
|
14
7
|
attr_reader :request, :response, :config, :soup
|
15
8
|
|
9
|
+
# Create a new Vanilla application
|
10
|
+
# Configuration options:
|
11
|
+
#
|
12
|
+
# :soup - provide the path to the soup data
|
13
|
+
# :soups - provide an array of paths to soup data
|
14
|
+
# :renderers - a hash of names to classes
|
15
|
+
# :default_renderer - the class to use when no renderer is provided;
|
16
|
+
# defaults to 'Vanilla::Renderers::Base'
|
17
|
+
# :default_layout_snip - the snip to use as a layout when rendering to HTML;
|
18
|
+
# defaults to 'layout'
|
19
|
+
# :root_snip - the snip to load for the root ('/') url;
|
20
|
+
# defaults to 'start'
|
16
21
|
def initialize(config={})
|
17
22
|
@config = config
|
18
23
|
if @config[:soup].nil? && @config[:soups].nil?
|
19
24
|
@config.merge!(:soup => File.expand_path("soup"))
|
20
25
|
end
|
21
26
|
@soup = prepare_soup(config)
|
27
|
+
prepare_renderers(config[:renderers])
|
22
28
|
end
|
23
29
|
|
24
30
|
# Returns a Rack-appropriate 3-element array (via Rack::Response#finish)
|
@@ -62,24 +68,10 @@ module Vanilla
|
|
62
68
|
end
|
63
69
|
end
|
64
70
|
|
65
|
-
# Given the snip and parameters, yield an instance of the appropriate
|
66
|
-
# Vanilla::Render::Base subclass
|
67
|
-
def rendering(snip)
|
68
|
-
renderer_instance = renderer_for(snip).new(self)
|
69
|
-
yield renderer_instance
|
70
|
-
rescue Exception => e
|
71
|
-
snip_name = snip ? snip.name : nil
|
72
|
-
"<pre>[Error rendering '#{snip_name}' - \"" +
|
73
|
-
e.message.gsub("<", "<").gsub(">", ">") + "\"]\n" +
|
74
|
-
e.backtrace.join("\n").gsub("<", "<").gsub(">", ">") + "</pre>"
|
75
|
-
end
|
76
|
-
|
77
71
|
# Returns the renderer class for a given snip
|
78
72
|
def renderer_for(snip)
|
79
|
-
if snip
|
80
|
-
|
81
|
-
elsif snip && snip.extension && !snip.extension.empty?
|
82
|
-
Vanilla::Renderers.const_get(renderer_for_extension(snip.extension))
|
73
|
+
if snip
|
74
|
+
find_renderer(snip.render_as || snip.extension)
|
83
75
|
else
|
84
76
|
default_renderer
|
85
77
|
end
|
@@ -89,10 +81,6 @@ module Vanilla
|
|
89
81
|
soup[config[:default_layout_snip] || 'layout']
|
90
82
|
end
|
91
83
|
|
92
|
-
def default_renderer
|
93
|
-
config[:default_renderer] || Vanilla::Renderers::Base
|
94
|
-
end
|
95
|
-
|
96
84
|
def layout_for(snip)
|
97
85
|
if snip
|
98
86
|
renderer_for(snip).new(self).layout_for(snip)
|
@@ -105,19 +93,49 @@ module Vanilla
|
|
105
93
|
@soup << attributes
|
106
94
|
end
|
107
95
|
|
96
|
+
def register_renderer(klass, *types)
|
97
|
+
types.each do |type|
|
98
|
+
if klass.is_a?(String)
|
99
|
+
klass = klass.split("::").inject(Object) { |o, name| o.const_get(name) }
|
100
|
+
end
|
101
|
+
@renderers[type.to_s] = klass
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
108
105
|
private
|
109
106
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
107
|
+
def prepare_renderers(additional_renderers={})
|
108
|
+
@renderers = Hash.new(config[:default_renderer] || Vanilla::Renderers::Base)
|
109
|
+
@renderers.merge!({
|
110
|
+
"base" => Vanilla::Renderers::Base,
|
111
|
+
"markdown" => Vanilla::Renderers::Markdown,
|
112
|
+
"bold" => Vanilla::Renderers::Bold,
|
113
|
+
"erb" => Vanilla::Renderers::Erb,
|
114
|
+
"rb" => Vanilla::Renderers::Ruby,
|
115
|
+
"ruby" => Vanilla::Renderers::Ruby,
|
116
|
+
"haml" => Vanilla::Renderers::Haml,
|
117
|
+
"raw" => Vanilla::Renderers::Raw,
|
118
|
+
"textile" => Vanilla::Renderers::Textile
|
119
|
+
})
|
120
|
+
additional_renderers.each { |name, klass| register_renderer(klass, name) } if additional_renderers
|
121
|
+
end
|
122
|
+
|
123
|
+
def find_renderer(name)
|
124
|
+
@renderers[(name ? name.downcase : nil)]
|
125
|
+
end
|
126
|
+
|
127
|
+
def default_renderer
|
128
|
+
@renderers[nil]
|
129
|
+
end
|
130
|
+
|
131
|
+
def rendering(snip)
|
132
|
+
renderer_instance = renderer_for(snip).new(self)
|
133
|
+
yield renderer_instance
|
134
|
+
rescue Exception => e
|
135
|
+
snip_name = snip ? snip.name : nil
|
136
|
+
"<pre>[Error rendering '#{snip_name}' - \"" +
|
137
|
+
e.message.gsub("<", "<").gsub(">", ">") + "\"]\n" +
|
138
|
+
e.backtrace.join("\n").gsub("<", "<").gsub(">", ">") + "</pre>"
|
121
139
|
end
|
122
140
|
|
123
141
|
def prepare_soup(config)
|
data/lib/vanilla/console.rb
CHANGED
@@ -2,8 +2,11 @@ require 'vanilla'
|
|
2
2
|
require 'irb'
|
3
3
|
|
4
4
|
def app(reload=false)
|
5
|
-
|
6
|
-
|
5
|
+
if !@__vanilla_console_app || reload
|
6
|
+
config = YAML.parse_file(ENV['VANILLA_CONFIG']) rescue {}
|
7
|
+
@__vanilla_console_app = Vanilla::App.new(config)
|
8
|
+
end
|
9
|
+
@__vanilla_console_app
|
7
10
|
end
|
8
11
|
|
9
12
|
puts "The Soup is simmering."
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Vanilla
|
2
|
+
module Renderers
|
3
|
+
autoload :Base, "vanilla/renderers/base"
|
4
|
+
autoload :Bold, "vanilla/renderers/bold"
|
5
|
+
autoload :Erb, "vanilla/renderers/erb"
|
6
|
+
autoload :Haml, "vanilla/renderers/haml"
|
7
|
+
autoload :Markdown, "vanilla/renderers/markdown"
|
8
|
+
autoload :Raw, "vanilla/renderers/raw"
|
9
|
+
autoload :Ruby, "vanilla/renderers/ruby"
|
10
|
+
autoload :Textile, "vanilla/renderers/textile"
|
11
|
+
end
|
12
|
+
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'vanilla/app'
|
2
1
|
require 'vanilla/snip_reference_parser'
|
3
2
|
|
4
3
|
module Vanilla
|
@@ -27,7 +26,7 @@ module Vanilla
|
|
27
26
|
end
|
28
27
|
|
29
28
|
def self.snip_regexp
|
30
|
-
%r{(\{[\w\-_\d]+(\s+[^\}.]+)?\})}
|
29
|
+
%r{(\{[\w\-_\d\.\"]+(\s+[^\}.]+)?\})}
|
31
30
|
end
|
32
31
|
|
33
32
|
def default_layout_snip
|
data/test/base_renderer_test.rb
CHANGED
@@ -18,6 +18,11 @@ describe Vanilla::Renderers::Base do
|
|
18
18
|
assert_response_body "loading content content", "/snip_with_inclusions"
|
19
19
|
end
|
20
20
|
|
21
|
+
should "be able to render a snip attribute" do
|
22
|
+
create_snip(:name => "snip_with_inclusions", :content => "loading {test.part}")
|
23
|
+
assert_response_body "loading part content", "/snip_with_inclusions"
|
24
|
+
end
|
25
|
+
|
21
26
|
should "perform snip inclusion when rendering a part" do
|
22
27
|
create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
|
23
28
|
assert_response_body "loading content content", "/snip_with_inclusions/part"
|
data/test/vanilla_app_test.rb
CHANGED
@@ -51,8 +51,8 @@ describe Vanilla::App do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
should "respect snip
|
55
|
-
app = Vanilla::App.new(:
|
54
|
+
should "respect snip renderers passed in the config" do
|
55
|
+
app = Vanilla::App.new(:renderers => {"markdown" => "Vanilla::Renderers::Bold"})
|
56
56
|
snip = create_snip(:name => "blah", :extension => "markdown")
|
57
57
|
assert_equal Vanilla::Renderers::Bold, app.renderer_for(snip)
|
58
58
|
end
|
@@ -72,12 +72,12 @@ describe Vanilla::App do
|
|
72
72
|
assert_raises(NameError) { @app.renderer_for(snip) }
|
73
73
|
end
|
74
74
|
|
75
|
-
should "load constants
|
75
|
+
should "load constants presented as a string" do
|
76
76
|
class ::MyRenderer
|
77
77
|
end
|
78
|
-
|
79
|
-
snip = create_snip(:name => "blah", :render_as => "
|
80
|
-
assert_equal MyRenderer,
|
78
|
+
app = Vanilla::App.new(:renderers => {"my_renderer" => "MyRenderer"})
|
79
|
+
snip = create_snip(:name => "blah", :render_as => "my_renderer")
|
80
|
+
assert_equal MyRenderer, app.renderer_for(snip)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -71,7 +71,7 @@ context "When presenting" do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
class
|
74
|
+
class CustomRenderer < ::Vanilla::Renderers::Base
|
75
75
|
def default_layout_snip
|
76
76
|
soup['custom-layout']
|
77
77
|
end
|
@@ -79,17 +79,18 @@ context "When presenting" do
|
|
79
79
|
|
80
80
|
context "a snip using a renderer that specifies a template" do
|
81
81
|
setup do
|
82
|
+
@app.register_renderer CustomRenderer, "custom"
|
82
83
|
create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
|
83
84
|
end
|
84
85
|
|
85
86
|
should "use the renderer's specified layout" do
|
86
|
-
create_snip :name => "test", :content => "this is a test", :render_as => "
|
87
|
+
create_snip :name => "test", :content => "this is a test", :render_as => "custom"
|
87
88
|
assert_response_body "<custom>this is a test</custom>", "/test"
|
88
89
|
end
|
89
90
|
|
90
91
|
should "use the snips layout when given" do
|
91
92
|
create_snip :name => "snip-custom-layout", :content => "<snipcustom>{current_snip}</snipcustom>"
|
92
|
-
create_snip :name => "test", :content => "this is a test", :render_as => "
|
93
|
+
create_snip :name => "test", :content => "this is a test", :render_as => "custom", :layout => "snip-custom-layout"
|
93
94
|
assert_response_body "<snipcustom>this is a test</snipcustom>", "/test"
|
94
95
|
end
|
95
96
|
end
|
@@ -97,7 +98,7 @@ context "When presenting" do
|
|
97
98
|
context "and a custom default renderer has been provided" do
|
98
99
|
should "use that renderer" do
|
99
100
|
@app = Vanilla::App.new(:default_renderer => ::Vanilla::Renderers::Bold)
|
100
|
-
create_snip :name => "layout", :content => "{current_snip}", :render_as => "
|
101
|
+
create_snip :name => "layout", :content => "{current_snip}", :render_as => "base"
|
101
102
|
create_snip :name => "test", :content => "test"
|
102
103
|
assert_response_body "<b>test</b>", "/test"
|
103
104
|
end
|
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:
|
4
|
+
hash: 45
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 14
|
9
|
+
- 1
|
10
|
+
version: 1.14.1
|
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-04-
|
18
|
+
date: 2011-04-26 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/vanilla/renderers/raw.rb
|
220
220
|
- lib/vanilla/renderers/ruby.rb
|
221
221
|
- lib/vanilla/renderers/textile.rb
|
222
|
+
- lib/vanilla/renderers.rb
|
222
223
|
- lib/vanilla/request.rb
|
223
224
|
- lib/vanilla/routes.rb
|
224
225
|
- lib/vanilla/snip_reference.rb
|