sinatra-export 0.9
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/Gemfile +2 -0
- data/Gemfile.lock +46 -0
- data/lib/sinatra/export.rb +88 -0
- data/readme.md +59 -0
- data/sinatra-export.gemspec +31 -0
- metadata +180 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sinatra-export (0.9)
|
5
|
+
rack
|
6
|
+
sinatra
|
7
|
+
sinatra-advanced-routes
|
8
|
+
term-ansicolor
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
awesome_print (1.1.0)
|
14
|
+
backports (2.6.5)
|
15
|
+
monkey-lib (0.5.4)
|
16
|
+
backports
|
17
|
+
rack (1.4.1)
|
18
|
+
rack-protection (1.3.2)
|
19
|
+
rack
|
20
|
+
rack-test (0.6.2)
|
21
|
+
rack (>= 1.0)
|
22
|
+
rake (10.0.2)
|
23
|
+
sinatra (1.3.3)
|
24
|
+
rack (~> 1.3, >= 1.3.6)
|
25
|
+
rack-protection (~> 1.2)
|
26
|
+
tilt (~> 1.3, >= 1.3.3)
|
27
|
+
sinatra-advanced-routes (0.5.1)
|
28
|
+
monkey-lib (~> 0.5.0)
|
29
|
+
sinatra (~> 1.0)
|
30
|
+
sinatra-sugar (~> 0.5.0)
|
31
|
+
sinatra-sugar (0.5.1)
|
32
|
+
monkey-lib (~> 0.5.0)
|
33
|
+
sinatra (~> 1.0)
|
34
|
+
term-ansicolor (1.0.7)
|
35
|
+
test-unit (2.5.2)
|
36
|
+
tilt (1.3.3)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
awesome_print
|
43
|
+
rack-test
|
44
|
+
rake
|
45
|
+
sinatra-export!
|
46
|
+
test-unit
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Sinatra
|
2
|
+
class Export
|
3
|
+
|
4
|
+
@@file_extensions = %w(css js xml json html csv)
|
5
|
+
|
6
|
+
attr_accessor :app
|
7
|
+
|
8
|
+
include Rack::Test::Methods
|
9
|
+
|
10
|
+
require 'term/ansicolor'
|
11
|
+
class ColorString < String
|
12
|
+
include Term::ANSIColor
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(app)
|
16
|
+
@app = app
|
17
|
+
end
|
18
|
+
|
19
|
+
def build!(dir)
|
20
|
+
handle_error_no_each_route! unless @app.respond_to?(:each_route)
|
21
|
+
handle_error_dir_not_found!(dir) unless dir_exists?(dir)
|
22
|
+
build_routes(dir)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_routes(dir)
|
28
|
+
@app.each_route do |route|
|
29
|
+
next if route.verb != 'GET' or not route.path.is_a? String
|
30
|
+
build_path(route.path, dir)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_path(path, dir)
|
35
|
+
::FileUtils.mkdir_p(dir_for_path(path, dir))
|
36
|
+
::File.open(file_for_path(path, dir), 'w+') do |f|
|
37
|
+
f.write(get_path(path).body)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_path(path)
|
42
|
+
self.get(path).tap do |resp|
|
43
|
+
handle_error_non_200!(path) unless resp.status == 200
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_for_path(path, dir)
|
48
|
+
if path.match(/[^\/\.]+.(#{file_extensions.join("|")})$/)
|
49
|
+
::File.join(dir, path)
|
50
|
+
else
|
51
|
+
::File.join(dir, path, 'index.html')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def dir_exists?(dir)
|
56
|
+
::File.exists?(dir) && ::File.directory?(dir)
|
57
|
+
end
|
58
|
+
|
59
|
+
def dir_for_path(path, dir)
|
60
|
+
file_for_path(path, dir).match(/(.*)\/[^\/]+$/)[1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def file_extensions
|
64
|
+
@@file_extensions
|
65
|
+
end
|
66
|
+
|
67
|
+
def env
|
68
|
+
ENV['RACK_ENV']
|
69
|
+
end
|
70
|
+
|
71
|
+
def handle_error_no_each_route!
|
72
|
+
handle_error!("can't call app.each_route, did you include sinatra-advanced-routes?")
|
73
|
+
end
|
74
|
+
|
75
|
+
def handle_error_dir_not_found!(dir)
|
76
|
+
handle_error!("can't find output directory: #{dir}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def handle_error_non_200!(path)
|
80
|
+
handle_error!("GET #{path} returned non-200 status code...")
|
81
|
+
end
|
82
|
+
|
83
|
+
def handle_error!(desc)
|
84
|
+
puts ColorString.new("failed: #{desc}").red; exit!
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# sinatra-export
|
2
|
+
|
3
|
+
> Exports your Sinatra app to static files. Depends on [sinatra-advanced-routes](https://github.com/rkh/sinatra-advanced-routes).
|
4
|
+
|
5
|
+
[](https://travis-ci.org/hooktstudios/sinatra-static)
|
6
|
+
[](https://codeclimate.com/github/hooktstudios/sinatra-static)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add to your Gemfile :
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sinatra-export'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
builder = Sinatra::Export.new(App)
|
20
|
+
builder.build!('public/')
|
21
|
+
```
|
22
|
+
|
23
|
+
## Getting started
|
24
|
+
|
25
|
+
Sample Sinatra application building static pages :
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'sinatra'
|
29
|
+
require 'sinatra/advanced_routes'
|
30
|
+
require 'sinatra_static'
|
31
|
+
|
32
|
+
class App < Sinatra::Base
|
33
|
+
|
34
|
+
register Sinatra::AdvancedRoutes
|
35
|
+
|
36
|
+
get '/' do
|
37
|
+
"homepage"
|
38
|
+
end
|
39
|
+
|
40
|
+
get '/contact' do
|
41
|
+
"contact"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
builder = Sinatra::Export.new(App)
|
47
|
+
builder.build!('public/')
|
48
|
+
```
|
49
|
+
|
50
|
+
Running your app ex. `ruby app.rb` will automatically generate theses files :
|
51
|
+
|
52
|
+
public/index.html -> "homepage"
|
53
|
+
public/contact/index.html -> "contact"
|
54
|
+
|
55
|
+
### Advanced assets management
|
56
|
+
|
57
|
+
If you wish to generate your assets (CSS, JS, images) with an assets packaging system,
|
58
|
+
you may use [Sinatra-AssetPack](https://github.com/rstacruz/sinatra-assetpack) and build
|
59
|
+
your assets in the same target directory with `rake assetpack:build` task.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'sinatra-export'
|
3
|
+
s.version = '0.9'
|
4
|
+
|
5
|
+
s.authors = ['Jean-Philippe Doyle', 'Paul Asmuth']
|
6
|
+
s.date = '2013-01-16'
|
7
|
+
s.description = 'Export your sinatra app to a directory of static files.'
|
8
|
+
s.summary = 'Sinatra static export.'
|
9
|
+
s.email = 'jeanphilippe.doyle@hooktstudios.com'
|
10
|
+
s.files = [
|
11
|
+
'Gemfile',
|
12
|
+
'Gemfile.lock',
|
13
|
+
'sinatra-export.gemspec',
|
14
|
+
'lib/sinatra/export.rb',
|
15
|
+
'readme.md'
|
16
|
+
]
|
17
|
+
s.homepage = 'http://github.com/hooktstudios/sinatra-export'
|
18
|
+
s.license = 'MIT'
|
19
|
+
s.required_ruby_version = '>= 1.8.7'
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'term-ansicolor'
|
22
|
+
s.add_runtime_dependency 'sinatra'
|
23
|
+
s.add_runtime_dependency 'sinatra-advanced-routes'
|
24
|
+
s.add_runtime_dependency 'rack'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rack-test'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'awesome_print'
|
29
|
+
s.add_development_dependency 'test-unit'
|
30
|
+
end
|
31
|
+
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.9'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jean-Philippe Doyle
|
9
|
+
- Paul Asmuth
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: term-ansicolor
|
17
|
+
prerelease: false
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
none: false
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
none: false
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: sinatra
|
33
|
+
prerelease: false
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
none: false
|
40
|
+
type: :runtime
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
none: false
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sinatra-advanced-routes
|
49
|
+
prerelease: false
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
none: false
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
none: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rack
|
65
|
+
prerelease: false
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
none: false
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
none: false
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rack-test
|
81
|
+
prerelease: false
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
none: false
|
88
|
+
type: :development
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
none: false
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake
|
97
|
+
prerelease: false
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
none: false
|
104
|
+
type: :development
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
none: false
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
prerelease: false
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
none: false
|
120
|
+
type: :development
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
none: false
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: test-unit
|
129
|
+
prerelease: false
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
none: false
|
136
|
+
type: :development
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
none: false
|
143
|
+
description: Export your sinatra app to a directory of static files.
|
144
|
+
email: jeanphilippe.doyle@hooktstudios.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- Gemfile
|
150
|
+
- Gemfile.lock
|
151
|
+
- sinatra-export.gemspec
|
152
|
+
- lib/sinatra/export.rb
|
153
|
+
- readme.md
|
154
|
+
homepage: http://github.com/hooktstudios/sinatra-export
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.8.7
|
166
|
+
none: false
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
none: false
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 1.8.24
|
176
|
+
signing_key:
|
177
|
+
specification_version: 3
|
178
|
+
summary: Sinatra static export.
|
179
|
+
test_files: []
|
180
|
+
has_rdoc:
|