mascot 0.1.1 → 0.1.2
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/version.rb +1 -1
- data/lib/mascot.rb +40 -8
- data/mascot.gemspec +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 343ff35dc45cb328c96b03d009e1d5363af15596
|
4
|
+
data.tar.gz: 3790e946be54e8797e486254c4c1abd34eaacc89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7d62cff29add7de74381c8b7fbdbdcdbd3adf69cac04f5202d9e29d4cb0d46fa37073cb61d2b2afd3414e97b991e834dd47cfb2ef11c204f76f9d8fd482fa0b
|
7
|
+
data.tar.gz: 21d6e1e972cc405b0c0178b1abf445ee7f341ee89b191ec6ea744eb020ad4dc90053054d8afaa7a1add49aa07fcf460369e9724e8eec550bff1a94c445f90143
|
data/lib/mascot/version.rb
CHANGED
data/lib/mascot.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "mascot/version"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require "forwardable"
|
4
|
+
require "pathname"
|
5
|
+
require "yaml"
|
6
|
+
require "mime/types"
|
5
7
|
|
8
|
+
module Mascot
|
6
9
|
# Parses metadata from the header of the page.
|
7
10
|
class Frontmatter
|
8
11
|
DELIMITER = "---".freeze
|
@@ -26,6 +29,11 @@ module Mascot
|
|
26
29
|
|
27
30
|
# Represents a page in a web server context.
|
28
31
|
class Resource
|
32
|
+
# If we can't resolve a mime type for the resource, we'll fall
|
33
|
+
# back to this binary octet-stream type so the client can download
|
34
|
+
# the resource and figure out what to do with it.
|
35
|
+
DEFAULT_MIME_TYPE = MIME::Types["application/octet-stream"].first
|
36
|
+
|
29
37
|
# TODO: I don't like the Binding, locals, and frontmatter
|
30
38
|
# being in the Resource. That should be moved to a page
|
31
39
|
# object and be delegated to that. Or perhaps the page body?
|
@@ -33,30 +41,54 @@ module Mascot
|
|
33
41
|
# We'll see how it evolves.
|
34
42
|
Binding = Struct.new(:data)
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
attr_reader :request_path, :file_path, :content_type
|
44
|
+
attr_reader :request_path, :file_path
|
39
45
|
|
40
46
|
extend Forwardable
|
41
47
|
def_delegators :@frontmatter, :data, :body
|
42
48
|
|
43
|
-
def initialize(request_path: , file_path: ,
|
49
|
+
def initialize(request_path: , file_path: , mime_type: nil)
|
44
50
|
@request_path = request_path
|
45
|
-
@content_type = content_type
|
46
51
|
@file_path = Pathname.new file_path
|
47
52
|
@frontmatter = Frontmatter.new File.read @file_path
|
53
|
+
@mime_types = Array(mime_type) if mime_type
|
48
54
|
end
|
49
55
|
|
50
56
|
# Locals that should be merged into or given to the rendering context.
|
51
57
|
def locals
|
52
58
|
{ current_page: Binding.new(data) }
|
53
59
|
end
|
60
|
+
|
61
|
+
# List of all file extensions.
|
62
|
+
def extensions
|
63
|
+
@file_path.basename.to_s.split(".").drop(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Returns the format extension.
|
67
|
+
def format_extension
|
68
|
+
extensions.first
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a list of the rendering extensions.
|
72
|
+
def template_extensions
|
73
|
+
extensions.drop(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
def mime_type
|
77
|
+
(@mime_types ||= Array(resolve_mime_type)).push(DEFAULT_MIME_TYPE).first
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
# Returns the mime type of the file extension. If a type can't
|
82
|
+
# be resolved then we'll just grab the first type.
|
83
|
+
def resolve_mime_type
|
84
|
+
MIME::Types.type_for(format_extension) if format_extension
|
85
|
+
end
|
54
86
|
end
|
55
87
|
|
56
88
|
# A collection of pages from a directory.
|
57
89
|
class Sitemap
|
58
90
|
# Default file pattern to pick up in sitemap
|
59
|
-
DEFAULT_GLOB = "
|
91
|
+
DEFAULT_GLOB = "**/**".freeze
|
60
92
|
# Default root path for sitemap.
|
61
93
|
DEFAULT_ROOT_DIR = Pathname.new(".").freeze
|
62
94
|
# Default root request path
|
data/mascot.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mime-types
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.99'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.99'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- bradgessler@gmail.com
|
@@ -81,8 +95,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
95
|
version: '0'
|
82
96
|
requirements: []
|
83
97
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.
|
98
|
+
rubygems_version: 2.5.1
|
85
99
|
signing_key:
|
86
100
|
specification_version: 4
|
87
101
|
summary: An embeddable file-backed content management system.
|
88
102
|
test_files: []
|
103
|
+
has_rdoc:
|