sinatra-pages 0.7.4 → 0.8.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 +9 -2
- data/Rakefile +5 -4
- data/lib/sinatra/pages.rb +5 -2
- data/spec/pages_spec.rb +23 -15
- metadata +5 -14
- data/spec/opts/rcov.opts +0 -5
- data/spec/opts/spec.opts +0 -9
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Sinatra Pages
|
2
|
-
This is a [Sinatra Extension][1] that renders any page located under the *views/* directory inside your [Sinatra][2] application.
|
2
|
+
This is a [Sinatra Extension][1] that renders any page or sub-pages located under the *views/* directory inside your [Sinatra][2] application.
|
3
3
|
|
4
4
|
### Installation
|
5
5
|
In order to install this gem, you just need to install the gem from your command line like this:
|
@@ -18,9 +18,16 @@ Before plug in this extension, you should create the following file structure in
|
|
18
18
|
|- config.ru
|
19
19
|
|- views/
|
20
20
|
|- home.haml
|
21
|
+
|- a_file.haml
|
22
|
+
|- another_file.haml
|
23
|
+
|- another_file/yet_another_file.haml
|
24
|
+
|- another_file/yet_another_file/still_another_file.haml
|
25
|
+
|- ...more file and subdirectories...
|
21
26
|
|- layout.haml
|
22
27
|
|- not_found.haml
|
23
28
|
|
29
|
+
The only restriction is extension imposes is that you have to create the *home.haml* and the *not_found.haml* files inside your *views/* directory. Then you're free to add any page under any file structure hierarchy inside this directory.
|
30
|
+
|
24
31
|
Then, you just need to plug it in inside your *config.ru* file.
|
25
32
|
|
26
33
|
require 'sinatra'
|
@@ -49,7 +56,7 @@ In case you would like to contribute on this library, here's the list of extra d
|
|
49
56
|
* [Julio Javier Cicchelli][7]
|
50
57
|
|
51
58
|
### Notes
|
52
|
-
This library is being developed by using the [Ruby 1.9.1 interpreter][8] and was not being tested on any other version of the interpreter.
|
59
|
+
This library is being developed by using the [Ruby 1.9.1 interpreter][8] and was not being tested on any other version of the interpreter nor any other implementation.
|
53
60
|
|
54
61
|
### License
|
55
62
|
This extension is licensed under the [MIT License][9].
|
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
desc "Install the generated Gem into your system."
|
19
19
|
task :install => [:clean, :package] do
|
20
|
-
sh 'gem19 install pkg/*.gem --no-ri --no-rdoc'
|
20
|
+
sh 'sudo gem19 install pkg/*.gem --no-ri --no-rdoc'
|
21
21
|
end
|
22
22
|
|
23
23
|
namespace :deployment do
|
@@ -41,7 +41,7 @@ task :deploy => ['deployment:repositories', 'deployment:gemcutter']
|
|
41
41
|
|
42
42
|
desc 'Functional testing with RSpec.'
|
43
43
|
Spec::Rake::SpecTask.new :spec do |task|
|
44
|
-
task.spec_opts = %w[--
|
44
|
+
task.spec_opts = %w[--colour --format profile --loadby mtime --reverse --timeout 20 --diff]
|
45
45
|
task.libs = %w[lib spec]
|
46
46
|
task.spec_files = FileList['spec/**/*.rb']
|
47
47
|
task.rcov = false
|
@@ -49,11 +49,12 @@ end
|
|
49
49
|
|
50
50
|
desc 'Functional testing with RSpec and RCov.'
|
51
51
|
Spec::Rake::SpecTask.new :rcov do |task|
|
52
|
-
task.spec_opts = %w[--
|
52
|
+
task.spec_opts = %w[--colour --format profile --loadby mtime --reverse --timeout 20 --diff]
|
53
53
|
task.libs = %w[lib spec]
|
54
54
|
task.spec_files = FileList['spec/*_spec.rb']
|
55
55
|
task.rcov = true
|
56
|
-
task.
|
56
|
+
task.rcov_dir = 'cov'
|
57
|
+
task.rcov_opts = %w[--text-summary --exclude spec/]
|
57
58
|
end
|
58
59
|
|
59
60
|
desc "Default is Functional testing with RSpec."
|
data/lib/sinatra/pages.rb
CHANGED
@@ -3,12 +3,15 @@ require 'haml'
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
class Pages < Sinatra::Base
|
6
|
-
%w[/? /:page].each do |route|
|
6
|
+
%w[/? /:page /*/:page].each do |route|
|
7
7
|
get route do
|
8
8
|
params[:page] = 'home' if params[:page].nil?
|
9
9
|
|
10
|
+
page_to_render = params[:splat].nil? ? '' : "#{params[:splat].first}/"
|
11
|
+
page_to_render << params[:page]
|
12
|
+
|
10
13
|
begin
|
11
|
-
haml
|
14
|
+
haml page_to_render.to_sym
|
12
15
|
rescue Errno::ENOENT
|
13
16
|
halt 404
|
14
17
|
end
|
data/spec/pages_spec.rb
CHANGED
@@ -7,14 +7,18 @@ describe Sinatra::Pages do
|
|
7
7
|
Sinatra::Pages
|
8
8
|
end
|
9
9
|
|
10
|
-
PAGES = ['Home',
|
10
|
+
PAGES = ['Home','Generic',{'Generic Test'=>'Test'},{'Another Generic Test'=>{'Generic Test'=>'Test'}},'Not Found']
|
11
11
|
|
12
12
|
file_of = ->(page){page.downcase.gsub ' ', '_'}
|
13
13
|
separate = ->(text){text.chomp.split("\n")}
|
14
|
-
create_file_for = ->(page, content=[]) do
|
14
|
+
create_file_for = ->(page, directory = 'views', content = []) do
|
15
|
+
page_to_create = page.class == String ? page : page.keys.first
|
15
16
|
content << '= "#{params[:page]}"' if content.empty?
|
16
17
|
|
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
|
18
22
|
end
|
19
23
|
|
20
24
|
before :all do
|
@@ -36,15 +40,17 @@ describe Sinatra::Pages do
|
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
|
-
it "should render just an existing page if the given route match the '/:page'
|
40
|
-
|
43
|
+
it "should render just an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
44
|
+
Dir.glob 'views/**/*.haml' do |file|
|
41
45
|
File.exist?("views/#{file_of.('Layout')}.haml").should be_false
|
42
|
-
File.exist?(
|
46
|
+
File.exist?(file).should be_true
|
47
|
+
|
48
|
+
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
43
49
|
|
44
|
-
get "/#{
|
50
|
+
get "#{directory}/#{File.basename(file, '.haml')}"
|
45
51
|
|
46
52
|
last_response.should be_ok
|
47
|
-
last_response.body.chomp.should ==
|
53
|
+
last_response.body.chomp.should == File.basename(file, '.haml')
|
48
54
|
end
|
49
55
|
end
|
50
56
|
|
@@ -61,7 +67,7 @@ describe Sinatra::Pages do
|
|
61
67
|
|
62
68
|
context "with a Layout file" do
|
63
69
|
before :all do
|
64
|
-
create_file_for.('Layout', ['Layout', '= yield'])
|
70
|
+
create_file_for.('Layout', 'views', ['Layout', '= yield'])
|
65
71
|
end
|
66
72
|
|
67
73
|
it "should render both the Layout and Home page if the given route is either empty or root." do
|
@@ -77,16 +83,18 @@ describe Sinatra::Pages do
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
it "should render both the Layout and an existing page if the given route match the '/:page'
|
81
|
-
|
86
|
+
it "should render both the Layout and an existing page if the given route match the '/:page' or '/*/:page' patterns." do
|
87
|
+
Dir.glob('views/**/*.haml').reject{|file| file =~ /layout/}.each do |file|
|
82
88
|
File.exist?("views/#{file_of.('Layout')}.haml").should be_true
|
83
|
-
File.exist?(
|
84
|
-
|
85
|
-
|
89
|
+
File.exist?(file).should be_true
|
90
|
+
|
91
|
+
directory = File.dirname(file)[5].nil? ? '' : File.dirname(file)[5, File.dirname(file).size]
|
92
|
+
|
93
|
+
get "#{directory}/#{File.basename(file, '.haml')}"
|
86
94
|
|
87
95
|
last_response.should be_ok
|
88
96
|
separate.(last_response.body).first.should == 'Layout'
|
89
|
-
separate.(last_response.body).last.should ==
|
97
|
+
separate.(last_response.body).last.should == File.basename(file, '.haml')
|
90
98
|
end
|
91
99
|
end
|
92
100
|
|
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: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio Javier Cicchelli
|
@@ -68,16 +68,13 @@ executables: []
|
|
68
68
|
|
69
69
|
extensions: []
|
70
70
|
|
71
|
-
extra_rdoc_files:
|
72
|
-
|
73
|
-
- LICENSE
|
71
|
+
extra_rdoc_files: []
|
72
|
+
|
74
73
|
files:
|
75
74
|
- LICENSE
|
76
75
|
- README.markdown
|
77
76
|
- Rakefile
|
78
77
|
- lib/sinatra/pages.rb
|
79
|
-
- spec/opts/rcov.opts
|
80
|
-
- spec/opts/spec.opts
|
81
78
|
- spec/pages_spec.rb
|
82
79
|
- spec/spec_helper.rb
|
83
80
|
has_rdoc: true
|
@@ -85,14 +82,8 @@ homepage: http://github.com/rock-n-code/sinatra-pages
|
|
85
82
|
licenses: []
|
86
83
|
|
87
84
|
post_install_message:
|
88
|
-
rdoc_options:
|
89
|
-
|
90
|
-
- Sinatra-Pages
|
91
|
-
- --main
|
92
|
-
- README.markdown
|
93
|
-
- --line-numbers
|
94
|
-
- --inline-source
|
95
|
-
- --charset=UTF-8
|
85
|
+
rdoc_options: []
|
86
|
+
|
96
87
|
require_paths:
|
97
88
|
- lib
|
98
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/spec/opts/rcov.opts
DELETED