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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 882aeff0d91ba61d58f331bedabeba0c865dbb7ef355c1fdafde7e1605113d2e
4
- data.tar.gz: 8ddfc8ea5bcbce38a35c8d0153f96adc4866f5529a074884e966b92a65dce642
3
+ metadata.gz: 8fd729f8831f7117dec77633ca687cb478952d674c26e1c4720f12bc2a019ff8
4
+ data.tar.gz: ecc6f32cb1c207f1b1c57bec0ec770706680a86f3c9ef75796a61ad9eea7e89a
5
5
  SHA512:
6
- metadata.gz: cc9caa2de2a10ac6a30f84876ad3a3e9bd070b2e3e9783f38763035d286ec46d55343fa6fbf5cb44c6b72fe3c67d773af7918cbcb714cdb10f2c4b4a6b52b1e4
7
- data.tar.gz: 04510c31f0ee4de0d1e035ddf56003f12e4553bdaaf1b4a8f82d24c0344bae443443b8d4f73c58e6ae7c3a5447e73f734f315964c30dcb400f85b28fa9066042
6
+ metadata.gz: e75b7b11f69b44d2015cd0262c1c3d93f87df7f78af881ef193e2de6b63e8ece2f0ae31649d73f27dbeb15c3a676c9a05b178a48f768ee1416abfe132a29fdbd
7
+ data.tar.gz: c8e6a752a8b64b5aeae3cefa9faf82f3a1d25d7051c664a93ad2ec6f813274805feae18f19adeefe4c8ae8cc14ac3f4ce85163ec1fd3a305905d2229b0098ff5
@@ -1,22 +1,17 @@
1
- require 'yaml'
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
- if matches = contents.match(FRONT_MATTER_PATTERN)
17
- @metadata = YAML.load(matches[1], symbolize_names: true)
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '7.0'
4
+ VERSION = '7.0.3'
5
5
  end
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: '7.0'
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