vanilla 1.11.4 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ if Object.const_defined?(:Gem)
24
24
 
25
25
  # Change these as appropriate
26
26
  s.name = "vanilla"
27
- s.version = "1.11.4"
27
+ s.version = "1.12.1"
28
28
  s.summary = "A bliki-type web content thing."
29
29
  s.author = "James Adam"
30
30
  s.email = "james@lazyatom.com.com"
@@ -57,18 +57,37 @@ if Object.const_defined?(:Gem)
57
57
  s.rubyforge_project = "vanilla"
58
58
  end
59
59
 
60
- # This task actually builds the gem. We also regenerate a static
60
+ # This task actually builds the gem. We also regenerate a static
61
61
  # .gemspec file, which is useful if something (i.e. GitHub) will
62
62
  # be automatically building a gem for this project. If you're not
63
63
  # using GitHub, edit as appropriate.
64
+ #
65
+ # To publish your gem online, install the 'gemcutter' gem; Read more
66
+ # about that here: http://gemcutter.org/pages/gem_docs
64
67
  Rake::GemPackageTask.new(spec) do |pkg|
65
68
  pkg.gem_spec = spec
69
+ end
66
70
 
67
- # Generate the gemspec file for github.
68
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
69
- File.open(file, "w") {|f| f << spec.to_ruby }
71
+ # Stolen from jeweler
72
+ def prettyify_array(gemspec_ruby, array_name)
73
+ gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
74
+ leadin, files = match[0..-2].split("[")
75
+ leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
76
+ end
70
77
  end
71
78
 
79
+ task :gemspec do
80
+ output = spec.to_ruby
81
+ output = prettyify_array(output, :files)
82
+ output = prettyify_array(output, :test_files)
83
+ output = prettyify_array(output, :extra_rdoc_files)
84
+
85
+ file = File.expand_path("../#{spec.name}.gemspec", __FILE__)
86
+ File.open(file, "w") {|f| f << output }
87
+ end
88
+
89
+ task :package => :gemspec
90
+
72
91
  # Generate documentation
73
92
  Rake::RDocTask.new do |rd|
74
93
  rd.main = "README"
@@ -81,47 +100,20 @@ if Object.const_defined?(:Gem)
81
100
  rm "#{spec.name}.gemspec"
82
101
  end
83
102
 
84
- # If you want to publish to RubyForge automatically, here's a simple
85
- # task to help do that. If you don't, just get rid of this.
86
- # Be sure to set up your Rubyforge account details with the Rubyforge
87
- # gem; you'll need to run `rubyforge setup` and `rubyforge config` at
88
- # the very least.
89
- begin
90
- require "rake/contrib/sshpublisher"
91
- namespace :rubyforge do
92
-
93
- desc "Release gem and RDoc documentation to RubyForge"
94
- task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
95
-
96
- namespace :release do
97
- desc "Release a new version of this gem"
98
- task :gem => [:package] do
99
- require 'rubyforge'
100
- rubyforge = RubyForge.new
101
- rubyforge.configure
102
- rubyforge.login
103
- rubyforge.userconfig['release_notes'] = spec.summary
104
- path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem")
105
- puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..."
106
- rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem)
107
- end
108
-
109
- desc "Publish RDoc to RubyForge."
110
- task :docs => [:rdoc] do
111
- config = YAML.load(
112
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
113
- )
114
-
115
- host = "#{config['username']}@rubyforge.org"
116
- remote_dir = "/var/www/gforge-projects/vanilla-rb/" # Should be the same as the rubyforge project name
117
- local_dir = 'rdoc'
118
-
119
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
120
- end
103
+ desc 'Tag the repository in git with gem version number'
104
+ task :tag => [:gemspec, :package] do
105
+ if `git diff --cached`.empty?
106
+ if `git tag`.split("\n").include?("v#{spec.version}")
107
+ raise "Version #{spec.version} has already been released"
121
108
  end
109
+ `git add #{File.expand_path("../#{spec.name}.gemspec", __FILE__)}`
110
+ `git commit -m "Released version #{spec.version}"`
111
+ `git tag v#{spec.version}`
112
+ `git push --tags`
113
+ `git push`
114
+ else
115
+ raise "Unstaged changes still waiting to be committed"
122
116
  end
123
- rescue LoadError
124
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
125
117
  end
126
118
  else
127
119
  puts "Gem management tasks unavailable, as rubygems was not fully loaded."
File without changes
data/config.ru CHANGED
@@ -1,4 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
1
3
  $:.unshift File.join(File.dirname(__FILE__), *%w[lib])
4
+
2
5
  require 'vanilla'
3
6
  require 'vanilla/static'
4
7
 
@@ -1,14 +1,13 @@
1
+ require 'soup'
1
2
  require 'vanilla/request'
2
3
  require 'vanilla/authentication'
3
4
  require 'vanilla/routes'
4
- require 'vanilla/soup/timestamp_backend'
5
5
 
6
6
  # Require the base set of renderers
7
7
  require 'vanilla/renderers/base'
8
8
  require 'vanilla/renderers/raw'
9
9
  require 'vanilla/renderers/erb'
10
10
 
11
-
12
11
  module Vanilla
13
12
  class App
14
13
  include Routes
@@ -32,7 +31,7 @@ module Vanilla
32
31
  output = formatted_render(request.snip, request.part, request.format)
33
32
  rescue => e
34
33
  @response.status = 500
35
- output = e.to_s
34
+ output = e.to_s + e.backtrace.join("\n")
36
35
  end
37
36
  response_format = request.format
38
37
  response_format = 'plain' if response_format == 'raw'
@@ -44,7 +43,7 @@ module Vanilla
44
43
  def formatted_render(snip, part=nil, format=nil)
45
44
  case format
46
45
  when 'html', nil
47
- Renderers::Erb.new(self).render(soup['system'], :main_template)
46
+ render(layout_for(snip))
48
47
  when 'raw', 'css', 'js'
49
48
  Renderers::Raw.new(self).render(snip, part || :content)
50
49
  when 'text', 'atom', 'xml'
@@ -69,15 +68,31 @@ module Vanilla
69
68
  renderer_instance = renderer_for(snip).new(self)
70
69
  yield renderer_instance
71
70
  rescue Exception => e
72
- "<pre>[Error rendering '#{snip.name}' - \"" +
71
+ snip_name = snip ? snip.name : nil
72
+ "<pre>[Error rendering '#{snip_name}' - \"" +
73
73
  e.message.gsub("<", "&lt;").gsub(">", "&gt;") + "\"]\n" +
74
74
  e.backtrace.join("\n").gsub("<", "&lt;").gsub(">", "&gt;") + "</pre>"
75
75
  end
76
76
 
77
77
  # Returns the renderer class for a given snip
78
78
  def renderer_for(snip)
79
- return Renderers::Base unless snip.render_as && !snip.render_as.empty?
80
- Vanilla::Renderers.const_get(snip.render_as)
79
+ if snip && snip.render_as && !snip.render_as.empty?
80
+ Vanilla::Renderers.const_get(snip.render_as)
81
+ else
82
+ Vanilla::Renderers::Base
83
+ end
84
+ end
85
+
86
+ def default_layout_snip
87
+ soup[config[:default_layout_snip] || 'layout']
88
+ end
89
+
90
+ def layout_for(snip)
91
+ if snip
92
+ renderer_for(snip).new(self).layout_for(snip)
93
+ else
94
+ default_layout_snip
95
+ end
81
96
  end
82
97
 
83
98
  # Other things can call this when a snip cannot be loaded.
@@ -30,6 +30,14 @@ module Vanilla
30
30
  %r{(\{[\w\-_\d]+(\s+[^\}.]+)?\})}
31
31
  end
32
32
 
33
+ def default_layout_snip
34
+ app.default_layout_snip
35
+ end
36
+
37
+ def layout_for(snip)
38
+ layout_snip = (snip && snip.layout) ? soup[snip.layout] : default_layout_snip
39
+ end
40
+
33
41
  # Default behaviour to include a snip's content
34
42
  def include_snips(content, enclosing_snip)
35
43
  content.gsub(Vanilla::Renderers::Base.snip_regexp) do
@@ -1,3 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
1
5
  require "shoulda"
2
6
  require "mocha"
3
7
  require "fileutils"
@@ -14,7 +18,7 @@ module Vanilla
14
18
 
15
19
  require "vanilla/dynasnips/current_snip"
16
20
  @app.soup << CurrentSnip.snip_attributes
17
- create_snip :name => "system", :main_template => "{current_snip}"
21
+ create_snip :name => "layout", :content => "{current_snip}"
18
22
  end
19
23
 
20
24
  def response_for(url)
@@ -34,9 +38,7 @@ module Vanilla
34
38
  end
35
39
 
36
40
  def set_main_template(template_content)
37
- system = @app.soup["system"] || Soup::Snip.new({:name => "system"}, @app.soup)
38
- system.main_template = template_content
39
- system.save
41
+ @app.soup << {:name => "layout", :content => template_content}
40
42
  end
41
43
 
42
44
  def create_snip(params)
@@ -1,2 +1,2 @@
1
1
  ---
2
- :soup: /Users/james/Code/lazyatom/vanilla-rb/test/tmp/soup
2
+ :soup: /Users/james/Dropbox/Code/vanilla-rb/test/tmp/soup
@@ -1,4 +1,5 @@
1
- CurrentSnip--- # Soup attributes
1
+ CurrentSnip
2
+
2
3
  :usage: |-
3
4
  The current_snip dyna normally returns the result of rendering the snip named by the
4
5
  'snip' value in the parameters. This way, it can be used in templates to place the currently
@@ -9,7 +10,5 @@ CurrentSnip--- # Soup attributes
9
10
  &#123;current_snip name&#125;
10
11
 
11
12
  will output the name of the current snip, or the name of the snip currently being edited.
12
- :created_at: 2010-07-14 13:45:49.767720 +01:00
13
13
  :name: current_snip
14
- :updated_at: 2010-07-14 13:45:49.767722 +01:00
15
14
  :render_as: Ruby
@@ -0,0 +1,3 @@
1
+ {current_snip}
2
+
3
+ :name: layout
@@ -64,6 +64,37 @@ class VanillaPresentingTest < Vanilla::TestCase
64
64
  end
65
65
  end
66
66
 
67
+ context "when presenting a snip with a custom layout" do
68
+ should "render the snips contents within that layout" do
69
+ create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
70
+ create_snip :name => "test", :content => "this is a test", :layout => "custom-layout"
71
+ assert_response_body "<custom>this is a test</custom>", "/test"
72
+ end
73
+ end
74
+
75
+ class ::Vanilla::Renderers::Custom < ::Vanilla::Renderers::Base
76
+ def default_layout_snip
77
+ soup['custom-layout']
78
+ end
79
+ end
80
+
81
+ context "when presenting a snip using a renderer that specifies a template" do
82
+ setup do
83
+ create_snip :name => "custom-layout", :content => "<custom>{current_snip}</custom>"
84
+ end
85
+
86
+ should "use the renderer's specified layout" do
87
+ create_snip :name => "test", :content => "this is a test", :render_as => "Custom"
88
+ assert_response_body "<custom>this is a test</custom>", "/test"
89
+ end
90
+
91
+ should "use the snips layout when given" do
92
+ create_snip :name => "snip-custom-layout", :content => "<snipcustom>{current_snip}</snipcustom>"
93
+ create_snip :name => "test", :content => "this is a test", :render_as => "Custom", :layout => "snip-custom-layout"
94
+ assert_response_body "<snipcustom>this is a test</snipcustom>", "/test"
95
+ end
96
+ end
97
+
67
98
  context "when a missing snip is requested" do
68
99
  should "render missing snip content in the main template" do
69
100
  assert_response_body "<tag>Couldn't find snip #{LinkTo.new(@app).handle("missing_snip")}</tag>", "/missing_snip"
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 37
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 11
8
- - 4
9
- version: 1.11.4
8
+ - 12
9
+ - 1
10
+ version: 1.12.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - James Adam
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-08 00:00:00 +01:00
18
+ date: 2010-11-18 00:00:00 +00:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rack
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 57
27
30
  segments:
28
31
  - 0
29
32
  - 9
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: soup
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 23
41
46
  segments:
42
47
  - 1
43
48
  - 0
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: ratom
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 25
55
62
  segments:
56
63
  - 0
57
64
  - 3
@@ -63,9 +70,11 @@ dependencies:
63
70
  name: RedCloth
64
71
  prerelease: false
65
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
66
74
  requirements:
67
75
  - - ">="
68
76
  - !ruby/object:Gem::Version
77
+ hash: 57
69
78
  segments:
70
79
  - 4
71
80
  - 1
@@ -77,9 +86,11 @@ dependencies:
77
86
  name: BlueCloth
78
87
  prerelease: false
79
88
  requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
80
90
  requirements:
81
91
  - - ">="
82
92
  - !ruby/object:Gem::Version
93
+ hash: 23
83
94
  segments:
84
95
  - 1
85
96
  - 0
@@ -91,9 +102,11 @@ dependencies:
91
102
  name: treetop
92
103
  prerelease: false
93
104
  requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
94
106
  requirements:
95
107
  - - ">="
96
108
  - !ruby/object:Gem::Version
109
+ hash: 5
97
110
  segments:
98
111
  - 1
99
112
  - 4
@@ -105,9 +118,11 @@ dependencies:
105
118
  name: warden
106
119
  prerelease: false
107
120
  requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
108
122
  requirements:
109
123
  - - ">="
110
124
  - !ruby/object:Gem::Version
125
+ hash: 15
111
126
  segments:
112
127
  - 0
113
128
  - 5
@@ -119,9 +134,11 @@ dependencies:
119
134
  name: shoulda
120
135
  prerelease: false
121
136
  requirement: &id008 !ruby/object:Gem::Requirement
137
+ none: false
122
138
  requirements:
123
139
  - - ">="
124
140
  - !ruby/object:Gem::Version
141
+ hash: 3
125
142
  segments:
126
143
  - 0
127
144
  version: "0"
@@ -131,9 +148,11 @@ dependencies:
131
148
  name: mocha
132
149
  prerelease: false
133
150
  requirement: &id009 !ruby/object:Gem::Requirement
151
+ none: false
134
152
  requirements:
135
153
  - - ">="
136
154
  - !ruby/object:Gem::Version
155
+ hash: 3
137
156
  segments:
138
157
  - 0
139
158
  version: "0"
@@ -143,9 +162,11 @@ dependencies:
143
162
  name: haml
144
163
  prerelease: false
145
164
  requirement: &id010 !ruby/object:Gem::Requirement
165
+ none: false
146
166
  requirements:
147
167
  - - ">="
148
168
  - !ruby/object:Gem::Version
169
+ hash: 3
149
170
  segments:
150
171
  - 0
151
172
  version: "0"
@@ -176,12 +197,11 @@ files:
176
197
  - test/snip_reference_test.rb
177
198
  - test/test_helper.rb
178
199
  - test/tmp/config.yml
179
- - test/tmp/soup/current_snip.yml
180
- - test/tmp/soup/system.yml
200
+ - test/tmp/soup/current_snip.snip
201
+ - test/tmp/soup/layout.snip
181
202
  - test/vanilla_app_test.rb
182
203
  - test/vanilla_presenting_test.rb
183
204
  - test/vanilla_request_test.rb
184
- - test/vanilla_soup_test.rb
185
205
  - lib/defensio.rb
186
206
  - lib/tasks/vanilla.rake
187
207
  - lib/vanilla/app.rb
@@ -221,7 +241,6 @@ files:
221
241
  - lib/vanilla/snips/start.rb
222
242
  - lib/vanilla/snips/system.rb
223
243
  - lib/vanilla/snips/tutorial.rb
224
- - lib/vanilla/soup/timestamp_backend.rb
225
244
  - lib/vanilla/static.rb
226
245
  - lib/vanilla.rb
227
246
  - bin/vanilla
@@ -240,23 +259,27 @@ rdoc_options:
240
259
  require_paths:
241
260
  - lib
242
261
  required_ruby_version: !ruby/object:Gem::Requirement
262
+ none: false
243
263
  requirements:
244
264
  - - ">="
245
265
  - !ruby/object:Gem::Version
266
+ hash: 3
246
267
  segments:
247
268
  - 0
248
269
  version: "0"
249
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
+ none: false
250
272
  requirements:
251
273
  - - ">="
252
274
  - !ruby/object:Gem::Version
275
+ hash: 3
253
276
  segments:
254
277
  - 0
255
278
  version: "0"
256
279
  requirements: []
257
280
 
258
281
  rubyforge_project: vanilla
259
- rubygems_version: 1.3.6
282
+ rubygems_version: 1.3.7
260
283
  signing_key:
261
284
  specification_version: 3
262
285
  summary: A bliki-type web content thing.
@@ -1,22 +0,0 @@
1
- require 'soup'
2
-
3
- module Vanilla
4
- module Soup
5
- class TimestampBackend
6
- def initialize(backend)
7
- @backend = backend
8
- end
9
-
10
- def save_snip(attributes)
11
- attributes[:created_at] ||= Time.now
12
- attributes[:created_at] = Time.parse(attributes[:created_at]) if attributes[:created_at].is_a?(String)
13
- attributes[:updated_at] = Time.now
14
- @backend.save_snip(attributes)
15
- end
16
-
17
- def method_missing(*args)
18
- @backend.__send__(*args)
19
- end
20
- end
21
- end
22
- end
@@ -1,5 +0,0 @@
1
- --- # Soup attributes
2
- :created_at: 2010-07-14 13:45:49.768201 +01:00
3
- :name: system
4
- :updated_at: 2010-07-14 13:45:49.768203 +01:00
5
- :main_template: "{current_snip}"
@@ -1,8 +0,0 @@
1
- require "test_helper"
2
-
3
- class VanillaSoupTest < Vanilla::TestCase
4
- should "convert timestamps to times" do
5
- snip = create_snip(:name => "temp", :created_at => Time.now.to_s)
6
- assert_kind_of Time, @app.soup["temp"].created_at
7
- end
8
- end