sinatra-pages 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,8 +3,6 @@ require 'rake/clean'
3
3
  require 'rake/gempackagetask'
4
4
  require 'spec/rake/spectask'
5
5
 
6
- GEM_COMMAND = RUBY_VERSION.to_f < 1.9 ? 'gem' : 'gem19'
7
-
8
6
  CLEAN.include %w[cov/ pkg/]
9
7
 
10
8
  desc 'Load the GemSpec definition file.'
@@ -19,7 +17,7 @@ end
19
17
 
20
18
  desc "Install the generated Gem into your system."
21
19
  task :install => [:clean, :package] do
22
- sh "sudo #{GEM_COMMAND} install pkg/*.gem --no-ri --no-rdoc"
20
+ sh "gem install pkg/*.gem --no-ri --no-rdoc"
23
21
  end
24
22
 
25
23
  namespace :deployment do
@@ -27,7 +25,7 @@ namespace :deployment do
27
25
  task :repositories do
28
26
  sh 'git checkout master'
29
27
  sh 'git merge development'
30
- sh 'git push rock-n-code master --tags'
28
+ sh 'git push github master --tags'
31
29
  sh 'git push server master --tags'
32
30
  sh 'git checkout development'
33
31
  end
@@ -43,7 +41,7 @@ task :deploy => ['deployment:repositories', 'deployment:gemcutter']
43
41
 
44
42
  desc 'Functional testing with RSpec.'
45
43
  Spec::Rake::SpecTask.new :spec do |task|
46
- task.spec_opts = %w[--colour --format profile --loadby mtime --reverse --timeout 20 --diff]
44
+ task.spec_opts = %w[--colour --format progress --loadby mtime --timeout 20 --diff --backtrace]
47
45
  task.libs = %w[lib spec]
48
46
  task.spec_files = FileList['spec/**/*.rb']
49
47
  task.rcov = false
@@ -51,7 +49,7 @@ end
51
49
 
52
50
  desc 'Functional testing with RSpec and RCov.'
53
51
  Spec::Rake::SpecTask.new :rcov do |task|
54
- task.spec_opts = %w[--colour --format profile --loadby mtime --reverse --timeout 20 --diff]
52
+ task.spec_opts = %w[--colour --format progress --loadby mtime --timeout 20 --diff --backtrace]
55
53
  task.libs = %w[lib spec]
56
54
  task.spec_files = FileList['spec/*_spec.rb']
57
55
  task.rcov = true
data/lib/sinatra/pages.rb CHANGED
@@ -4,7 +4,10 @@ require 'haml'
4
4
  module Sinatra
5
5
  module Pages
6
6
  def self.registered(app)
7
- %w[/? /:page /*/:page].each do |route|
7
+ app.set :root, Dir.pwd
8
+ app.enable :static
9
+
10
+ %w[/? /:page/? /*/:page/?].each do |route|
8
11
  app.get route do
9
12
  params[:page] = 'home' if params[:page].nil?
10
13
 
data/spec/helpers.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ module HelperMethods
4
+ def file_of(page)
5
+ page.downcase.gsub(' ', '_')
6
+ end
7
+
8
+ def separate(text)
9
+ text.chomp.split("\n")
10
+ end
11
+
12
+ def create_file_for(page, directory = 'views', content = [])
13
+ page_to_create = page.class == String ? page : page.keys.first
14
+ content << '= "#{params[:page]}"' if content.empty?
15
+
16
+ Dir.mkdir "#{directory}/" unless File.exist? "#{directory}/"
17
+ File.open("#{directory}/#{file_of(page_to_create)}.haml", 'w'){|file| content.each{|line| file.puts line}}
18
+
19
+ create_file_for(page.values.first, "#{directory}/#{file_of(page.keys.first)}") if page.class == Hash
20
+ end
21
+ end
data/spec/pages_spec.rb CHANGED
@@ -2,34 +2,71 @@ require 'spec_helper'
2
2
 
3
3
  describe Sinatra::Pages do
4
4
  include Rack::Test::Methods
5
+ include HelperMethods
5
6
 
6
7
  def app
7
- Sinatra::Application
8
+ TestApp
8
9
  end
9
10
 
10
- PAGES = ['Home','Generic',{'Generic Test'=>'Test'},{'Another Generic Test'=>{'Generic Test'=>'Test'}},'Not Found']
11
-
12
11
  before :all do
13
12
  PAGES.each{|page| create_file_for(page)}
14
13
  end
15
14
 
16
- context "uses HTTP GET request method" do
15
+ context 'built-in settings' do
16
+ context 'by default' do
17
+ subject {app}
18
+ its(:root) {should == Dir.pwd}
19
+ its(:public) {should == File.join(Dir.pwd, 'public')}
20
+ its(:views) {should == File.join(Dir.pwd, 'views')}
21
+ its(:static) {should == true}
22
+ end
23
+
24
+ context 'on defining' do
25
+ before {app.set :root, Dir.pwd}
26
+
27
+ context '#root' do
28
+ subject {app.set :root, File.dirname(__FILE__)}
29
+ its(:root) {should == File.dirname(__FILE__)}
30
+ its(:public) {should == File.join(File.dirname(__FILE__), 'public')}
31
+ its(:views) {should == File.join(File.dirname(__FILE__), 'views')}
32
+ its(:static) {should == true}
33
+ end
34
+
35
+ context '#public' do
36
+ subject {app.set :public, File.join(File.dirname(__FILE__), 'public')}
37
+ its(:root) {should == Dir.pwd}
38
+ its(:public) {should == File.join(File.dirname(__FILE__), 'public')}
39
+ its(:views) {should == File.join(Dir.pwd, 'views')}
40
+ its(:static) {should == true}
41
+ end
42
+
43
+ context '#views' do
44
+ subject {app.set :views, File.join(File.dirname(__FILE__), 'views')}
45
+ its(:root) {should == Dir.pwd}
46
+ its(:public) {should == File.join(Dir.pwd, 'public')}
47
+ its(:views) {should == File.join(File.dirname(__FILE__), 'views')}
48
+ its(:static) {should == true}
49
+ end
50
+ end
51
+ end
52
+
53
+ context "on HTTP GET" do
17
54
  context "in synchronous mode" do
18
55
  context "with no Layout file" do
19
- it "should render just the Home page if the given route is either empty or root." do
56
+ it "should render only the Home page if the given route is either empty or root." do
20
57
  File.exist?("views/#{file_of('Layout')}.haml").should be_false
21
58
  File.exist?("views/#{file_of('Home')}.haml").should be_true
22
59
 
23
60
  ['/', ''].each do |route|
24
61
  get route
25
-
62
+
26
63
  last_request.should_not be_xhr
27
64
  last_response.should be_ok
28
65
  last_response.body.chomp.should == file_of('Home')
29
66
  end
30
67
  end
31
68
 
32
- it "should render just an existing page if the given route match the '/:page' or '/*/:page' patterns." do
69
+ it "should render only an existing page if the given route match the '/:page' or '/*/:page' patterns." do
33
70
  Dir.glob 'views/**/*.haml' do |file|
34
71
  File.exist?("views/#{file_of('Layout')}.haml").should be_false
35
72
  File.exist?(file).should be_true
@@ -44,7 +81,7 @@ describe Sinatra::Pages do
44
81
  end
45
82
  end
46
83
 
47
- it "should render just the Not Found page if a given route can't find its static page on 'views/'." do
84
+ it "should render only the Not Found page if a given route can't find its static page on 'views/'." do
48
85
  File.exist?("views/#{file_of('Layout')}.haml").should be_false
49
86
  File.exist?("views/#{file_of('Do Not Exist')}.haml").should be_false
50
87
 
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,10 @@
1
- require 'sinatra'
2
- require 'rack/test'
3
- require 'fileutils'
4
1
  require File.join(Dir.pwd, %w{lib sinatra pages})
2
+ require 'rack/test'
3
+ require 'helpers'
5
4
 
6
- set :environment, :test
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
5
+ ENV['RACK_ENV'] = 'test'
6
+ PAGES = ['Home','Generic',{'Generic Test'=>'Test'},{'Another Generic Test'=>{'Generic Test'=>'Test'}},'Not Found']
16
7
 
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
8
+ class TestApp < Sinatra::Base
9
+ register Sinatra::Pages
25
10
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 0
10
+ version: 1.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Julio Javier Cicchelli
@@ -9,59 +15,89 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-03-13 00:00:00 +01:00
18
+ date: 2010-08-03 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: sinatra
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 0.9.4
24
- version:
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  - !ruby/object:Gem::Dependency
26
38
  name: haml
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
30
42
  requirements:
31
43
  - - ">="
32
44
  - !ruby/object:Gem::Version
33
- version: 2.2.20
34
- version:
45
+ hash: 25
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 15
50
+ version: 3.0.15
51
+ type: :runtime
52
+ version_requirements: *id002
35
53
  - !ruby/object:Gem::Dependency
36
54
  name: rspec
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
40
58
  requirements:
41
59
  - - ">="
42
60
  - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 1
64
+ - 3
65
+ - 0
43
66
  version: 1.3.0
44
- version:
67
+ type: :development
68
+ version_requirements: *id003
45
69
  - !ruby/object:Gem::Dependency
46
70
  name: rcov
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
50
74
  requirements:
51
75
  - - ">="
52
76
  - !ruby/object:Gem::Version
77
+ hash: 43
78
+ segments:
79
+ - 0
80
+ - 9
81
+ - 8
53
82
  version: 0.9.8
54
- version:
83
+ type: :development
84
+ version_requirements: *id004
55
85
  - !ruby/object:Gem::Dependency
56
86
  name: rack-test
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
60
90
  requirements:
61
91
  - - ">="
62
92
  - !ruby/object:Gem::Version
63
- version: 0.5.3
64
- version:
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ - 5
97
+ - 4
98
+ version: 0.5.4
99
+ type: :development
100
+ version_requirements: *id005
65
101
  description: " A Sinatra extension for static pages rendering.\n"
66
102
  email: javier@rock-n-code.com
67
103
  executables: []
@@ -75,6 +111,7 @@ files:
75
111
  - README.markdown
76
112
  - Rakefile
77
113
  - lib/sinatra/pages.rb
114
+ - spec/helpers.rb
78
115
  - spec/pages_spec.rb
79
116
  - spec/spec_helper.rb
80
117
  has_rdoc: true
@@ -87,24 +124,35 @@ rdoc_options: []
87
124
  require_paths:
88
125
  - lib
89
126
  required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
90
128
  requirements:
91
129
  - - ">="
92
130
  - !ruby/object:Gem::Version
131
+ hash: 59
132
+ segments:
133
+ - 1
134
+ - 8
135
+ - 6
93
136
  version: 1.8.6
94
- version:
95
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
96
139
  requirements:
97
140
  - - ">="
98
141
  - !ruby/object:Gem::Version
142
+ hash: 17
143
+ segments:
144
+ - 1
145
+ - 3
146
+ - 5
99
147
  version: 1.3.5
100
- version:
101
148
  requirements: []
102
149
 
103
150
  rubyforge_project:
104
- rubygems_version: 1.3.5
151
+ rubygems_version: 1.3.7
105
152
  signing_key:
106
153
  specification_version: 3
107
154
  summary: A Sinatra extension for static pages rendering.
108
155
  test_files:
156
+ - spec/helpers.rb
109
157
  - spec/pages_spec.rb
110
158
  - spec/spec_helper.rb