mascot-server 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d84d308b56e6f20990771ba0681078b332533ff
4
+ data.tar.gz: 4f6031a79b988752050fd6e38c374e84ebfe76d7
5
+ SHA512:
6
+ metadata.gz: 6f6b5059b5bf0125c7bd51206159709a072ba70cee3016fd6ec830a99be8176c135a308b9d93d076b71a73494e56f22755a4a23a7a7813544be2c2e5bcd1c922
7
+ data.tar.gz: 91afc29fa0a418756543dded0df8935e7a76e01bd225445ca413571ab8dfda726314b7e444057f6869c620ff70fd4cc67ecdd8667033155f977d0e3e42ef0a75
@@ -0,0 +1,3 @@
1
+ require "mascot"
2
+
3
+ run Mascot::Server.glob("spec/pages/*")
@@ -0,0 +1,47 @@
1
+ require "mascot"
2
+
3
+ module Mascot
4
+ require "tilt"
5
+
6
+ class TiltRenderer
7
+ def initialize(resource)
8
+ @resource = resource
9
+ end
10
+
11
+ def render
12
+ template = engine.new { |t| @resource.body }
13
+ template.render(Object.new, @resource.locals)
14
+ end
15
+
16
+ private
17
+ def engine
18
+ Tilt[@resource.file_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(sitemap, relative_to: "/")
27
+ @relative_to = Pathname.new(relative_to)
28
+ @sitemap = sitemap
29
+ end
30
+
31
+ def call(env)
32
+ req = Rack::Request.new(env)
33
+ if resource = @sitemap.find_by_request_path(normalize_path(req.path))
34
+ [ 200, {"Content-Type" => resource.content_type}, [TiltRenderer.new(resource).render] ]
35
+ else
36
+ [ 404, {"Content-Type" => "text/plain"}, ["Not Found"]]
37
+ end
38
+ end
39
+
40
+ private
41
+ # If we mount this middleware in a path other than root, we need to configure it
42
+ # so that it correctly maps the request path to the content path.
43
+ def normalize_path(request_path)
44
+ ROOT_PATH.join(Pathname.new(request_path).relative_path_from(@relative_to)).to_s
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
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('../../mascot/lib/mascot/version', __FILE__)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mascot-server"
8
+ spec.version = Mascot::VERSION
9
+ spec.authors = ["Brad Gessler"]
10
+ spec.email = ["bradgessler@gmail.com"]
11
+
12
+ spec.summary = %q{Mascot rack app for stand-alone of embedded usage.}
13
+ spec.homepage = "https://github.com/bradgessler/mascot"
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 "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "haml", "~> 4.0"
24
+ spec.add_development_dependency "rack-test"
25
+ spec.add_development_dependency "rack"
26
+
27
+ spec.add_runtime_dependency "mascot", spec.version
28
+ spec.add_dependency "tilt"
29
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mascot-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Brad Gessler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mascot
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: tilt
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - bradgessler@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - config.ru
133
+ - lib/mascot-server.rb
134
+ - mascot-server.gemspec
135
+ homepage: https://github.com/bradgessler/mascot
136
+ licenses: []
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Mascot rack app for stand-alone of embedded usage.
158
+ test_files: []