perron 0.16.0 → 0.18.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 +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +25 -2
- data/app/controllers/perron/searches_controller.rb +48 -0
- data/app/helpers/perron/feeds_helper.rb +7 -0
- data/app/helpers/perron/markdown_helper.rb +3 -3
- data/app/helpers/perron/meta_tags_helper.rb +17 -0
- data/bin/release +19 -4
- data/lib/generators/perron/templates/README.md.tt +31 -7
- data/lib/generators/perron/templates/initializer.rb.tt +11 -11
- data/lib/generators/rails/content/USAGE +40 -15
- data/lib/generators/rails/content/content_generator.rb +53 -15
- data/lib/generators/rails/content/templates/controller.rb.tt +1 -5
- data/lib/generators/rails/content/templates/model.rb.tt +11 -0
- data/lib/generators/rails/content/templates/root.erb.tt +1 -1
- data/lib/generators/rails/content/templates/show.html.erb.tt +1 -1
- data/lib/perron/collection.rb +10 -1
- data/lib/perron/configuration.rb +14 -6
- data/lib/perron/content/data.rb +6 -2
- data/lib/perron/data_source/class_methods.rb +58 -0
- data/lib/perron/data_source/helper_context.rb +20 -0
- data/lib/perron/data_source/item.rb +37 -0
- data/lib/perron/{data → data_source}/proxy.rb +1 -1
- data/lib/perron/data_source.rb +155 -0
- data/lib/perron/engine.rb +12 -0
- data/lib/perron/html_processor/syntax_highlight.rb +2 -0
- data/lib/perron/output_server.rb +7 -2
- data/lib/perron/relation.rb +51 -0
- data/lib/perron/resource/associations.rb +2 -2
- data/lib/perron/resource/class_methods.rb +14 -4
- data/lib/perron/resource/configuration.rb +8 -11
- data/lib/perron/resource/core.rb +11 -0
- data/lib/perron/resource/metadata.rb +1 -1
- data/lib/perron/resource/related/stop_words.rb +20 -20
- data/lib/perron/resource/related.rb +73 -52
- data/lib/perron/resource/scopes.rb +29 -0
- data/lib/perron/resource/searchable.rb +19 -0
- data/lib/perron/resource/sourceable.rb +2 -2
- data/lib/perron/resource/sweeper.rb +45 -0
- data/lib/perron/resource/table_of_content.rb +0 -18
- data/lib/perron/resource.rb +34 -24
- data/lib/perron/site/builder/additional_routes.rb +23 -0
- data/lib/perron/site/builder/feeds/author.rb +2 -1
- data/lib/perron/site/builder/paths.rb +2 -9
- data/lib/perron/site/builder/sitemap.rb +20 -2
- data/lib/perron/site/builder.rb +2 -0
- data/lib/perron/site.rb +3 -3
- data/lib/perron/tasks/build.rake +8 -1
- data/lib/perron/version.rb +1 -1
- data/lib/perron.rb +1 -1
- data/perron.gemspec +1 -0
- metadata +29 -7
- data/app/helpers/feeds_helper.rb +0 -5
- data/app/helpers/meta_tags_helper.rb +0 -15
- data/lib/perron/data.rb +0 -145
- data/lib/perron/root.rb +0 -13
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.
|
|
4
|
+
version: 0.18.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rails Designer Developers
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: 7.2.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: mata
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.8.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.8.0
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: csv
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -78,10 +92,11 @@ files:
|
|
|
78
92
|
- Gemfile.lock
|
|
79
93
|
- README.md
|
|
80
94
|
- Rakefile
|
|
81
|
-
- app/
|
|
82
|
-
- app/helpers/meta_tags_helper.rb
|
|
95
|
+
- app/controllers/perron/searches_controller.rb
|
|
83
96
|
- app/helpers/perron/erb_helper.rb
|
|
97
|
+
- app/helpers/perron/feeds_helper.rb
|
|
84
98
|
- app/helpers/perron/markdown_helper.rb
|
|
99
|
+
- app/helpers/perron/meta_tags_helper.rb
|
|
85
100
|
- bin/console
|
|
86
101
|
- bin/rails
|
|
87
102
|
- bin/release
|
|
@@ -100,8 +115,11 @@ files:
|
|
|
100
115
|
- lib/perron/collection.rb
|
|
101
116
|
- lib/perron/configuration.rb
|
|
102
117
|
- lib/perron/content/data.rb
|
|
103
|
-
- lib/perron/
|
|
104
|
-
- lib/perron/
|
|
118
|
+
- lib/perron/data_source.rb
|
|
119
|
+
- lib/perron/data_source/class_methods.rb
|
|
120
|
+
- lib/perron/data_source/helper_context.rb
|
|
121
|
+
- lib/perron/data_source/item.rb
|
|
122
|
+
- lib/perron/data_source/proxy.rb
|
|
105
123
|
- lib/perron/deprecator.rb
|
|
106
124
|
- lib/perron/engine.rb
|
|
107
125
|
- lib/perron/errors.rb
|
|
@@ -115,6 +133,7 @@ files:
|
|
|
115
133
|
- lib/perron/metatags.rb
|
|
116
134
|
- lib/perron/output_server.rb
|
|
117
135
|
- lib/perron/refinements/delete_suffixes.rb
|
|
136
|
+
- lib/perron/relation.rb
|
|
118
137
|
- lib/perron/resource.rb
|
|
119
138
|
- lib/perron/resource/associations.rb
|
|
120
139
|
- lib/perron/resource/class_methods.rb
|
|
@@ -127,13 +146,16 @@ files:
|
|
|
127
146
|
- lib/perron/resource/related.rb
|
|
128
147
|
- lib/perron/resource/related/stop_words.rb
|
|
129
148
|
- lib/perron/resource/renderer.rb
|
|
149
|
+
- lib/perron/resource/scopes.rb
|
|
150
|
+
- lib/perron/resource/searchable.rb
|
|
130
151
|
- lib/perron/resource/separator.rb
|
|
131
152
|
- lib/perron/resource/slug.rb
|
|
132
153
|
- lib/perron/resource/sourceable.rb
|
|
154
|
+
- lib/perron/resource/sweeper.rb
|
|
133
155
|
- lib/perron/resource/table_of_content.rb
|
|
134
|
-
- lib/perron/root.rb
|
|
135
156
|
- lib/perron/site.rb
|
|
136
157
|
- lib/perron/site/builder.rb
|
|
158
|
+
- lib/perron/site/builder/additional_routes.rb
|
|
137
159
|
- lib/perron/site/builder/assets.rb
|
|
138
160
|
- lib/perron/site/builder/feeds.rb
|
|
139
161
|
- lib/perron/site/builder/feeds/author.rb
|
|
@@ -170,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
170
192
|
- !ruby/object:Gem::Version
|
|
171
193
|
version: '0'
|
|
172
194
|
requirements: []
|
|
173
|
-
rubygems_version: 4.0.
|
|
195
|
+
rubygems_version: 4.0.6
|
|
174
196
|
specification_version: 4
|
|
175
197
|
summary: Rails-based static site generator
|
|
176
198
|
test_files: []
|
data/app/helpers/feeds_helper.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module MetaTagsHelper
|
|
4
|
-
def meta_tags(options = {}) = Perron::Metatags.new(resource.metadata).render(options)
|
|
5
|
-
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
Resource = Data.define(:path, :collection, :metadata, :published_at)
|
|
9
|
-
|
|
10
|
-
def resource
|
|
11
|
-
return Resource.new(request.path, nil, @metadata, nil) if @metadata.present?
|
|
12
|
-
|
|
13
|
-
@resource || Resource.new(request.path, nil, {}, nil)
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/perron/data.rb
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "csv"
|
|
4
|
-
|
|
5
|
-
module Perron
|
|
6
|
-
class Data < SimpleDelegator
|
|
7
|
-
def initialize(identifier)
|
|
8
|
-
@identifier = identifier
|
|
9
|
-
@file_path = self.class.path_for!(identifier)
|
|
10
|
-
@records = records
|
|
11
|
-
|
|
12
|
-
super(records)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
class << self
|
|
16
|
-
def all
|
|
17
|
-
parts = name.to_s.split("::").drop(2)
|
|
18
|
-
identifier = parts.empty? ? name.demodulize.underscore : parts.map(&:underscore).join("/")
|
|
19
|
-
|
|
20
|
-
new(identifier)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def find(id)
|
|
24
|
-
all.find { it[:id] == id || it["id"] == id }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def path_for(identifier)
|
|
28
|
-
path = Pathname.new(identifier)
|
|
29
|
-
|
|
30
|
-
return path.to_s if path.file? && path.absolute?
|
|
31
|
-
|
|
32
|
-
base_path = Rails.root.join("app", "content", "data")
|
|
33
|
-
|
|
34
|
-
SUPPORTED_EXTENSIONS.lazy.map { base_path.join("#{identifier}#{it}") }.find(&:exist?)&.to_s
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def path_for!(identifier)
|
|
38
|
-
path_for(identifier).tap do |path|
|
|
39
|
-
raise Errors::FileNotFoundError, "No data file found for `#{identifier}`" unless path
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def directory?(identifier) = Dir.exist?(Rails.root.join("app", "content", "data", identifier))
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
PARSER_METHODS = {
|
|
49
|
-
".yml" => :parse_yaml, ".yaml" => :parse_yaml,
|
|
50
|
-
".json" => :parse_json, ".csv" => :parse_csv
|
|
51
|
-
}.freeze
|
|
52
|
-
SUPPORTED_EXTENSIONS = PARSER_METHODS.keys
|
|
53
|
-
|
|
54
|
-
def records
|
|
55
|
-
content = rendered_from(@file_path)
|
|
56
|
-
data = parsed_from(content, @file_path)
|
|
57
|
-
|
|
58
|
-
unless data.is_a?(Array)
|
|
59
|
-
raise Errors::DataParseError, "Data in `#{@file_path}` must be an array of objects."
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
data.map { Item.new(it, identifier: @identifier) }
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def rendered_from(path)
|
|
66
|
-
raw_content = File.read(path)
|
|
67
|
-
|
|
68
|
-
render_erb(raw_content)
|
|
69
|
-
rescue NameError, ArgumentError, SyntaxError => error
|
|
70
|
-
raise Errors::DataParseError, "Failed to render ERB in `#{path}`: (#{error.class}) #{error.message}"
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def parsed_from(content, path)
|
|
74
|
-
extension = File.extname(path)
|
|
75
|
-
parser_method = PARSER_METHODS.fetch(extension) do
|
|
76
|
-
raise Errors::UnsupportedDataFormatError, "Unsupported data format: #{extension}"
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
send(parser_method, content)
|
|
80
|
-
rescue Psych::SyntaxError, JSON::ParserError, CSV::MalformedCSVError => error
|
|
81
|
-
raise Errors::DataParseError, "Failed to parse data format in `#{path}`: (#{error.class}) #{error.message}"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def render_erb(content) = ERB.new(content).result(HelperContext.instance.get_binding)
|
|
85
|
-
|
|
86
|
-
def parse_yaml(content)
|
|
87
|
-
YAML.safe_load(content, permitted_classes: [Symbol, Time], aliases: true)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def parse_json(content)
|
|
91
|
-
JSON.parse(content, symbolize_names: true)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def parse_csv(content)
|
|
95
|
-
CSV.new(content, headers: true, header_converters: :symbol).to_a.map(&:to_h)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
class HelperContext
|
|
99
|
-
include Singleton
|
|
100
|
-
|
|
101
|
-
def initialize
|
|
102
|
-
self.class.include ActionView::Helpers::AssetUrlHelper
|
|
103
|
-
self.class.include ActionView::Helpers::DateHelper
|
|
104
|
-
self.class.include Rails.application.routes.url_helpers
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def get_binding = binding
|
|
108
|
-
|
|
109
|
-
def default_url_options = Perron.configuration.default_url_options || {}
|
|
110
|
-
end
|
|
111
|
-
private_constant :HelperContext
|
|
112
|
-
|
|
113
|
-
class Item
|
|
114
|
-
def initialize(attributes, identifier:)
|
|
115
|
-
@attributes = attributes.transform_keys(&:to_sym)
|
|
116
|
-
@identifier = identifier
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def [](key) = @attributes[key.to_sym]
|
|
120
|
-
|
|
121
|
-
def association_value(key) = self[key]
|
|
122
|
-
|
|
123
|
-
def to_partial_path
|
|
124
|
-
@to_partial_path ||= begin
|
|
125
|
-
identifier = @identifier.to_s
|
|
126
|
-
collection = File.extname(identifier).present? ? File.basename(identifier, ".*") : identifier
|
|
127
|
-
element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.singularize(File.basename(collection)))
|
|
128
|
-
|
|
129
|
-
File.join("content", collection, element)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def method_missing(method_name, *arguments, &block)
|
|
134
|
-
return super if !@attributes.key?(method_name) || arguments.any? || block
|
|
135
|
-
|
|
136
|
-
@attributes[method_name]
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
140
|
-
@attributes.key?(method_name) || super
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
private_constant :Item
|
|
144
|
-
end
|
|
145
|
-
end
|