mascot 0.1.10 → 0.1.11
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 +4 -3
- data/lib/mascot/asset.rb +2 -2
- data/lib/mascot/extensions/layouts.rb +27 -0
- data/lib/mascot/extensions/proc_manipulator.rb +19 -0
- data/lib/mascot/frontmatter.rb +4 -1
- data/lib/mascot/resources_pipeline.rb +10 -0
- data/lib/mascot/safe_root.rb +1 -1
- data/lib/mascot/{sitemap.rb → site.rb} +15 -16
- data/lib/mascot/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d49c4a14896b46d0fdcd7aedd1250a104e9b5048
|
4
|
+
data.tar.gz: 101a6a075f65556c4dc0a86ca69e7a5c39459a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65db308403d25699fd58e498e09a7c390b885894709ebb60be396eeca3f1faed0d65c574dfc75164325272462bd7672e230f505694c6e1b15a7e2f5ba1b6addc
|
7
|
+
data.tar.gz: eec51f4ec3bd95bf28831e097a646acd3faeba341529f75eb3bb93a844ffdff87c44d3aa9d9d78d29d703897bde3fb7b1960d0bda74abf8f96d73e3dfe127f61
|
data/lib/mascot.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "mascot/version"
|
2
2
|
|
3
3
|
module Mascot
|
4
|
-
# Raised if a user attempts to access a resource outside of the
|
4
|
+
# Raised if a user attempts to access a resource outside of the site path.
|
5
5
|
UnsafePathAccessError = Class.new(SecurityError)
|
6
6
|
|
7
7
|
# Raised by Resources if a path is added that's not a valid path.
|
@@ -12,8 +12,9 @@ module Mascot
|
|
12
12
|
|
13
13
|
autoload :Asset, "mascot/asset"
|
14
14
|
autoload :Frontmatter, "mascot/frontmatter"
|
15
|
-
autoload :
|
15
|
+
autoload :ResourcesPipeline, "mascot/resources_pipeline"
|
16
16
|
autoload :Resources, "mascot/resources"
|
17
17
|
autoload :Resource, "mascot/resource"
|
18
|
-
autoload :
|
18
|
+
autoload :SafeRoot, "mascot/safe_root"
|
19
|
+
autoload :Site, "mascot/site"
|
19
20
|
end
|
data/lib/mascot/asset.rb
CHANGED
@@ -50,7 +50,7 @@ module Mascot
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def mime_type
|
53
|
-
@mime_type ||=
|
53
|
+
@mime_type ||= inferred_mime_type || DEFAULT_MIME_TYPE
|
54
54
|
end
|
55
55
|
|
56
56
|
def exists?
|
@@ -75,7 +75,7 @@ module Mascot
|
|
75
75
|
# Returns the mime type of the file extension. If a type can't
|
76
76
|
# be resolved then we'll just grab the first type.
|
77
77
|
def inferred_mime_type
|
78
|
-
MIME::Types.type_for(format_extension) if format_extension
|
78
|
+
MIME::Types.type_for(format_extension).first if format_extension
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mascot
|
2
|
+
module Extensions
|
3
|
+
# Register layouts with resources that match certain patterns.
|
4
|
+
class Layouts
|
5
|
+
Rule = Struct.new(:layout, :processor)
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@rules = Array.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Register a layout for a set of resources.
|
12
|
+
def layout(layout, &block)
|
13
|
+
@rules << Rule.new(layout, block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def process_resources(resources)
|
17
|
+
resources.each do |resource|
|
18
|
+
@rules.each do |rule|
|
19
|
+
if rule.processor.call(resource)
|
20
|
+
resource.data["layout"] ||= rule.layout
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mascot
|
2
|
+
module Extensions
|
3
|
+
class ProcManipulator
|
4
|
+
def initialize(block)
|
5
|
+
@block = block
|
6
|
+
end
|
7
|
+
|
8
|
+
def process_resources(resources)
|
9
|
+
resources.each do |resource|
|
10
|
+
if @block.arity == 1
|
11
|
+
@block.call resource
|
12
|
+
else # This will blow up if 0 or greater than 2.
|
13
|
+
@block.call resource, resources
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/mascot/frontmatter.rb
CHANGED
@@ -2,9 +2,12 @@ require "yaml"
|
|
2
2
|
|
3
3
|
module Mascot
|
4
4
|
# Parses metadata from the header of the page.
|
5
|
+
|
6
|
+
# TODO: Redo this to use File readline and pos to
|
7
|
+
# perform faster
|
5
8
|
class Frontmatter
|
6
9
|
DELIMITER = "---".freeze
|
7
|
-
PATTERN = /\A(#{DELIMITER}\n(
|
10
|
+
PATTERN = /\A(#{DELIMITER}\n(.+?)\n#{DELIMITER}\n*)?(.+)\Z/m
|
8
11
|
|
9
12
|
attr_reader :body
|
10
13
|
|
data/lib/mascot/safe_root.rb
CHANGED
@@ -2,7 +2,7 @@ require "pathname"
|
|
2
2
|
|
3
3
|
module Mascot
|
4
4
|
# Validates if a path is within another path. This prevents
|
5
|
-
# users from accidentally selecting a file outside of their
|
5
|
+
# users from accidentally selecting a file outside of their site,
|
6
6
|
# which could be insured.
|
7
7
|
class SafeRoot
|
8
8
|
def initialize(path: )
|
@@ -1,21 +1,18 @@
|
|
1
1
|
require "pathname"
|
2
|
+
require "mascot/extensions/proc_manipulator"
|
2
3
|
|
3
4
|
module Mascot
|
4
5
|
# A collection of pages from a directory.
|
5
|
-
class
|
6
|
-
# Default file pattern to pick up in
|
6
|
+
class Site
|
7
|
+
# Default file pattern to pick up in site
|
7
8
|
DEFAULT_GLOB = "**/**".freeze
|
8
|
-
# Default root path for
|
9
|
+
# Default root path for site.
|
9
10
|
DEFAULT_ROOT_PATH = Pathname.new(".").freeze
|
10
|
-
# Default root request path
|
11
|
-
DEFAULT_ROOT_REQUEST_PATH = Pathname.new("/").freeze
|
12
11
|
|
13
|
-
attr_reader :root, :
|
12
|
+
attr_reader :root, :resources_pipeline
|
14
13
|
|
15
|
-
def initialize(root: DEFAULT_ROOT_PATH
|
14
|
+
def initialize(root: DEFAULT_ROOT_PATH)
|
16
15
|
self.root = root
|
17
|
-
self.request_path = request_path
|
18
|
-
@extensions = []
|
19
16
|
end
|
20
17
|
|
21
18
|
# Lazy stream of files that will be rendered by resources.
|
@@ -29,10 +26,16 @@ module Mascot
|
|
29
26
|
def resources
|
30
27
|
Resources.new(root_file_path: root).tap do |resources|
|
31
28
|
assets.each { |a| resources.add_asset a }
|
32
|
-
|
29
|
+
resources_pipeline.process resources
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
33
|
+
# Quick and dirty way to manipulate resources in the site without
|
34
|
+
# creating classes that implement the #process_resources method
|
35
|
+
def manipulate(&block)
|
36
|
+
resources_pipeline << Extensions::ProcManipulator.new(block)
|
37
|
+
end
|
38
|
+
|
36
39
|
# Find the page with a path.
|
37
40
|
def get(request_path)
|
38
41
|
resources.get(request_path)
|
@@ -42,15 +45,11 @@ module Mascot
|
|
42
45
|
@root = Pathname.new(path)
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
46
|
-
@
|
48
|
+
def resources_pipeline
|
49
|
+
@resources_pipeline ||= ResourcesPipeline.new
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
50
|
-
def process_resources(resources)
|
51
|
-
@extensions.each { |exstension| exstension.process_resources(resources) }
|
52
|
-
end
|
53
|
-
|
54
53
|
def safe_root
|
55
54
|
SafeRoot.new(path: root)
|
56
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.11
|
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-08-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,11 +75,14 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- lib/mascot.rb
|
77
77
|
- lib/mascot/asset.rb
|
78
|
+
- lib/mascot/extensions/layouts.rb
|
79
|
+
- lib/mascot/extensions/proc_manipulator.rb
|
78
80
|
- lib/mascot/frontmatter.rb
|
79
81
|
- lib/mascot/resource.rb
|
80
82
|
- lib/mascot/resources.rb
|
83
|
+
- lib/mascot/resources_pipeline.rb
|
81
84
|
- lib/mascot/safe_root.rb
|
82
|
-
- lib/mascot/
|
85
|
+
- lib/mascot/site.rb
|
83
86
|
- lib/mascot/version.rb
|
84
87
|
- mascot.gemspec
|
85
88
|
homepage: https://github.com/bradgessler/mascot
|