dimples 3.0.7 → 4.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
  SHA1:
3
- metadata.gz: 2d3f5d7e758762e3cba7f8d53520a06c1a7abe3f
4
- data.tar.gz: be2d879b4f1475166d56b4210f03e26afe3834e9
3
+ metadata.gz: e347e41fcd6d975535e6acb93dae09e600b0b8aa
4
+ data.tar.gz: 4de9555a39ed438e94f76c4caef2ac79b0407914
5
5
  SHA512:
6
- metadata.gz: 2eb2cd4791972d0475602e3860a8054e1ad1d554c31b8933d9551b4e5549f27de10dbdadb6cf6da19603e1c7dd4aef35781e9e6d5db2090da85a803057b9c85e
7
- data.tar.gz: 0a4f49d040199d11db9b8d5a4df417db3f60cfb65786263d3265617f4f3166cde8d39885fa311ff25313442dbaf3213ec3f658fd0a7503ef4c8d05419f7e8ecf
6
+ metadata.gz: 2c76600d5243dd598286c17d36f177391cd2f7d1bb820f7c4281599f5b98937479462cf5cf1a5e5860a5f6c31910d9dbfd822030f9e18be9fda2c81c31105fa7
7
+ data.tar.gz: f502ff18da072fe8d6c0844b2691de1a72ecbdbe137c4fb68c37801cfbb437588ba6b837e97d005e989a3ba17d186da7e7f667d21660e2c98cdcdd93e379d64d
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
5
5
 
6
6
  require 'dimples'
7
7
  require 'dimples/version'
8
+ require 'json'
8
9
  require 'trollop'
9
10
 
10
11
  trap('SIGINT') do
@@ -37,30 +38,33 @@ unless valid_commands.include?(command)
37
38
  end
38
39
 
39
40
  lib_path = File.join(Dir.pwd, options[:lib])
40
- config_path = File.join(Dir.pwd, options[:config] || 'config', 'site.yml')
41
-
42
- config_hash = {}
41
+ config_path = options[:config] || File.join(Dir.pwd, 'config.json')
43
42
 
44
43
  if File.exist?(config_path)
45
44
  begin
46
- config_hash = YAML.load_file(config_path) || {}
47
- rescue
48
- Trollop.die 'Invalid or malformed YAML config file'
45
+ config = JSON.parse(File.read(config_path), symbolize_names: true)
46
+ rescue => e
47
+ puts e.inspect
48
+ Trollop.die "Invalid or malformed config file (#{config_path})"
49
49
  end
50
- elsif options[:config]
51
- Trollop.die 'Unable to find config file'
50
+ else
51
+ Trollop.die "Unable to find config file (#{config_path})"
52
52
  end
53
53
 
54
- config_hash['verbose_logging'] = true if options[:verbose]
55
- config = Dimples::Configuration.new(config_hash)
54
+ config[:verbose_logging] = options[:verbose] || false
56
55
 
57
56
  if Dir.exist?(lib_path)
58
- Dir.glob(File.join(lib_path, '**', '*')) do |path|
57
+ Dir.glob(File.join(lib_path, '**', '*.rb')) do |path|
59
58
  require path
60
59
  end
61
60
  end
62
61
 
63
- site_klass = config.class_override(:site) || Dimples::Site
62
+ site_klass = if config[:class_overrides][:site]
63
+ Object.const_get(config[:class_overrides][:site])
64
+ else
65
+ Dimples::Site
66
+ end
67
+
64
68
  site = site_klass.new(config)
65
69
 
66
70
  case command.to_sym
@@ -10,7 +10,7 @@ module Dimples
10
10
  def initialize(site, slug)
11
11
  @site = site
12
12
  @slug = slug
13
- @name = @site.config['category_names'][slug] || slug.capitalize
13
+ @name = @site.config[:category_names][slug.to_sym] || slug.capitalize
14
14
  @posts = []
15
15
  end
16
16
 
@@ -4,83 +4,70 @@ module Dimples
4
4
  # A class that models a site's configuration.
5
5
  class Configuration
6
6
  def initialize(config = {})
7
- @settings = Dimples::Configuration.default_settings
8
-
9
- config.each_key do |key|
10
- if @settings[key].is_a?(Hash)
11
- @settings[key].merge!(config[key])
12
- else
13
- @settings[key] = config[key]
14
- end
15
- end
7
+ @settings = Configuration.default_settings.merge(config)
16
8
  end
17
9
 
18
10
  def [](key)
19
11
  @settings[key]
20
12
  end
21
13
 
22
- def class_override(type)
23
- klass = @settings['class_overrides'][type.to_s]
24
- Object.const_get(klass) unless klass.nil?
25
- end
26
-
27
14
  def self.default_settings
28
15
  {
29
- 'source_path' => Dir.pwd,
30
- 'destination_path' => File.join(Dir.pwd, 'site'),
31
- 'verbose_logging' => false,
32
- 'class_overrides' => { site: nil, post: nil },
33
- 'rendering' => {},
34
- 'category_names' => {},
35
- 'paths' => default_paths,
36
- 'layouts' => default_layouts,
37
- 'pagination' => default_pagination,
38
- 'generation' => default_generation,
39
- 'date_formats' => default_date_formats
16
+ source_path: Dir.pwd,
17
+ destination_path: File.join(Dir.pwd, 'site'),
18
+ verbose_logging: false,
19
+ class_overrides: { site: nil, post: nil },
20
+ rendering: {},
21
+ category_names: {},
22
+ paths: default_paths,
23
+ layouts: default_layouts,
24
+ pagination: default_pagination,
25
+ generation: default_generation,
26
+ date_formats: default_date_formats
40
27
  }
41
28
  end
42
29
 
43
30
  def self.default_layouts
44
31
  {
45
- 'posts' => 'posts',
46
- 'post' => 'post',
47
- 'category' => 'category',
48
- 'year_archives' => 'year_archives',
49
- 'month_archives' => 'month_archives',
50
- 'day_archives' => 'day_archives'
32
+ posts: 'posts',
33
+ post: 'post',
34
+ category: 'category',
35
+ year_archives: 'year_archives',
36
+ month_archives: 'month_archives',
37
+ day_archives: 'day_archives'
51
38
  }
52
39
  end
53
40
 
54
41
  def self.default_paths
55
42
  {
56
- 'archives' => 'archives',
57
- 'posts' => 'archives/%Y/%m/%d',
58
- 'categories' => 'archives/categories'
43
+ archives: 'archives',
44
+ posts: 'archives/%Y/%m/%d',
45
+ categories: 'archives/categories'
59
46
  }
60
47
  end
61
48
 
62
49
  def self.default_pagination
63
50
  {
64
- 'per_page' => 10
51
+ per_page: 10
65
52
  }
66
53
  end
67
54
 
68
55
  def self.default_generation
69
56
  {
70
- 'categories' => true,
71
- 'year_archives' => true,
72
- 'month_archives' => true,
73
- 'day_archives' => true,
74
- 'feeds' => true,
75
- 'category_feeds' => true
57
+ categories: true,
58
+ year_archives: true,
59
+ month_archives: true,
60
+ day_archives: true,
61
+ feeds: true,
62
+ category_feeds: true
76
63
  }
77
64
  end
78
65
 
79
66
  def self.default_date_formats
80
67
  {
81
- 'year' => '%Y',
82
- 'month' => '%Y-%m',
83
- 'day' => '%Y-%m-%d'
68
+ year: '%Y',
69
+ month: '%Y-%m',
70
+ day: '%Y-%m-%d'
84
71
  }
85
72
  end
86
73
  end
@@ -21,7 +21,7 @@ module Dimples
21
21
 
22
22
  if @path
23
23
  @filename = File.basename(@path, File.extname(@path))
24
- @output_directory = File.dirname(@path).gsub(
24
+ @output_directory = File.dirname(@path).sub(
25
25
  @site.source_paths[:pages],
26
26
  @site.output_paths[:site]
27
27
  )
@@ -5,9 +5,9 @@ module Dimples
5
5
  module Pagination
6
6
  def paginate(site, items, path, layout, options = {})
7
7
  context = options.delete(:context) || {}
8
- url = path.gsub(site.output_paths[:site], '') + '/'
8
+ url = path.sub(site.output_paths[:site], '') + '/'
9
9
  per_page = options.delete(:per_page) ||
10
- site.config['pagination']['per_page']
10
+ site.config[:pagination][:per_page]
11
11
 
12
12
  pager = Pager.new(url, items, per_page, options)
13
13
 
@@ -22,7 +22,7 @@ module Dimples
22
22
 
23
23
  @filename = 'index'
24
24
  @slug = parts[4]
25
- @layout = @site.config['layouts']['post']
25
+ @layout = @site.config[:layouts][:post]
26
26
 
27
27
  self.date = Time.mktime(parts[1], parts[2], parts[3])
28
28
 
@@ -38,8 +38,8 @@ module Dimples
38
38
  callback = proc { contents }
39
39
 
40
40
  if @path
41
- ext = File.extname(@path)[1..-1]
42
- options = @site.config['rendering'][ext] || {}
41
+ extension = File.extname(@path)[1..-1]
42
+ options = @site.config[:rendering][extension.to_sym] || {}
43
43
  Tilt.new(@path, options, &callback)
44
44
  else
45
45
  Tilt::StringTemplate.new(&callback)
@@ -17,8 +17,8 @@ module Dimples
17
17
  attr_accessor :post_class
18
18
  attr_accessor :errors
19
19
 
20
- def initialize(config)
21
- @config = config
20
+ def initialize(config = {})
21
+ @config = Dimples::Configuration.new(config)
22
22
 
23
23
  @templates = {}
24
24
  @categories = {}
@@ -29,18 +29,24 @@ module Dimples
29
29
  @archives = { year: {}, month: {}, day: {} }
30
30
  @latest_post = false
31
31
 
32
- @post_class = @config.class_override(:post) || Dimples::Post
32
+ @post_class = if @config[:class_overrides][:post]
33
+ Object.const_get(config[:class_overrides][:post])
34
+ else
35
+ Dimples::Post
36
+ end
33
37
 
34
- @source_paths = { root: File.expand_path(@config['source_path']) }
35
- @output_paths = { site: File.expand_path(@config['destination_path']) }
38
+ @source_paths = { root: File.expand_path(@config[:source_path]) }
39
+ @output_paths = { site: File.expand_path(@config[:destination_path]) }
36
40
 
37
41
  %w[pages posts public templates].each do |path|
38
42
  @source_paths[path.to_sym] = File.join(@source_paths[:root], path)
39
43
  end
40
44
 
41
45
  %w[archives posts categories].each do |path|
42
- output_path = File.join(@output_paths[:site], @config['paths'][path])
43
- @output_paths[path.to_sym] = output_path
46
+ path_sym = path.to_sym
47
+ @output_paths[path_sym] = File.join(
48
+ @output_paths[:site], @config[:paths][path_sym]
49
+ )
44
50
  end
45
51
  end
46
52
 
@@ -53,7 +59,7 @@ module Dimples
53
59
  unless @posts.count.zero?
54
60
  generate_posts
55
61
  generate_archives
56
- generate_categories if @config['generation']['categories']
62
+ generate_categories if @config[:generation][:categories]
57
63
  end
58
64
 
59
65
  copy_assets
@@ -68,7 +74,7 @@ module Dimples
68
74
  end
69
75
 
70
76
  def scan_files
71
- Dimples.logger.debug('Scanning files...') if @config['verbose_logging']
77
+ Dimples.logger.debug('Scanning files...') if @config[:verbose_logging]
72
78
 
73
79
  scan_templates
74
80
  scan_pages
@@ -83,8 +89,8 @@ module Dimples
83
89
  if parent_path == @source_paths[:templates]
84
90
  slug = template.slug
85
91
  else
86
- relative_path = parent_path.gsub(@source_paths[:templates], '')[1..-1]
87
- slug = relative_path.gsub(File::SEPARATOR, '.') + ".#{template.slug}"
92
+ relative_path = parent_path.sub(@source_paths[:templates], '')[1..-1]
93
+ slug = relative_path.sub(File::SEPARATOR, '.') + ".#{template.slug}"
88
94
  end
89
95
 
90
96
  @templates[slug] = template
@@ -144,7 +150,7 @@ module Dimples
144
150
  end
145
151
 
146
152
  def generate_posts
147
- if @config['verbose_logging']
153
+ if @config[:verbose_logging]
148
154
  Dimples.logger.debug_generation('posts', @posts.length)
149
155
  end
150
156
 
@@ -154,14 +160,14 @@ module Dimples
154
160
  self,
155
161
  @posts,
156
162
  @output_paths[:archives],
157
- @config['layouts']['posts']
163
+ @config[:layouts][:posts]
158
164
  )
159
165
 
160
- generate_posts_feeds if @config['generation']['feeds']
166
+ generate_posts_feeds if @config[:generation][:feeds]
161
167
  end
162
168
 
163
169
  def generate_pages
164
- if @config['verbose_logging']
170
+ if @config[:verbose_logging]
165
171
  Dimples.logger.debug_generation('pages', @pages.length)
166
172
  end
167
173
 
@@ -169,7 +175,7 @@ module Dimples
169
175
  end
170
176
 
171
177
  def generate_categories
172
- if @config['verbose_logging']
178
+ if @config[:verbose_logging]
173
179
  Dimples.logger.debug_generation('category pages', @categories.length)
174
180
  end
175
181
 
@@ -185,31 +191,32 @@ module Dimples
185
191
  self,
186
192
  category.posts,
187
193
  path,
188
- @config['layouts']['category'],
194
+ @config[:layouts][:category],
189
195
  options
190
196
  )
191
197
  end
192
198
 
193
- generate_category_feeds if @config['generation']['category_feeds']
199
+ generate_category_feeds if @config[:generation][:category_feeds]
194
200
  end
195
201
 
196
202
  def generate_archives
197
203
  %w[year month day].each do |date_type|
198
- next unless @config['generation']["#{date_type}_archives"]
204
+ date_archives_sym = "#{date_type}_archives".to_sym
205
+ next unless @config[:generation][date_archives_sym]
199
206
 
200
207
  @archives[date_type.to_sym].each do |date, posts|
201
- year, month, day = date.split('/')
208
+ year, month, day = date.split('-')
202
209
 
203
210
  dates = { year: year }
204
211
  dates[:month] = month if month
205
212
  dates[:day] = day if day
206
213
 
207
214
  path = File.join(@output_paths[:archives], dates.values)
208
- layout = @config['layouts']["#{date_type}_archives"]
215
+ layout = @config[:layouts][date_archives_sym]
209
216
 
210
217
  options = {
211
218
  context: dates,
212
- title: posts[0].date.strftime(@config['date_formats'][date_type])
219
+ title: posts[0].date.strftime(@config[:date_formats][date_type.to_sym])
213
220
  }
214
221
 
215
222
  paginate(self, posts, path, layout, options)
@@ -233,14 +240,14 @@ module Dimples
233
240
  end
234
241
 
235
242
  def generate_posts_feeds
236
- posts = @posts[0..@config['pagination']['per_page'] - 1]
243
+ posts = @posts[0..@config[:pagination][:per_page] - 1]
237
244
  generate_feeds(@output_paths[:site], posts: posts)
238
245
  end
239
246
 
240
247
  def generate_category_feeds
241
248
  @categories.each_value do |category|
242
249
  path = File.join(@output_paths[:categories], category.slug)
243
- posts = category.posts[0..@config['pagination']['per_page'] - 1]
250
+ posts = category.posts[0..@config[:pagination][:per_page] - 1]
244
251
 
245
252
  generate_feeds(path, posts: posts, category: category.slug)
246
253
  end
@@ -252,7 +259,7 @@ module Dimples
252
259
 
253
260
  def copy_assets
254
261
  if Dir.exist?(@source_paths[:public])
255
- Dimples.logger.debug('Copying assets...') if @config['verbose_logging']
262
+ Dimples.logger.debug('Copying assets...') if @config[:verbose_logging]
256
263
 
257
264
  path = File.join(@source_paths[:public], '.')
258
265
  FileUtils.cp_r(path, @output_paths[:site])
@@ -274,11 +281,11 @@ module Dimples
274
281
  end
275
282
 
276
283
  def archive_month(year, month)
277
- @archives[:month]["#{year}/#{month}"] ||= []
284
+ @archives[:month]["#{year}-#{month}"] ||= []
278
285
  end
279
286
 
280
287
  def archive_day(year, month, day)
281
- @archives[:day]["#{year}/#{month}/#{day}"] ||= []
288
+ @archives[:day]["#{year}-#{month}-#{day}"] ||= []
282
289
  end
283
290
  end
284
291
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '3.0.7'
4
+ VERSION = '4.0.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: 3.0.7
4
+ version: 4.0.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: 2017-08-31 00:00:00.000000000 Z
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2.7'
75
+ - !ruby/object:Gem::Dependency
76
+ name: little-fixtures
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.0.1
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.1
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: minitest
77
91
  requirement: !ruby/object:Gem::Requirement