perron 0.13.0 → 0.13.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/perron/templates/README.md.tt +3 -3
- data/lib/perron/collection.rb +3 -1
- data/lib/perron/engine.rb +2 -1
- data/lib/perron/resource.rb +3 -0
- data/lib/perron/site/validate.rb +66 -0
- data/lib/perron/site.rb +5 -2
- data/lib/perron/tasks/validate.rake +6 -0
- data/lib/perron/version.rb +1 -1
- metadata +4 -2
- /data/lib/perron/tasks/{perron.rake → build.rake} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d169d3715ddcc7ff8a40cd17c3ac263fcd8cf6ef64a796ef697ab01d07da98fa
|
|
4
|
+
data.tar.gz: 53b6a77e3bdbea6d9e808689321ed42833d8b2a8a48ab9035fbb11edfe7d5bfa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3fb4193f86022bb65bcf36093c66e3145a0a7304d3170d1f83d0cb26fd9be00aaea4258a0e58c4f566d00279522f8e51cbbe12544311e93a1bde58fe9ccad166
|
|
7
|
+
data.tar.gz: 623ceec51ddac7e99049d7862a9d51ca04bf3fc8abe2eb78d9170bf8107df39fb3695e34c911006623fe83bfe533237e2812e1989de553d06dbc5d664fff4589
|
data/Gemfile.lock
CHANGED
|
@@ -44,14 +44,14 @@ feature[:name]
|
|
|
44
44
|
|
|
45
45
|
You can render data collections directly using Rails-like partial rendering. When you call `render` on a data collection, Perron will automatically render a partial for each item.
|
|
46
46
|
```erb
|
|
47
|
-
|
|
47
|
+
<%%= render Perron::Site.data.features %>
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
This expects a partial at `app/views/content/features/_feature.html.erb` that will be rendered once for each feature in your data file. The individual record is made available as a local variable matching the singular form of the collection name.
|
|
51
51
|
```erb
|
|
52
52
|
<!-- app/views/content/features/_feature.html.erb -->
|
|
53
53
|
<div class="feature">
|
|
54
|
-
<h4
|
|
55
|
-
<p
|
|
54
|
+
<h4><%%= feature.name %></h4>
|
|
55
|
+
<p><%%= feature.description %></p>
|
|
56
56
|
</div>
|
|
57
57
|
```
|
data/lib/perron/collection.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Perron
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def all(resource_class = "Content::#{name.classify}".safe_constantize)
|
|
19
|
-
|
|
19
|
+
Dir.glob("#{@collection_path}/**/*.*").map do |file_path|
|
|
20
20
|
resource_class.new(file_path)
|
|
21
21
|
end.select(&:published?)
|
|
22
22
|
end
|
|
@@ -35,5 +35,7 @@ module Perron
|
|
|
35
35
|
Perron.configuration.allowed_extensions.lazy.map { File.join(@collection_path, [file_name, it].join(".")) }.find { File.exist?(it) }
|
|
36
36
|
)
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
def validate = Perron::Site::Validate.new(collections: [self]).validate
|
|
38
40
|
end
|
|
39
41
|
end
|
data/lib/perron/engine.rb
CHANGED
data/lib/perron/resource.rb
CHANGED
|
@@ -15,6 +15,8 @@ module Perron
|
|
|
15
15
|
class Resource
|
|
16
16
|
ID_LENGTH = 8
|
|
17
17
|
|
|
18
|
+
include ActiveModel::Validations
|
|
19
|
+
|
|
18
20
|
include Perron::Resource::Configuration
|
|
19
21
|
include Perron::Resource::Core
|
|
20
22
|
include Perron::Resource::ClassMethods
|
|
@@ -24,6 +26,7 @@ module Perron
|
|
|
24
26
|
attr_reader :file_path, :id
|
|
25
27
|
|
|
26
28
|
def initialize(file_path)
|
|
29
|
+
@errors = ActiveModel::Errors.new(self)
|
|
27
30
|
@file_path = file_path
|
|
28
31
|
@id = generate_id
|
|
29
32
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Perron
|
|
4
|
+
module Site
|
|
5
|
+
class Validate
|
|
6
|
+
def initialize(collections: Perron::Site.collections)
|
|
7
|
+
@collections = collections
|
|
8
|
+
@failures = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def validate
|
|
12
|
+
@collections.each { validate_collection it }
|
|
13
|
+
|
|
14
|
+
[
|
|
15
|
+
puts,
|
|
16
|
+
failures_report,
|
|
17
|
+
puts
|
|
18
|
+
].compact_blank.join
|
|
19
|
+
|
|
20
|
+
puts [
|
|
21
|
+
"Validation finished",
|
|
22
|
+
(" with #{@failures.count} failures" if @failures.any?),
|
|
23
|
+
"."
|
|
24
|
+
].join
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
Failure = ::Data.define(:identifier, :errors)
|
|
30
|
+
|
|
31
|
+
GREEN = "\e[32m"
|
|
32
|
+
RED = "\e[31m"
|
|
33
|
+
RESET = "\e[0m"
|
|
34
|
+
|
|
35
|
+
def validate_collection(collection)
|
|
36
|
+
collection.resources.each do |resource|
|
|
37
|
+
resource.validate ? success : failed(resource)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def success = print "#{GREEN}.#{RESET}"
|
|
42
|
+
|
|
43
|
+
def failed(resource)
|
|
44
|
+
print "#{RED}F#{RESET}"
|
|
45
|
+
|
|
46
|
+
errors = []
|
|
47
|
+
|
|
48
|
+
if resource.respond_to?(:errors) && resource.errors.respond_to?(:full_messages) && resource.errors.any?
|
|
49
|
+
errors = resource.errors.full_messages
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@failures << Failure.new(identifier: resource.file_path, errors: errors)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def failures_report
|
|
56
|
+
@failures.each do |failure|
|
|
57
|
+
puts "Resource: #{failure.identifier}"
|
|
58
|
+
|
|
59
|
+
failure.errors.each do |error_message|
|
|
60
|
+
puts " - #{error_message}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
data/lib/perron/site.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "perron/site/builder"
|
|
4
3
|
require "perron/collection"
|
|
5
4
|
require "perron/data"
|
|
6
5
|
require "perron/data/proxy"
|
|
6
|
+
require "perron/site/builder"
|
|
7
|
+
require "perron/site/validate"
|
|
7
8
|
|
|
8
9
|
module Perron
|
|
9
10
|
module Site
|
|
@@ -11,8 +12,10 @@ module Perron
|
|
|
11
12
|
|
|
12
13
|
def build = Perron::Site::Builder.new.build
|
|
13
14
|
|
|
15
|
+
def validate = Perron::Site::Validate.new.validate
|
|
16
|
+
|
|
14
17
|
def collections
|
|
15
|
-
|
|
18
|
+
Dir.children(Perron.configuration.input)
|
|
16
19
|
.select { File.directory?(File.join(Perron.configuration.input, it)) }
|
|
17
20
|
.reject { it == "data" }
|
|
18
21
|
.map { Collection.new(it) }
|
data/lib/perron/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: perron
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.13.
|
|
4
|
+
version: 0.13.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rails Designer Developers
|
|
@@ -135,7 +135,9 @@ files:
|
|
|
135
135
|
- lib/perron/site/builder/paths.rb
|
|
136
136
|
- lib/perron/site/builder/public_files.rb
|
|
137
137
|
- lib/perron/site/builder/sitemap.rb
|
|
138
|
-
- lib/perron/
|
|
138
|
+
- lib/perron/site/validate.rb
|
|
139
|
+
- lib/perron/tasks/build.rake
|
|
140
|
+
- lib/perron/tasks/validate.rake
|
|
139
141
|
- lib/perron/version.rb
|
|
140
142
|
- perron.gemspec
|
|
141
143
|
homepage: https://perron.railsdesigner.com/
|
|
File without changes
|