perron 0.0.1 → 0.5.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 +17 -0
- data/Gemfile.lock +269 -0
- data/README.md +182 -0
- data/Rakefile +9 -0
- data/app/helpers/meta_tags_helper.rb +17 -0
- data/app/helpers/perron/markdown_helper.rb +9 -0
- data/bin/console +10 -0
- data/bin/rails +17 -0
- data/bin/release +19 -0
- data/bin/setup +8 -0
- data/lib/generators/content/content_generator.rb +45 -0
- data/lib/generators/content/templates/controller.rb.tt +17 -0
- data/lib/generators/content/templates/index.html.erb.tt +11 -0
- data/lib/generators/content/templates/model.rb.tt +2 -0
- data/lib/generators/content/templates/root.erb.tt +5 -0
- data/lib/generators/content/templates/show.html.erb.tt +7 -0
- data/lib/generators/perron/install_generator.rb +9 -0
- data/lib/generators/perron/templates/initializer.rb.tt +22 -0
- data/lib/perron/configuration.rb +63 -0
- data/lib/perron/engine.rb +13 -0
- data/lib/perron/errors.rb +9 -0
- data/lib/perron/html_processor/target_blank.rb +23 -0
- data/lib/perron/html_processor.rb +28 -0
- data/lib/perron/markdown.rb +54 -0
- data/lib/perron/metatags.rb +82 -0
- data/lib/perron/refinements/delete_suffixes.rb +12 -0
- data/lib/perron/root.rb +13 -0
- data/lib/perron/site/builder/assets.rb +67 -0
- data/lib/perron/site/builder/page.rb +51 -0
- data/lib/perron/site/builder/paths.rb +40 -0
- data/lib/perron/site/builder/public_files.rb +40 -0
- data/lib/perron/site/builder.rb +44 -0
- data/lib/perron/site/collection.rb +28 -0
- data/lib/perron/site/resource/class_methods.rb +43 -0
- data/lib/perron/site/resource/context.rb +13 -0
- data/lib/perron/site/resource/core.rb +15 -0
- data/lib/perron/site/resource/publishable.rb +51 -0
- data/lib/perron/site/resource/separator.rb +31 -0
- data/lib/perron/site/resource/slug.rb +20 -0
- data/lib/perron/site/resource.rb +62 -0
- data/lib/perron/site.rb +33 -0
- data/lib/perron/tasks/perron.rake +12 -0
- data/lib/perron/version.rb +3 -0
- data/lib/perron.rb +11 -1
- data/perron.gemspec +22 -0
- metadata +69 -6
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Perron
|
4
|
+
class Resource
|
5
|
+
module Publishable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
def published?
|
10
|
+
return true if Rails.env.development?
|
11
|
+
|
12
|
+
return false if metadata.draft == true
|
13
|
+
return false if metadata.published == false
|
14
|
+
return false if publication_date&.after?(Time.current)
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def scheduled? = publication_date&.after?(Time.current)
|
20
|
+
|
21
|
+
def publication_date
|
22
|
+
@publication_date ||= begin
|
23
|
+
from_meta = metadata.published_at.present? ? begin
|
24
|
+
Time.zone.parse(metadata.published_at.to_s)
|
25
|
+
rescue
|
26
|
+
nil
|
27
|
+
end : nil
|
28
|
+
|
29
|
+
from_meta || date_from_filename
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias_method :published_at, :publication_date
|
33
|
+
|
34
|
+
def scheduled_at
|
35
|
+
publication_date if scheduled?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
DATE_REGEX = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})-/
|
42
|
+
|
43
|
+
def date_from_filename
|
44
|
+
return @date_from_filename if defined?(@date_from_filename)
|
45
|
+
|
46
|
+
match = File.basename(file_path).match(DATE_REGEX)
|
47
|
+
@date_from_filename = match ? Date.new(match[:year].to_i, match[:month].to_i, match[:day].to_i).in_time_zone : nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Perron
|
4
|
+
class Resource
|
5
|
+
class Separator
|
6
|
+
attr_reader :content
|
7
|
+
|
8
|
+
def initialize(content)
|
9
|
+
parsed(content)
|
10
|
+
end
|
11
|
+
|
12
|
+
def metadata
|
13
|
+
@metadata_with_dot_access ||= ActiveSupport::OrderedOptions.new.tap do |options|
|
14
|
+
@metadata.each { |key, value| options[key] = value }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def parsed(content)
|
21
|
+
if content =~ /\A---\s*(.*?)\s*---\s*(.*)/m
|
22
|
+
@metadata = YAML.safe_load($1, permitted_classes: [Date, Time]) || {}
|
23
|
+
@content = $2.strip
|
24
|
+
else
|
25
|
+
@metadata = {}
|
26
|
+
@content = content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "perron/refinements/delete_suffixes"
|
4
|
+
|
5
|
+
module Perron
|
6
|
+
class Resource
|
7
|
+
class Slug
|
8
|
+
using Perron::SuffixStripping
|
9
|
+
|
10
|
+
def initialize(resource)
|
11
|
+
@resource = resource
|
12
|
+
@metadata = resource.metadata
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@metadata.slug.presence || @resource.filename.sub(/^[\d-]+-/, "").delete_suffixes(Perron.configuration.allowed_extensions)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "perron/site/resource/core"
|
4
|
+
require "perron/site/resource/class_methods"
|
5
|
+
require "perron/site/resource/publishable"
|
6
|
+
require "perron/site/resource/slug"
|
7
|
+
require "perron/site/resource/context"
|
8
|
+
require "perron/site/resource/separator"
|
9
|
+
|
10
|
+
module Perron
|
11
|
+
class Resource
|
12
|
+
ID_LENGTH = 8
|
13
|
+
|
14
|
+
include Perron::Resource::Core
|
15
|
+
include Perron::Resource::ClassMethods
|
16
|
+
include Perron::Resource::Publishable
|
17
|
+
|
18
|
+
attr_reader :file_path, :id
|
19
|
+
|
20
|
+
def initialize(file_path)
|
21
|
+
@file_path = file_path
|
22
|
+
@id = generate_id
|
23
|
+
|
24
|
+
raise Errors::FileNotFoundError, "No such file: #{file_path}" unless File.exist?(file_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def filename = File.basename(@file_path)
|
28
|
+
|
29
|
+
def slug = Perron::Resource::Slug.new(self).create
|
30
|
+
alias_method :path, :slug
|
31
|
+
alias_method :to_param, :slug
|
32
|
+
|
33
|
+
def content
|
34
|
+
if processable?
|
35
|
+
ERB.new(Perron::Resource::Separator.new(raw_content).content).result(context.binding)
|
36
|
+
else
|
37
|
+
Perron::Resource::Separator.new(raw_content).content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def metadata = Perron::Resource::Separator.new(raw_content).metadata
|
42
|
+
|
43
|
+
def raw_content = File.read(@file_path)
|
44
|
+
alias_method :raw, :raw_content
|
45
|
+
|
46
|
+
def collection = Collection.new(self.class.model_name.collection)
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def processable?
|
51
|
+
@file_path.ends_with?(".erb") || metadata.erb == true
|
52
|
+
end
|
53
|
+
|
54
|
+
def generate_id
|
55
|
+
Digest::SHA1.hexdigest(
|
56
|
+
@file_path.delete_prefix(Perron.configuration.input).parameterize
|
57
|
+
).first(ID_LENGTH)
|
58
|
+
end
|
59
|
+
|
60
|
+
def context = Perron::Resource::Context.new(self)
|
61
|
+
end
|
62
|
+
end
|
data/lib/perron/site.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "perron/site/builder"
|
4
|
+
require "perron/site/collection"
|
5
|
+
require "perron/site/resource"
|
6
|
+
|
7
|
+
module Perron
|
8
|
+
module Site
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def build = Perron::Site::Builder.new.build
|
12
|
+
|
13
|
+
def name = Perron.configuration.site_name
|
14
|
+
|
15
|
+
def email = Perron.configuration.site_email
|
16
|
+
|
17
|
+
def url
|
18
|
+
options = Perron.configuration.default_url_options
|
19
|
+
|
20
|
+
"#{options[:protocol]}://#{options[:host]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def collections
|
24
|
+
@collections ||= Dir.children(Perron.configuration.input)
|
25
|
+
.select { File.directory?(File.join(Perron.configuration.input, it)) }
|
26
|
+
.map { Collection.new(it) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def collection(name)
|
30
|
+
Collection.new(name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :perron do
|
2
|
+
desc "Generate static HTML files from Perron collections"
|
3
|
+
task build: :environment do
|
4
|
+
Perron::Site.build
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
Rake::Task["assets:precompile"].enhance do
|
9
|
+
next if Perron.configuration.mode.standalone?
|
10
|
+
|
11
|
+
Perron::Site.build
|
12
|
+
end
|
data/lib/perron.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "perron/version"
|
4
|
+
require "perron/configuration"
|
5
|
+
require "perron/errors"
|
6
|
+
require "perron/root"
|
7
|
+
require "perron/site"
|
8
|
+
require "perron/markdown"
|
9
|
+
require "perron/metatags"
|
10
|
+
require "perron/engine"
|
11
|
+
|
1
12
|
module Perron
|
2
|
-
# TBD
|
3
13
|
end
|
data/perron.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "lib/perron/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "perron"
|
5
|
+
spec.version = Perron::VERSION
|
6
|
+
spec.authors = ["Rails Designer Developers"]
|
7
|
+
spec.email = "devs@railsdeigner.com"
|
8
|
+
|
9
|
+
spec.summary = "Rails-based static site generator"
|
10
|
+
spec.description = "Perron is a Rails-based static site generator that follows Rails conventions. It allows you to create content collections with markdown or ERB, configure SEO metadata, and build production-ready static sites while leveraging your existing Rails knowledge with familiar patterns and minimal configuration."
|
11
|
+
spec.homepage = "https://github.com/Rails-Designer/perron"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/Rails-Designer/perron/"
|
16
|
+
|
17
|
+
spec.files = Dir["{bin,app,lib}/**/*", "Rakefile", "README.md", "perron.gemspec", "Gemfile", "Gemfile.lock"]
|
18
|
+
|
19
|
+
spec.required_ruby_version = ">= 3.4.0"
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 7.2.0"
|
22
|
+
end
|
metadata
CHANGED
@@ -1,25 +1,88 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rails Designer Developers
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
-
dependencies:
|
12
|
-
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rails
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 7.2.0
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 7.2.0
|
26
|
+
description: Perron is a Rails-based static site generator that follows Rails conventions.
|
27
|
+
It allows you to create content collections with markdown or ERB, configure SEO
|
28
|
+
metadata, and build production-ready static sites while leveraging your existing
|
29
|
+
Rails knowledge with familiar patterns and minimal configuration.
|
13
30
|
email: devs@railsdeigner.com
|
14
31
|
executables: []
|
15
32
|
extensions: []
|
16
33
|
extra_rdoc_files: []
|
17
34
|
files:
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- app/helpers/meta_tags_helper.rb
|
40
|
+
- app/helpers/perron/markdown_helper.rb
|
41
|
+
- bin/console
|
42
|
+
- bin/rails
|
43
|
+
- bin/release
|
44
|
+
- bin/setup
|
45
|
+
- lib/generators/content/content_generator.rb
|
46
|
+
- lib/generators/content/templates/controller.rb.tt
|
47
|
+
- lib/generators/content/templates/index.html.erb.tt
|
48
|
+
- lib/generators/content/templates/model.rb.tt
|
49
|
+
- lib/generators/content/templates/root.erb.tt
|
50
|
+
- lib/generators/content/templates/show.html.erb.tt
|
51
|
+
- lib/generators/perron/install_generator.rb
|
52
|
+
- lib/generators/perron/templates/initializer.rb.tt
|
18
53
|
- lib/perron.rb
|
54
|
+
- lib/perron/configuration.rb
|
55
|
+
- lib/perron/engine.rb
|
56
|
+
- lib/perron/errors.rb
|
57
|
+
- lib/perron/html_processor.rb
|
58
|
+
- lib/perron/html_processor/target_blank.rb
|
59
|
+
- lib/perron/markdown.rb
|
60
|
+
- lib/perron/metatags.rb
|
61
|
+
- lib/perron/refinements/delete_suffixes.rb
|
62
|
+
- lib/perron/root.rb
|
63
|
+
- lib/perron/site.rb
|
64
|
+
- lib/perron/site/builder.rb
|
65
|
+
- lib/perron/site/builder/assets.rb
|
66
|
+
- lib/perron/site/builder/page.rb
|
67
|
+
- lib/perron/site/builder/paths.rb
|
68
|
+
- lib/perron/site/builder/public_files.rb
|
69
|
+
- lib/perron/site/collection.rb
|
70
|
+
- lib/perron/site/resource.rb
|
71
|
+
- lib/perron/site/resource/class_methods.rb
|
72
|
+
- lib/perron/site/resource/context.rb
|
73
|
+
- lib/perron/site/resource/core.rb
|
74
|
+
- lib/perron/site/resource/publishable.rb
|
75
|
+
- lib/perron/site/resource/separator.rb
|
76
|
+
- lib/perron/site/resource/slug.rb
|
77
|
+
- lib/perron/tasks/perron.rake
|
78
|
+
- lib/perron/version.rb
|
79
|
+
- perron.gemspec
|
19
80
|
homepage: https://github.com/Rails-Designer/perron
|
20
81
|
licenses:
|
21
82
|
- MIT
|
22
|
-
metadata:
|
83
|
+
metadata:
|
84
|
+
homepage_uri: https://github.com/Rails-Designer/perron
|
85
|
+
source_code_uri: https://github.com/Rails-Designer/perron/
|
23
86
|
rdoc_options: []
|
24
87
|
require_paths:
|
25
88
|
- lib
|
@@ -27,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
27
90
|
requirements:
|
28
91
|
- - ">="
|
29
92
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
93
|
+
version: 3.4.0
|
31
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
32
95
|
requirements:
|
33
96
|
- - ">="
|
@@ -36,5 +99,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
99
|
requirements: []
|
37
100
|
rubygems_version: 3.6.7
|
38
101
|
specification_version: 4
|
39
|
-
summary: Rails-
|
102
|
+
summary: Rails-based static site generator
|
40
103
|
test_files: []
|