sinatra-fuzzy_layout 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59c79a758df3a89091e7651f882fb7c33e4493e5
4
- data.tar.gz: b0250e34e0f1277847914f6abc8e37a541a40f70
3
+ metadata.gz: d74b35bd384d72ec9f024c664944effb024bc428
4
+ data.tar.gz: 5d0d037ef04558e7ce1327c3eb2754fea7e62c6d
5
5
  SHA512:
6
- metadata.gz: dcad67d2e96111669ddb8c029449edac0d09371f09e9b537e471ef1af84c6e60bed2ede7b7fdd1364e91ecc75d50f4e03b9fedfafd49138298abc7dbf7047fa0
7
- data.tar.gz: 3fc6d4d32e10b6e1e1dcbabe8c5e3e9c99c6de7eaa97bb60bab8d916d9c7b14e21f9bb4c0aca13be2ea8dfee20d89235539cd6da80eb61bdebd73f3d3d652883
6
+ metadata.gz: 20f09b9338826f50aa92c735c8fe1b0a399dc2341f8276d302c06c273b54f3aa26f9cb3ca27c15a04c220646e2f4a9172a5483e2eeed56bb1fd41d5717480a63
7
+ data.tar.gz: b3ace296e584e4ca6686ba2e499e2a07635d8eb140e3f8075a7113ec675e5400ad3de6dfd6015df21c857c3dcf770125fccd94bf21f90023d0d99050ba487137
@@ -97,10 +97,11 @@ module Sinatra
97
97
  # A Symbol representing the name of the view. For example, `:index`
98
98
 
99
99
  def get_new_options_and_template(options, template)
100
+ old_option = options.fetch(:layout) { false }
100
101
  if settings.enable_list.has_the_template?(template)
101
- options[:layout] = true
102
+ options.merge!(:layout => (true && old_option))
102
103
  elsif settings.disable_list.has_the_template?(template)
103
- options[:layout] = false
104
+ options.merge!(:layout => (false || old_option))
104
105
  end
105
106
 
106
107
  options
@@ -108,14 +109,16 @@ module Sinatra
108
109
  end
109
110
 
110
111
  def enable_layout_for(*templates)
111
- Base.set :enable_list, templates || []
112
+ settings.enable_list.push(*templates)
112
113
  end
113
114
 
114
115
  def disable_layout_for(*templates)
115
- Base.set :disable_list, templates || []
116
+ settings.disable_list.push(*templates)
116
117
  end
117
118
 
118
119
  def self.registered(app)
120
+ app.set :enable_list, []
121
+ app.set :disable_list, []
119
122
  app.helpers TemplatesHelpers
120
123
  end
121
124
  end
@@ -0,0 +1,15 @@
1
+ require "sinatra"
2
+ require File.expand_path("../../../lib/sinatra/fuzzy_layout.rb", __FILE__)
3
+
4
+ enable_layout_for :one
5
+ disable_layout_for "one", :two, /f\w{3}/
6
+
7
+ get '/' do
8
+ erb :index, :layout => false
9
+ end
10
+
11
+ get('/one') { erb :one }
12
+ get('/two') { erb :two }
13
+ get('/three') { erb :three }
14
+ get('/four') { erb :four, :layout => true }
15
+ get('/five') { erb :five, :layout => false }
@@ -0,0 +1,20 @@
1
+ require "sinatra/base"
2
+ require File.expand_path("../../../lib/sinatra/fuzzy_layout.rb", __FILE__)
3
+
4
+ class SampleApp < Sinatra::Base
5
+ register Sinatra::FuzzyLayout
6
+
7
+ enable_layout_for :one
8
+ disable_layout_for "one"
9
+ disable_layout_for /f\w{3}/
10
+
11
+ get '/' do
12
+ erb :index, :layout => false
13
+ end
14
+
15
+ get('/one') { erb :one }
16
+ get('/two') { erb :two }
17
+ get('/three') { erb :three }
18
+ get('/four') { erb :four }
19
+ get('/five') { erb :five }
20
+ end
@@ -0,0 +1,19 @@
1
+ require "sinatra/base"
2
+ require File.expand_path("../../../lib/sinatra/fuzzy_layout.rb", __FILE__)
3
+
4
+ class SampleApp < Sinatra::Base
5
+ register Sinatra::FuzzyLayout
6
+
7
+ disable_layout_for "one"
8
+ disable_layout_for /f\w{3}/
9
+
10
+ get '/' do
11
+ erb :index, :layout => false
12
+ end
13
+
14
+ get('/one') { erb :one }
15
+ get('/two') { erb :two }
16
+ get('/three') { erb :three }
17
+ get('/four') { erb :four }
18
+ get('/five') { erb :five }
19
+ end
@@ -0,0 +1 @@
1
+ <em>five</em>
@@ -0,0 +1 @@
1
+ <em>four</em>
@@ -0,0 +1 @@
1
+ <em>Spartaa!!</em>
@@ -0,0 +1 @@
1
+ <h1>This is <%= yield %></h1>
@@ -0,0 +1 @@
1
+ <em>one</em>
@@ -0,0 +1 @@
1
+ <em>three</em>
@@ -0,0 +1 @@
1
+ <em>two</em>
@@ -0,0 +1,47 @@
1
+ require_relative "spec_helper"
2
+ require_relative "apps/classic"
3
+
4
+ describe "Classical app structure" do
5
+
6
+ def app
7
+ Sinatra::Application
8
+ end
9
+
10
+ it "should not have a layout for the template 'index.erb'" do
11
+ get('/')
12
+ last_response.should be_ok
13
+ last_response.body.should == "<em>Spartaa!!</em>\n"
14
+ end
15
+
16
+ it "should not have a layout for the template 'one.erb'" do
17
+ get('/one')
18
+ last_response.should be_ok
19
+ last_response.body.should == "<em>one</em>\n"
20
+ end
21
+
22
+ it "should not have a layout for the template 'two.erb'" do
23
+ get('/two')
24
+ last_response.should be_ok
25
+ last_response.body.should == "<em>two</em>\n"
26
+ end
27
+
28
+ it "should have a layout for the template 'three.erb'" do
29
+ get('/three')
30
+ last_response.should be_ok
31
+ last_response.body.should == "<h1>This is <em>three</em>\n</h1>\n"
32
+ end
33
+
34
+ it "should have a layout for the template 'four.erb'" do
35
+ get('/four')
36
+ last_response.should be_ok
37
+ last_response.body.should == "<h1>This is <em>four</em>\n</h1>\n"
38
+ end
39
+
40
+ it "should not have a layout for the template 'five.erb'" do
41
+ get('/five')
42
+ last_response.should be_ok
43
+ last_response.body.should == "<em>five</em>\n"
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,46 @@
1
+ require_relative "spec_helper"
2
+ require_relative "apps/modular"
3
+
4
+ describe 'Modular Style Application' do
5
+
6
+ def app
7
+ SampleApp
8
+ end
9
+
10
+ it "should not have a layout for the template 'index.erb'" do
11
+ get('/')
12
+ last_response.should be_ok
13
+ last_response.body.should == "<em>Spartaa!!</em>\n"
14
+ end
15
+
16
+ it "should not have a layout for the template 'one.erb'" do
17
+ get('/one')
18
+ last_response.should be_ok
19
+ last_response.body.should == "<em>one</em>\n"
20
+ end
21
+
22
+ it "should have a layout for the template 'two.erb'" do
23
+ get('/two')
24
+ last_response.should be_ok
25
+ last_response.body.should == "<h1>This is <em>two</em>\n</h1>\n"
26
+ end
27
+
28
+ it "should have a layout for the template 'three.erb'" do
29
+ get('/three')
30
+ last_response.should be_ok
31
+ last_response.body.should == "<h1>This is <em>three</em>\n</h1>\n"
32
+ end
33
+
34
+ it "should not have a layout for the template 'four.erb'" do
35
+ get('/four')
36
+ last_response.should be_ok
37
+ last_response.body.should == "<em>four</em>\n"
38
+ end
39
+
40
+ it "should not have a layout for the template 'five.erb'" do
41
+ get('/five')
42
+ last_response.should be_ok
43
+ last_response.body.should == "<em>five</em>\n"
44
+ end
45
+
46
+ end
@@ -0,0 +1,46 @@
1
+ require_relative "spec_helper"
2
+ require_relative "apps/modular_without_enable"
3
+
4
+ describe 'Modular Style Application Without Enable Layouts directive' do
5
+
6
+ def app
7
+ SampleApp
8
+ end
9
+
10
+ it "should not have a layout for the template 'index.erb'" do
11
+ get('/')
12
+ last_response.should be_ok
13
+ last_response.body.should == "<em>Spartaa!!</em>\n"
14
+ end
15
+
16
+ it "should not have a layout for the template 'one.erb'" do
17
+ get('/one')
18
+ last_response.should be_ok
19
+ last_response.body.should == "<em>one</em>\n"
20
+ end
21
+
22
+ it "should have a layout for the template 'two.erb'" do
23
+ get('/two')
24
+ last_response.should be_ok
25
+ last_response.body.should == "<h1>This is <em>two</em>\n</h1>\n"
26
+ end
27
+
28
+ it "should have a layout for the template 'three.erb'" do
29
+ get('/three')
30
+ last_response.should be_ok
31
+ last_response.body.should == "<h1>This is <em>three</em>\n</h1>\n"
32
+ end
33
+
34
+ it "should not have a layout for the template 'four.erb'" do
35
+ get('/four')
36
+ last_response.should be_ok
37
+ last_response.body.should == "<em>four</em>\n"
38
+ end
39
+
40
+ it "should not have a layout for the template 'five.erb'" do
41
+ get('/five')
42
+ last_response.should be_ok
43
+ last_response.body.should == "<em>five</em>\n"
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-fuzzy_layout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kashyap
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,24 +81,20 @@ files:
81
81
  - lib/sinatra/fuzzy_layout.rb
82
82
  - Rakefile
83
83
  - README.md
84
- - spec/fuzzy_layout_spec.rb
85
- - spec/sample_app.rb
86
- - spec/sample_app_multiple.rb
84
+ - spec/apps/classic.rb
85
+ - spec/apps/modular.rb
86
+ - spec/apps/modular_without_enable.rb
87
+ - spec/apps/views/five.erb
88
+ - spec/apps/views/four.erb
89
+ - spec/apps/views/index.erb
90
+ - spec/apps/views/layout.erb
91
+ - spec/apps/views/one.erb
92
+ - spec/apps/views/three.erb
93
+ - spec/apps/views/two.erb
94
+ - spec/classic_app_spec.rb
95
+ - spec/modular_app_spec.rb
96
+ - spec/modular_app_without_enable_spec.rb
87
97
  - spec/spec_helper.rb
88
- - spec/views/five.haml
89
- - spec/views/five.slim
90
- - spec/views/four.haml
91
- - spec/views/four.slim
92
- - spec/views/index.haml
93
- - spec/views/index.slim
94
- - spec/views/layout.haml
95
- - spec/views/layout.slim
96
- - spec/views/one.haml
97
- - spec/views/one.slim
98
- - spec/views/three.haml
99
- - spec/views/three.slim
100
- - spec/views/two.haml
101
- - spec/views/two.slim
102
98
  homepage: ''
103
99
  licenses:
104
100
  - MIT
@@ -127,22 +123,18 @@ summary: In Sinatra, the user can disable the layout template either globally o
127
123
  support to enable or disable the layout rendering based on Regex description. Refer
128
124
  to Readme for more details
129
125
  test_files:
130
- - spec/fuzzy_layout_spec.rb
131
- - spec/sample_app.rb
132
- - spec/sample_app_multiple.rb
126
+ - spec/apps/classic.rb
127
+ - spec/apps/modular.rb
128
+ - spec/apps/modular_without_enable.rb
129
+ - spec/apps/views/five.erb
130
+ - spec/apps/views/four.erb
131
+ - spec/apps/views/index.erb
132
+ - spec/apps/views/layout.erb
133
+ - spec/apps/views/one.erb
134
+ - spec/apps/views/three.erb
135
+ - spec/apps/views/two.erb
136
+ - spec/classic_app_spec.rb
137
+ - spec/modular_app_spec.rb
138
+ - spec/modular_app_without_enable_spec.rb
133
139
  - spec/spec_helper.rb
134
- - spec/views/five.haml
135
- - spec/views/five.slim
136
- - spec/views/four.haml
137
- - spec/views/four.slim
138
- - spec/views/index.haml
139
- - spec/views/index.slim
140
- - spec/views/layout.haml
141
- - spec/views/layout.slim
142
- - spec/views/one.haml
143
- - spec/views/one.slim
144
- - spec/views/three.haml
145
- - spec/views/three.slim
146
- - spec/views/two.haml
147
- - spec/views/two.slim
148
140
  has_rdoc:
@@ -1,85 +0,0 @@
1
- require_relative "spec_helper"
2
- require_relative "sample_app"
3
- require_relative "sample_app_multiple"
4
-
5
- describe 'Test App with single declaration of enable or disable directives' do
6
-
7
- def app
8
- SampleApp
9
- end
10
-
11
- it "disables layout if route level :layout => false is set" do
12
- get('/')
13
- last_response.should be_ok
14
- last_response.body.should == "<em>Spartaa!!</em>\n"
15
- end
16
-
17
- it "enables layout when layout is both enabled and disabled" do
18
- get('/one')
19
- last_response.should be_ok
20
- last_response.body.should == "<h1>This is <em>one</em></h1>\n"
21
- end
22
-
23
- it "works when template is specified as a string" do
24
- get('/two')
25
- last_response.should be_ok
26
- last_response.body.should == "<em>two</em>\n"
27
- end
28
-
29
- context "works when template is specified as a regex" do
30
- it "should not have a layout for the route four" do
31
- get('/four')
32
- last_response.should be_ok
33
- last_response.body.should == "<em>four</em>\n"
34
- end
35
-
36
- it "should not have a layout for the route five" do
37
- get('/five')
38
- last_response.should be_ok
39
- last_response.body.should == "<em>five</em>\n"
40
- end
41
- end
42
-
43
- end
44
-
45
-
46
-
47
- describe 'Test App with multiple declarations of enable directives' do
48
-
49
- def app
50
- SampleAppMultiple
51
- end
52
-
53
- it "disables layout if route level :layout => false is set" do
54
- get('/')
55
- last_response.should be_ok
56
- last_response.body.should == "<em>Spartaa!!</em>\n"
57
- end
58
-
59
- it "enables layout when layout is both enabled and disabled" do
60
- get('/one')
61
- last_response.should be_ok
62
- last_response.body.should == "<h1>This is <em>one</em></h1>\n"
63
- end
64
-
65
- it "works when template is specified as a string" do
66
- get('/two')
67
- last_response.should be_ok
68
- last_response.body.should == "<em>two</em>\n"
69
- end
70
-
71
- context "works when template is specified as a regex" do
72
- it "should not have a layout for the route four" do
73
- get('/four')
74
- last_response.should be_ok
75
- last_response.body.should == "<em>four</em>\n"
76
- end
77
-
78
- it "should not have a layout for the route five" do
79
- get('/five')
80
- last_response.should be_ok
81
- last_response.body.should == "<em>five</em>\n"
82
- end
83
- end
84
-
85
- end
@@ -1,20 +0,0 @@
1
- require "sinatra/base"
2
- require "haml"
3
- require File.expand_path("../../lib/sinatra/fuzzy_layout.rb", __FILE__)
4
-
5
- class SampleApp < Sinatra::Base
6
- register Sinatra::FuzzyLayout
7
-
8
- enable_layout_for :one
9
- disable_layout_for "one", "two", /f\w{3}/
10
-
11
- get '/' do
12
- haml :index, :layout => false
13
- end
14
-
15
- get('/one') { haml :one }
16
- get('/two') { haml :two }
17
- get('/three') { haml :three }
18
- get('/four') { haml :four }
19
- get('/five') { haml :five }
20
- end
@@ -1,21 +0,0 @@
1
- require "sinatra/base"
2
- require "haml"
3
- require File.expand_path("../../lib/sinatra/fuzzy_layout.rb", __FILE__)
4
-
5
- class SampleAppMultiple < Sinatra::Base
6
- register Sinatra::FuzzyLayout
7
-
8
- enable_layout_for :one
9
- disable_layout_for "one"
10
- disable_layout_for "two", /f\w{3}/
11
-
12
- get '/' do
13
- haml :index, :layout => false
14
- end
15
-
16
- get('/one') { haml :one }
17
- get('/two') { haml :two }
18
- get('/three') { haml :three }
19
- get('/four') { haml :four }
20
- get('/five') { haml :five }
21
- end
@@ -1 +0,0 @@
1
- %em five
@@ -1 +0,0 @@
1
- em five
@@ -1 +0,0 @@
1
- %em four
@@ -1 +0,0 @@
1
- em four
@@ -1 +0,0 @@
1
- %em Spartaa!!
@@ -1 +0,0 @@
1
- em Spartaa!!
@@ -1 +0,0 @@
1
- %h1 This is #{yield}
@@ -1 +0,0 @@
1
- h1 This is #{yield}
@@ -1 +0,0 @@
1
- %em one
@@ -1 +0,0 @@
1
- em one
@@ -1 +0,0 @@
1
- %em three
@@ -1 +0,0 @@
1
- em three
@@ -1 +0,0 @@
1
- %em two
@@ -1 +0,0 @@
1
- em two