perron 0.13.0 → 0.13.2

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: 4a0f1b173ae94ac69df1bf9fe680062fa7d07ef6af132677313e80a1d909cb68
4
- data.tar.gz: 6e6c7865e13a312b6bdac601d6d8878f13136c8d70734ceb5c03fa5ea8d83159
3
+ metadata.gz: c9220fa63d98abad0b69758811716bdb3bd445f61e918adb0edee0c54064444d
4
+ data.tar.gz: 6c360d6a12e27664810f0e0936724587e5a4b21d6eaa1d83c13ecb554e868416
5
5
  SHA512:
6
- metadata.gz: '066983a2578dabbc1d1033f8e9d36065ff03cd9d46fde15cc77348086c114e23c9052aff9e2087bc7e429584bcdb99821bdb1195ba908053f7b5d80966b6133c'
7
- data.tar.gz: 98eafaeed24b4395c55f4847cf672941f99f551833f15c29cf6a8e3974c8ff0d4da7facc6af87e400e95449b6b76687f3f3c89e14ee3ef60cd1b89583271f0f1
6
+ metadata.gz: ce70a594ace145f7cb1a15e97ee6c6c3fa310d59dd17b9c15d774a5272d3bc6ad74da41443b37a7b150c346342dffb7f681c781f3df9a9574fb4af50277d6228
7
+ data.tar.gz: bf44b04d4a9bb4ef81706a2a75088979cdc808a3ed6f139909f803c50fec6125a675e6272c595c20710204472b7e8c6750ba7bae55ab47bf9704baef9e903892
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- perron (0.13.0)
4
+ perron (0.13.2)
5
5
  csv
6
6
  json
7
7
  psych
@@ -41,7 +41,7 @@ class ContentGenerator < Rails::Generators::NamedBase
41
41
  return unless pages_controller?
42
42
  return if root_route_exists?
43
43
 
44
- inject_into_file "config/routes.rb", " root to: \"content/pages#show\"\n", before: /^\s*end\s*$/
44
+ inject_into_file "config/routes.rb", " root to: \"content/pages#root\"\n", before: /^\s*end\s*$/
45
45
  end
46
46
 
47
47
  private
@@ -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
- <%= render Perron::Site.data.features %>
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><%= feature.name %></h4>
55
- <p><%= feature.description %></p>
54
+ <h4><%%= feature.name %></h4>
55
+ <p><%%= feature.description %></p>
56
56
  </div>
57
57
  ```
@@ -16,7 +16,7 @@ module Perron
16
16
  end
17
17
 
18
18
  def all(resource_class = "Content::#{name.classify}".safe_constantize)
19
- @all ||= Dir.glob("#{@collection_path}/**/*.*").map do |file_path|
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
@@ -7,7 +7,8 @@ module Perron
7
7
  end
8
8
 
9
9
  rake_tasks do
10
- load File.expand_path("../tasks/perron.rake", __FILE__)
10
+ load File.expand_path("../tasks/build.rake", __FILE__)
11
+ load File.expand_path("../tasks/validate.rake", __FILE__)
11
12
  end
12
13
  end
13
14
  end
@@ -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
- @collections ||= Dir.children(Perron.configuration.input)
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) }
@@ -0,0 +1,6 @@
1
+ namespace :perron do
2
+ desc "Validate all site resources"
3
+ task validate: :environment do
4
+ Perron::Site.validate
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Perron
2
- VERSION = "0.13.0"
2
+ VERSION = "0.13.2"
3
3
  end
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.0
4
+ version: 0.13.2
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/tasks/perron.rake
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