sitepress-core 0.1.23 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sitepress-core.rb +3 -0
- data/lib/sitepress/middleware/request_cache.rb +26 -0
- data/lib/sitepress/site.rb +19 -2
- data/lib/sitepress/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8de27ae96f7b22a1365f8ee3db46834b2a690c6e
|
4
|
+
data.tar.gz: 3cd8b05e8d6198cf5672d9a05eb7ca3a766af3b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50ebdd80f22f4b4efdb67f2adeb977cfbcf0bc9e604f218cf30afacd55255e7512d18b90a966f485829234154cd75bb378b0ad92de8eca3165adcb45a4ad66f8
|
7
|
+
data.tar.gz: 94f3fcc3de1d3f7595de7bb2993aea11d0a1d1955aa9f0ae89995a144701d142d696e06210120ecad0214217bdba4dd55eee91beb6967d39f0af1592791d492b
|
data/lib/sitepress-core.rb
CHANGED
@@ -16,4 +16,7 @@ module Sitepress
|
|
16
16
|
autoload :ResourcesPipeline, "sitepress/resources_pipeline"
|
17
17
|
autoload :ResourcesNode, "sitepress/resources_node"
|
18
18
|
autoload :Site, "sitepress/site"
|
19
|
+
module Middleware
|
20
|
+
autoload :RequestCache, "sitepress/middleware/request_cache"
|
21
|
+
end
|
19
22
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sitepress
|
2
|
+
module Middleware
|
3
|
+
# Reloads the Sitepress cache between requests if cache resources is enabled.
|
4
|
+
# This ensures that the Sitepress resources are loaded only once per request
|
5
|
+
# for development environments so that the site isn're reloaded per call. Used
|
6
|
+
# from the Rails app and from the stand-alone Sitepress server.
|
7
|
+
class RequestCache
|
8
|
+
def initialize(app, site:)
|
9
|
+
@app, @site = app, site
|
10
|
+
end
|
11
|
+
|
12
|
+
# Cache resources for the duration of the request, even if
|
13
|
+
# caching is disabled.
|
14
|
+
def call(env)
|
15
|
+
cache_resources = @site.cache_resources
|
16
|
+
begin
|
17
|
+
@site.cache_resources = true
|
18
|
+
@app.call env
|
19
|
+
ensure
|
20
|
+
@site.cache_resources = cache_resources
|
21
|
+
@site.clear_resources_cache unless @site.cache_resources
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/sitepress/site.rb
CHANGED
@@ -24,6 +24,9 @@ module Sitepress
|
|
24
24
|
|
25
25
|
def initialize(root_path: DEFAULT_ROOT_PATH)
|
26
26
|
self.root_path = root_path
|
27
|
+
# When Site#resources is called, the results should be cached in production
|
28
|
+
# environments for performance reasons, but not in development environments.
|
29
|
+
self.cache_resources = false
|
27
30
|
end
|
28
31
|
|
29
32
|
# A tree representation of the resourecs wthin the site. The root is a node that's
|
@@ -37,8 +40,13 @@ module Sitepress
|
|
37
40
|
|
38
41
|
# Returns a list of all the resources within #root.
|
39
42
|
def resources
|
40
|
-
|
41
|
-
|
43
|
+
with_resources_cache do
|
44
|
+
ResourceCollection.new(node: root, root_path: root_path)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_resources_cache
|
49
|
+
@_resources = nil
|
42
50
|
end
|
43
51
|
|
44
52
|
# Root path to website project. Contains helpers, pages, and more.
|
@@ -51,6 +59,10 @@ module Sitepress
|
|
51
59
|
root_path.join("pages")
|
52
60
|
end
|
53
61
|
|
62
|
+
def helpers_path
|
63
|
+
root_path.join("helpers")
|
64
|
+
end
|
65
|
+
|
54
66
|
# Quick and dirty way to manipulate resources in the site without
|
55
67
|
# creating classes that implement the #process_resources method.
|
56
68
|
#
|
@@ -91,6 +103,11 @@ module Sitepress
|
|
91
103
|
end
|
92
104
|
|
93
105
|
private
|
106
|
+
def with_resources_cache
|
107
|
+
clear_resources_cache unless cache_resources
|
108
|
+
@_resources ||= yield
|
109
|
+
end
|
110
|
+
|
94
111
|
# Lazy stream of files that will be rendered by resources.
|
95
112
|
def pages_assets(glob = DEFAULT_GLOB)
|
96
113
|
Dir.glob(pages_path.join(glob)).select(&File.method(:file?)).lazy.map do |path|
|
data/lib/sitepress/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sitepress-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
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-11-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/sitepress/extensions/proc_manipulator.rb
|
81
81
|
- lib/sitepress/formats.rb
|
82
82
|
- lib/sitepress/frontmatter.rb
|
83
|
+
- lib/sitepress/middleware/request_cache.rb
|
83
84
|
- lib/sitepress/resource.rb
|
84
85
|
- lib/sitepress/resource_collection.rb
|
85
86
|
- lib/sitepress/resources_node.rb
|