sinatra-pages 1.0.0 → 1.1.0
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.markdown +1 -1
- data/spec/pages_spec.rb +39 -51
- data/spec/spec_helper.rb +19 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -86,7 +86,7 @@ In case you would like to contribute on this library, here's the list of extra d
|
|
86
86
|
* [Julio Javier Cicchelli][7]
|
87
87
|
|
88
88
|
### Notes
|
89
|
-
This
|
89
|
+
This extension have been tested on the versions 1.8.6, 1.8.7 and 1.9.1 of the [Ruby interpreter][8].
|
90
90
|
|
91
91
|
### License
|
92
92
|
This extension is licensed under the [MIT License][9].
|
data/spec/pages_spec.rb
CHANGED
@@ -9,41 +9,29 @@ describe Sinatra::Pages do
|
|
9
9
|
|
10
10
|
PAGES = ['Home','Generic',{'Generic Test'=>'Test'},{'Another Generic Test'=>{'Generic Test'=>'Test'}},'Not Found']
|
11
11
|
|
12
|
-
file_of = ->(page){page.downcase.gsub ' ', '_'}
|
13
|
-
separate = ->(text){text.chomp.split("\n")}
|
14
|
-
create_file_for = ->(page, directory = 'views', content = []) do
|
15
|
-
page_to_create = page.class == String ? page : page.keys.first
|
16
|
-
content << '= "#{params[:page]}"' if content.empty?
|
17
|
-
|
18
|
-
Dir.mkdir "#{directory}/" unless File.exist? "#{directory}/"
|
19
|
-
File.open("#{directory}/#{file_of.(page_to_create)}.haml", 'w'){|file| content.each{|line| file.puts line}}
|
20
|
-
|
21
|
-
create_file_for.(page.values.first, "#{directory}/#{file_of.(page.keys.first)}") if page.class == Hash
|
22
|
-
end
|
23
|
-
|
24
12
|
before :all do
|
25
|
-
PAGES.each{|page| create_file_for
|
13
|
+
PAGES.each{|page| create_file_for(page)}
|
26
14
|
end
|
27
15
|
|
28
16
|
context "uses HTTP GET request method" do
|
29
17
|
context "in synchronous mode" do
|
30
18
|
context "with no Layout file" do
|
31
19
|
it "should render just the Home page if the given route is either empty or root." do
|
32
|
-
File.exist?("views/#{file_of
|
33
|
-
File.exist?("views/#{file_of
|
20
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
21
|
+
File.exist?("views/#{file_of('Home')}.haml").should be_true
|
34
22
|
|
35
23
|
['/', ''].each do |route|
|
36
24
|
get route
|
37
25
|
|
38
26
|
last_request.should_not be_xhr
|
39
27
|
last_response.should be_ok
|
40
|
-
last_response.body.chomp.should == file_of
|
28
|
+
last_response.body.chomp.should == file_of('Home')
|
41
29
|
end
|
42
30
|
end
|
43
31
|
|
44
32
|
it "should render just an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
45
33
|
Dir.glob 'views/**/*.haml' do |file|
|
46
|
-
File.exist?("views/#{file_of
|
34
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
47
35
|
File.exist?(file).should be_true
|
48
36
|
|
49
37
|
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
@@ -57,39 +45,39 @@ describe Sinatra::Pages do
|
|
57
45
|
end
|
58
46
|
|
59
47
|
it "should render just the Not Found page if a given route can't find its static page on 'views/'." do
|
60
|
-
File.exist?("views/#{file_of
|
61
|
-
File.exist?("views/#{file_of
|
48
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
49
|
+
File.exist?("views/#{file_of('Do Not Exist')}.haml").should be_false
|
62
50
|
|
63
|
-
get "/#{file_of
|
51
|
+
get "/#{file_of('Do Not Exist')}"
|
64
52
|
|
65
53
|
last_request.should_not be_xhr
|
66
54
|
last_response.should be_not_found
|
67
|
-
last_response.body.chomp.should == file_of
|
55
|
+
last_response.body.chomp.should == file_of('Not Found')
|
68
56
|
end
|
69
57
|
end
|
70
58
|
|
71
59
|
context "with Layout file" do
|
72
60
|
before :all do
|
73
|
-
create_file_for
|
61
|
+
create_file_for('Layout', 'views', ['Layout', '= yield'])
|
74
62
|
end
|
75
63
|
|
76
64
|
it "should render both the Layout and Home page if the given route is either empty or root." do
|
77
|
-
File.exist?("views/#{file_of
|
78
|
-
File.exist?("views/#{file_of
|
65
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
66
|
+
File.exist?("views/#{file_of('Home')}.haml").should be_true
|
79
67
|
|
80
68
|
['/', ''].each do |route|
|
81
69
|
get route
|
82
70
|
|
83
71
|
last_request.should_not be_xhr
|
84
72
|
last_response.should be_ok
|
85
|
-
separate
|
86
|
-
separate
|
73
|
+
separate(last_response.body).first.should == 'Layout'
|
74
|
+
separate(last_response.body).last.should == file_of('Home')
|
87
75
|
end
|
88
76
|
end
|
89
77
|
|
90
78
|
it "should render both the Layout and an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
91
79
|
Dir.glob('views/**/*.haml').reject{|file| file =~ /layout/}.each do |file|
|
92
|
-
File.exist?("views/#{file_of
|
80
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
93
81
|
File.exist?(file).should be_true
|
94
82
|
|
95
83
|
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
@@ -98,21 +86,21 @@ describe Sinatra::Pages do
|
|
98
86
|
|
99
87
|
last_request.should_not be_xhr
|
100
88
|
last_response.should be_ok
|
101
|
-
separate
|
102
|
-
separate
|
89
|
+
separate(last_response.body).first.should == 'Layout'
|
90
|
+
separate(last_response.body).last.should == File.basename(file, '.haml')
|
103
91
|
end
|
104
92
|
end
|
105
93
|
|
106
94
|
it "should render both the Layout and the Not Found page if a given route can't find its static page on 'views/'." do
|
107
|
-
File.exist?("views/#{file_of
|
108
|
-
File.exist?("views/#{file_of
|
95
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
96
|
+
File.exist?("views/#{file_of('Do Not Exist')}.haml").should be_false
|
109
97
|
|
110
|
-
get "/#{file_of
|
98
|
+
get "/#{file_of('Do Not Exist')}"
|
111
99
|
|
112
100
|
last_request.should_not be_xhr
|
113
101
|
last_response.should be_not_found
|
114
|
-
separate
|
115
|
-
separate
|
102
|
+
separate(last_response.body).first.should == 'Layout'
|
103
|
+
separate(last_response.body).last.should == file_of('Not Found')
|
116
104
|
end
|
117
105
|
|
118
106
|
after :all do
|
@@ -124,21 +112,21 @@ describe Sinatra::Pages do
|
|
124
112
|
context "in asynchronous mode" do
|
125
113
|
context "with no Layout file" do
|
126
114
|
it "should render just the Home page if the given route is either empty or root." do
|
127
|
-
File.exist?("views/#{file_of
|
128
|
-
File.exist?("views/#{file_of
|
115
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
116
|
+
File.exist?("views/#{file_of('Home')}.haml").should be_true
|
129
117
|
|
130
118
|
['/', ''].each do |route|
|
131
119
|
request route, :method => 'GET', :xhr => true
|
132
120
|
|
133
121
|
last_request.should be_xhr
|
134
122
|
last_response.should be_ok
|
135
|
-
last_response.body.chomp.should == file_of
|
123
|
+
last_response.body.chomp.should == file_of('Home')
|
136
124
|
end
|
137
125
|
end
|
138
126
|
|
139
127
|
it "should render just an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
140
128
|
Dir.glob 'views/**/*.haml' do |file|
|
141
|
-
File.exist?("views/#{file_of
|
129
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
142
130
|
File.exist?(file).should be_true
|
143
131
|
|
144
132
|
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
@@ -152,38 +140,38 @@ describe Sinatra::Pages do
|
|
152
140
|
end
|
153
141
|
|
154
142
|
it "should render just the Not Found page if a given route can't find its static page on 'views/." do
|
155
|
-
File.exist?("views/#{file_of
|
156
|
-
File.exist?("views/#{file_of
|
143
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_false
|
144
|
+
File.exist?("views/#{file_of('Do Not Exist')}.haml").should be_false
|
157
145
|
|
158
|
-
request "/#{file_of
|
146
|
+
request "/#{file_of('Do Not Exist')}", :method => 'GET', :xhr => true
|
159
147
|
|
160
148
|
last_request.should be_xhr
|
161
149
|
last_response.should be_not_found
|
162
|
-
last_response.body.chomp.should == file_of
|
150
|
+
last_response.body.chomp.should == file_of('Not Found')
|
163
151
|
end
|
164
152
|
end
|
165
153
|
|
166
154
|
context "with a Layout file" do
|
167
155
|
before :all do
|
168
|
-
create_file_for
|
156
|
+
create_file_for('Layout', 'views', ['Layout', '= yield'])
|
169
157
|
end
|
170
158
|
|
171
159
|
it "should render both the Layout and Home page if the given route is either empty or root." do
|
172
|
-
File.exist?("views/#{file_of
|
173
|
-
File.exist?("views/#{file_of
|
160
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
161
|
+
File.exist?("views/#{file_of('Home')}.haml").should be_true
|
174
162
|
|
175
163
|
['/', ''].each do |route|
|
176
164
|
request route, :method => 'GET', :xhr => true
|
177
165
|
|
178
166
|
last_request.should be_xhr
|
179
167
|
last_response.should be_ok
|
180
|
-
last_response.body.chomp.should == file_of
|
168
|
+
last_response.body.chomp.should == file_of('Home')
|
181
169
|
end
|
182
170
|
end
|
183
171
|
|
184
172
|
it "should render both the Layout and an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
185
173
|
Dir.glob('views/**/*.haml').reject{|file| file =~ /layout/}.each do |file|
|
186
|
-
File.exist?("views/#{file_of
|
174
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
187
175
|
File.exist?(file).should be_true
|
188
176
|
|
189
177
|
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
@@ -197,14 +185,14 @@ describe Sinatra::Pages do
|
|
197
185
|
end
|
198
186
|
|
199
187
|
it "should render both the Layout and the Not Found page if a given route can't find its static page on 'views/'." do
|
200
|
-
File.exist?("views/#{file_of
|
201
|
-
File.exist?("views/#{file_of
|
188
|
+
File.exist?("views/#{file_of('Layout')}.haml").should be_true
|
189
|
+
File.exist?("views/#{file_of('Do Not Exist')}.haml").should be_false
|
202
190
|
|
203
|
-
request "/#{file_of
|
191
|
+
request "/#{file_of('Do Not Exist')}", :method => 'GET', :xhr => true
|
204
192
|
|
205
193
|
last_request.should be_xhr
|
206
194
|
last_response.should be_not_found
|
207
|
-
last_response.body.chomp.should == file_of
|
195
|
+
last_response.body.chomp.should == file_of('Not Found')
|
208
196
|
end
|
209
197
|
|
210
198
|
after :all do
|
data/spec/spec_helper.rb
CHANGED
@@ -4,4 +4,22 @@ require 'fileutils'
|
|
4
4
|
require File.join(Dir.pwd, %w{lib sinatra pages})
|
5
5
|
|
6
6
|
set :environment, :test
|
7
|
-
set :views, "#{Dir.pwd}/views"
|
7
|
+
set :views, "#{Dir.pwd}/views"
|
8
|
+
|
9
|
+
def file_of(page)
|
10
|
+
page.downcase.gsub(' ', '_')
|
11
|
+
end
|
12
|
+
|
13
|
+
def separate(text)
|
14
|
+
text.chomp.split("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_file_for(page, directory = 'views', content = [])
|
18
|
+
page_to_create = page.class == String ? page : page.keys.first
|
19
|
+
content << '= "#{params[:page]}"' if content.empty?
|
20
|
+
|
21
|
+
Dir.mkdir "#{directory}/" unless File.exist? "#{directory}/"
|
22
|
+
File.open("#{directory}/#{file_of(page_to_create)}.haml", 'w'){|file| content.each{|line| file.puts line}}
|
23
|
+
|
24
|
+
create_file_for(page.values.first, "#{directory}/#{file_of(page.keys.first)}") if page.class == Hash
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Javier Cicchelli
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.0a
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: haml
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.2.
|
33
|
+
version: 2.2.20
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: rspec
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements:
|
91
91
|
- - ">="
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 1.
|
93
|
+
version: 1.8.6
|
94
94
|
version:
|
95
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|