perron 0.0.1 → 0.6.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +273 -0
  4. data/README.md +221 -0
  5. data/Rakefile +9 -0
  6. data/app/helpers/meta_tags_helper.rb +17 -0
  7. data/app/helpers/perron/markdown_helper.rb +9 -0
  8. data/bin/console +10 -0
  9. data/bin/rails +17 -0
  10. data/bin/release +19 -0
  11. data/bin/setup +8 -0
  12. data/lib/generators/content/content_generator.rb +45 -0
  13. data/lib/generators/content/templates/controller.rb.tt +17 -0
  14. data/lib/generators/content/templates/index.html.erb.tt +11 -0
  15. data/lib/generators/content/templates/model.rb.tt +2 -0
  16. data/lib/generators/content/templates/root.erb.tt +5 -0
  17. data/lib/generators/content/templates/show.html.erb.tt +7 -0
  18. data/lib/generators/perron/install_generator.rb +16 -0
  19. data/lib/generators/perron/templates/README.md.tt +30 -0
  20. data/lib/generators/perron/templates/initializer.rb.tt +22 -0
  21. data/lib/perron/configuration.rb +63 -0
  22. data/lib/perron/engine.rb +13 -0
  23. data/lib/perron/errors.rb +13 -0
  24. data/lib/perron/html_processor/target_blank.rb +23 -0
  25. data/lib/perron/html_processor.rb +28 -0
  26. data/lib/perron/markdown.rb +54 -0
  27. data/lib/perron/metatags.rb +82 -0
  28. data/lib/perron/refinements/delete_suffixes.rb +12 -0
  29. data/lib/perron/root.rb +13 -0
  30. data/lib/perron/site/builder/assets.rb +67 -0
  31. data/lib/perron/site/builder/page.rb +51 -0
  32. data/lib/perron/site/builder/paths.rb +40 -0
  33. data/lib/perron/site/builder/public_files.rb +40 -0
  34. data/lib/perron/site/builder.rb +44 -0
  35. data/lib/perron/site/collection.rb +28 -0
  36. data/lib/perron/site/data.rb +144 -0
  37. data/lib/perron/site/resource/class_methods.rb +43 -0
  38. data/lib/perron/site/resource/core.rb +15 -0
  39. data/lib/perron/site/resource/publishable.rb +51 -0
  40. data/lib/perron/site/resource/separator.rb +31 -0
  41. data/lib/perron/site/resource/slug.rb +20 -0
  42. data/lib/perron/site/resource.rb +62 -0
  43. data/lib/perron/site.rb +34 -0
  44. data/lib/perron/tasks/perron.rake +12 -0
  45. data/lib/perron/version.rb +3 -0
  46. data/lib/perron.rb +11 -1
  47. data/perron.gemspec +26 -0
  48. metadata +112 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adaceff47ea616f74cae034e46a3118592519103709fa65c9c8909492a8b1abb
4
- data.tar.gz: d80d4b86cb22002462cc7c99217cbf784e95a14df860ea529911c5c6d127ddf0
3
+ metadata.gz: f91a86bc7ff57f28eb58ef9aac6b1d3e94c008a3570df359aca5f5e6b416c7e7
4
+ data.tar.gz: 53cd0a23ce3fbcd1fe90aa07a26577f34e66be5a8fd018c596498e34c67c5718
5
5
  SHA512:
6
- metadata.gz: 3cbb1fc5c50b598ec29a85f1fbf5ce5b34a0052e0354b1bd05fa7e0446ad5784f3d0d2de113daed351d97f9471ad03623df23f55118ee25ddbc70493c253acf9
7
- data.tar.gz: a90e0f986a7dfbeafa2c85264814750f5d9e050d7f8a4595532ed483c9bde8d0c59c2f72568149ca2c3319ec43e73783bf5dbe63761ed6e062b6174e7b7055f2
6
+ metadata.gz: dd5f18ac803ece9604f9187047c637e4be0f1ad31fb77bce0d73f97dc633ba60644a4d2638deadc2d2d05e6f5152e8050ecc4823caa1dd2c64d0da487618ee85
7
+ data.tar.gz: e99ffd6732c726f78f4a5e3f2ce07c571019b43d8028539ea1a5d6ad0d75f52f74d254808e3585f0d0e546b2d453e880f2291b2e088dc8e6fe8e63b496f5990d
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rails", "~> 7.2.0"
8
+
9
+ group :development do
10
+ gem "standard", "~> 1.50.0"
11
+ end
12
+
13
+ group :development, :test do
14
+ gem "rake", "~> 13.3.0"
15
+ gem "minitest", "~> 5.25", ">= 5.25.5"
16
+ gem "debug", "~> 1.11.0"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,273 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ perron (0.6.0)
5
+ csv
6
+ json
7
+ psych
8
+ rails (>= 7.2.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actioncable (7.2.2.1)
14
+ actionpack (= 7.2.2.1)
15
+ activesupport (= 7.2.2.1)
16
+ nio4r (~> 2.0)
17
+ websocket-driver (>= 0.6.1)
18
+ zeitwerk (~> 2.6)
19
+ actionmailbox (7.2.2.1)
20
+ actionpack (= 7.2.2.1)
21
+ activejob (= 7.2.2.1)
22
+ activerecord (= 7.2.2.1)
23
+ activestorage (= 7.2.2.1)
24
+ activesupport (= 7.2.2.1)
25
+ mail (>= 2.8.0)
26
+ actionmailer (7.2.2.1)
27
+ actionpack (= 7.2.2.1)
28
+ actionview (= 7.2.2.1)
29
+ activejob (= 7.2.2.1)
30
+ activesupport (= 7.2.2.1)
31
+ mail (>= 2.8.0)
32
+ rails-dom-testing (~> 2.2)
33
+ actionpack (7.2.2.1)
34
+ actionview (= 7.2.2.1)
35
+ activesupport (= 7.2.2.1)
36
+ nokogiri (>= 1.8.5)
37
+ racc
38
+ rack (>= 2.2.4, < 3.2)
39
+ rack-session (>= 1.0.1)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.2)
42
+ rails-html-sanitizer (~> 1.6)
43
+ useragent (~> 0.16)
44
+ actiontext (7.2.2.1)
45
+ actionpack (= 7.2.2.1)
46
+ activerecord (= 7.2.2.1)
47
+ activestorage (= 7.2.2.1)
48
+ activesupport (= 7.2.2.1)
49
+ globalid (>= 0.6.0)
50
+ nokogiri (>= 1.8.5)
51
+ actionview (7.2.2.1)
52
+ activesupport (= 7.2.2.1)
53
+ builder (~> 3.1)
54
+ erubi (~> 1.11)
55
+ rails-dom-testing (~> 2.2)
56
+ rails-html-sanitizer (~> 1.6)
57
+ activejob (7.2.2.1)
58
+ activesupport (= 7.2.2.1)
59
+ globalid (>= 0.3.6)
60
+ activemodel (7.2.2.1)
61
+ activesupport (= 7.2.2.1)
62
+ activerecord (7.2.2.1)
63
+ activemodel (= 7.2.2.1)
64
+ activesupport (= 7.2.2.1)
65
+ timeout (>= 0.4.0)
66
+ activestorage (7.2.2.1)
67
+ actionpack (= 7.2.2.1)
68
+ activejob (= 7.2.2.1)
69
+ activerecord (= 7.2.2.1)
70
+ activesupport (= 7.2.2.1)
71
+ marcel (~> 1.0)
72
+ activesupport (7.2.2.1)
73
+ base64
74
+ benchmark (>= 0.3)
75
+ bigdecimal
76
+ concurrent-ruby (~> 1.0, >= 1.3.1)
77
+ connection_pool (>= 2.2.5)
78
+ drb
79
+ i18n (>= 1.6, < 2)
80
+ logger (>= 1.4.2)
81
+ minitest (>= 5.1)
82
+ securerandom (>= 0.3)
83
+ tzinfo (~> 2.0, >= 2.0.5)
84
+ ast (2.4.3)
85
+ base64 (0.3.0)
86
+ benchmark (0.4.1)
87
+ bigdecimal (3.2.2)
88
+ builder (3.3.0)
89
+ concurrent-ruby (1.3.5)
90
+ connection_pool (2.5.3)
91
+ crass (1.0.6)
92
+ csv (3.3.5)
93
+ date (3.4.1)
94
+ debug (1.11.0)
95
+ irb (~> 1.10)
96
+ reline (>= 0.3.8)
97
+ drb (2.2.3)
98
+ erb (5.0.1)
99
+ erubi (1.13.1)
100
+ globalid (1.2.1)
101
+ activesupport (>= 6.1)
102
+ i18n (1.14.7)
103
+ concurrent-ruby (~> 1.0)
104
+ io-console (0.8.0)
105
+ irb (1.15.2)
106
+ pp (>= 0.6.0)
107
+ rdoc (>= 4.0.0)
108
+ reline (>= 0.4.2)
109
+ json (2.12.2)
110
+ language_server-protocol (3.17.0.5)
111
+ lint_roller (1.1.0)
112
+ logger (1.7.0)
113
+ loofah (2.24.1)
114
+ crass (~> 1.0.2)
115
+ nokogiri (>= 1.12.0)
116
+ mail (2.8.1)
117
+ mini_mime (>= 0.1.1)
118
+ net-imap
119
+ net-pop
120
+ net-smtp
121
+ marcel (1.0.4)
122
+ mini_mime (1.1.5)
123
+ minitest (5.25.5)
124
+ net-imap (0.5.9)
125
+ date
126
+ net-protocol
127
+ net-pop (0.1.2)
128
+ net-protocol
129
+ net-protocol (0.2.2)
130
+ timeout
131
+ net-smtp (0.5.1)
132
+ net-protocol
133
+ nio4r (2.7.4)
134
+ nokogiri (1.18.8-aarch64-linux-gnu)
135
+ racc (~> 1.4)
136
+ nokogiri (1.18.8-aarch64-linux-musl)
137
+ racc (~> 1.4)
138
+ nokogiri (1.18.8-arm-linux-gnu)
139
+ racc (~> 1.4)
140
+ nokogiri (1.18.8-arm-linux-musl)
141
+ racc (~> 1.4)
142
+ nokogiri (1.18.8-arm64-darwin)
143
+ racc (~> 1.4)
144
+ nokogiri (1.18.8-x86_64-darwin)
145
+ racc (~> 1.4)
146
+ nokogiri (1.18.8-x86_64-linux-gnu)
147
+ racc (~> 1.4)
148
+ nokogiri (1.18.8-x86_64-linux-musl)
149
+ racc (~> 1.4)
150
+ parallel (1.27.0)
151
+ parser (3.3.8.0)
152
+ ast (~> 2.4.1)
153
+ racc
154
+ pp (0.6.2)
155
+ prettyprint
156
+ prettyprint (0.2.0)
157
+ prism (1.4.0)
158
+ psych (5.2.6)
159
+ date
160
+ stringio
161
+ racc (1.8.1)
162
+ rack (3.1.16)
163
+ rack-session (2.1.1)
164
+ base64 (>= 0.1.0)
165
+ rack (>= 3.0.0)
166
+ rack-test (2.2.0)
167
+ rack (>= 1.3)
168
+ rackup (2.2.1)
169
+ rack (>= 3)
170
+ rails (7.2.2.1)
171
+ actioncable (= 7.2.2.1)
172
+ actionmailbox (= 7.2.2.1)
173
+ actionmailer (= 7.2.2.1)
174
+ actionpack (= 7.2.2.1)
175
+ actiontext (= 7.2.2.1)
176
+ actionview (= 7.2.2.1)
177
+ activejob (= 7.2.2.1)
178
+ activemodel (= 7.2.2.1)
179
+ activerecord (= 7.2.2.1)
180
+ activestorage (= 7.2.2.1)
181
+ activesupport (= 7.2.2.1)
182
+ bundler (>= 1.15.0)
183
+ railties (= 7.2.2.1)
184
+ rails-dom-testing (2.3.0)
185
+ activesupport (>= 5.0.0)
186
+ minitest
187
+ nokogiri (>= 1.6)
188
+ rails-html-sanitizer (1.6.2)
189
+ loofah (~> 2.21)
190
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
191
+ railties (7.2.2.1)
192
+ actionpack (= 7.2.2.1)
193
+ activesupport (= 7.2.2.1)
194
+ irb (~> 1.13)
195
+ rackup (>= 1.0.0)
196
+ rake (>= 12.2)
197
+ thor (~> 1.0, >= 1.2.2)
198
+ zeitwerk (~> 2.6)
199
+ rainbow (3.1.1)
200
+ rake (13.3.0)
201
+ rdoc (6.14.2)
202
+ erb
203
+ psych (>= 4.0.0)
204
+ regexp_parser (2.10.0)
205
+ reline (0.6.1)
206
+ io-console (~> 0.5)
207
+ rubocop (1.75.8)
208
+ json (~> 2.3)
209
+ language_server-protocol (~> 3.17.0.2)
210
+ lint_roller (~> 1.1.0)
211
+ parallel (~> 1.10)
212
+ parser (>= 3.3.0.2)
213
+ rainbow (>= 2.2.2, < 4.0)
214
+ regexp_parser (>= 2.9.3, < 3.0)
215
+ rubocop-ast (>= 1.44.0, < 2.0)
216
+ ruby-progressbar (~> 1.7)
217
+ unicode-display_width (>= 2.4.0, < 4.0)
218
+ rubocop-ast (1.45.1)
219
+ parser (>= 3.3.7.2)
220
+ prism (~> 1.4)
221
+ rubocop-performance (1.25.0)
222
+ lint_roller (~> 1.1)
223
+ rubocop (>= 1.75.0, < 2.0)
224
+ rubocop-ast (>= 1.38.0, < 2.0)
225
+ ruby-progressbar (1.13.0)
226
+ securerandom (0.4.1)
227
+ standard (1.50.0)
228
+ language_server-protocol (~> 3.17.0.2)
229
+ lint_roller (~> 1.0)
230
+ rubocop (~> 1.75.5)
231
+ standard-custom (~> 1.0.0)
232
+ standard-performance (~> 1.8)
233
+ standard-custom (1.0.2)
234
+ lint_roller (~> 1.0)
235
+ rubocop (~> 1.50)
236
+ standard-performance (1.8.0)
237
+ lint_roller (~> 1.1)
238
+ rubocop-performance (~> 1.25.0)
239
+ stringio (3.1.7)
240
+ thor (1.3.2)
241
+ timeout (0.4.3)
242
+ tzinfo (2.0.6)
243
+ concurrent-ruby (~> 1.0)
244
+ unicode-display_width (3.1.4)
245
+ unicode-emoji (~> 4.0, >= 4.0.4)
246
+ unicode-emoji (4.0.4)
247
+ useragent (0.16.11)
248
+ websocket-driver (0.8.0)
249
+ base64
250
+ websocket-extensions (>= 0.1.0)
251
+ websocket-extensions (0.1.5)
252
+ zeitwerk (2.7.3)
253
+
254
+ PLATFORMS
255
+ aarch64-linux-gnu
256
+ aarch64-linux-musl
257
+ arm-linux-gnu
258
+ arm-linux-musl
259
+ arm64-darwin
260
+ x86_64-darwin
261
+ x86_64-linux-gnu
262
+ x86_64-linux-musl
263
+
264
+ DEPENDENCIES
265
+ debug (~> 1.11.0)
266
+ minitest (~> 5.25, >= 5.25.5)
267
+ perron!
268
+ rails (~> 7.2.0)
269
+ rake (~> 13.3.0)
270
+ standard (~> 1.50.0)
271
+
272
+ BUNDLED WITH
273
+ 2.6.8
data/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # Perron
2
+
3
+ A Rails-based static site generator.
4
+
5
+ **Sponsored By [Rails Designer](https://railsdesigner.com/)**
6
+
7
+ <a href="https://railsdesigner.com/" target="_blank">
8
+ <picture>
9
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Rails-Designer/perron/HEAD/.github/logo-dark.svg">
10
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Rails-Designer/perron/HEAD/.github/logo-light.svg">
11
+ <img alt="Rails Designer" src="https://raw.githubusercontent.com/Rails-Designer/perron/HEAD/.github/logo-light.svg" width="240" style="max-width: 100%;">
12
+ </picture>
13
+ </a>
14
+
15
+
16
+ ## Getting Started
17
+
18
+ ### Installation
19
+
20
+ Start by generating the configuration file:
21
+ ```bash
22
+ rails generate perron:install
23
+ ```
24
+
25
+ This creates an initializer:
26
+ ```ruby
27
+ Perron.configure do |config|
28
+ config.site_name = "AppRefresher"
29
+
30
+ # Override the defaults (meta) title suffix
31
+ # Default: `— Perron.configuration.site_name`
32
+ # config.title_suffix = nil
33
+ end
34
+ ```
35
+
36
+
37
+ ## Mode
38
+
39
+ Perron can operate in two modes, configured via `config.mode`. This allows you to build either a full static site or integrate pages into a dynamic Rails application.
40
+
41
+ | **Mode** | `:standalone` (default) | `:integrated` |
42
+ | :--- | :--- | :--- |
43
+ | **Use Case** | Full static site for hosts like Netlify/Vercel | Add static pages to a live Rails app |
44
+ | **Output** | `output/` directory | `public/` directory |
45
+ | **Asset Handling** | Via Perron | Via Asset Pipeline |
46
+
47
+
48
+ ## Creating Content
49
+
50
+ Perron is, just like Rails, designed with convention over configuration in mind. Content is stored in `app/content/*/*.{erb,md}`. Content is backed by a class, located in `app/models/content/` that inherits from `Perron::Resource`.
51
+
52
+ The controllers are located in `app/controllers/content/`. To make them available, create a route: `resources :posts, module: :content, only: %w[index show]`.
53
+
54
+
55
+ ### Collections
56
+
57
+ ```bash
58
+ bin/rails generate content Post
59
+ ```
60
+
61
+ This will create the following files:
62
+
63
+ * `app/models/content/post.rb`
64
+ * `app/controllers/content/posts_controller.rb`
65
+ * `app/views/content/posts/index.html.erb`
66
+ * `app/views/content/posts/show.html.erb`
67
+ * Adds route: `resources :posts, module: :content, only: %w[index show]`
68
+
69
+
70
+ ### Setting a Root Page
71
+
72
+ To set a root page, include `Perron::Root` in your `Content::PagesController` and add a `app/content/pages/root.[md,erb]` file (make sure to set `slug: "/"` in its frontmatter).
73
+
74
+ This is automatically added when you create a `Page` collection.
75
+
76
+
77
+ ## Markdown Support
78
+
79
+ Perron supports markdown with the `markdownify` helper.
80
+
81
+ There are no markdown gems bundled by default, so you'll need to add one of these:
82
+
83
+ - CommonMarker
84
+ - Kramdown
85
+ - Redcarpet
86
+
87
+ ```bash
88
+ bundle add {commonmarker,kramdown,redcarpet}
89
+ ```
90
+
91
+
92
+ ## Data Files
93
+
94
+ Perron can consume structured data from YML, JSON, or CSV files, making them available within your templates.
95
+ This is useful for populating features, team members, or any other repeated data structure.
96
+
97
+ ### Usage
98
+
99
+ To use a data file, instantiate `Perron::Data` with the basename of the file and iterate over the result.
100
+ ```erb
101
+ <% Perron::Data.new("features").each do |feature| %>
102
+ <h4><%= feature.name %></h4>
103
+ <p><%= feature.description %></p>
104
+ <% end %>
105
+ ```
106
+
107
+ ### File Location and Formats
108
+
109
+ By default, Perron looks up `app/content/data/` for files with a `.yml`, `.json`, or `.csv` extension.
110
+ For a `new("features")` call, it would find `features.yml`, `features.json`, or `features.csv`. You can also provide a full, absolute path to any data file.
111
+
112
+ ### Accessing Data
113
+
114
+ The wrapper object provides flexible, read-only access to each record's attributes. Both dot notation and hash-like key access are supported.
115
+ ```ruby
116
+ feature.name
117
+ feature[:name]
118
+ ```
119
+
120
+
121
+ ## Metatags
122
+
123
+ The `meta_tags` helper automatically generates SEO and social sharing meta tags for your pages.
124
+
125
+
126
+ ### Usage
127
+
128
+ In your layout (e.g., `app/views/layouts/application.html.erb`), add the helper to the `<head>` section:
129
+ ```erb
130
+ <head>
131
+
132
+ <%= meta_tags %>
133
+
134
+ </head>
135
+ ```
136
+
137
+ You can render specific subsets of tags:
138
+ ```erb
139
+ <%= meta_tags only: %w[title description] %>
140
+ ```
141
+
142
+ Or exclude certain tags:
143
+ ```erb
144
+ <%= meta_tags except: %w[twitter_card twitter_image] %>
145
+ ```
146
+
147
+ ### Priority
148
+
149
+ Values are determined with the following precedence, from highest to lowest:
150
+
151
+ #### 1. Controller Action
152
+
153
+ Define a `@metadata` instance variable in your controller:
154
+ ```ruby
155
+ class Content::PostsController < ApplicationController
156
+ def index
157
+ @metadata = {
158
+ title: "All Blog Posts",
159
+ description: "A collection of our articles."
160
+ }
161
+ @resources = Content::Post.all
162
+ end
163
+ end
164
+ ```
165
+
166
+ #### 2. Page Frontmatter
167
+
168
+ Add values to the YAML frontmatter in content files:
169
+
170
+ ```yaml
171
+ ---
172
+ title: My Awesome Post
173
+ description: A deep dive into how meta tags work.
174
+ image: /assets/images/my-awesome-post.png
175
+ author: Kendall
176
+ ---
177
+
178
+ Your content here…
179
+ ```
180
+
181
+ #### 3. Default Values
182
+
183
+ Set site-wide defaults in the initializer:
184
+ ```ruby
185
+ Perron.configure do |config|
186
+ # …
187
+
188
+ config.metadata.description = "AI-powered tool to keep your knowledge base articles images/screenshots and content up-to-date"
189
+ config.metadata.author = "Rails Designer"
190
+ end
191
+ ```
192
+
193
+
194
+ ## Building Your Static Site
195
+
196
+ When in `standalone` mode and you're ready to generate your static site, run:
197
+ ```bash
198
+ RAILS_ENV=production rails perron:build
199
+ ```
200
+
201
+ This will create your static site in the configured output directory (`output` by default).
202
+
203
+
204
+ ## Sites using Perron
205
+
206
+ Sites that use Perron.
207
+
208
+ ### Standalone (as a SSG)
209
+ - [AppRefresher](https://apprefresher.com)
210
+
211
+ ### Integrated (part of a Rails app)
212
+ - [Rails Designers (private community for Rails UI engineers](https://railsdesigners.com)
213
+
214
+ ## Contributing
215
+
216
+ This project uses [Standard](https://github.com/testdouble/standard) for formatting Ruby code. Please run `be standardrb` before submitting pull requests. Run tests with `rails test`.
217
+
218
+
219
+ ## License
220
+
221
+ Perron is released under the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+ require "standard/rake"
6
+
7
+ Minitest::TestTask.create
8
+
9
+ task default: %i[test standard]
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MetaTagsHelper
4
+ def meta_tags(options = {})
5
+ Perron::Metatags.new(source).render(options)
6
+ end
7
+
8
+ private
9
+
10
+ Source = Data.define(:path, :metadata, :published_at)
11
+
12
+ def source
13
+ return Source.new(request.path, @metadata, nil) if @metadata.present?
14
+
15
+ @resource || Source.new(request.path, {}, nil)
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "perron/markdown"
4
+
5
+ module Perron
6
+ module MarkdownHelper
7
+ def markdownify(content = nil, &block) = Perron::Markdown.render(content || capture(&block).strip_heredoc)
8
+ end
9
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "perron"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "irb"
10
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path("..", __dir__)
6
+ ENGINE_PATH = File.expand_path("../lib/perron/engine", __dir__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
10
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
11
+
12
+ require "rails"
13
+
14
+ require "action_controller/railtie"
15
+ require "action_view/railtie"
16
+
17
+ require "rails/engine/commands"
data/bin/release ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env bash
2
+
3
+ VERSION=$1
4
+
5
+ if [ -z "$VERSION" ]; then
6
+ echo "Error: The version number is required."
7
+ echo "Usage: $0 <version-number>"
8
+ exit 1
9
+ fi
10
+
11
+ printf "module Perron\n VERSION = \"$VERSION\"\nend\n" > ./lib/perron/version.rb
12
+ bundle
13
+ git add Gemfile.lock lib/perron/version.rb
14
+ git commit -m "Bump version for $VERSION"
15
+ git push
16
+ git tag v$VERSION
17
+ git push --tags
18
+ gem build perron.gemspec
19
+ gem push "perron-$VERSION.gem"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ require "rails/generators/base"
2
+
3
+ class ContentGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ argument :actions, type: :array, default: %w[index show], desc: "Specify which actions to generate (index/show)"
7
+
8
+ def create_model
9
+ template "model.rb.tt", File.join("app/models/content", "#{file_name}.rb")
10
+ end
11
+
12
+ def create_controller
13
+ template "controller.rb.tt", File.join("app/controllers/content", "#{plural_file_name}_controller.rb")
14
+ end
15
+
16
+ def create_views
17
+ empty_directory view_directory
18
+
19
+ actions.each do |action|
20
+ template "#{action}.html.erb.tt", File.join(view_directory, "#{action}.html.erb")
21
+ end
22
+ end
23
+
24
+ def create_content_directory = FileUtils.mkdir_p(content_directory)
25
+
26
+ def create_pages_root
27
+ return unless pages_controller?
28
+
29
+ template "root.erb.tt", File.join(content_directory, "root.erb")
30
+ end
31
+
32
+ def add_content_route
33
+ route "resources :#{plural_file_name}, module: :content, only: %w[#{actions.join(" ")}]"
34
+ end
35
+
36
+ private
37
+
38
+ def view_directory = Rails.root.join("app", "views", "content", plural_file_name)
39
+
40
+ def content_directory = Rails.root.join("app", "content", plural_file_name)
41
+
42
+ def plural_class_name = plural_name.camelize
43
+
44
+ def pages_controller? = plural_file_name == "pages"
45
+ end
@@ -0,0 +1,17 @@
1
+ class Content::<%= plural_class_name %>Controller < ApplicationController
2
+ <%- if pages_controller? -%>
3
+ include Perron::Root
4
+ <%- end -%>
5
+
6
+ <%- if actions.include?("index") -%>
7
+ def index
8
+ @resources = Content::<%= class_name %>.all
9
+ end
10
+
11
+ <%- end -%>
12
+ <%- if actions.include?("show") -%>
13
+ def show
14
+ @resource = Content::<%= class_name %>.find(params[:id])
15
+ end
16
+ <%- end -%>
17
+ end
@@ -0,0 +1,11 @@
1
+ <h1>
2
+ <%= plural_class_name %>
3
+ </h1>
4
+
5
+ <ul>
6
+ <%% @resources.each do |resource| %>
7
+ <li>
8
+ <%%= link_to resource.filename, resource %>
9
+ </li>
10
+ <%% end %>
11
+ </ul>
@@ -0,0 +1,2 @@
1
+ class Content::<%= class_name %> < Perron::Resource
2
+ end