sinatra-export 0.9.5 → 1.0.1

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.tar.gz.sig CHANGED
Binary file
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-export (0.9.5)
4
+ sinatra-export (1.0.1)
5
5
  rack
6
+ rack-test
7
+ rake
6
8
  sinatra
7
9
  sinatra-advanced-routes
8
10
  term-ansicolor
@@ -13,25 +15,24 @@ GEM
13
15
  awesome_print (1.1.0)
14
16
  backports (3.1.1)
15
17
  columnize (0.3.6)
16
- debugger (1.4.0)
18
+ debugger (1.5.0)
17
19
  columnize (>= 0.3.1)
18
- debugger-linecache (~> 1.1.1)
20
+ debugger-linecache (~> 1.2.0)
19
21
  debugger-ruby_core_source (~> 1.2.0)
20
- debugger-linecache (1.1.2)
21
- debugger-ruby_core_source (>= 1.1.1)
22
+ debugger-linecache (1.2.0)
22
23
  debugger-ruby_core_source (1.2.0)
23
24
  monkey-lib (0.5.4)
24
25
  backports
25
26
  rack (1.5.2)
26
- rack-protection (1.4.0)
27
+ rack-protection (1.5.0)
27
28
  rack
28
29
  rack-test (0.6.2)
29
30
  rack (>= 1.0)
30
31
  rake (10.0.3)
31
- sinatra (1.3.5)
32
- rack (~> 1.4)
33
- rack-protection (~> 1.3)
34
- tilt (~> 1.3, >= 1.3.3)
32
+ sinatra (1.4.1)
33
+ rack (~> 1.5, >= 1.5.2)
34
+ rack-protection (~> 1.4)
35
+ tilt (~> 1.3, >= 1.3.4)
35
36
  sinatra-advanced-routes (0.5.2)
36
37
  monkey-lib (~> 0.5.0)
37
38
  sinatra (~> 1.0)
@@ -41,7 +42,7 @@ GEM
41
42
  sinatra (~> 1.0)
42
43
  term-ansicolor (1.1.1)
43
44
  test-unit (2.5.4)
44
- tilt (1.3.5)
45
+ tilt (1.3.6)
45
46
 
46
47
  PLATFORMS
47
48
  ruby
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Exports all your Sinatra application routes to static files in your public folder.
4
4
 
5
- [![Build Status](https://travis-ci.org/hooktstudios/sinatra-export.png)](https://travis-ci.org/hooktstudios/sinatra-export)
5
+ [![Build Status](https://travis-ci.org/hooktstudios/sinatra-export.png?branch=master)](https://travis-ci.org/hooktstudios/sinatra-export)
6
6
  [![Dependency Status](https://gemnasium.com/hooktstudios/sinatra-export.png)](https://gemnasium.com/hooktstudios/sinatra-export)
7
7
  [![Code Climate](https://codeclimate.com/github/hooktstudios/sinatra-export.png)](https://codeclimate.com/github/hooktstudios/sinatra-export)
8
8
  [![Gem Version](https://badge.fury.io/rb/sinatra-export.png)](https://rubygems.org/gems/sinatra-export)
@@ -15,17 +15,11 @@ Add to your `Gemfile` :
15
15
  gem 'sinatra-export'
16
16
  ```
17
17
 
18
- Setup your application with [sinatra-advanced-routes](https://github.com/hooktstudios/sinatra-advanced-routes) :
19
-
20
- ```ruby
21
- register Sinatra::AdvancedRoutes
22
- ```
23
-
24
18
  Setup your `Rakefile` :
25
19
 
26
20
  ```ruby
27
21
  APP_FILE = 'app.rb'
28
- APP_CLASS = 'App'
22
+ APP_CLASS = 'Sinatra::Application'
29
23
 
30
24
  require 'sinatra/export/rake'
31
25
  ```
@@ -36,25 +30,18 @@ Sample Sinatra application building static pages :
36
30
 
37
31
  ```ruby
38
32
  require 'sinatra'
39
- require 'sinatra/advanced_routes'
40
33
  require 'sinatra/export'
41
34
 
42
- class App < Sinatra::Base
43
-
44
- register Sinatra::AdvancedRoutes
45
-
46
- get '/' do
47
- "<h1>My homepage</h1>"
48
- end
49
-
50
- get '/contact' do
51
- "<h1>My contact page<h1>"
52
- end
35
+ get '/' do
36
+ "<h1>My homepage</h1>"
37
+ end
53
38
 
54
- get '/data.json' do
55
- "{test: 'ok'}"
56
- end
39
+ get '/contact' do
40
+ "<h1>My contact page<h1>"
41
+ end
57
42
 
43
+ get '/data.json' do
44
+ "{test: 'ok'}"
58
45
  end
59
46
  ```
60
47
 
@@ -71,7 +58,7 @@ Running your app ex. `rake sinatra:export` will automatically generate theses fi
71
58
  Or invoke it manually within ruby code :
72
59
 
73
60
  ````ruby
74
- Sinatra::Export.new(App).build!
61
+ App.export!
75
62
  ```
76
63
 
77
64
  ## Other resources
@@ -88,4 +75,4 @@ See [CONTRIBUTING.md](https://github.com/hooktstudios/sinatra-export/blob/master
88
75
 
89
76
  ![hooktstudios](http://hooktstudios.com/logo.png)
90
77
 
91
- [sinatra-export](https://rubygems.org/gems/sinatra-export) is maintained and funded by [hooktstudios](https://github.com/hooktstudios)
78
+ [sinatra-export](https://rubygems.org/gems/sinatra-export) is maintained and funded by [hooktstudios](https://github.com/hooktstudios)
@@ -0,0 +1,14 @@
1
+ ##################################################
2
+ # NOTE FOR UPGRADING FROM PRE-1.0 VERSION #
3
+ ##################################################
4
+
5
+ Sinatra::Export is now a Sinatra extension
6
+ and advanced routes are auto-loaded.
7
+
8
+ To upgrade, replace in your application :
9
+
10
+ register Sinatra::AdvancedRoutes
11
+
12
+ with :
13
+
14
+ register Sinatra::Export
@@ -1,100 +1,101 @@
1
+ require 'sinatra/base'
2
+ require 'sinatra/advanced_routes'
1
3
  require 'rack/test'
2
4
  require 'term/ansicolor'
3
5
 
4
6
  module Sinatra
5
- class Export
7
+ module Export
6
8
 
7
- @@file_extensions = %w(css js xml json html csv)
8
-
9
- attr_accessor :app
10
-
11
- include Rack::Test::Methods
12
-
13
-
14
- class ColorString < String
15
- include Term::ANSIColor
16
- end
17
-
18
- def initialize(app)
19
- @app = app
9
+ def self.registered(app)
10
+ if app.extensions.nil? or !app.extensions.include?(Sinatra::AdvancedRoutes)
11
+ app.register Sinatra::AdvancedRoutes
12
+ end
13
+ app.set :export_extensions, %w(css js xml json html csv)
14
+ app.extend ClassMethods
20
15
  end
21
16
 
22
- def build!
23
- dir = @app.public_folder
24
- handle_error_no_each_route! unless @app.respond_to?(:each_route)
25
- handle_error_dir_not_found!(dir) unless dir_exists?(dir)
26
- build_routes(dir)
17
+ module ClassMethods
18
+ def export!
19
+ Builder.new(self).build!
20
+ end
27
21
  end
28
22
 
29
- private
23
+ class Builder
24
+ include Rack::Test::Methods
30
25
 
31
- def build_routes(dir)
32
- @app.each_route do |route|
33
- next if route.verb != 'GET' or not route.path.is_a? String
34
- build_path(route.path, dir)
26
+ class ColorString < String
27
+ include Term::ANSIColor
35
28
  end
36
- end
37
29
 
38
- def build_path(path, dir)
39
- response = get_path(path)
40
- body = response.body
41
- mtime = response.headers.key?("Last-Modified") ?
42
- Time.httpdate(response.headers["Last-Modified"]) : Time.now
43
- file_path = file_for_path(path, dir)
44
- dir_path = dir_for_path(path, dir)
45
-
46
- ::FileUtils.mkdir_p(dir_path)
47
- ::File.open(file_path, 'w+') do |f|
48
- f.write(body)
30
+ def initialize(app)
31
+ @app = app
49
32
  end
50
- ::FileUtils.touch(file_path, :mtime => mtime)
51
- end
52
33
 
53
- def get_path(path)
54
- self.get(path).tap do |resp|
55
- handle_error_non_200!(path) unless resp.status == 200
34
+ def app
35
+ @app
56
36
  end
57
- end
58
37
 
59
- def file_for_path(path, dir)
60
- if path.match(/[^\/\.]+.(#{file_extensions.join("|")})$/)
61
- ::File.join(dir, path)
62
- else
63
- ::File.join(dir, path, 'index.html')
38
+ def build!
39
+ dir = app.public_folder
40
+ handle_error_dir_not_found!(dir) unless dir_exists?(dir)
41
+ app.each_route do |route|
42
+ next if route.verb != 'GET' or not route.path.is_a? String
43
+ build_path(route.path, dir)
44
+ end
64
45
  end
65
- end
66
-
67
- def dir_exists?(dir)
68
- ::File.exists?(dir) && ::File.directory?(dir)
69
- end
70
46
 
71
- def dir_for_path(path, dir)
72
- file_for_path(path, dir).match(/(.*)\/[^\/]+$/)[1]
47
+ private
48
+
49
+ def build_path(path, dir)
50
+ response = get_path(path)
51
+ body = response.body
52
+ mtime = response.headers.key?("Last-Modified") ?
53
+ Time.httpdate(response.headers["Last-Modified"]) : Time.now
54
+ file_path = file_for_path(path, dir)
55
+ dir_path = dir_for_path(path, dir)
56
+
57
+ ::FileUtils.mkdir_p(dir_path)
58
+ ::File.open(file_path, 'w+') do |f|
59
+ f.write(body)
60
+ end
61
+ ::FileUtils.touch(file_path, :mtime => mtime)
62
+ end
63
+
64
+ def get_path( path)
65
+ get(path).tap do |resp|
66
+ handle_error_non_200!(path) unless resp.status == 200
67
+ end
68
+ end
69
+
70
+ def file_for_path(path, dir)
71
+ if path.match(/[^\/\.]+.(#{app.settings.export_extensions.join("|")})$/)
72
+ ::File.join(dir, path)
73
+ else
74
+ ::File.join(dir, path, 'index.html')
75
+ end
76
+ end
77
+
78
+ def dir_exists?(dir)
79
+ ::File.exists?(dir) && ::File.directory?(dir)
80
+ end
81
+
82
+ def dir_for_path(path, dir)
83
+ file_for_path(path, dir).match(/(.*)\/[^\/]+$/)[1]
84
+ end
85
+
86
+ def handle_error_dir_not_found!(dir)
87
+ handle_error!("can't find output directory: #{dir}")
88
+ end
89
+
90
+ def handle_error_non_200!(path)
91
+ handle_error!("GET #{path} returned non-200 status code...")
92
+ end
93
+
94
+ def handle_error!(desc)
95
+ puts ColorString.new("failed: #{desc}").red; exit!
96
+ end
73
97
  end
74
-
75
- def file_extensions
76
- @@file_extensions
77
- end
78
-
79
- def env
80
- ENV['RACK_ENV']
81
- end
82
-
83
- def handle_error_no_each_route!
84
- handle_error!("can't call app.each_route, did you include sinatra-advanced-routes?")
85
- end
86
-
87
- def handle_error_dir_not_found!(dir)
88
- handle_error!("can't find output directory: #{dir}")
89
- end
90
-
91
- def handle_error_non_200!(path)
92
- handle_error!("GET #{path} returned non-200 status code...")
93
- end
94
-
95
- def handle_error!(desc)
96
- puts ColorString.new("failed: #{desc}").red; exit!
97
- end
98
-
99
98
  end
99
+
100
+ register Sinatra::Export
100
101
  end
@@ -27,7 +27,6 @@ end
27
27
  namespace :sinatra do
28
28
  desc "Export static application"
29
29
  task :export do
30
- require 'sinatra/export'
31
- Sinatra::Export.new(app).build!
30
+ app.export!
32
31
  end
33
32
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'sinatra-export'
3
- s.version = '0.9.5'
3
+ s.version = '1.0.1'
4
4
 
5
5
  s.authors = ['Jean-Philippe Doyle', 'Paul Asmuth']
6
6
  s.description = 'Exports all your Sinatra application routes to static files in your public folder'
@@ -15,15 +15,22 @@ Gem::Specification.new do |s|
15
15
  'lib/sinatra/export.rb',
16
16
  'lib/sinatra/export/rake.rb',
17
17
  'README.md',
18
- 'LICENSE'
18
+ 'LICENSE',
19
+ 'UPGRADING'
19
20
  ]
20
21
  s.homepage = 'http://github.com/hooktstudios/sinatra-export'
21
22
  s.license = 'MIT'
22
23
  s.required_ruby_version = '>= 1.8.7'
23
24
 
25
+ if File.exists?('UPGRADING')
26
+ s.post_install_message = File.read("UPGRADING")
27
+ end
28
+
24
29
  s.add_runtime_dependency 'term-ansicolor'
25
30
  s.add_runtime_dependency 'sinatra'
26
31
  s.add_runtime_dependency 'sinatra-advanced-routes'
27
32
  s.add_runtime_dependency 'rack'
33
+ s.add_runtime_dependency 'rake'
34
+ s.add_runtime_dependency 'rack-test'
28
35
  end
29
36
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -38,7 +38,7 @@ cert_chain:
38
38
  MjN3ZTRFMUx2ZlJuNWdWNzdEaWo2czlWNEhIek1CdUx3bk5iOFQrNmxPblVX
39
39
  YnRpSWRkRAplOGM4aTdQbHJ6aFZKLzhzWFVKc0NreUU4ZDJNeVJ5amx4TT0K
40
40
  LS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
41
- date: 2013-03-11 00:00:00.000000000 Z
41
+ date: 2013-03-17 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: term-ansicolor
@@ -104,6 +104,38 @@ dependencies:
104
104
  - - ! '>='
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: rake
109
+ requirement: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ type: :runtime
116
+ prerelease: false
117
+ version_requirements: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rack-test
125
+ requirement: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
107
139
  description: Exports all your Sinatra application routes to static files in your public
108
140
  folder
109
141
  email: jeanphilippe.doyle@hooktstudios.com
@@ -118,10 +150,15 @@ files:
118
150
  - lib/sinatra/export/rake.rb
119
151
  - README.md
120
152
  - LICENSE
153
+ - UPGRADING
121
154
  homepage: http://github.com/hooktstudios/sinatra-export
122
155
  licenses:
123
156
  - MIT
124
- post_install_message:
157
+ post_install_message: ! "##################################################\n# NOTE
158
+ FOR UPGRADING FROM PRE-1.0 VERSION #\n##################################################\n\nSinatra::Export
159
+ is now a Sinatra extension\nand advanced routes are auto-loaded.\n\nTo upgrade,
160
+ replace in your application :\n\n register Sinatra::AdvancedRoutes\n\nwith :\n\n
161
+ \ register Sinatra::Export"
125
162
  rdoc_options: []
126
163
  require_paths:
127
164
  - lib
metadata.gz.sig CHANGED
Binary file