mascot 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cbf26b5dbbcb679dee59b1f38f93d73dfd8bab7
4
- data.tar.gz: 53bb98405c06bf85705c397c69bba07992895038
3
+ metadata.gz: 61813ce31c75f235460581aec9bfd67dedec526b
4
+ data.tar.gz: a7c09c30caea3e1c71cb253666283a95dd5e7a74
5
5
  SHA512:
6
- metadata.gz: 4ac9c815391409fd3e57fd942a23b49e7d106cf58f117e9e19f5155860c4f6958fbaeb3a3774658e4b46216788e48abb08efda31d7e74bbc57c4df1e084409d4
7
- data.tar.gz: 49099b0682866088cb2aba0cbd16397682a280084de69cade3e378392b3306020be20bd9d0a805c8fa55ec20f5c5f1f65adb67c29aba5310360d94426bbc497c
6
+ metadata.gz: 16d66edf40c7634003a189231d7f9a0b514f2c9eb80d3044522b34cc5b2fbff00115044e2509a4fdc7dc6c61e0279325eb57ac0f3bcf849a19eaa1e3b7a466fc
7
+ data.tar.gz: ca883b566b665f1b7a81800ad3b308118d0f5db1f61ea2ef2833d86150ee4ae15304eb6d51dcfc0c7f4816420fcdaa7e2e0ae460631b08ec80504c6247d286d7
@@ -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
@@ -12,8 +12,18 @@ module Mascot
12
12
 
13
13
  attr_reader :root_path, :resources_pipeline
14
14
 
15
- def initialize(root_path: DEFAULT_ROOT_PATH)
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
- root.flatten
39
+ @resources = nil unless cache_resources
40
+ @resources ||= ResourceCollection.new(node: root, root_path: root_path)
30
41
  end
31
42
 
32
- def glob(pattern)
33
- paths = Dir.glob root_path.join(pattern)
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
@@ -1,3 +1,3 @@
1
1
  module Mascot
2
- VERSION = "0.1.15"
2
+ VERSION = "0.1.16"
3
3
  end
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.15
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-06 00:00:00.000000000 Z
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