mascot-server 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mascot-server.rb +16 -5
  3. metadata +4 -5
  4. data/config.ru +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acde64d6e753e074adebc7ecf54d33566b63ac12
4
- data.tar.gz: 2ed7e2c07f7641217693378229b28cbb19870551
3
+ metadata.gz: 61bb9c9d9d5d746f7df49a41afb647918554e08e
4
+ data.tar.gz: cc6c0ffaee98320f7a6eeb58fca068e20de1d705
5
5
  SHA512:
6
- metadata.gz: ec22afd919bafac12e077107c54ca30e4b3fc0c292d46fc98269fafe4fd7ec53a10c72fe04caebfb2348f5b0b95d4a62008ef73defb3abb1200225ead8e86e48
7
- data.tar.gz: eb8f3244835fbfe9834f15220457eca3c253fd34aa5b62e16f85442ce5d49f544221b6e23e67112602fd73cae7f63b0c2b96e0baf2c8fa202f1f333805430718
6
+ metadata.gz: e913c603786f9c2ae12ed5e4d629f70b029316b1f753a689743b1f7f84552c2a69b5b5fd17f426b6995e49ca9979848f1d219e670ac857927ac5ea03409d7dd1
7
+ data.tar.gz: 7e328d480cc0726b26fb34992ec153f43631784be0fa57b6faf2dd9992edd5189c4958f94c85ee6fa4a90a957d58fa11645cf943629c6b4af959ad1212f5a774
data/lib/mascot-server.rb CHANGED
@@ -1,15 +1,16 @@
1
1
  require "mascot"
2
2
  require "tilt"
3
+ require "pathname"
3
4
 
4
5
  module Mascot
5
- class TiltRenderer
6
+ class TiltResourceRenderer
6
7
  def initialize(resource)
7
8
  @resource = resource
8
9
  end
9
10
 
10
- def render
11
+ def render(locals: {}, layout: "layout")
11
12
  template = engine.new { @resource.body }
12
- template.render(Object.new, {current_page: @resource})
13
+ template.render(Object.new, **locals.merge(resource: @resource))
13
14
  end
14
15
 
15
16
  private
@@ -30,9 +31,19 @@ module Mascot
30
31
  def call(env)
31
32
  req = Rack::Request.new(env)
32
33
  resource = @sitemap.get req.path
34
+ # TODO: Memoize this per request and between requests eventually.
35
+ resources = @sitemap.resources
33
36
 
34
- if resource
35
- [ 200, {"Content-Type" => resource.mime_type.to_s}, [TiltRenderer.new(resource).render] ]
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) ]
36
47
  else
37
48
  [ 404, {"Content-Type" => "text/plain"}, ["Not Found"]]
38
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mascot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.7
61
+ version: 0.1.8
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.7
68
+ version: 0.1.8
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tilt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,7 +87,6 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - config.ru
91
90
  - lib/mascot-server.rb
92
91
  - mascot-server.gemspec
93
92
  homepage: https://github.com/bradgessler/mascot
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- require "mascot-server"
2
-
3
- sitemap = Mascot::Sitemap.new(root: "spec/pages")
4
- run Mascot::Server.new(sitemap: sitemap)