dimples 10.2.0 → 10.3.1

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: b82d0d0b1768cb2feeaa99bdcffdbe091e4a74464e1626ab945fa6261f44b066
4
- data.tar.gz: 905531f3cd50da2854b43b413c69459c26c36faae05b18de53e434f9d4b8405f
3
+ metadata.gz: 9b26a3e1592398021aab828178c2dbb71bb521f99db69503b196195806745721
4
+ data.tar.gz: aae282b44ca14b4a244ef9f1827c7f186f654b7ebd83ed8818b4af3388eb8910
5
5
  SHA512:
6
- metadata.gz: 34b59758473587a23629d2459c95362f12484a43f9395c6f188eb6f90adf83b648b7cab6be8e47f4755992a60e6578bc2c2906db626f132bb5bb75d4388e1533
7
- data.tar.gz: 7caf87e0d6fe6435b9b1459b2d3a111ee5952ca6bf98b5db4f0b90752aad262f417c6ef024e02dd7a8873384a2fa18e1eaa0722cc39579e550181f459e582a7c
6
+ metadata.gz: e6c9b35b7da2435a8361a006e668b18249b56c34747ca1f0bd0774ed0c6d652211e04a1a9edae0a5e776c018cdd1767a2261bc276cc67d1819d070c25a6aa8c4
7
+ data.tar.gz: dc34dc37e9d0961a2445aea5132647cc88ab0da6886274a45c1a830e5d32f247e20c3c16f0a726582ae87b826a00df6da8804eb051088dd4a0a5799e415618cd
data/bin/dimples CHANGED
@@ -18,7 +18,7 @@ if File.exist?(config_path)
18
18
  end
19
19
 
20
20
  begin
21
- Dimples::Site.generate(config)
21
+ Dimples::Site.generate(config:)
22
22
  rescue StandardError => e
23
23
  puts "Error generating site: #{e}"
24
24
  end
@@ -10,6 +10,7 @@ module Dimples
10
10
  def self.defaults
11
11
  {
12
12
  build: './site',
13
+ source: Dir.pwd,
13
14
  pathnames: { posts: 'posts', categories: 'categories' },
14
15
  pagination: { page_prefix: 'page_', per_page: 5 }
15
16
  }
@@ -18,7 +19,7 @@ module Dimples
18
19
  def initialize(options = {})
19
20
  options = Config.defaults.merge(options)
20
21
 
21
- @source_paths = expand_paths(File.expand_path(Dir.pwd), SOURCE_PATHS.dup)
22
+ @source_paths = expand_paths(File.expand_path(options[:source]), SOURCE_PATHS.dup)
22
23
  @build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
23
24
  @pagination = options[:pagination]
24
25
  end
data/lib/dimples/pager.rb CHANGED
@@ -7,11 +7,11 @@ module Dimples
7
7
 
8
8
  attr_reader :current_page, :previous_page, :next_page, :page_count
9
9
 
10
- def self.paginate(site, url, posts, metadata = {})
11
- new(site, url, posts).paginate(metadata)
10
+ def self.paginate(site:, url:, posts:, metadata: {})
11
+ new(site:, url:, posts:).paginate(metadata)
12
12
  end
13
13
 
14
- def initialize(site, url, posts)
14
+ def initialize(site:, url:, posts:)
15
15
  @site = site
16
16
  @url = url
17
17
  @posts = posts
@@ -28,8 +28,8 @@ module Dimples
28
28
  step_to(index)
29
29
 
30
30
  @site.layouts['posts']&.write(
31
- File.join(@site.config.build_paths[:root], current_page_url, 'index.html'),
32
- metadata.merge(pagination: self.metadata, url: current_page_url)
31
+ output_path: File.join(@site.config.build_paths[:root], current_page_url, 'index.html'),
32
+ metadata: metadata.merge(pagination: self.metadata, url: current_page_url)
33
33
  )
34
34
  end
35
35
  end
data/lib/dimples/site.rb CHANGED
@@ -10,11 +10,11 @@ module Dimples
10
10
  class Site
11
11
  attr_accessor :config
12
12
 
13
- def self.generate(config = {})
14
- new(config).generate
13
+ def self.generate(config: {})
14
+ new(config:).generate
15
15
  end
16
16
 
17
- def initialize(config = {})
17
+ def initialize(config: {})
18
18
  @config = Config.new(config)
19
19
  end
20
20
 
@@ -30,19 +30,19 @@ module Dimples
30
30
 
31
31
  def posts
32
32
  @posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
33
- Dimples::Sources::Post.new(self, path)
33
+ Dimples::Sources::Post.new(site: self, path:)
34
34
  end.sort_by!(&:date).reverse!
35
35
  end
36
36
 
37
37
  def pages
38
38
  @pages ||= Dir.glob(File.join(@config.source_paths[:pages], '**', '*.erb')).map do |path|
39
- Dimples::Sources::Page.new(self, path)
39
+ Dimples::Sources::Page.new(site: self, path:)
40
40
  end
41
41
  end
42
42
 
43
43
  def layouts
44
44
  @layouts ||= Dir.glob(File.join(@config.source_paths[:layouts], '**', '*.erb')).to_h do |path|
45
- [File.basename(path, '.erb'), Dimples::Sources::Layout.new(self, path)]
45
+ [File.basename(path, '.erb'), Dimples::Sources::Layout.new(site: self, path:)]
46
46
  end
47
47
  end
48
48
 
@@ -64,29 +64,50 @@ module Dimples
64
64
  private
65
65
 
66
66
  def generate_posts
67
- posts.each(&:write)
68
- Pager.paginate(self, @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/'), posts)
69
- generate_feed(@config.build_paths[:root], posts)
67
+ posts.each { |post| generate_post(post) }
68
+
69
+ Pager.paginate(
70
+ site: self,
71
+ url: @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/'),
72
+ posts:
73
+ )
74
+
75
+ generate_feed(output_path: @config.build_paths[:root], posts:)
76
+ end
77
+
78
+ def generate_post(post)
79
+ post.write
80
+ end
81
+
82
+ def generate_pages
83
+ pages.each { |page| generate_page(page) }
84
+ end
85
+
86
+ def generate_page(page)
87
+ page.write
70
88
  end
71
89
 
72
90
  def generate_categories
73
91
  categories.each do |category, posts|
74
92
  metadata = { title: category.capitalize, category: category }
75
- Pager.paginate(self, "/categories/#{category}/", posts, metadata)
76
- generate_feed(File.join(@config.build_paths[:root], 'categories', category), posts)
77
- end
78
- end
79
93
 
80
- def generate_pages
81
- pages.each(&:write)
94
+ Pager.paginate(
95
+ site: self,
96
+ url: "/categories/#{category}/",
97
+ posts:,
98
+ metadata:
99
+ )
100
+
101
+ generate_feed(output_path: File.join(@config.build_paths[:root], 'categories', category), posts:)
102
+ end
82
103
  end
83
104
 
84
- def generate_feed(output_path, posts)
105
+ def generate_feed(output_path:, posts:)
85
106
  return if layouts['feed'].nil?
86
107
 
87
108
  layouts['feed'].write(
88
- File.join(output_path, 'feed.atom'),
89
- posts: posts.slice(0, 10)
109
+ output_path: File.join(output_path, 'feed.atom'),
110
+ metadata: { posts: posts.slice(0, 10) }
90
111
  )
91
112
  end
92
113
 
@@ -6,53 +6,50 @@ module Dimples
6
6
  class Base
7
7
  FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m
8
8
 
9
- attr_accessor :path, :metadata, :contents
9
+ attr_accessor :path, :metadata, :contents, :rendered_contents
10
10
 
11
- def initialize(site, path)
11
+ def initialize(site:, path:)
12
12
  @site = site
13
13
  @path = File.expand_path(path)
14
-
15
- @metadata = default_metadata
16
14
  @contents = File.read(@path)
17
15
 
18
16
  parse_metadata(@contents)
19
- assign_metadata
20
17
  end
21
18
 
22
19
  def parse_metadata(contents)
20
+ @metadata = default_metadata
21
+
23
22
  matches = contents.match(FRONT_MATTER_PATTERN)
24
23
  return unless matches
25
24
 
26
25
  @metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
27
26
  @contents = matches.post_match.strip
28
- end
29
27
 
30
- def assign_metadata
31
28
  @metadata.each_key do |key|
32
29
  self.class.send(:define_method, key.to_sym) { @metadata[key] }
33
30
  end
34
31
  end
35
32
 
36
- def write(output_path = nil, metadata = {})
33
+ def write(output_path: nil, metadata: {})
37
34
  output_path = File.join(output_directory, filename) if output_path.nil?
38
35
  output_dir = File.dirname(output_path)
39
36
 
40
37
  @metadata[:url] = url_for(output_dir)
41
38
 
42
- output = render(metadata)
39
+ output = render(context: metadata)
43
40
 
44
41
  FileUtils.mkdir_p(output_dir) unless File.directory?(output_dir)
45
42
  File.write(output_path, output)
46
43
  end
47
44
 
48
- def render(render_metadata = {}, body = nil)
49
- render_metadata[:site] ||= @site.metadata
50
- render_metadata[:page] ||= metadata
45
+ def render(context: {}, body: nil)
46
+ context[:site] ||= @site.metadata
47
+ context[:page] ||= metadata
51
48
 
52
- output = template.render(Metadata.new(render_metadata)) { body }
53
- return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
49
+ @rendered_contents = template.render(Metadata.new(context)) { body }
50
+ return @rendered_contents unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
54
51
 
55
- @site.layouts[@metadata[:layout]].render(render_metadata, output)
52
+ @site.layouts[@metadata[:layout]].render(context:, body: @rendered_contents)
56
53
  end
57
54
 
58
55
  def output_directory
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '10.2.0'
4
+ VERSION = '10.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.2.0
4
+ version: 10.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: erb
@@ -76,7 +75,6 @@ licenses:
76
75
  - MIT
77
76
  metadata:
78
77
  rubygems_mfa_required: 'true'
79
- post_install_message:
80
78
  rdoc_options: []
81
79
  require_paths:
82
80
  - lib
@@ -91,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
89
  - !ruby/object:Gem::Version
92
90
  version: '0'
93
91
  requirements: []
94
- rubygems_version: 3.3.3
95
- signing_key:
92
+ rubygems_version: 3.6.7
96
93
  specification_version: 4
97
94
  summary: A basic static site generator
98
95
  test_files: []