dimples 10.1.4 → 10.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc9b0a5d7daa298ddcb448b6c01a87cb523f93476073e3b5fc96ae990ae315e3
4
- data.tar.gz: 35b8c6c8794af46c60d79594d63b79eff43323b488db487451d30a203b4610e3
3
+ metadata.gz: b82d0d0b1768cb2feeaa99bdcffdbe091e4a74464e1626ab945fa6261f44b066
4
+ data.tar.gz: 905531f3cd50da2854b43b413c69459c26c36faae05b18de53e434f9d4b8405f
5
5
  SHA512:
6
- metadata.gz: 6130823fd14607307d064fe8a38b6e9ad9afc98c95390ecc32fea62597159f7ff308b74b4b0d09905e85c57b1b13a23c5822f931d8236da223b0f321d41b1a61
7
- data.tar.gz: 2746165d1e77dbf494e33126cf64718a1d7ec6781e789996453ec03655a8c3915ecb1e30ead8475d5d8722dae9c47a35adcb36d8b6000eefa0ccd17d1394f21f
6
+ metadata.gz: 34b59758473587a23629d2459c95362f12484a43f9395c6f188eb6f90adf83b648b7cab6be8e47f4755992a60e6578bc2c2906db626f132bb5bb75d4388e1533
7
+ data.tar.gz: 7caf87e0d6fe6435b9b1459b2d3a111ee5952ca6bf98b5db4f0b90752aad262f417c6ef024e02dd7a8873384a2fa18e1eaa0722cc39579e550181f459e582a7c
data/bin/dimples CHANGED
@@ -12,10 +12,8 @@ config = {}
12
12
  if File.exist?(config_path)
13
13
  config = begin
14
14
  YAML.safe_load_file(config_path, symbolize_names: true)
15
- rescue YAML::Error
16
- puts 'Failed to parse config - using defaults'
17
- ensure
18
- {}
15
+ rescue StandardError => e
16
+ puts "Failed to parse config #{e} - using defaults"
19
17
  end
20
18
  end
21
19
 
@@ -3,31 +3,31 @@
3
3
  module Dimples
4
4
  # Configuration settings for a site.
5
5
  class Config
6
+ SOURCE_PATHS = { pages: 'pages', posts: 'posts', layouts: 'layouts', static: 'static' }.freeze
7
+
8
+ attr_accessor :source_paths, :build_paths, :pagination
9
+
6
10
  def self.defaults
7
11
  {
8
- sources: { root: '.', posts: './posts', pages: './pages', layouts: './layouts', static: './static' },
9
- output: { root: './site', posts: './site/posts', categories: './site/categories' }
12
+ build: './site',
13
+ pathnames: { posts: 'posts', categories: 'categories' },
14
+ pagination: { page_prefix: 'page_', per_page: 5 }
10
15
  }
11
16
  end
12
17
 
13
18
  def initialize(options = {})
14
- @options = Config.defaults
19
+ options = Config.defaults.merge(options)
15
20
 
16
- options&.each do |key, value|
17
- @options[key]&.merge!(value)
18
- end
19
-
20
- %i[sources output].each do |type|
21
- @options[type].each { |key, value| @options[type][key] = File.expand_path(value) }
22
- end
21
+ @source_paths = expand_paths(File.expand_path(Dir.pwd), SOURCE_PATHS.dup)
22
+ @build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
23
+ @pagination = options[:pagination]
23
24
  end
24
25
 
25
- def dig(*args)
26
- @options.dig(*args)
27
- end
26
+ def expand_paths(root, paths)
27
+ root = File.expand_path(root)
28
28
 
29
- def [](key)
30
- @options[key]
29
+ paths.transform_values! { |value| File.expand_path(File.join(root, value)) }
30
+ paths.tap { |expanded_paths| expanded_paths[:root] = root }
31
31
  end
32
32
  end
33
33
  end
data/lib/dimples/pager.rb CHANGED
@@ -3,8 +3,6 @@
3
3
  module Dimples
4
4
  # A class for paginating a collection of posts.
5
5
  class Pager
6
- PER_PAGE = 5
7
-
8
6
  include Enumerable
9
7
 
10
8
  attr_reader :current_page, :previous_page, :next_page, :page_count
@@ -18,8 +16,8 @@ module Dimples
18
16
  @url = url
19
17
  @posts = posts
20
18
 
21
- @per_page = @site.config.dig(:pagination, :per_page) || PER_PAGE
22
- @page_prefix = @site.config.dig(:pagination, :page_prefix) || 'page_'
19
+ @per_page = @site.config.pagination[:per_page]
20
+ @page_prefix = @site.config.pagination[:page_prefix]
23
21
  @page_count = (posts.length.to_f / @per_page.to_i).ceil
24
22
 
25
23
  step_to(1)
@@ -30,7 +28,7 @@ module Dimples
30
28
  step_to(index)
31
29
 
32
30
  @site.layouts['posts']&.write(
33
- File.join(@site.config[:output][:root], current_page_url, 'index.html'),
31
+ File.join(@site.config.build_paths[:root], current_page_url, 'index.html'),
34
32
  metadata.merge(pagination: self.metadata, url: current_page_url)
35
33
  )
36
34
  end
data/lib/dimples/site.rb CHANGED
@@ -29,19 +29,19 @@ module Dimples
29
29
  end
30
30
 
31
31
  def posts
32
- @posts ||= Dir.glob(File.join(@config[:sources][:posts], '**', '*.markdown')).map do |path|
32
+ @posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
33
33
  Dimples::Sources::Post.new(self, path)
34
34
  end.sort_by!(&:date).reverse!
35
35
  end
36
36
 
37
37
  def pages
38
- @pages ||= Dir.glob(File.join(@config[:sources][:pages], '**', '*.erb')).map do |path|
38
+ @pages ||= Dir.glob(File.join(@config.source_paths[:pages], '**', '*.erb')).map do |path|
39
39
  Dimples::Sources::Page.new(self, path)
40
40
  end
41
41
  end
42
42
 
43
43
  def layouts
44
- @layouts ||= Dir.glob(File.join(@config[:sources][:layouts], '**', '*.erb')).to_h do |path|
44
+ @layouts ||= Dir.glob(File.join(@config.source_paths[:layouts], '**', '*.erb')).to_h do |path|
45
45
  [File.basename(path, '.erb'), Dimples::Sources::Layout.new(self, path)]
46
46
  end
47
47
  end
@@ -65,15 +65,15 @@ module Dimples
65
65
 
66
66
  def generate_posts
67
67
  posts.each(&:write)
68
- Pager.paginate(self, @config[:output][:posts].gsub(@config[:output][:root], '').concat('/'), posts)
69
- generate_feed(@config[:output][:root], posts)
68
+ Pager.paginate(self, @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/'), posts)
69
+ generate_feed(@config.build_paths[:root], posts)
70
70
  end
71
71
 
72
72
  def generate_categories
73
73
  categories.each do |category, posts|
74
74
  metadata = { title: category.capitalize, category: category }
75
75
  Pager.paginate(self, "/categories/#{category}/", posts, metadata)
76
- generate_feed(File.join(@config[:output][:root], 'categories', category), posts)
76
+ generate_feed(File.join(@config.build_paths[:root], 'categories', category), posts)
77
77
  end
78
78
  end
79
79
 
@@ -91,15 +91,17 @@ module Dimples
91
91
  end
92
92
 
93
93
  def prepare_output_directory
94
- raise "The site directory (#{@config[:output][:root]}) already exists." if Dir.exist?(@config[:output][:root])
94
+ if Dir.exist?(@config.build_paths[:root])
95
+ raise "The site directory (#{@config.build_paths[:root]}) already exists."
96
+ end
95
97
 
96
- Dir.mkdir(@config[:output][:root])
98
+ Dir.mkdir(@config.build_paths[:root])
97
99
  end
98
100
 
99
101
  def copy_assets
100
- return unless Dir.exist?(@config[:sources][:static])
102
+ return unless Dir.exist?(@config.source_paths[:static])
101
103
 
102
- FileUtils.cp_r(File.join(@config[:sources][:static], '.'), @config[:output][:root])
104
+ FileUtils.cp_r(File.join(@config.source_paths[:static], '.'), @config.build_paths[:root])
103
105
  end
104
106
  end
105
107
  end
@@ -56,11 +56,11 @@ module Dimples
56
56
  end
57
57
 
58
58
  def output_directory
59
- @site.config[:output][:root]
59
+ @site.config.build_paths[:root]
60
60
  end
61
61
 
62
62
  def url_for(path)
63
- path.gsub(@site.config[:output][:root], '').concat('/')
63
+ path.gsub(@site.config.build_paths[:root], '').concat('/')
64
64
  end
65
65
 
66
66
  def template
@@ -6,8 +6,8 @@ module Dimples
6
6
  class Page < Base
7
7
  def output_directory
8
8
  @output_directory ||= File.dirname(@path).gsub(
9
- @site.config[:sources][:pages],
10
- @site.config[:output][:root]
9
+ @site.config.source_paths[:pages],
10
+ @site.config.build_paths[:root]
11
11
  ).concat('/')
12
12
  end
13
13
 
@@ -6,8 +6,8 @@ module Dimples
6
6
  class Post < Base
7
7
  def output_directory
8
8
  @output_directory ||= File.dirname(@path).gsub(
9
- @site.config[:sources][:posts],
10
- @site.config[:output][:posts]
9
+ @site.config.source_paths[:posts],
10
+ @site.config.build_paths[:posts]
11
11
  ).concat("/#{slug}/")
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '10.1.4'
4
+ VERSION = '10.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.1.4
4
+ version: 10.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-30 00:00:00.000000000 Z
11
+ date: 2024-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erb