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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20ad54943b5639b800d32713819e23c9b751f913
4
- data.tar.gz: 5031a70579df3a16bc6ab53977e38e94edab5759
3
+ metadata.gz: bdc49baa4203f9ce612869dd38f0227c6cbfa398
4
+ data.tar.gz: 1024d14598013310e88f8873710d5b75160e071c
5
5
  SHA512:
6
- metadata.gz: 26dbe7188ab2aec6b95a3a03ce7b82ae5801447a1f87160ff3f52cde85d13971fb3d8e6cca98992f4181ef06c9d4366c4bdc8db006c9021e25d2c881b9ebf264
7
- data.tar.gz: 889d6e0725e3bd05d87f743751f2f13946d783a1c19c9c2ec770427cd1005b15769aeedabc1f53bef3338cac62a5ce020923441ffb800b84df0306162aff2923
6
+ metadata.gz: 17626674f1a683fa339193657a940ef79c5de30134e6fab0457878f11d1a459b849d2ac82ab90afeec46ac45c40006b92ffe8d49721b830640e6daac19a6aa39
7
+ data.tar.gz: 33ba963492ff135c7ebf5e006589a9c2897f43e0a3d85bee762a2da1a82ca3000ebf47ef3e8cf4f99b4a1352487e4453a22a93243f5042e0a560890ab7192aa6
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rack-single-page-app.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem 'mustache'
8
+ end
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
- ### Rack
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
@@ -8,6 +8,7 @@ rescue Bundler::BundlerError => ex
8
8
  exit e.status_code
9
9
  end
10
10
 
11
+ require "bundler/gem_tasks"
11
12
  require 'rdoc/task'
12
13
  require 'rake/testtask'
13
14
  require 'git-version-bump/rake-tasks'
@@ -0,0 +1 @@
1
+ require 'rack/single_page_app'
@@ -2,25 +2,63 @@ require 'rack'
2
2
  require 'git-version-bump'
3
3
 
4
4
  module Rack
5
- # Rack::SinglePageApp is a default endpoint. Initialize with the path to
6
- # your index page.
5
+ module SinglePageApp
6
+ def self.release
7
+ GVB.version
8
+ end
7
9
 
8
- class SinglePageApp
9
10
  F = ::File
10
11
 
11
- def self.release
12
- GVB.version
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
- def initialize(path)
16
- file = F.expand_path(path)
17
- @content = F.read(file)
18
- @length = @content.size.to_s
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
- def call(env)
22
- [200, {'Content-Type' => 'text/html', 'Content-Length' => @length}, [@content]]
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.0.0
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-08-14 00:00:00.000000000 Z
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.4.5
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.