mascot 0.1.15 → 0.1.16
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/mascot.rb +1 -0
- data/lib/mascot/resource_collection.rb +33 -0
- data/lib/mascot/site.rb +15 -14
- data/lib/mascot/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: 61813ce31c75f235460581aec9bfd67dedec526b
|
4
|
+
data.tar.gz: a7c09c30caea3e1c71cb253666283a95dd5e7a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d66edf40c7634003a189231d7f9a0b514f2c9eb80d3044522b34cc5b2fbff00115044e2509a4fdc7dc6c61e0279325eb57ac0f3bcf849a19eaa1e3b7a466fc
|
7
|
+
data.tar.gz: ca883b566b665f1b7a81800ad3b308118d0f5db1f61ea2ef2833d86150ee4ae15304eb6d51dcfc0c7f4816420fcdaa7e2e0ae460631b08ec80504c6247d286d7
|
data/lib/mascot.rb
CHANGED
@@ -12,6 +12,7 @@ module Mascot
|
|
12
12
|
autoload :Formats, "mascot/formats"
|
13
13
|
autoload :Frontmatter, "mascot/frontmatter"
|
14
14
|
autoload :Resource, "mascot/resource"
|
15
|
+
autoload :ResourceCollection, "mascot/resource_collection"
|
15
16
|
autoload :ResourcesPipeline, "mascot/resources_pipeline"
|
16
17
|
autoload :ResourcesNode, "mascot/resources_node"
|
17
18
|
autoload :Site, "mascot/site"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mascot
|
2
|
+
# Represents a collection of resources. Provides interfaces to query
|
3
|
+
# resource via globbing, paths, etc.
|
4
|
+
class ResourceCollection
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :resources, :each, :size
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
# Used by `#glob` to determine the full path when
|
11
|
+
# given a relative glob pattern.
|
12
|
+
attr_reader :root_path
|
13
|
+
|
14
|
+
def initialize(node: , root_path: ".")
|
15
|
+
@node = node
|
16
|
+
@root_path = Pathname.new(root_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def glob(pattern)
|
20
|
+
paths = Dir.glob root_path.join(pattern)
|
21
|
+
resources.select { |r| paths.include? r.asset.path.to_s }
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(request_path)
|
25
|
+
@node.get(request_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def resources
|
30
|
+
@node.flatten
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/mascot/site.rb
CHANGED
@@ -12,8 +12,18 @@ module Mascot
|
|
12
12
|
|
13
13
|
attr_reader :root_path, :resources_pipeline
|
14
14
|
|
15
|
-
|
15
|
+
# Cache resources for production runs of Mascot. Development
|
16
|
+
# modes don't cache to optimize for files reloading.
|
17
|
+
attr_accessor :cache_resources
|
18
|
+
alias :cache_resources? :cache_resources
|
19
|
+
|
20
|
+
# TODO: Get rid of these so that folks have ot call site.resources.get ...
|
21
|
+
extend Forwardable
|
22
|
+
def_delegators :resources, :get, :glob
|
23
|
+
|
24
|
+
def initialize(root_path: DEFAULT_ROOT_PATH, cache_resources: false)
|
16
25
|
self.root_path = root_path
|
26
|
+
self.cache_resources = cache_resources
|
17
27
|
end
|
18
28
|
|
19
29
|
# A tree representation of the resourecs wthin the site.
|
@@ -26,17 +36,12 @@ module Mascot
|
|
26
36
|
|
27
37
|
# Returns a list of all the resources within #root.
|
28
38
|
def resources
|
29
|
-
|
39
|
+
@resources = nil unless cache_resources
|
40
|
+
@resources ||= ResourceCollection.new(node: root, root_path: root_path)
|
30
41
|
end
|
31
42
|
|
32
|
-
def
|
33
|
-
|
34
|
-
resources.select { |r| paths.include? r.asset.path.to_s }
|
35
|
-
end
|
36
|
-
|
37
|
-
# Find the page with a path.
|
38
|
-
def get(request_path)
|
39
|
-
root.get(request_path)
|
43
|
+
def root_path=(path)
|
44
|
+
@root_path = Pathname.new(path)
|
40
45
|
end
|
41
46
|
|
42
47
|
# Quick and dirty way to manipulate resources in the site without
|
@@ -45,10 +50,6 @@ module Mascot
|
|
45
50
|
resources_pipeline << Extensions::ProcManipulator.new(block)
|
46
51
|
end
|
47
52
|
|
48
|
-
def root_path=(path)
|
49
|
-
@root_path = Pathname.new(path)
|
50
|
-
end
|
51
|
-
|
52
53
|
def resources_pipeline
|
53
54
|
@resources_pipeline ||= ResourcesPipeline.new
|
54
55
|
end
|
data/lib/mascot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mascot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.16
|
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-09-
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/mascot/formats.rb
|
82
82
|
- lib/mascot/frontmatter.rb
|
83
83
|
- lib/mascot/resource.rb
|
84
|
+
- lib/mascot/resource_collection.rb
|
84
85
|
- lib/mascot/resources_node.rb
|
85
86
|
- lib/mascot/resources_pipeline.rb
|
86
87
|
- lib/mascot/site.rb
|