dimples 7.0.4 → 8.0.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: ec92ee367aa0923a32bd9638a7fc72c074ac4e6447bee213de65279747ff9344
4
- data.tar.gz: 7ec38efb0f64cc6c7681a836062663da96542bff95d5f7283f4fd1dd69e05069
3
+ metadata.gz: 119a5b996b99fd1cf525e2928fcee146d226463d589d0c90cc8fc35234556006
4
+ data.tar.gz: 7556145973db1abb0245c1684b600b162000806d13bd7a4074740f41b8581d52
5
5
  SHA512:
6
- metadata.gz: 6fcd12629c5d6e61507207f244880a96672ddb19f5dd1156c257ce0c44956ce438b29edc8b870ede84ff1c84f15a33ccf2c954e3edaf85065de4eba454613e24
7
- data.tar.gz: c1871eeb7a84bc5d61973d15bd4c1e98e7c2c4bc52234aa22d671efbf2769d0f5a1b437df237d8c3debf2b9733cf40ed578ef892e566cb4622b8272b9001ae71
6
+ metadata.gz: 9f33146ac6dde0b55514b55e7abe3c39bb70c6d5c9d23faf1bf043ec9d16047c0b795b28693a00d0c570e42a6491e566043e4f0cc5a30fd8af502917e19b2f1b
7
+ data.tar.gz: a6199859fa63efa39d2d4b772e2836b539ccc86c54b3a435fd791b9a97c90f6271f42e6020254cac735a159bfadc80f2c88d97b15dc4c2cdeca91e7054466256
data/bin/dimples CHANGED
@@ -1,14 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.join(__dir__, "..", "lib"))
5
5
 
6
- require 'dimples'
6
+ require "dimples"
7
7
 
8
- path = if ARGV[0]
9
- File.expand_path(ARGV[0])
10
- else
11
- File.join(Dir.pwd, 'site')
12
- end
8
+ source_path = ARGV[0]
9
+ output_path = ARGV[1]
13
10
 
14
- Dimples::Site.generate(path)
11
+ config_path = File.join(Dir.pwd, "config.yml")
12
+
13
+ config = {}
14
+
15
+ if File.exist?(config_path)
16
+ begin
17
+ config = YAML.safe_load(File.read(config_path), symbolize_names: true)
18
+ rescue YAML::Error
19
+ puts "Error reading config file - reverting to defaults"
20
+ end
21
+ end
22
+
23
+ begin
24
+ Dimples::Site.generate(source_path, output_path, config)
25
+ rescue Dimples::Error => error
26
+ puts "Error: #{error.message}"
27
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'frontmatter'
3
+ require_relative "frontmatter"
4
4
 
5
5
  module Dimples
6
6
  class Document
@@ -13,7 +13,7 @@ module Dimples
13
13
  @metadata, @contents = Dimples::FrontMatter.parse(File.read(path))
14
14
  else
15
15
  @metadata = {}
16
- @contents = ''
16
+ @contents = ""
17
17
  end
18
18
 
19
19
  @metadata.merge!(metadata)
@@ -24,18 +24,18 @@ module Dimples
24
24
  end
25
25
 
26
26
  def basename
27
- @metadata.fetch(:filename, 'index')
27
+ @metadata.fetch(:filename, "index")
28
28
  end
29
29
 
30
30
  def extension
31
- @metadata.fetch(:extension, 'html')
31
+ @metadata.fetch(:extension, "html")
32
32
  end
33
33
 
34
34
  def layout
35
35
  @metadata.fetch(:layout, nil)
36
36
  end
37
37
 
38
- def render(context = {}, content = '')
38
+ def render(context = {}, content = "")
39
39
  context_obj = Object.new
40
40
  context.each do |key, value|
41
41
  context_obj.instance_variable_set("@#{key}", value)
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dimples
4
+ class Error < StandardError
5
+ end
6
+
7
+ class GenerationError < Error
8
+ end
9
+
10
+ class RenderingError < Error
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
3
+ require "yaml"
4
4
 
5
5
  module Dimples
6
6
  module FrontMatter
data/lib/dimples/page.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'document'
3
+ require_relative "document"
4
4
 
5
5
  module Dimples
6
6
  class Page < Document
data/lib/dimples/pager.rb CHANGED
@@ -12,7 +12,7 @@ module Dimples
12
12
  @url = url
13
13
  @posts = posts
14
14
  @per_page = options.fetch(:per_page, PER_PAGE)
15
- @page_prefix = options.fetch(:page_prefix, 'page_')
15
+ @page_prefix = options.fetch(:page_prefix, "page_")
16
16
  @page_count = (posts.length.to_f / @per_page.to_i).ceil
17
17
 
18
18
  step_to(1)
@@ -43,7 +43,7 @@ module Dimples
43
43
  end
44
44
 
45
45
  def current_page_url
46
- @current_page != 1 ? "#{@url}#{@page_prefix}#{@current_page}" : @url
46
+ (@current_page != 1) ? "#{@url}#{@page_prefix}#{@current_page}" : @url
47
47
  end
48
48
 
49
49
  def first_page_url
@@ -51,13 +51,13 @@ module Dimples
51
51
  end
52
52
 
53
53
  def last_page_url
54
- @page_count != 1 ? "#{@url}#{@page_prefix}#{@page_count}" : @url
54
+ (@page_count != 1) ? "#{@url}#{@page_prefix}#{@page_count}" : @url
55
55
  end
56
56
 
57
57
  def previous_page_url
58
58
  return unless @previous_page
59
59
 
60
- @previous_page != 1 ? "#{@url}#{@page_prefix}#{@previous_page}" : @url
60
+ (@previous_page != 1) ? "#{@url}#{@page_prefix}#{@previous_page}" : @url
61
61
  end
62
62
 
63
63
  def next_page_url
data/lib/dimples/post.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'document'
3
+ require_relative "document"
4
4
 
5
- require 'date'
5
+ require "date"
6
6
 
7
7
  module Dimples
8
8
  class Post < Document
@@ -11,11 +11,11 @@ module Dimples
11
11
  end
12
12
 
13
13
  def layout
14
- @metadata.fetch(:layout, 'post')
14
+ @metadata.fetch(:layout, "post")
15
15
  end
16
16
 
17
17
  def slug
18
- File.basename(@path, '.markdown')
18
+ File.basename(@path, ".markdown")
19
19
  end
20
20
  end
21
21
  end
data/lib/dimples/site.rb CHANGED
@@ -1,28 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'pager'
3
+ require_relative "pager"
4
4
 
5
- require 'fileutils'
6
- require 'tilt'
7
- require 'date'
5
+ require "fileutils"
6
+ require "tilt"
7
+ require "date"
8
8
 
9
9
  module Dimples
10
10
  class Site
11
- def self.generate(output_path)
12
- new(output_path).generate
11
+ DEFAULT_CONFIG = { overwrite_directory: false }
12
+
13
+ def self.generate(source_path, output_path, config)
14
+ new(source_path, output_path, config).generate
13
15
  end
14
16
 
15
- attr_accessor :posts, :categories
17
+ attr_accessor :posts, :pages, :categories, :config
16
18
 
17
- def initialize(output_path)
19
+ def initialize(source_path, output_path, config)
18
20
  @paths = {
19
- source: File.expand_path(Dir.pwd),
20
- destination: File.expand_path(output_path)
21
+ source: File.expand_path(source_path || Dir.pwd),
22
+ destination: File.expand_path(output_path || File.join(Dir.pwd, "site"))
21
23
  }
22
24
 
23
- @config = read_config
25
+ @config = DEFAULT_CONFIG
26
+ @config.merge!(config) if config&.is_a?(Hash)
24
27
 
25
- %w[pages posts static templates].each { |type| @paths[type.to_sym] = File.join(@paths[:source], type) }
28
+ %w[pages posts static templates].each do |type|
29
+ @paths[type.to_sym] = File.join(@paths[:source], type)
30
+ end
26
31
 
27
32
  scan_posts
28
33
  scan_pages
@@ -31,8 +36,11 @@ module Dimples
31
36
 
32
37
  def generate
33
38
  if Dir.exist?(@paths[:destination])
34
- puts "Error: The output directory (#{@paths[:destination]}) already exists."
35
- return
39
+ unless @config[:overwrite_directory]
40
+ raise GenerationError.new("The build directory (#{@paths[:destination]}) already exists.")
41
+ end
42
+
43
+ FileUtils.rm_rf(@paths[:destination])
36
44
  end
37
45
 
38
46
  Dir.mkdir(@paths[:destination])
@@ -46,16 +54,8 @@ module Dimples
46
54
 
47
55
  private
48
56
 
49
- def read_config
50
- config_path = File.join(@paths[:source], '.config')
51
-
52
- return {} unless File.exist?(config_path)
53
-
54
- YAML.safe_load(File.read(config_path), symbolize_names: true)
55
- end
56
-
57
57
  def read_files(path)
58
- Dir[File.join(path, '**', '*.*')].sort
58
+ Dir[File.join(path, "**", "*.*")].sort
59
59
  end
60
60
 
61
61
  def scan_posts
@@ -65,7 +65,7 @@ module Dimples
65
65
  @categories = {}
66
66
 
67
67
  @posts.each do |post|
68
- post.categories.each do |category|
68
+ post.categories&.each do |category|
69
69
  @categories[category] ||= []
70
70
  @categories[category] << post
71
71
  end
@@ -73,18 +73,17 @@ module Dimples
73
73
  end
74
74
 
75
75
  def scan_pages
76
- @pages = read_files(@paths[:pages]).map do |path|
77
- Dimples::Page.new(path)
78
- end
76
+ @pages = read_files(@paths[:pages]).map { |path| Dimples::Page.new(path) }
79
77
  end
80
78
 
81
79
  def scan_templates
82
- @templates = {}.tap do |templates|
83
- read_files(@paths[:templates]).each do |path|
84
- key = File.basename(path, '.erb')
85
- templates[key] = Dimples::Template.new(path)
80
+ @templates =
81
+ {}.tap do |templates|
82
+ read_files(@paths[:templates]).each do |path|
83
+ key = File.basename(path, ".erb")
84
+ templates[key] = Dimples::Template.new(path)
85
+ end
86
86
  end
87
- end
88
87
  end
89
88
 
90
89
  def write_file(path, content)
@@ -95,23 +94,27 @@ module Dimples
95
94
  end
96
95
 
97
96
  def generate_paginated_posts(posts, path, context = {})
98
- pager = Dimples::Pager.new("#{path.sub(@paths[:destination], '')}/", posts)
97
+ pager = Dimples::Pager.new("#{path.sub(@paths[:destination], "")}/", posts)
99
98
 
100
99
  pager.each do |index|
101
- page = Dimples::Page.new(nil, layout: 'posts')
102
-
103
- page_path = if index == 1
104
- path
105
- else
106
- File.join(path, "page_#{index}")
107
- end
108
-
109
- write_file(File.join(page_path, page.filename), render(page, context.merge!(pagination: pager.to_context)))
100
+ page = Dimples::Page.new(nil, layout: "posts")
101
+
102
+ page_path =
103
+ if index == 1
104
+ path
105
+ else
106
+ File.join(path, "page_#{index}")
107
+ end
108
+
109
+ write_file(
110
+ File.join(page_path, page.filename),
111
+ render(page, context.merge!(pagination: pager.to_context))
112
+ )
110
113
  end
111
114
  end
112
115
 
113
116
  def generate_posts
114
- directory_path = File.join(@paths[:destination], @config.dig(:paths, :posts) || 'posts')
117
+ directory_path = File.join(@paths[:destination], @config.dig(:paths, :posts) || "posts")
115
118
  Dir.mkdir(directory_path)
116
119
 
117
120
  @posts.each do |post|
@@ -125,11 +128,12 @@ module Dimples
125
128
 
126
129
  def generate_pages
127
130
  @pages.each do |page|
128
- path = if page.path
129
- File.dirname(page.path).sub(@paths[:pages], @paths[:destination])
130
- else
131
- @paths[:destination]
132
- end
131
+ path =
132
+ if page.path
133
+ File.dirname(page.path).sub(@paths[:pages], @paths[:destination])
134
+ else
135
+ @paths[:destination]
136
+ end
133
137
 
134
138
  write_file(File.join(path, page.filename), render(page, page: page))
135
139
  end
@@ -137,7 +141,7 @@ module Dimples
137
141
 
138
142
  def generate_categories
139
143
  @categories.each do |category, posts|
140
- category_path = File.join(@paths[:destination], 'categories', category)
144
+ category_path = File.join(@paths[:destination], "categories", category)
141
145
 
142
146
  generate_paginated_posts(posts, category_path, category: category)
143
147
  generate_feed(posts.slice(0, 10), category_path)
@@ -145,14 +149,14 @@ module Dimples
145
149
  end
146
150
 
147
151
  def generate_feed(posts, path)
148
- page = Dimples::Page.new(nil, layout: 'feed')
149
- write_file(File.join(path, 'feed.atom'), render(page, posts: posts))
152
+ page = Dimples::Page.new(nil, layout: "feed")
153
+ write_file(File.join(path, "feed.atom"), render(page, posts: posts))
150
154
  end
151
155
 
152
156
  def copy_assets
153
157
  return unless Dir.exist?(@paths[:static])
154
158
 
155
- FileUtils.cp_r(File.join(@paths[:static], '.'), @paths[:destination])
159
+ FileUtils.cp_r(File.join(@paths[:static], "."), @paths[:destination])
156
160
  end
157
161
 
158
162
  def render(object, context = {}, content = nil)
@@ -160,7 +164,8 @@ module Dimples
160
164
 
161
165
  output = object.render(context, content)
162
166
 
163
- output = render(@templates[object.layout], context, output) if object.layout && @templates[object.layout]
167
+ output = render(@templates[object.layout], context, output) if object.layout &&
168
+ @templates[object.layout]
164
169
 
165
170
  output
166
171
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'document'
3
+ require_relative "document"
4
4
 
5
5
  module Dimples
6
6
  class Template < Document
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '7.0.4'
4
+ VERSION = "8.0.0"
5
5
  end
data/lib/dimples.rb CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  $LOAD_PATH.unshift(__dir__)
4
4
 
5
- require 'dimples/page'
6
- require 'dimples/post'
7
- require 'dimples/template'
8
- require 'dimples/site'
5
+ require "dimples/errors"
6
+ require "dimples/page"
7
+ require "dimples/post"
8
+ require "dimples/template"
9
+ require "dimples/site"
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: 7.0.4
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-17 00:00:00.000000000 Z
11
+ date: 2023-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -58,28 +58,56 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 12.3.3
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 12.3.3
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.10'
75
+ version: '3.12'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.10'
82
+ version: '3.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.22'
97
+ - !ruby/object:Gem::Dependency
98
+ name: standard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.28'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.28'
83
111
  description: A simple tool for building static websites.
84
112
  email:
85
113
  - d+dimples@waferbaby.com
@@ -91,6 +119,7 @@ files:
91
119
  - bin/dimples
92
120
  - lib/dimples.rb
93
121
  - lib/dimples/document.rb
122
+ - lib/dimples/errors.rb
94
123
  - lib/dimples/frontmatter.rb
95
124
  - lib/dimples/page.rb
96
125
  - lib/dimples/pager.rb
@@ -102,13 +131,13 @@ homepage: http://github.com/waferbaby/dimples
102
131
  licenses:
103
132
  - MIT
104
133
  metadata: {}
105
- post_install_message:
134
+ post_install_message:
106
135
  rdoc_options: []
107
136
  require_paths:
108
137
  - lib
109
138
  required_ruby_version: !ruby/object:Gem::Requirement
110
139
  requirements:
111
- - - ">="
140
+ - - ">"
112
141
  - !ruby/object:Gem::Version
113
142
  version: '2.7'
114
143
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -117,8 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
146
  - !ruby/object:Gem::Version
118
147
  version: '0'
119
148
  requirements: []
120
- rubygems_version: 3.1.6
121
- signing_key:
149
+ rubygems_version: 3.3.7
150
+ signing_key:
122
151
  specification_version: 4
123
152
  summary: A basic static site generator
124
153
  test_files: []