satanic_pages 0.2.0 → 0.3.0
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/README.md +22 -0
- data/lib/satanic_pages/controller.rb +2 -0
- data/lib/satanic_pages/frontmatter.rb +50 -0
- data/lib/satanic_pages/layout_helper.rb +2 -0
- data/lib/satanic_pages/markdown_template_handler.rb +4 -14
- data/lib/satanic_pages/page.rb +1 -13
- data/lib/satanic_pages/railtie.rb +2 -0
- data/lib/satanic_pages/version.rb +3 -1
- data/lib/satanic_pages.rb +5 -3
- metadata +2 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c0ba138a00f4ba596ba407c0609e62f415cb0e89b570097fd87ae8f04040da1
|
4
|
+
data.tar.gz: 12bb35a382f16e9118d2ecc327844dfee1729ae88ca34f78852870168bb900b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bf85437c0980b47b39f2b8c13bfd6225e463520d94c80d7df45544cc5ac6cdf8f1aea921cbf88f5ebd139c48931a3d1477ab571f0e4c12e0472bf77a18b2679
|
7
|
+
data.tar.gz: 8d94f595ed06305b1e886ba1cb4085fe5e98b1b10369bdb219ed6fb66b5c8779d36fe4b70186d91286e0deee213f6f1bc4b3423665b4237a5c71060de2433587
|
data/README.md
CHANGED
@@ -39,6 +39,28 @@ In `app/views/layouts/pages.html.erb`:
|
|
39
39
|
<% end %>
|
40
40
|
```
|
41
41
|
|
42
|
+
Frontmatter is supplied as a struct like object.
|
43
|
+
|
44
|
+
Given this frontmatter:
|
45
|
+
|
46
|
+
```yaml
|
47
|
+
---
|
48
|
+
author: Beelzebub
|
49
|
+
---
|
50
|
+
```
|
51
|
+
|
52
|
+
Use `!` and `?` method helpers for added strictness.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
data.author # => "Beelzebub"
|
56
|
+
data.author! # => "Beelzebub"
|
57
|
+
data.author? # => true
|
58
|
+
|
59
|
+
data.title # => nil
|
60
|
+
data.title! # => raises SatanicPages::Frontmatter::MissingAttributeError
|
61
|
+
data.title? # => false
|
62
|
+
```
|
63
|
+
|
42
64
|
## Installation
|
43
65
|
Add this line to your application's Gemfile:
|
44
66
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SatanicPages
|
4
|
+
class Frontmatter
|
5
|
+
class MissingAttributeError < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(hash)
|
9
|
+
@hash = (hash&.with_indifferent_access || {}).freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
@hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(name, *args)
|
17
|
+
if name.to_s.end_with?("!")
|
18
|
+
attribute = name.to_s.chomp("!").to_sym
|
19
|
+
|
20
|
+
unless @hash[attribute]
|
21
|
+
raise MissingAttributeError, "Missing attribute: #{name.to_s.chomp("!")}"
|
22
|
+
end
|
23
|
+
|
24
|
+
@hash[attribute]
|
25
|
+
|
26
|
+
elsif name.to_s.end_with?("?")
|
27
|
+
@hash[name.to_s.chomp("?").to_sym].present?
|
28
|
+
|
29
|
+
else
|
30
|
+
@hash[name]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.parse(source)
|
35
|
+
frontmatter = nil
|
36
|
+
|
37
|
+
rest = source.gsub(/\A---\n(.*?)\n---\n/m) do
|
38
|
+
begin
|
39
|
+
frontmatter = YAML.safe_load($1)
|
40
|
+
""
|
41
|
+
rescue => e
|
42
|
+
Rails.logger.error("Error parsing frontmatter: #{e.message}")
|
43
|
+
$&
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
[new(frontmatter), rest]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,21 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SatanicPages
|
2
4
|
class MarkdownTemplateHandler < MarkdownRails::Renderer::Rails
|
3
5
|
def preprocess(source)
|
4
|
-
frontmatter =
|
5
|
-
|
6
|
-
content = source.gsub(/\A---\n(.*?)\n---\n/m) do
|
7
|
-
begin
|
8
|
-
frontmatter = YAML.safe_load($1)
|
9
|
-
""
|
10
|
-
rescue => e
|
11
|
-
Rails.logger.error("Error parsing frontmatter: #{e.message}")
|
12
|
-
$&
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
data = OpenStruct.new(frontmatter)
|
6
|
+
frontmatter, rest = Frontmatter.parse(source)
|
17
7
|
|
18
|
-
render(inline:
|
8
|
+
render(inline: rest, handler: :erb, locals: {data: frontmatter})
|
19
9
|
# Remove template comments
|
20
10
|
.gsub(/<!-- (BEGIN|END) (.*) -->/, "")
|
21
11
|
# Force HTML tags to be inline
|
data/lib/satanic_pages/page.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "ostruct"
|
4
|
-
|
5
3
|
module SatanicPages
|
6
4
|
class Page
|
7
5
|
def initialize(full_path, base_path)
|
@@ -28,17 +26,7 @@ module SatanicPages
|
|
28
26
|
|
29
27
|
@raw = File.read(full_path)
|
30
28
|
|
31
|
-
@content = @raw
|
32
|
-
begin
|
33
|
-
@data = OpenStruct.new(YAML.safe_load($1))
|
34
|
-
nil
|
35
|
-
rescue => e
|
36
|
-
Rails.logger.error("Error parsing frontmatter: #{e.message}")
|
37
|
-
$&
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
@data ||= OpenStruct.new
|
29
|
+
@data, @content = Frontmatter.parse(@raw)
|
42
30
|
end
|
43
31
|
end
|
44
32
|
end
|
data/lib/satanic_pages.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "markdown-rails"
|
2
4
|
|
3
5
|
require "satanic_pages/version"
|
4
6
|
require "satanic_pages/railtie"
|
5
7
|
|
6
|
-
require "satanic_pages/page"
|
7
|
-
require "satanic_pages/page_list"
|
8
|
-
|
9
8
|
require "satanic_pages/controller"
|
9
|
+
require "satanic_pages/frontmatter"
|
10
10
|
require "satanic_pages/layout_helper"
|
11
|
+
require "satanic_pages/page"
|
12
|
+
require "satanic_pages/page_list"
|
11
13
|
|
12
14
|
module SatanicPages
|
13
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: satanic_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
@@ -9,20 +9,6 @@ bindir: bin
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
|
-
- !ruby/object:Gem::Dependency
|
13
|
-
name: ostruct
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
-
requirements:
|
16
|
-
- - ">="
|
17
|
-
- !ruby/object:Gem::Version
|
18
|
-
version: '0.6'
|
19
|
-
type: :runtime
|
20
|
-
prerelease: false
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
-
requirements:
|
23
|
-
- - ">="
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
version: '0.6'
|
26
12
|
- !ruby/object:Gem::Dependency
|
27
13
|
name: rails
|
28
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +49,7 @@ files:
|
|
63
49
|
- Rakefile
|
64
50
|
- lib/satanic_pages.rb
|
65
51
|
- lib/satanic_pages/controller.rb
|
52
|
+
- lib/satanic_pages/frontmatter.rb
|
66
53
|
- lib/satanic_pages/layout_helper.rb
|
67
54
|
- lib/satanic_pages/markdown_template_handler.rb
|
68
55
|
- lib/satanic_pages/page.rb
|