dimples 7.0 → 7.0.3
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/dimples/document.rb +5 -10
- data/lib/dimples/frontmatter.rb +18 -0
- data/lib/dimples/pager.rb +3 -3
- data/lib/dimples/site.rb +10 -1
- data/lib/dimples/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fd729f8831f7117dec77633ca687cb478952d674c26e1c4720f12bc2a019ff8
|
4
|
+
data.tar.gz: ecc6f32cb1c207f1b1c57bec0ec770706680a86f3c9ef75796a61ad9eea7e89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75b7b11f69b44d2015cd0262c1c3d93f87df7f78af881ef193e2de6b63e8ece2f0ae31649d73f27dbeb15c3a676c9a05b178a48f768ee1416abfe132a29fdbd
|
7
|
+
data.tar.gz: c8e6a752a8b64b5aeae3cefa9faf82f3a1d25d7051c664a93ad2ec6f813274805feae18f19adeefe4c8ae8cc14ac3f4ce85163ec1fd3a305905d2229b0098ff5
|
data/lib/dimples/document.rb
CHANGED
@@ -1,22 +1,17 @@
|
|
1
|
-
|
1
|
+
require_relative 'frontmatter'
|
2
2
|
|
3
3
|
module Dimples
|
4
4
|
class Document
|
5
|
-
FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m.freeze
|
6
|
-
|
7
5
|
attr_accessor :metadata, :contents, :path, :rendered_contents
|
8
6
|
|
9
7
|
def initialize(path = nil)
|
10
8
|
@path = path
|
11
|
-
@metadata = {}
|
12
9
|
|
13
10
|
if @path
|
14
|
-
@contents = File.read(path)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@contents = matches.post_match.strip
|
19
|
-
end
|
11
|
+
@metadata, @contents = Dimples::FrontMatter.parse(File.read(path))
|
12
|
+
else
|
13
|
+
@metadata = {}
|
14
|
+
@contents = ''
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
module FrontMatter
|
5
|
+
PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m.freeze
|
6
|
+
|
7
|
+
def self.parse(contents)
|
8
|
+
metadata = {}
|
9
|
+
|
10
|
+
if matches = contents.match(PATTERN)
|
11
|
+
metadata = YAML.load(matches[1], symbolize_names: true)
|
12
|
+
contents = matches.post_match.strip
|
13
|
+
end
|
14
|
+
|
15
|
+
[metadata, contents]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/dimples/pager.rb
CHANGED
@@ -11,11 +11,11 @@ module Dimples
|
|
11
11
|
attr_reader :next_page
|
12
12
|
attr_reader :page_count
|
13
13
|
|
14
|
-
def initialize(url, posts)
|
14
|
+
def initialize(url, posts, options = {})
|
15
15
|
@url = url
|
16
16
|
@posts = posts
|
17
|
-
@per_page = PER_PAGE
|
18
|
-
@page_prefix = 'page_'
|
17
|
+
@per_page = options.fetch(:per_page, PER_PAGE)
|
18
|
+
@page_prefix = options.fetch(:page_prefix, 'page_')
|
19
19
|
@page_count = (posts.length.to_f / @per_page.to_i).ceil
|
20
20
|
|
21
21
|
step_to(1)
|
data/lib/dimples/site.rb
CHANGED
@@ -19,6 +19,8 @@ module Dimples
|
|
19
19
|
destination: File.expand_path(output_path)
|
20
20
|
}
|
21
21
|
|
22
|
+
@config = read_config
|
23
|
+
|
22
24
|
%w[pages posts static templates].each do |type|
|
23
25
|
@paths[type.to_sym] = File.join(@paths[:source], type)
|
24
26
|
end
|
@@ -45,6 +47,13 @@ module Dimples
|
|
45
47
|
|
46
48
|
private
|
47
49
|
|
50
|
+
def read_config
|
51
|
+
config_path = File.join(@paths[:source], '.config')
|
52
|
+
|
53
|
+
return {} unless File.exist?(config_path)
|
54
|
+
YAML.load(File.read(config_path), symbolize_names: true)
|
55
|
+
end
|
56
|
+
|
48
57
|
def read_files(path)
|
49
58
|
Dir[File.join(path, '**', '*.*')].sort
|
50
59
|
end
|
@@ -107,7 +116,7 @@ module Dimples
|
|
107
116
|
end
|
108
117
|
|
109
118
|
def generate_posts
|
110
|
-
directory_path = File.join(@paths[:destination], 'posts')
|
119
|
+
directory_path = File.join(@paths[:destination], @config.dig(:paths, :posts) || 'posts')
|
111
120
|
Dir.mkdir(directory_path)
|
112
121
|
|
113
122
|
@posts.each do |post|
|
data/lib/dimples/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- bin/dimples
|
92
92
|
- lib/dimples.rb
|
93
93
|
- lib/dimples/document.rb
|
94
|
+
- lib/dimples/frontmatter.rb
|
94
95
|
- lib/dimples/page.rb
|
95
96
|
- lib/dimples/pager.rb
|
96
97
|
- lib/dimples/post.rb
|