dimples 13.0.0 → 13.0.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: 3b1507135dbcefde4af262ac48bc5b5fb34fb70d6ee8907f79fd65c53baccf37
4
- data.tar.gz: e78540206127d0891cbbb3d6c04f21cf9ebbd98205f7c742feb8a0ee337245ed
3
+ metadata.gz: 820b81c83ff8701c08520801dd39dc165578fbaa4e994699c2a3c3c5f8fe6a73
4
+ data.tar.gz: 3de38112fe45ea95eed771573c06401dbe6899dfd1883443fd20debfe64a6f5e
5
5
  SHA512:
6
- metadata.gz: 5bb98fd65d3c953670d26c2b932d295c7ac478b77c1fa12f655104acc5350c51f8b85daa83efadc64fadf5a2c1f4cf3606a9b9ef80bdb2cd4ee3fc657e2420d1
7
- data.tar.gz: ad6d763c238811a49d755b69d23fbbdf3f332b08594602fbc3fbf7bc0b468346720bf01dee04e00241178d052d8ba57e0f8a147742bb04ba19c76e0ef6511cad
6
+ metadata.gz: 7676867a9acd8b29cc96e67c9396597e49ee8ae9e038e18087bfced6deca8a914a588c4fccf4e7c10e1fd11177af5a89b4c800d2a9ade78bc8860ded74a098bf
7
+ data.tar.gz: c86035f512c293e338468d4fd944eb046a1e4023fd9294758f30985f4ea380c49cf3279fbf37b24a03c2d5e935845768c9b36274c8738980edcbc17602057ef8
@@ -4,10 +4,11 @@ module Dimples
4
4
  # Configuration settings for a site.
5
5
  class Config
6
6
  SOURCE_PATHS = {
7
+ data: 'data',
7
8
  pages: 'pages',
8
9
  posts: 'posts',
9
- templates: 'templates',
10
- static: 'static'
10
+ static: 'static',
11
+ templates: 'templates'
11
12
  }.freeze
12
13
 
13
14
  attr_accessor :source_paths, :build_paths, :site, :pagination, :generation
@@ -4,9 +4,18 @@ module Dimples
4
4
  # Context used when rendering an item in a template
5
5
  class Context
6
6
  def self.from_hash(hash)
7
- hash.transform_values! { |value| value.is_a?(Hash) ? Context.from_hash(value) : value }
7
+ hash.transform_values! do |value|
8
+ case value
9
+ when Hash
10
+ Context.from_hash(value)
11
+ when Array
12
+ value.map { |item| item.is_a?(Hash) ? Context.from_hash(item) : item }
13
+ else
14
+ value
15
+ end
16
+ end
8
17
 
9
- Struct.new(*hash.keys) do |_klass|
18
+ Struct.new(*hash.keys.map(&:to_sym)) do |_klass|
10
19
  def method_missing(_method_name, *_args)
11
20
  nil
12
21
  end
data/lib/dimples/site.rb CHANGED
@@ -29,7 +29,7 @@ module Dimples
29
29
  end
30
30
 
31
31
  def posts
32
- @posts ||= source_files(path: :posts, extension: 'markdown').map do |path|
32
+ @posts ||= source_files(key: :posts, extension: 'markdown').map do |path|
33
33
  Dimples::Post.new(site: self, path: path)
34
34
  end
35
35
  .sort_by!(&:date)
@@ -37,19 +37,28 @@ module Dimples
37
37
  end
38
38
 
39
39
  def pages
40
- @pages ||= source_files(path: :pages, extension: 'erb').map do |path|
40
+ @pages ||= source_files(key: :pages, extension: 'erb').map do |path|
41
41
  Dimples::Template.new(site: self, path: path)
42
42
  end
43
43
  end
44
44
 
45
45
  def templates
46
- @templates ||= source_files(path: :templates, extension: 'erb').to_h do |path|
47
- key = File.basename(
48
- path.gsub(@config.source_paths[:templates] + File::SEPARATOR, '').tr(File::SEPARATOR, '_'),
49
- '.erb'
50
- )
46
+ @templates ||= source_files(key: :templates, extension: 'erb').to_h do |path|
47
+ key = File.basename(flatten_source_path(path:, key: :templates), '.erb').to_sym
48
+ [key, Dimples::Template.new(site: self, path: path)]
49
+ end
50
+ end
51
51
 
52
- [key.to_sym, Dimples::Template.new(site: self, path: path)]
52
+ def data
53
+ @data ||= source_files(key: :data, extension: 'json').to_h do |path|
54
+ key = File.basename(flatten_source_path(path:, key: :data), ".json").to_sym
55
+ value = begin
56
+ Context.from_hash(JSON.parse(File.read(path)))
57
+ rescue JSON::ParserError
58
+ nil
59
+ end
60
+
61
+ [key, value]
53
62
  end
54
63
  end
55
64
 
@@ -66,8 +75,12 @@ module Dimples
66
75
 
67
76
  private
68
77
 
69
- def source_files(path:, extension:)
70
- Dir.glob(File.join(@config.source_paths[path], '**', "*.#{extension}"))
78
+ def source_files(key:, extension:)
79
+ Dir.glob(File.join(@config.source_paths[key], '**', "*.#{extension}"))
80
+ end
81
+
82
+ def flatten_source_path(path:, key:)
83
+ path.gsub(@config.source_paths[key] + File::SEPARATOR, '').tr(File::SEPARATOR, '_')
71
84
  end
72
85
 
73
86
  def generate_posts
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '13.0.0'
4
+ VERSION = '13.0.1'
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: 13.0.0
4
+ version: 13.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan