mascot 0.1.14 → 0.1.15

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: 6be4b1751690e6c59370910168e633fa512d4179
4
- data.tar.gz: 953289c76d1245c7e037a5a32ededad0321ca8cc
3
+ metadata.gz: 3cbf26b5dbbcb679dee59b1f38f93d73dfd8bab7
4
+ data.tar.gz: 53bb98405c06bf85705c397c69bba07992895038
5
5
  SHA512:
6
- metadata.gz: 61471911d2ef4efb0c017e371d4fa563af64116e40360a0eff0062d14f2397343755c9de4930ea01a8470f66408ef29a136994a1d07236e715ec42b136612df9
7
- data.tar.gz: 2a24c41a5618965f225570b912346fa0d2b9863076c2e1e1d876efe6ea78dc79ee65847297dfcd64dc45f86a26f2868e288bfcb91c5d6e6c6f9658c205eb57d9
6
+ metadata.gz: 4ac9c815391409fd3e57fd942a23b49e7d106cf58f117e9e19f5155860c4f6958fbaeb3a3774658e4b46216788e48abb08efda31d7e74bbc57c4df1e084409d4
7
+ data.tar.gz: 49099b0682866088cb2aba0cbd16397682a280084de69cade3e378392b3306020be20bd9d0a805c8fa55ec20f5c5f1f65adb67c29aba5310360d94426bbc497c
@@ -14,7 +14,7 @@ module Mascot
14
14
  end
15
15
 
16
16
  def process_resources(node)
17
- node.resources.each do |resource|
17
+ node.flatten.each do |resource|
18
18
  @rules.each do |rule|
19
19
  if rule.processor.call(resource)
20
20
  resource.data["layout"] ||= rule.layout
@@ -6,7 +6,7 @@ module Mascot
6
6
  end
7
7
 
8
8
  def process_resources(node)
9
- node.resources.each do |resource|
9
+ node.flatten.each do |resource|
10
10
  if @block.arity == 1
11
11
  @block.call resource
12
12
  else # This will blow up if 0 or greater than 2.
@@ -48,26 +48,12 @@ module Mascot
48
48
  child_nodes.empty?
49
49
  end
50
50
 
51
- class Resources
52
- include Enumerable
53
-
54
- def initialize(node: )
55
- @node = node
56
- end
57
-
58
- def each(&block)
59
- @node.formats.each(&block)
60
- @node.children.each { |child| child.resources.each(&block) }
61
- end
62
-
63
- def glob(pattern)
64
- paths = Dir.glob(pattern)
65
- select { |r| paths.include? r.asset.path.to_s }
51
+ def flatten(resources: [])
52
+ formats.each{ |resource| resources << resource }
53
+ children.each do |child|
54
+ child.flatten.each{ |resource| resources << resource }
66
55
  end
67
- end
68
-
69
- def resources
70
- Resources.new(node: self)
56
+ resources
71
57
  end
72
58
 
73
59
  def remove
@@ -91,18 +77,18 @@ module Mascot
91
77
  end
92
78
  alias :[]= :add
93
79
 
94
- def get_resource(path)
80
+ def get(path)
95
81
  *path, ext = tokenize(path)
96
82
  if node = dig(*path)
97
83
  node.formats.ext(ext)
98
84
  end
99
85
  end
100
86
 
101
- def get(path)
102
- *path, ext = tokenize(path)
87
+ def get_node(path)
88
+ *path, _ = tokenize(path)
103
89
  dig(*path)
104
90
  end
105
- alias :[] :get
91
+ alias :[] :get_node
106
92
 
107
93
  def inspect
108
94
  "<#{self.class}: formats=#{formats.map(&:request_path)} children=#{children.map(&:name).inspect}>"
data/lib/mascot/site.rb CHANGED
@@ -16,27 +16,33 @@ module Mascot
16
16
  self.root_path = root_path
17
17
  end
18
18
 
19
- def glob(glob)
20
- root.resources.glob(root_path.join(glob))
21
- end
22
-
23
- # Returns a list of resources.
19
+ # A tree representation of the resourecs wthin the site.
24
20
  def root
25
- ResourcesNode.new.tap do |root_node|
26
- DirectoryCollection.new(assets: assets, path: root_path).mount(root_node)
27
- resources_pipeline.process root_node
21
+ ResourcesNode.new.tap do |node|
22
+ DirectoryCollection.new(assets: assets, path: root_path).mount(node)
23
+ resources_pipeline.process node
28
24
  end
29
25
  end
30
26
 
31
- # Quick and dirty way to manipulate resources in the site without
32
- # creating classes that implement the #process_resources method
33
- def manipulate(&block)
34
- resources_pipeline << Extensions::ProcManipulator.new(block)
27
+ # Returns a list of all the resources within #root.
28
+ def resources
29
+ root.flatten
30
+ end
31
+
32
+ def glob(pattern)
33
+ paths = Dir.glob root_path.join(pattern)
34
+ resources.select { |r| paths.include? r.asset.path.to_s }
35
35
  end
36
36
 
37
37
  # Find the page with a path.
38
38
  def get(request_path)
39
- root.get_resource(request_path)
39
+ root.get(request_path)
40
+ end
41
+
42
+ # Quick and dirty way to manipulate resources in the site without
43
+ # creating classes that implement the #process_resources method
44
+ def manipulate(&block)
45
+ resources_pipeline << Extensions::ProcManipulator.new(block)
40
46
  end
41
47
 
42
48
  def root_path=(path)
@@ -1,3 +1,3 @@
1
1
  module Mascot
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
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.14
4
+ version: 0.1.15
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-03 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler