rack-single-page-app 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/README.md +13 -3
- data/Rakefile +1 -0
- data/lib/rack-single-page-app.rb +1 -0
- data/lib/rack/single_page_app.rb +50 -12
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc49baa4203f9ce612869dd38f0227c6cbfa398
|
4
|
+
data.tar.gz: 1024d14598013310e88f8873710d5b75160e071c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17626674f1a683fa339193657a940ef79c5de30134e6fab0457878f11d1a459b849d2ac82ab90afeec46ac45c40006b92ffe8d49721b830640e6daac19a6aa39
|
7
|
+
data.tar.gz: 33ba963492ff135c7ebf5e006589a9c2897f43e0a3d85bee762a2da1a82ca3000ebf47ef3e8cf4f99b4a1352487e4453a22a93243f5042e0a560890ab7192aa6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -22,16 +22,26 @@ gem 'rack-single-page-app', :require => 'rack/single_page_app'
|
|
22
22
|
|
23
23
|
## Configuration
|
24
24
|
|
25
|
-
###
|
25
|
+
### Static Index Page
|
26
26
|
|
27
|
-
In `config.ru`, configure `Rack::SinglePageApp` by passing the destination file to the constructor:
|
27
|
+
In `config.ru`, configure `Rack::SinglePageApp::Index` by passing the destination file to the constructor:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
run Rack::SinglePageApp.new("public/index.html")
|
30
|
+
run Rack::SinglePageApp::Index.new("public/index.html")
|
31
31
|
```
|
32
32
|
|
33
33
|
Generally, you'll run `Rack::Static` higher up in your `config.ru` so that you deliver static assets prior to single-page-app fall-through.
|
34
34
|
|
35
|
+
### Mustache Templates
|
36
|
+
|
37
|
+
Use `Rack::SinglePageApp::Template` to compile the static output from a Mustache template. Pass the path to the template and a context object to the constructor:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
run Rack::SinglePageApp::Index.new("templates/index.html", context)
|
41
|
+
```
|
42
|
+
|
43
|
+
Note that this template will be compiled once in-memory when the app starts up, and the content will be static for the lifetime of the app.
|
44
|
+
|
35
45
|
### Testing
|
36
46
|
|
37
47
|
To contribute to the project, begin by cloning the repo and installing the necessary gems:
|
data/Rakefile
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/single_page_app'
|
data/lib/rack/single_page_app.rb
CHANGED
@@ -2,25 +2,63 @@ require 'rack'
|
|
2
2
|
require 'git-version-bump'
|
3
3
|
|
4
4
|
module Rack
|
5
|
-
|
6
|
-
|
5
|
+
module SinglePageApp
|
6
|
+
def self.release
|
7
|
+
GVB.version
|
8
|
+
end
|
7
9
|
|
8
|
-
class SinglePageApp
|
9
10
|
F = ::File
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# The base Rack application which sends default HTML content.
|
13
|
+
class Base
|
14
|
+
# @param content [String] Response body content
|
15
|
+
def initialize(content)
|
16
|
+
@content = content
|
17
|
+
@length = @content.size.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
[200, {'Content-Type' => 'text/html', 'Content-Length' => @length}, [@content]]
|
22
|
+
end
|
13
23
|
end
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
25
|
+
# Respond to generic server requests with a static HTML index page.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# run Rack::SinglePageApp::Index('assets/index.html')
|
29
|
+
#
|
30
|
+
class Index < Base
|
31
|
+
# @param path [String] Path to static file
|
32
|
+
def initialize(path)
|
33
|
+
file = F.expand_path(path)
|
34
|
+
super(F.read(file))
|
35
|
+
end
|
19
36
|
end
|
20
37
|
|
21
|
-
|
22
|
-
|
38
|
+
# Respond to generic server requests with a Mustache template, rendered with
|
39
|
+
# the provided context.
|
40
|
+
#
|
41
|
+
# Mustache is an optional dependency, so needs to be required before this
|
42
|
+
# object is constructed.
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# require 'mustache'
|
46
|
+
#
|
47
|
+
# context = {
|
48
|
+
# title: "App Title",
|
49
|
+
# body_class: "app-layout app-layout-fixed-width",
|
50
|
+
# root_element_id: "app-root",
|
51
|
+
# }
|
52
|
+
# run Rack::SinglePageApp::Template.new('assets/index.mustache', context)
|
53
|
+
#
|
54
|
+
class Template < Base
|
55
|
+
# @param path [String] Path to template
|
56
|
+
# @param context [Hash] Context object
|
57
|
+
def initialize(path, context)
|
58
|
+
template = F.read(F.expand_path(path))
|
59
|
+
output = ::Mustache.render(template, context)
|
60
|
+
super(output)
|
61
|
+
end
|
23
62
|
end
|
24
63
|
end
|
25
64
|
end
|
26
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-single-page-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Sharp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- Rakefile
|
102
102
|
- bin/console
|
103
103
|
- bin/setup
|
104
|
+
- lib/rack-single-page-app.rb
|
104
105
|
- lib/rack/single_page_app.rb
|
105
106
|
- rack-single-page-app.gemspec
|
106
107
|
homepage: https://github.com/qnm/rack-single-page-app
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.2.2
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: A rack middleware to assist running a single-page-app on rack.
|