mascot 0.1.1 → 0.1.2

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: 1b96718fe4066629deac2c79b956e1e36e39f744
4
- data.tar.gz: 8d9564c9bc6a359959d9aec2b13763c2e44a16d0
3
+ metadata.gz: 343ff35dc45cb328c96b03d009e1d5363af15596
4
+ data.tar.gz: 3790e946be54e8797e486254c4c1abd34eaacc89
5
5
  SHA512:
6
- metadata.gz: 66bb9062c2991e61f4dfe92b46840e4875ecf1bf238dcbe7c08b7cfc50d7038bd574ee928b763d87f35f527968e09a708c3eae277fe2601ac9f62f0ee6f47b65
7
- data.tar.gz: f0ac9e69ac911d470c517a0670748681c4df96af8678331a4b1da645229e9ba8f91b1149c25172eb5ae895c6394357179e04ef69662e12db16885c456348c37e
6
+ metadata.gz: c7d62cff29add7de74381c8b7fbdbdcdbd3adf69cac04f5202d9e29d4cb0d46fa37073cb61d2b2afd3414e97b991e834dd47cfb2ef11c204f76f9d8fd482fa0b
7
+ data.tar.gz: 21d6e1e972cc405b0c0178b1abf445ee7f341ee89b191ec6ea744eb020ad4dc90053054d8afaa7a1add49aa07fcf460369e9724e8eec550bff1a94c445f90143
@@ -1,3 +1,3 @@
1
1
  module Mascot
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/mascot.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require "mascot/version"
2
2
 
3
- module Mascot
4
- require "yaml"
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
- CONTENT_TYPE = "text/html".freeze
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: , content_type: CONTENT_TYPE)
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 = "**/*.*".freeze
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
@@ -20,4 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler", "~> 1.11"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
+
24
+ spec.add_runtime_dependency "mime-types", ">= 2.99"
23
25
  end
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.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.2.3
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: