sitepress-server 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/sitepress-server.rb +52 -0
- data/sitepress-server.gemspec +26 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f00977c770a251875d7d3f484e0fccf36007bf1b
|
4
|
+
data.tar.gz: bef9a35e0480ecc8c9abc61e888309594667d085
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c829547e1fe9bfd9147fda4fbbb0cbe81046ef6e2d22db66bcddd50dfa19aa15daa66b6ae13e851853d9f2f9bade4accb920a9be5547e2322e22b933eccbe26b
|
7
|
+
data.tar.gz: 83654da6d04f45d885814c5de6e75542d5b6521c2814aa83b78503242395ad636a1db807fd1b9c526a9641e81e8ae194e84ab754e43729d63aeeac40dc441c09
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "sitepress"
|
2
|
+
require "tilt"
|
3
|
+
require "pathname"
|
4
|
+
|
5
|
+
module Sitepress
|
6
|
+
class TiltResourceRenderer
|
7
|
+
def initialize(resource)
|
8
|
+
@resource = resource
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(locals: {}, layout: "layout")
|
12
|
+
template = engine.new { @resource.body }
|
13
|
+
template.render(Object.new, **locals.merge(resource: @resource))
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def engine
|
18
|
+
Tilt[@resource.asset.path]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Mount inside of a config.ru file to run this as a server.
|
23
|
+
class Server
|
24
|
+
ROOT_PATH = Pathname.new("/")
|
25
|
+
|
26
|
+
def initialize(site: , relative_to: "/")
|
27
|
+
@relative_to = Pathname.new(relative_to)
|
28
|
+
@site = site
|
29
|
+
end
|
30
|
+
|
31
|
+
def call(env)
|
32
|
+
req = Rack::Request.new(env)
|
33
|
+
resource = @site.get req.path
|
34
|
+
# TODO: Memoize this per request and between requests eventually.
|
35
|
+
resources = @site.root
|
36
|
+
|
37
|
+
if resource
|
38
|
+
body = if resource.asset.template_extensions.empty?
|
39
|
+
# TODO: This is not efficient for huge files. Research how Rack::File
|
40
|
+
# serves this up (or just take that, maybe mount it as a cascading middleware.)
|
41
|
+
resource.body
|
42
|
+
else
|
43
|
+
TiltResourceRenderer.new(resource).render(locals: {resources: resources})
|
44
|
+
end
|
45
|
+
|
46
|
+
[ 200, {"Content-Type" => resource.mime_type.to_s}, Array(body) ]
|
47
|
+
else
|
48
|
+
[ 404, {"Content-Type" => "text/plain"}, ["Not Found"]]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require File.expand_path('../../sitepress/lib/sitepress/version', __FILE__)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sitepress-server"
|
8
|
+
spec.version = Sitepress::VERSION
|
9
|
+
spec.authors = ["Brad Gessler"]
|
10
|
+
spec.email = ["bradgessler@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sitepress rack app for stand-alone of embedded usage.}
|
13
|
+
spec.homepage = "https://github.com/bradgessler/sitepress"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "haml", "~> 4.0"
|
21
|
+
spec.add_development_dependency "rack-test"
|
22
|
+
spec.add_development_dependency "rack"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "sitepress", spec.version
|
25
|
+
spec.add_runtime_dependency "tilt"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sitepress-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.16
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Gessler
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: haml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-test
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sitepress
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.16
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.16
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tilt
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- bradgessler@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- lib/sitepress-server.rb
|
91
|
+
- sitepress-server.gemspec
|
92
|
+
homepage: https://github.com/bradgessler/sitepress
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Sitepress rack app for stand-alone of embedded usage.
|
115
|
+
test_files: []
|
116
|
+
has_rdoc:
|