mascot 0.1.7 → 0.1.8
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/asset.rb +14 -0
- data/lib/mascot/resource.rb +3 -3
- data/lib/mascot/resources.rb +8 -3
- data/lib/mascot/sitemap.rb +8 -2
- data/lib/mascot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d510dd53ca2657a10b5affc6b3b8341901bc8ffa
|
4
|
+
data.tar.gz: d3040d129e750287723d1b2dd3de61f510fab3ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c87ea232640e0aa17705fde60ed48c3ac73fc61e08fe19f1af2f275aa58761f42267f9d2e504ff05f0d9809fae81ae3a16b44bee28e5450904ff81bd911bfaba
|
7
|
+
data.tar.gz: 3ec7f3d89b496c3d8a534ed652a05a048444bde577bfcaf88dbdee704eb47fa87952fbcd054ed19623d1b0a6268c0651710b044732333e1c867f2df11b876ef8
|
data/lib/mascot/asset.rb
CHANGED
@@ -30,6 +30,10 @@ module Mascot
|
|
30
30
|
path.basename.to_s.split(".").drop(1)
|
31
31
|
end
|
32
32
|
|
33
|
+
def basename
|
34
|
+
path.basename.to_s.split(".").first
|
35
|
+
end
|
36
|
+
|
33
37
|
# Returns the format extension.
|
34
38
|
def format_extension
|
35
39
|
extensions.first
|
@@ -53,6 +57,16 @@ module Mascot
|
|
53
57
|
File.exists? path
|
54
58
|
end
|
55
59
|
|
60
|
+
# Spits out a reasonable default request path. This may be changed
|
61
|
+
# via Resource#request_path.
|
62
|
+
def to_request_path
|
63
|
+
if ext = format_extension
|
64
|
+
path.dirname.join(basename).sub_ext(".#{ext}").to_s
|
65
|
+
else
|
66
|
+
path.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
56
70
|
private
|
57
71
|
def frontmatter
|
58
72
|
Frontmatter.new File.read @path
|
data/lib/mascot/resource.rb
CHANGED
@@ -14,8 +14,8 @@ module Mascot
|
|
14
14
|
attr_accessor :request_path, :asset
|
15
15
|
attr_writer :body, :data
|
16
16
|
|
17
|
-
def initialize(
|
18
|
-
self.request_path = request_path
|
17
|
+
def initialize(asset: , request_path: nil)
|
18
|
+
self.request_path = request_path || asset.to_request_path
|
19
19
|
@asset = asset
|
20
20
|
end
|
21
21
|
|
@@ -32,7 +32,7 @@ module Mascot
|
|
32
32
|
# We freeze the value to ensure users can't modify
|
33
33
|
# the request_path string in place (e.g. Resource#request_path.capitalize!)
|
34
34
|
# and throw the resource out of sync with the Resources collection.
|
35
|
-
@request_path = request_path.
|
35
|
+
@request_path = request_path.to_s.freeze
|
36
36
|
changed
|
37
37
|
notify_observers self, old_request_path
|
38
38
|
end
|
data/lib/mascot/resources.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require "pathname"
|
3
|
+
|
1
4
|
module Mascot
|
2
5
|
class Resources
|
3
6
|
include Enumerable
|
@@ -18,6 +21,10 @@ module Mascot
|
|
18
21
|
@routes.values.last
|
19
22
|
end
|
20
23
|
|
24
|
+
def request_paths
|
25
|
+
@routes.keys
|
26
|
+
end
|
27
|
+
|
21
28
|
def glob(pattern = "**/**")
|
22
29
|
paths = safe_root.glob @root_file_path.join(pattern)
|
23
30
|
select { |r| paths.include? r.asset.path.to_s}
|
@@ -53,7 +60,7 @@ module Mascot
|
|
53
60
|
end
|
54
61
|
|
55
62
|
def add_asset(asset, request_path: nil)
|
56
|
-
add Resource.new asset: asset, request_path: asset_path_to_request_path(request_path || asset.
|
63
|
+
add Resource.new asset: asset, request_path: asset_path_to_request_path(request_path || asset.to_request_path)
|
57
64
|
end
|
58
65
|
|
59
66
|
private
|
@@ -86,8 +93,6 @@ module Mascot
|
|
86
93
|
def asset_path_to_request_path(path)
|
87
94
|
# Relative path of resource to the file_path of this project.
|
88
95
|
relative_path = Pathname.new(path).relative_path_from(@root_file_path)
|
89
|
-
# Removes the .fooz.baz
|
90
|
-
File.join("/", relative_path).to_s.sub(/\..*/, '')
|
91
96
|
end
|
92
97
|
|
93
98
|
def safe_root
|
data/lib/mascot/sitemap.rb
CHANGED
@@ -10,11 +10,12 @@ module Mascot
|
|
10
10
|
# Default root request path
|
11
11
|
DEFAULT_ROOT_REQUEST_PATH = Pathname.new("/").freeze
|
12
12
|
|
13
|
-
attr_reader :root, :request_path
|
13
|
+
attr_reader :root, :request_path, :extensions
|
14
14
|
|
15
15
|
def initialize(root: DEFAULT_ROOT_PATH, request_path: DEFAULT_ROOT_REQUEST_PATH)
|
16
16
|
self.root = root
|
17
17
|
self.request_path = request_path
|
18
|
+
@extensions = []
|
18
19
|
end
|
19
20
|
|
20
21
|
# Lazy stream of files that will be rendered by resources.
|
@@ -28,6 +29,7 @@ module Mascot
|
|
28
29
|
def resources
|
29
30
|
Resources.new(root_file_path: root).tap do |resources|
|
30
31
|
assets.each { |a| resources.add_asset a }
|
32
|
+
process_resources resources
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -45,8 +47,12 @@ module Mascot
|
|
45
47
|
end
|
46
48
|
|
47
49
|
private
|
50
|
+
def process_resources(resources)
|
51
|
+
@extensions.each { |exstension| exstension.process_resources(resources) }
|
52
|
+
end
|
53
|
+
|
48
54
|
def safe_root
|
49
|
-
|
55
|
+
SafeRoot.new(path: root)
|
50
56
|
end
|
51
57
|
end
|
52
58
|
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.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-
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|