vanilla 1.13.2 → 1.13.3
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/README_FOR_APP +9 -18
- data/Rakefile +1 -1
- data/config.ru +2 -1
- data/lib/vanilla.rb +1 -1
- data/lib/vanilla/app.rb +22 -26
- data/lib/vanilla/renderers/base.rb +6 -3
- data/lib/vanilla/request.rb +1 -1
- data/test/soup/blah.snip +4 -0
- data/test/soup/blah.snip.erb +4 -0
- data/test/soup/blah.snip.haml +4 -0
- data/test/soup/blah.snip.markdown +4 -0
- data/test/soup/blah.snip.rb +4 -0
- data/test/soup/blah.snip.textile +4 -0
- data/test/soup/current_snip.snip +14 -0
- data/test/soup/layout.snip +4 -0
- data/test/soup/test.snip +3 -0
- data/test/soup/test_dyna.snip +7 -0
- data/test/test_helper.rb +8 -24
- data/test/vanilla_app_test.rb +15 -19
- data/test/vanilla_presenting_test.rb +9 -0
- data/test/vanilla_request_test.rb +0 -11
- metadata +18 -6
data/README_FOR_APP
CHANGED
|
@@ -7,7 +7,7 @@ What you've got:
|
|
|
7
7
|
config.ru - this is the rack configuration, which is used to start
|
|
8
8
|
the application by your webserver
|
|
9
9
|
config.yml - the configuration; by default it specifies the directory
|
|
10
|
-
which contains the soup
|
|
10
|
+
which contains the soup(s)
|
|
11
11
|
soup/ - the default soup directory, where your snips are stored
|
|
12
12
|
|
|
13
13
|
|
|
@@ -16,32 +16,23 @@ For an overview of vanilla, start your site and look at the tutorial:
|
|
|
16
16
|
$ rackup # then open http://localhost:9292/vanilla-rb-tutorial
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
$ rake vanilla:add_user
|
|
24
|
-
|
|
25
|
-
Your other option is to edit the soup directly; you can edit any file
|
|
26
|
-
in the soup directory using your favourite editor, and the changes
|
|
27
|
-
will be reflected automatically. The snip files are slightly modified
|
|
28
|
-
YAML files. Here's one describing Soup itself, in soup/soup.yml:
|
|
19
|
+
You can edit any file in the soup directory using your favourite editor,
|
|
20
|
+
and the changes will be reflected automatically. The snip files are
|
|
21
|
+
slightly modified YAML files. Here's one describing Soup itself, in
|
|
22
|
+
soup/system/tutorial/soup.snip:
|
|
29
23
|
|
|
30
24
|
Soup is a data store supporting the {link_to snip}-space that {link_to vanilla-rb} expects.
|
|
31
25
|
|
|
32
26
|
It's hosted on github [here][github].
|
|
33
27
|
|
|
34
28
|
[github]: http://github.com/lazyatom/soup
|
|
35
|
-
|
|
29
|
+
|
|
36
30
|
:name: soup
|
|
37
31
|
:created_at: 2009-09-27 14:14:16.096231 +01:00
|
|
38
32
|
:updated_at: 2009-09-27 14:14:16.096232 +01:00
|
|
39
33
|
:render_as: Markdown
|
|
40
34
|
|
|
41
|
-
The 'content' of the snip is at the top of the file, followed by
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
which starts the rest of the snip attributes. Again, see the online
|
|
46
|
-
tutorial for information about what each attribute signifies.
|
|
35
|
+
The 'content' of the snip is at the top of the file, followed by the
|
|
36
|
+
rest of the snip attributes. Again, see the online tutorial for information
|
|
37
|
+
about what each attribute signifies.
|
|
47
38
|
|
data/Rakefile
CHANGED
|
@@ -48,7 +48,7 @@ if Object.const_defined?(:Gem)
|
|
|
48
48
|
s.add_dependency("treetop", ">= 1.4.1")
|
|
49
49
|
s.add_dependency("haml")
|
|
50
50
|
|
|
51
|
-
s.add_development_dependency("kintama") # add any other gems for testing/development
|
|
51
|
+
s.add_development_dependency("kintama", ">= 0.1.5") # 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
|
data/config.ru
CHANGED
|
@@ -5,6 +5,7 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[lib])
|
|
|
5
5
|
require 'vanilla'
|
|
6
6
|
require 'vanilla/static'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
config = YAML.parse_file(ENV['VANILLA_CONFIG'])
|
|
9
|
+
app = Vanilla::App.new(config)
|
|
9
10
|
use Vanilla::Static, File.join(File.dirname(__FILE__), 'public')
|
|
10
11
|
run app
|
data/lib/vanilla.rb
CHANGED
data/lib/vanilla/app.rb
CHANGED
|
@@ -13,8 +13,11 @@ module Vanilla
|
|
|
13
13
|
|
|
14
14
|
attr_reader :request, :response, :config, :soup
|
|
15
15
|
|
|
16
|
-
def initialize(
|
|
17
|
-
|
|
16
|
+
def initialize(config={})
|
|
17
|
+
@config = config
|
|
18
|
+
if @config[:soup].nil? && @config[:soups].nil?
|
|
19
|
+
@config.merge!(:soup => File.expand_path("soup"))
|
|
20
|
+
end
|
|
18
21
|
@soup = prepare_soup(config)
|
|
19
22
|
end
|
|
20
23
|
|
|
@@ -42,9 +45,9 @@ module Vanilla
|
|
|
42
45
|
when 'html', nil
|
|
43
46
|
render(layout_for(snip))
|
|
44
47
|
when 'raw', 'css', 'js'
|
|
45
|
-
Renderers::Raw.new(self).render(snip, part
|
|
48
|
+
Renderers::Raw.new(self).render(snip, part)
|
|
46
49
|
when 'text', 'atom', 'xml'
|
|
47
|
-
render(snip, part
|
|
50
|
+
render(snip, part)
|
|
48
51
|
else
|
|
49
52
|
raise "Unknown format '#{format}'"
|
|
50
53
|
end
|
|
@@ -78,7 +81,7 @@ module Vanilla
|
|
|
78
81
|
elsif snip && snip.extension && !snip.extension.empty?
|
|
79
82
|
Vanilla::Renderers.const_get(renderer_for_extension(snip.extension))
|
|
80
83
|
else
|
|
81
|
-
|
|
84
|
+
default_renderer
|
|
82
85
|
end
|
|
83
86
|
end
|
|
84
87
|
|
|
@@ -86,6 +89,10 @@ module Vanilla
|
|
|
86
89
|
soup[config[:default_layout_snip] || 'layout']
|
|
87
90
|
end
|
|
88
91
|
|
|
92
|
+
def default_renderer
|
|
93
|
+
config[:default_renderer] || Vanilla::Renderers::Base
|
|
94
|
+
end
|
|
95
|
+
|
|
89
96
|
def layout_for(snip)
|
|
90
97
|
if snip
|
|
91
98
|
renderer_for(snip).new(self).layout_for(snip)
|
|
@@ -94,34 +101,23 @@ module Vanilla
|
|
|
94
101
|
end
|
|
95
102
|
end
|
|
96
103
|
|
|
97
|
-
# Other things can call this when a snip cannot be loaded.
|
|
98
|
-
def render_missing_snip(snip_name)
|
|
99
|
-
"[snip '#{snip_name}' cannot be found]"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
104
|
def snip(attributes)
|
|
103
105
|
@soup << attributes
|
|
104
106
|
end
|
|
105
107
|
|
|
106
108
|
private
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
mapping[extension]
|
|
116
|
-
end
|
|
110
|
+
DEFAULT_EXTENSION_RENDERERS = Hash.new("Base").merge({
|
|
111
|
+
"markdown" => "Markdown",
|
|
112
|
+
"textile" => "Textile",
|
|
113
|
+
"erb" => "Erb",
|
|
114
|
+
"rb" => "Ruby",
|
|
115
|
+
"haml" => "Haml"
|
|
116
|
+
})
|
|
117
117
|
|
|
118
|
-
def
|
|
119
|
-
|
|
120
|
-
@
|
|
121
|
-
@config[:filename] = config_file
|
|
122
|
-
def @config.save!
|
|
123
|
-
File.open(self[:filename], 'w') { |f| f.puts self.to_yaml }
|
|
124
|
-
end
|
|
118
|
+
def renderer_for_extension(extension)
|
|
119
|
+
@renderer_mapping ||= DEFAULT_EXTENSION_RENDERERS.merge(@config[:extensions] || {})
|
|
120
|
+
@renderer_mapping[extension]
|
|
125
121
|
end
|
|
126
122
|
|
|
127
123
|
def prepare_soup(config)
|
|
@@ -50,11 +50,10 @@ module Vanilla
|
|
|
50
50
|
# Render the snip or snip part with the given args, and the current
|
|
51
51
|
# context, but with the default renderer for that snip. We dispatch
|
|
52
52
|
# *back* out to the root Vanilla.render method to do this.
|
|
53
|
-
snip = soup[snip_name]
|
|
54
|
-
if snip
|
|
53
|
+
if snip = soup[snip_name]
|
|
55
54
|
app.render(snip, snip_attribute, snip_args, enclosing_snip)
|
|
56
55
|
else
|
|
57
|
-
|
|
56
|
+
render_missing_snip(snip_name)
|
|
58
57
|
end
|
|
59
58
|
else
|
|
60
59
|
"malformed snip reference: #{$1.inspect}"
|
|
@@ -67,6 +66,10 @@ module Vanilla
|
|
|
67
66
|
@parser.parse(string)
|
|
68
67
|
end
|
|
69
68
|
|
|
69
|
+
def render_missing_snip(snip_name)
|
|
70
|
+
"[snip '#{snip_name}' cannot be found]"
|
|
71
|
+
end
|
|
72
|
+
|
|
70
73
|
# Default rendering behaviour. Subclasses shouldn't really need to touch this.
|
|
71
74
|
def render(snip, part=:content, args=[], enclosing_snip=snip)
|
|
72
75
|
prepare(snip, part, args, enclosing_snip)
|
data/lib/vanilla/request.rb
CHANGED
|
@@ -48,7 +48,7 @@ module Vanilla
|
|
|
48
48
|
request.path_info
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
URL_ROOT = /\A
|
|
51
|
+
URL_ROOT = /\A\/?\Z/ # i.e. / or nothing
|
|
52
52
|
URL_SNIP = /\A\/([\w\-\s]+)(\/|\.(\w+))?\Z/ # i.e. /start, /start.html
|
|
53
53
|
URL_SNIP_AND_PART = /\A\/([\w\-\s]+)\/([\w\-\s]+)(\/|\.(\w+))?\Z/ # i.e. /blah/part, /blah/part.raw
|
|
54
54
|
|
data/test/soup/blah.snip
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
{current_snip name}
|
|
11
|
+
|
|
12
|
+
will output the name of the current snip, or the name of the snip currently being edited.
|
|
13
|
+
:render_as: Ruby
|
|
14
|
+
:name: current_snip
|
data/test/soup/test.snip
ADDED
data/test/test_helper.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'bundler/setup'
|
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
|
4
4
|
|
|
5
5
|
require "kintama"
|
|
6
|
-
require "mocha"
|
|
6
|
+
require "kintama/mocha"
|
|
7
7
|
require "fileutils"
|
|
8
8
|
require "rack/mock"
|
|
9
9
|
require "vanilla"
|
|
@@ -11,9 +11,8 @@ require "vanilla"
|
|
|
11
11
|
module Vanilla
|
|
12
12
|
module Test
|
|
13
13
|
def setup_clean_environment
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@app = Vanilla::App.new(config_file_for_tests)
|
|
14
|
+
clean_environment
|
|
15
|
+
@app = Vanilla::App.new(:soup => soup_path)
|
|
17
16
|
|
|
18
17
|
require "vanilla/dynasnips/current_snip"
|
|
19
18
|
@app.soup << CurrentSnip.snip_attributes
|
|
@@ -56,17 +55,13 @@ module Vanilla
|
|
|
56
55
|
File.join(File.dirname(__FILE__), "tmp")
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
def config_file_for_tests
|
|
60
|
-
File.join(test_app_directory, "config.yml")
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def config_for_tests(options={})
|
|
64
|
-
File.open(config_file_for_tests, 'w') { |f| f.write({:soup => soup_path}.update(options).to_yaml) }
|
|
65
|
-
end
|
|
66
|
-
|
|
67
58
|
def soup_path
|
|
68
59
|
File.expand_path(File.join(test_app_directory, "soup"))
|
|
69
60
|
end
|
|
61
|
+
|
|
62
|
+
def clean_environment
|
|
63
|
+
FileUtils.rm_rf(test_app_directory)
|
|
64
|
+
end
|
|
70
65
|
end
|
|
71
66
|
end
|
|
72
67
|
|
|
@@ -76,16 +71,5 @@ Kintama.setup do
|
|
|
76
71
|
end
|
|
77
72
|
|
|
78
73
|
Kintama.teardown do
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
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
|
|
90
|
-
end
|
|
74
|
+
clean_environment
|
|
91
75
|
end
|
data/test/vanilla_app_test.rb
CHANGED
|
@@ -13,32 +13,22 @@ describe Vanilla::App do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
context "when being configured" do
|
|
16
|
-
should "
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
should "default the root snip to 'start'" do
|
|
17
|
+
create_snip :name => "start", :content => "default"
|
|
18
|
+
assert_response_body "default", "/"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
should "
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
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({:soup => soup_path, :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
|
-
assert config[:saved]
|
|
21
|
+
should "allow a customised root snip" do
|
|
22
|
+
create_snip :name => "start", :content => "default"
|
|
23
|
+
create_snip :name => "custom", :content => "custom"
|
|
24
|
+
@app = Vanilla::App.new(:soup => soup_path, :root_snip => "custom")
|
|
25
|
+
assert_response_body "custom", "/"
|
|
36
26
|
end
|
|
37
27
|
end
|
|
38
28
|
|
|
39
29
|
context "when detecting the snip renderer" do
|
|
40
30
|
setup do
|
|
41
|
-
@app = Vanilla::App.new
|
|
31
|
+
@app = Vanilla::App.new
|
|
42
32
|
end
|
|
43
33
|
|
|
44
34
|
should "return the constant refered to in the render_as property of the snip" do
|
|
@@ -61,6 +51,12 @@ describe Vanilla::App do
|
|
|
61
51
|
end
|
|
62
52
|
end
|
|
63
53
|
|
|
54
|
+
should "respect snip extensions pass in the config" do
|
|
55
|
+
app = Vanilla::App.new(:extensions => {"markdown" => "Bold"})
|
|
56
|
+
snip = create_snip(:name => "blah", :extension => "markdown")
|
|
57
|
+
assert_equal Vanilla::Renderers::Bold, app.renderer_for(snip)
|
|
58
|
+
end
|
|
59
|
+
|
|
64
60
|
should "return Vanilla::Renderers::Base if no render_as property exists" do
|
|
65
61
|
snip = create_snip(:name => "blah")
|
|
66
62
|
assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
|
|
@@ -94,6 +94,15 @@ context "When presenting" do
|
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
+
context "and a custom default renderer has been provided" do
|
|
98
|
+
should "use that renderer" do
|
|
99
|
+
@app = Vanilla::App.new(:default_renderer => ::Vanilla::Renderers::Bold)
|
|
100
|
+
create_snip :name => "layout", :content => "{current_snip}", :render_as => "Base"
|
|
101
|
+
create_snip :name => "test", :content => "test"
|
|
102
|
+
assert_response_body "<b>test</b>", "/test"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
97
106
|
context "and a missing snip is requested" do
|
|
98
107
|
should "render missing snip content in the main template" do
|
|
99
108
|
assert_response_body "<tag>Couldn't find snip #{LinkTo.new(@app).handle("missing_snip")}</tag>", "/missing_snip"
|
|
@@ -11,17 +11,6 @@ describe Vanilla::Request do
|
|
|
11
11
|
should "set format to 'html'" do
|
|
12
12
|
assert_equal "html", @request.format
|
|
13
13
|
end
|
|
14
|
-
|
|
15
|
-
context "with a start snip configuration set" do
|
|
16
|
-
setup do
|
|
17
|
-
config_for_tests(:root_snip => "custom")
|
|
18
|
-
@app = Vanilla::App.new(config_file_for_tests)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
should "use specified snip as default" do
|
|
22
|
-
assert_equal "custom", Vanilla::Request.new(mock_env_for_url("/"), @app).snip_name
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
14
|
end
|
|
26
15
|
|
|
27
16
|
context "when requesting urls" do
|
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: 37
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 13
|
|
9
|
-
-
|
|
10
|
-
version: 1.13.
|
|
9
|
+
- 3
|
|
10
|
+
version: 1.13.3
|
|
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-
|
|
18
|
+
date: 2011-04-20 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -136,10 +136,12 @@ dependencies:
|
|
|
136
136
|
requirements:
|
|
137
137
|
- - ">="
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
|
-
hash:
|
|
139
|
+
hash: 17
|
|
140
140
|
segments:
|
|
141
141
|
- 0
|
|
142
|
-
|
|
142
|
+
- 1
|
|
143
|
+
- 5
|
|
144
|
+
version: 0.1.5
|
|
143
145
|
type: :development
|
|
144
146
|
version_requirements: *id008
|
|
145
147
|
- !ruby/object:Gem::Dependency
|
|
@@ -179,6 +181,16 @@ files:
|
|
|
179
181
|
- test/ruby_renderer_test.rb
|
|
180
182
|
- test/snip_reference_parser_test.rb
|
|
181
183
|
- test/snip_reference_test.rb
|
|
184
|
+
- test/soup/blah.snip
|
|
185
|
+
- test/soup/blah.snip.erb
|
|
186
|
+
- test/soup/blah.snip.haml
|
|
187
|
+
- test/soup/blah.snip.markdown
|
|
188
|
+
- test/soup/blah.snip.rb
|
|
189
|
+
- test/soup/blah.snip.textile
|
|
190
|
+
- test/soup/current_snip.snip
|
|
191
|
+
- test/soup/layout.snip
|
|
192
|
+
- test/soup/test.snip
|
|
193
|
+
- test/soup/test_dyna.snip
|
|
182
194
|
- test/test_helper.rb
|
|
183
195
|
- test/vanilla_app_test.rb
|
|
184
196
|
- test/vanilla_presenting_test.rb
|