sinatra-pages 0.2.1 → 0.3.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.
Files changed (3) hide show
  1. data/lib/sinatra/pages.rb +6 -2
  2. data/spec/pages_spec.rb +18 -2
  3. metadata +1 -1
data/lib/sinatra/pages.rb CHANGED
@@ -3,8 +3,12 @@ require 'haml'
3
3
 
4
4
  module Sinatra
5
5
  class Pages < Sinatra::Base
6
- get '/?' do
7
- haml :home
6
+ %w[/? /:page].each do |route|
7
+ get route do
8
+ params[:page] = 'home' if params[:page].nil?
9
+
10
+ haml params[:page].to_sym
11
+ end
8
12
  end
9
13
  end
10
14
  end
data/spec/pages_spec.rb CHANGED
@@ -7,14 +7,19 @@ describe Sinatra::Pages do
7
7
  Sinatra::Pages
8
8
  end
9
9
 
10
+ PAGES = ['Home', 'Generic', 'Generic Test', 'Another Generic Test']
11
+
12
+ file_of = ->(page){page.downcase.gsub ' ', '_'}
13
+ create_file_for = ->(page){File.open("views/#{file_of.(page)}.haml", 'w'){|file| file << page}}
14
+
10
15
  before :all do
11
16
  FileUtils.mkdir 'views'
12
- File.open('views/home.haml', 'w'){|file| file << 'Home'}
17
+ PAGES.each{|page| create_file_for.(page)}
13
18
  end
14
19
 
15
20
  context "when using the HTTP GET request method" do
16
21
  it "should render the Home page if the given route is either empty or root." do
17
- File.exist?('views/home.haml').should be_true
22
+ File.exist?("views/#{file_of.('Home')}.haml").should be_true
18
23
 
19
24
  ['/', ''].each do |route|
20
25
  get route
@@ -23,6 +28,17 @@ describe Sinatra::Pages do
23
28
  last_response.body.chomp.should == 'Home'
24
29
  end
25
30
  end
31
+
32
+ it "should render an existing page if the given route match the '/:page' pattern." do
33
+ PAGES.each do |page|
34
+ File.exist?("views/#{file_of.(page)}.haml").should be_true
35
+
36
+ get "/#{file_of.(page)}"
37
+
38
+ last_response.should be_ok
39
+ last_response.body.chomp.should == page
40
+ end
41
+ end
26
42
  end
27
43
 
28
44
  after :all do
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Javier Cicchelli