sinatra-partial 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ ## v0.3.1 ##
2
+
3
+ 28th of May 2012
4
+
5
+ * Fixed a bug where partials called within a route would not have layout set to false by default. To be honest, I think it's a change in the Sinatra codebase, but it was easily fixed by setting layout to false with the partial method. This does, however, mean that partial can't be called to run a layout, but if you're using it that way then you're using it wrong! Try just calling `haml` or `erb`.
6
+ * Improved the examples by adding a config.rb and config.ru. Not only does it mean the examples can be run from the command line easier, but I think it's a good way to set up an app to help with testing.
7
+
1
8
  ## v0.3.0 ##
2
9
 
3
10
  23rd of April 2012
@@ -4,14 +4,17 @@ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
4
  require_relative "../../lib/sinatra/partial.rb"
5
5
  require_relative "../whitespace_remove.rb"
6
6
 
7
-
8
- class AppNoUnderscores < Sinatra::Base
9
- register Sinatra::Partial
10
- use WhiteSpaceRemove
11
-
12
- News = ["This", "is", "all", "new"]
13
-
14
- get "/" do
15
- haml :home
7
+ module AppNoUnderscores
8
+ class App < Sinatra::Base
9
+ register Sinatra::Partial
10
+ use WhiteSpaceRemove
11
+
12
+ News = ["This", "is", "all", "new"]
13
+
14
+
15
+ get "/" do
16
+ magic = partial :magic
17
+ haml :home, :locals => { :show_me_magic => magic }
18
+ end
16
19
  end
17
- end
20
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module AppNoUnderscores
4
+
5
+ require_relative "./app.rb"
6
+
7
+ def self.app
8
+ Rack::Builder.app do
9
+ run App
10
+ end
11
+ end # self.app
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ root = File.expand_path File.dirname(__FILE__)
8
+ require File.join( root , "./config.rb" )
9
+
10
+ # everything else separate module/file (config.rb) to make it easier to set up tests
11
+
12
+ map "/" do
13
+ run AppNoUnderscores.app
14
+ end
@@ -1,2 +1,4 @@
1
1
  %p
2
2
  Hello, World
3
+
4
+ #{show_me_magic}
@@ -0,0 +1,2 @@
1
+ %p
2
+ Show me magic!
@@ -4,16 +4,19 @@ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
4
  require_relative "../../lib/sinatra/partial.rb"
5
5
  require_relative "../whitespace_remove.rb"
6
6
 
7
- class AppWithUnderscores < Sinatra::Base
8
- register Sinatra::Partial
9
- use WhiteSpaceRemove
10
-
11
- News = ["This", "is", "all", "new"]
12
-
13
- set :partial_underscores, true
14
-
15
-
16
- get "/" do
17
- haml :home
7
+ module AppWithUnderscores
8
+ class App < Sinatra::Base
9
+ register Sinatra::Partial
10
+ use WhiteSpaceRemove
11
+
12
+ News = ["This", "is", "all", "new"]
13
+
14
+ set :partial_underscores, true
15
+
16
+
17
+ get "/" do
18
+ magic = partial :magic
19
+ haml :home, :locals => { :show_me_magic => magic }
20
+ end
18
21
  end
19
- end
22
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module AppWithUnderscores
4
+
5
+ require_relative "./app.rb"
6
+
7
+ def self.app
8
+ Rack::Builder.app do
9
+ run App
10
+ end
11
+ end # self.app
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ root = File.expand_path File.dirname(__FILE__)
8
+ require File.join( root , "./config.rb" )
9
+
10
+ # everything else separate module/file (config.rb) to make it easier to set up tests
11
+
12
+ map "/" do
13
+ run AppWithUnderscores.app
14
+ end
@@ -0,0 +1,2 @@
1
+ %p
2
+ Show me magic!
@@ -1,2 +1,3 @@
1
1
  %p
2
2
  Hello, World
3
+ #{show_me_magic}
@@ -4,16 +4,19 @@ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
4
  require_relative "../../lib/sinatra/partial.rb"
5
5
  require_relative "../whitespace_remove.rb"
6
6
 
7
- class AppWithUnderscoresAndErb < Sinatra::Base
8
- register Sinatra::Partial
9
- use WhiteSpaceRemove
10
-
11
- News = ["This", "is", "all", "new"]
12
-
13
- set :partial_underscores, true
14
- set :partial_template_engine, :erb
7
+ module AppWithUnderscoresAndErb
8
+ class App < Sinatra::Base
9
+ register Sinatra::Partial
10
+ use WhiteSpaceRemove
15
11
 
16
- get "/" do
17
- erb :home
12
+ News = ["This", "is", "all", "new"]
13
+
14
+ enable :partial_underscores
15
+ set :partial_template_engine, :erb
16
+
17
+ get "/" do
18
+ magic = partial :magic
19
+ erb :home, :locals => { :show_me_magic => magic }
20
+ end
18
21
  end
19
22
  end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module AppWithUnderscoresAndErb
4
+
5
+ require_relative "./app.rb"
6
+
7
+ def self.app
8
+ Rack::Builder.app do
9
+ run App
10
+ end
11
+ end # self.app
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ root = File.expand_path File.dirname(__FILE__)
8
+ require File.join( root , "./config.rb" )
9
+
10
+ # everything else separate module/file (config.rb) to make it easier to set up tests
11
+
12
+ map "/" do
13
+ run AppWithUnderscoresAndErb.app
14
+ end
@@ -0,0 +1 @@
1
+ <p>Show me magic!</p>
@@ -1,3 +1,4 @@
1
1
  <p>
2
2
  Hello, World
3
- </p>
3
+ </p>
4
+ <%= show_me_magic %>
@@ -4,18 +4,20 @@ require File.expand_path( File.join File.dirname(__FILE__), "../ext/kernel.rb")
4
4
  require_relative "../../lib/sinatra/partial.rb"
5
5
  require_relative "../whitespace_remove.rb"
6
6
 
7
- class AppWithUnderscoresAndErbAndSubdirs < Sinatra::Base
8
- register Sinatra::Partial
9
- use WhiteSpaceRemove
10
-
11
- News = ["This", "is", "all", "new"]
12
-
13
- set :partial_underscores, true
14
- set :partial_template_engine, :erb
15
-
16
-
17
- get "/" do
18
- erb :home
7
+ module AppWithUnderscoresAndErbAndSubdirs
8
+ class App < Sinatra::Base
9
+ register Sinatra::Partial
10
+ use WhiteSpaceRemove
11
+
12
+ News = ["This", "is", "all", "new"]
13
+
14
+ enable :partial_underscores
15
+ set :partial_template_engine, :erb
16
+
17
+
18
+ get "/" do
19
+ magic = partial :"partials/magic"
20
+ erb :home, :locals => { :show_me_magic => magic }
21
+ end
19
22
  end
20
- end
21
-
23
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ module AppWithUnderscoresAndErbAndSubdirs
4
+
5
+ require_relative "./app.rb"
6
+
7
+ def self.app
8
+ Rack::Builder.app do
9
+ run App
10
+ end
11
+ end # self.app
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ root = File.expand_path File.dirname(__FILE__)
8
+ require File.join( root , "./config.rb" )
9
+
10
+ # everything else separate module/file (config.rb) to make it easier to set up tests
11
+
12
+ map "/" do
13
+ run AppWithUnderscoresAndErbAndSubdirs.app
14
+ end
@@ -1,3 +1,4 @@
1
1
  <p>
2
2
  Hello, World
3
- </p>
3
+ </p>
4
+ <%= show_me_magic %>
@@ -54,6 +54,7 @@ module Sinatra
54
54
  # # => renders views/meta/_news.haml once per item in :collection,
55
55
  # with the local variable `news` being the current item in the iteration
56
56
  def partial(partial_name, options={})
57
+ options.merge! :layout => false
57
58
  partial_location = partial_name.to_s
58
59
  engine = options.fetch(:template_engine, settings.partial_template_engine)
59
60
  underscores = options.fetch(:underscores, settings.partial_underscores)
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Partial
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
@@ -4,13 +4,13 @@ require "spec_helper"
4
4
 
5
5
  require_relative "../lib/sinatra/partial.rb"
6
6
 
7
- require_relative "../examples/app_no_underscores/app.rb"
8
- require_relative "../examples/app_with_underscores/app.rb"
9
- require_relative "../examples/app_with_underscores_and_erb/app.rb"
10
- require_relative "../examples/app_with_underscores_and_erb_and_subdirs/app.rb"
7
+ require_relative "../examples/app_no_underscores/config.rb"
8
+ require_relative "../examples/app_with_underscores/config.rb"
9
+ require_relative "../examples/app_with_underscores_and_erb/config.rb"
10
+ require_relative "../examples/app_with_underscores_and_erb_and_subdirs/config.rb"
11
11
 
12
12
  shared_examples_for "all in examples dir" do
13
- let(:expected) { "<html><head></head><body><p>Time is #{Time.now}</p><ul><li class='klassic'>This</li><li class='klassic'>is</li><li class='klassic'>all</li><li class='klassic'>new</li></ul><p>A is A</p><p>B is B</p><p>C is C</p><p>D is D</p><p>Hello, World</p></body></html>" }
13
+ let(:expected) { "<html><head></head><body><p>Time is #{Time.now}</p><ul><li class='klassic'>This</li><li class='klassic'>is</li><li class='klassic'>all</li><li class='klassic'>new</li></ul><p>A is A</p><p>B is B</p><p>C is C</p><p>D is D</p><p>Hello, World</p><p>Show me magic!</p></body></html>" }
14
14
  subject { browser.last_response }
15
15
  it { should be_ok }
16
16
  it { subject.body.should == expected }
@@ -24,7 +24,7 @@ Apps = [AppNoUnderscores, AppWithUnderscores, AppWithUnderscoresAndErb, AppWithU
24
24
 
25
25
  Apps.each do |app|
26
26
  describe app.to_s do
27
- let(:browser){ new_session( app ) }
27
+ let(:browser){ new_session( app.app ) }
28
28
  before{ browser.get '/' }
29
29
  it_should_behave_like "all in examples dir"
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-partial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-04-23 00:00:00.000000000 Z
14
+ date: 2012-05-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: sinatra
@@ -44,27 +44,39 @@ files:
44
44
  - README.markdown
45
45
  - Rakefile
46
46
  - examples/app_no_underscores/app.rb
47
+ - examples/app_no_underscores/config.rb
48
+ - examples/app_no_underscores/config.ru
47
49
  - examples/app_no_underscores/views/home.haml
48
50
  - examples/app_no_underscores/views/layout.haml
49
51
  - examples/app_no_underscores/views/locality.haml
52
+ - examples/app_no_underscores/views/magic.haml
50
53
  - examples/app_no_underscores/views/meta.haml
51
54
  - examples/app_no_underscores/views/news.haml
52
55
  - examples/app_with_underscores/app.rb
56
+ - examples/app_with_underscores/config.rb
57
+ - examples/app_with_underscores/config.ru
53
58
  - examples/app_with_underscores/views/_locality.haml
59
+ - examples/app_with_underscores/views/_magic.haml
54
60
  - examples/app_with_underscores/views/_meta.haml
55
61
  - examples/app_with_underscores/views/_news.haml
56
62
  - examples/app_with_underscores/views/home.haml
57
63
  - examples/app_with_underscores/views/layout.haml
58
64
  - examples/app_with_underscores_and_erb/app.rb
65
+ - examples/app_with_underscores_and_erb/config.rb
66
+ - examples/app_with_underscores_and_erb/config.ru
59
67
  - examples/app_with_underscores_and_erb/views/_locality.erb
68
+ - examples/app_with_underscores_and_erb/views/_magic.erb
60
69
  - examples/app_with_underscores_and_erb/views/_meta.erb
61
70
  - examples/app_with_underscores_and_erb/views/_news.erb
62
71
  - examples/app_with_underscores_and_erb/views/home.erb
63
72
  - examples/app_with_underscores_and_erb/views/layout.erb
64
73
  - examples/app_with_underscores_and_erb_and_subdirs/app.rb
74
+ - examples/app_with_underscores_and_erb_and_subdirs/config.rb
75
+ - examples/app_with_underscores_and_erb_and_subdirs/config.ru
65
76
  - examples/app_with_underscores_and_erb_and_subdirs/views/home.erb
66
77
  - examples/app_with_underscores_and_erb_and_subdirs/views/layout.erb
67
78
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_locality.erb
79
+ - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_magic.erb
68
80
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_meta.erb
69
81
  - examples/app_with_underscores_and_erb_and_subdirs/views/partials/_news.erb
70
82
  - examples/ext/kernel.rb
@@ -97,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
109
  version: '0'
98
110
  requirements: []
99
111
  rubyforge_project:
100
- rubygems_version: 1.8.22
112
+ rubygems_version: 1.8.24
101
113
  signing_key:
102
114
  specification_version: 3
103
115
  summary: A sinatra extension for render partials.