sinatra-export 0.9 → 0.9.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/lib/sinatra/export.rb +4 -1
- data/lib/sinatra/export/rake.rb +33 -0
- data/readme.md +25 -18
- data/sinatra-export.gemspec +2 -1
- metadata +2 -1
data/lib/sinatra/export.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
1
3
|
module Sinatra
|
2
4
|
class Export
|
3
5
|
|
@@ -16,7 +18,8 @@ module Sinatra
|
|
16
18
|
@app = app
|
17
19
|
end
|
18
20
|
|
19
|
-
def build!
|
21
|
+
def build!
|
22
|
+
dir = @app.public_folder
|
20
23
|
handle_error_no_each_route! unless @app.respond_to?(:each_route)
|
21
24
|
handle_error_dir_not_found!(dir) unless dir_exists?(dir)
|
22
25
|
build_routes(dir)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Rake task based on sinatra-assetpack test helper
|
2
|
+
# © 2011, Rico Sta. Cruz. Released under the MIT License
|
3
|
+
# @link http://www.opensource.org/licenses/mit-license.php
|
4
|
+
# @link https://github.com/rstacruz/sinatra-assetpack
|
5
|
+
|
6
|
+
unless defined?(APP_FILE) && defined?(APP_CLASS)
|
7
|
+
$stderr.write "Error: Please set APP_FILE, APP_CLASS before setting up Sinatra::Export rake tasks.\n"
|
8
|
+
$stderr.write "Example:\n"
|
9
|
+
$stderr.write " APP_FILE = 'app.rb'\n"
|
10
|
+
$stderr.write " APP_CLASS = 'App'\n"
|
11
|
+
$stderr.write " require 'sinatra/export/rake'\n"
|
12
|
+
$stderr.write "\n"
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
def class_from_string(str)
|
17
|
+
str.split('::').inject(Object) do |mod, class_name|
|
18
|
+
mod.const_get(class_name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def app
|
23
|
+
require File.expand_path(APP_FILE, Dir.pwd)
|
24
|
+
class_from_string(APP_CLASS)
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :sinatra do
|
28
|
+
desc "Export static application"
|
29
|
+
task :export do
|
30
|
+
require 'sinatra/export'
|
31
|
+
Sinatra::Export.new(app).build!
|
32
|
+
end
|
33
|
+
end
|
data/readme.md
CHANGED
@@ -2,57 +2,64 @@
|
|
2
2
|
|
3
3
|
> Exports your Sinatra app to static files. Depends on [sinatra-advanced-routes](https://github.com/rkh/sinatra-advanced-routes).
|
4
4
|
|
5
|
-
[](https://codeclimate.com/github/hooktstudios/sinatra-
|
5
|
+
[](https://travis-ci.org/hooktstudios/sinatra-export)
|
6
|
+
[](https://codeclimate.com/github/hooktstudios/sinatra-export)
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
-
Add to your Gemfile :
|
10
|
+
Add to your `Gemfile` :
|
11
11
|
|
12
12
|
```ruby
|
13
13
|
gem 'sinatra-export'
|
14
14
|
```
|
15
15
|
|
16
|
-
|
16
|
+
Setup your `Rakefile` :
|
17
17
|
|
18
|
-
```ruby
|
19
|
-
builder = Sinatra::Export.new(App)
|
20
|
-
builder.build!('public/')
|
21
18
|
```
|
19
|
+
APP_FILE = 'app.rb'
|
20
|
+
APP_CLASS = 'App'
|
22
21
|
|
23
|
-
|
22
|
+
require 'sinatra/export/rake'
|
23
|
+
```
|
24
|
+
|
25
|
+
## Quick Start
|
24
26
|
|
25
27
|
Sample Sinatra application building static pages :
|
26
28
|
|
27
29
|
```ruby
|
28
30
|
require 'sinatra'
|
29
31
|
require 'sinatra/advanced_routes'
|
30
|
-
require '
|
32
|
+
require 'sinatra/export'
|
31
33
|
|
32
34
|
class App < Sinatra::Base
|
33
35
|
|
34
36
|
register Sinatra::AdvancedRoutes
|
35
37
|
|
36
38
|
get '/' do
|
37
|
-
"homepage"
|
39
|
+
"<h1>My homepage</h1>"
|
38
40
|
end
|
39
41
|
|
40
42
|
get '/contact' do
|
41
|
-
"contact"
|
43
|
+
"<h1>My contact page<h1>"
|
42
44
|
end
|
43
45
|
|
44
46
|
end
|
45
|
-
|
46
|
-
builder = Sinatra::Export.new(App)
|
47
|
-
builder.build!('public/')
|
48
47
|
```
|
49
48
|
|
50
|
-
Running your app ex. `
|
49
|
+
Running your app ex. `rake sinatra:export` will automatically generate theses files :
|
50
|
+
|
51
|
+
public/index.html -> "<h1>My homepage</h1>"
|
52
|
+
public/contact/index.html -> "<h1>My contact page<h1>"
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
rake sinatra:export
|
57
|
+
|
58
|
+
Or invoke it manually :
|
51
59
|
|
52
|
-
|
53
|
-
public/contact/index.html -> "contact"
|
60
|
+
Sinatra::Export.new(App).build!
|
54
61
|
|
55
|
-
### Advanced
|
62
|
+
### Advanced Assets Management
|
56
63
|
|
57
64
|
If you wish to generate your assets (CSS, JS, images) with an assets packaging system,
|
58
65
|
you may use [Sinatra-AssetPack](https://github.com/rstacruz/sinatra-assetpack) and build
|
data/sinatra-export.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'sinatra-export'
|
3
|
-
s.version = '0.9'
|
3
|
+
s.version = '0.9.1'
|
4
4
|
|
5
5
|
s.authors = ['Jean-Philippe Doyle', 'Paul Asmuth']
|
6
6
|
s.date = '2013-01-16'
|
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
'Gemfile.lock',
|
13
13
|
'sinatra-export.gemspec',
|
14
14
|
'lib/sinatra/export.rb',
|
15
|
+
'lib/sinatra/export/rake.rb',
|
15
16
|
'readme.md'
|
16
17
|
]
|
17
18
|
s.homepage = 'http://github.com/hooktstudios/sinatra-export'
|
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:
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- Gemfile.lock
|
151
151
|
- sinatra-export.gemspec
|
152
152
|
- lib/sinatra/export.rb
|
153
|
+
- lib/sinatra/export/rake.rb
|
153
154
|
- readme.md
|
154
155
|
homepage: http://github.com/hooktstudios/sinatra-export
|
155
156
|
licenses:
|