satanic_pages 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 987d127931d6e1d4de5d33ca3f32152548398400f15b98f44b7cc2d4ce0c8a1e
4
- data.tar.gz: 8ed37d65b7f3d28fc15a2cb3ac5c8a70622c9e6e477776e89e5bc034e3b9f6b3
3
+ metadata.gz: d7f12bb06b37c9fb4c72dd76b00d111ab35f58dde16ff29f41e0350d8804d63b
4
+ data.tar.gz: 73ef5b7324c50858573da13826bcda8d78b25bb67095a155a080b78cfdd95cec
5
5
  SHA512:
6
- metadata.gz: 32a1ba9449540998e948cafeb851c7147116f2283803c47e9c2af158b99a4fad2c9be5a3c9e64fde362eac3ef4ecec45774e4acb49a52f55d72f0b3e194dec8b
7
- data.tar.gz: 696de60cfd8b96e8988260f1c53892d6f2b38054348eb17e898cc64fae83ea3888d5ac8bbebc0b87973a00e6ebfc7e16b990658ddaa2963fc28058109f094d8b
6
+ metadata.gz: 3cb2f5dbba04939875fa95820be43e2b77a83533f6c40c1829be5830626589383be67f9eaccfe2e84c9c7e6a34826537ede83623913c43baa49ca9481d3b0fb8
7
+ data.tar.gz: bdc640c0ca7eb05ad61d2add08038cdf34ac03a236683bbc8a278008c710e4be0895aede818cd4adfab02820ec51c19f02e9d09c9e3b6316c123f63c1bf5066e
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <center><img src="https://s3.brnbw.com/Artboard-GDaMBcpYEJ.png" alt="Satanic Pages" width=762 /></center>
2
2
 
3
- Static pages with YAML frontmatter, embedded in your Rails app.
3
+ Static Markdown pages with YAML frontmatter and inline Erb, embedded in your Rails app.
4
4
 
5
5
  As simple as, …
6
6
  **`app/views/pages/exorcism_tips.html.md`:**
@@ -14,12 +14,12 @@ tags:
14
14
  - devil worship
15
15
  - activity ideas
16
16
  ---
17
- By <%= current_page.author %>.
17
+ By <%= data.author %>.
18
18
 
19
19
  Through trial and error, I've found that the perfect exorcism
20
20
  starts with a refreshing drink.
21
21
 
22
- Tagged <%= render "tag_list", tags: current_page.tags %>:
22
+ Tagged <%= render "tag_list", tags: data.tags %>:
23
23
 
24
24
  ## Devilishly good lemonade recipe
25
25
 
@@ -32,7 +32,7 @@ In `app/views/layouts/pages.html.erb`:
32
32
 
33
33
  ```ruby
34
34
  <%= render_layout "application" do %>
35
- <h1><%= current_page.title %></h1>
35
+ <h1><%= data.title %></h1>
36
36
  <article>
37
37
  <%= yield %>
38
38
  </article>
@@ -44,7 +44,7 @@ Add this line to your application's Gemfile:
44
44
 
45
45
  ```sh
46
46
  $ bundle add satanic_pages
47
- $ bundle add markdown-rails # optional, but probably
47
+ $ bundle install
48
48
  ```
49
49
 
50
50
  Add the _Concern_ to a regular controller:
@@ -3,7 +3,7 @@ module SatanicPages
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- helper_method :current_page
6
+ helper_method :data
7
7
  end
8
8
 
9
9
  class_methods do
@@ -17,37 +17,28 @@ module SatanicPages
17
17
  end
18
18
 
19
19
  def show
20
- @test = "wut"
21
20
  render_static_page
22
21
  end
23
22
 
24
23
  private
25
24
 
26
- def slug_param
27
- params.require(:page)
28
- end
29
-
30
- def pages
31
- self.class.pages
25
+ def render_static_page
26
+ # For nested pages, we need to render the template directly using its full path
27
+ # Construct the template path based on the controller's view path and the page path
28
+ template_path = "#{controller_path}/#{current_page.path}"
29
+ render(template: template_path)
32
30
  end
33
31
 
34
32
  def current_page
35
- pages.find(slug_param)
33
+ @page ||= self.class.pages.find(slug_param)
36
34
  end
37
35
 
38
- # Bit of a hack here. As Rails resolves the layout pretty late, there's no
39
- # public way of looking it up at this point.
40
- # We do however control the rendering, probably, so the only thing we check
41
- # for is if the controller class has called self.layout.
42
- def page_layout
43
- self.class._layout || "application"
36
+ def slug_param
37
+ params.require(:page)
44
38
  end
45
39
 
46
- def render_static_page
47
- # For nested pages, we need to render the template directly using its full path
48
- # Construct the template path based on the controller's view path and the page path
49
- template_path = "#{controller_path}/#{current_page.path}"
50
- render(template: template_path)
40
+ def data
41
+ current_page&.data
51
42
  end
52
43
  end
53
44
  end
@@ -0,0 +1,9 @@
1
+ module SatanicPages
2
+ module LayoutHelper
3
+ # Thank you Sitepress for this lil' goodie
4
+ # https://github.com/sitepress/sitepress/blob/738aae7eaef61b494ad90786bc9f796374088ee1/sitepress-server/rails/app/helpers/application_helper.rb#L18
5
+ def render_layout(layout, **kwargs, &block)
6
+ render(html: capture(&block), layout: "layouts/#{layout}", **kwargs)
7
+ end
8
+ end
9
+ end
@@ -15,7 +15,7 @@ module SatanicPages
15
15
 
16
16
  data = OpenStruct.new(frontmatter)
17
17
 
18
- render(inline: content, handler: :erb, locals: {current_page: data})
18
+ render(inline: content, handler: :erb, locals: {data:})
19
19
  # Remove template comments
20
20
  .gsub(/<!-- (BEGIN|END) (.*) -->/, "")
21
21
  # Force HTML tags to be inline
@@ -16,8 +16,6 @@ module SatanicPages
16
16
 
17
17
  attr_reader :slug, :path, :full_path, :content, :data
18
18
 
19
- delegate_missing_to :data
20
-
21
19
  private
22
20
 
23
21
  def parse!
@@ -5,8 +5,8 @@ module SatanicPages
5
5
  class PageNotFound < StandardError
6
6
  end
7
7
 
8
- def initialize(ctrl)
9
- @base_path = Rails.root.join("app/views/", ctrl)
8
+ def initialize(controller_name)
9
+ @base_path = Rails.root.join("app/views/", controller_name)
10
10
 
11
11
  @pages = Dir[base_path + "**/*.html*"]
12
12
  .reject { |path| path.match?(/(^_|\/_)/) }
@@ -18,12 +18,18 @@ module SatanicPages
18
18
 
19
19
  attr_reader :base_path, :pages
20
20
 
21
- def find(path)
21
+ def find!(path)
22
22
  @pages.fetch(path)
23
23
  rescue KeyError
24
24
  raise PageNotFound, "No page `#{path}' found at #{base_path}"
25
25
  end
26
26
 
27
+ def find(path)
28
+ find!(path)
29
+ rescue PageNotFound
30
+ nil
31
+ end
32
+
27
33
  def match?(req_path)
28
34
  path = req_path.gsub(/^\//, "")
29
35
  pages.keys.include?(path)
@@ -0,0 +1,12 @@
1
+ module SatanicPages
2
+ class Railtie < ::Rails::Railtie
3
+ initializer("satanic_pages.view_helpers") do
4
+ ActiveSupport.on_load(:action_view) { include SatanicPages::LayoutHelper }
5
+ end
6
+
7
+ initializer("satanic_pages.register_markdown") do
8
+ require "satanic_pages/markdown_template_handler"
9
+
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module SatanicPages
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/satanic_pages.rb CHANGED
@@ -1,8 +1,13 @@
1
+ require "markdown-rails"
2
+
1
3
  require "satanic_pages/version"
2
- require "satanic_pages/engine"
4
+ require "satanic_pages/railtie"
3
5
 
4
6
  require "satanic_pages/page"
5
7
  require "satanic_pages/page_list"
6
8
 
9
+ require "satanic_pages/controller"
10
+ require "satanic_pages/layout_helper"
11
+
7
12
  module SatanicPages
8
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satanic_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
@@ -37,6 +37,20 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '7'
40
+ - !ruby/object:Gem::Dependency
41
+ name: markdown-rails
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '2'
40
54
  description: An embeddable static pages engine for Rails apps and the devil
41
55
  email:
42
56
  - mikkel@brnbw.com
@@ -47,13 +61,13 @@ files:
47
61
  - MIT-LICENSE
48
62
  - README.md
49
63
  - Rakefile
50
- - app/controllers/concerns/satanic_pages/controller.rb
51
- - app/helpers/satanic_pages/layout_helper.rb
52
64
  - lib/satanic_pages.rb
53
- - lib/satanic_pages/engine.rb
65
+ - lib/satanic_pages/controller.rb
66
+ - lib/satanic_pages/layout_helper.rb
54
67
  - lib/satanic_pages/markdown_template_handler.rb
55
68
  - lib/satanic_pages/page.rb
56
69
  - lib/satanic_pages/page_list.rb
70
+ - lib/satanic_pages/railtie.rb
57
71
  - lib/satanic_pages/version.rb
58
72
  homepage: https://github.com/mikker/satanic_pages
59
73
  licenses:
@@ -1,7 +0,0 @@
1
- module SatanicPages::LayoutHelper
2
- # Thank you Sitepress for this lil' goodie
3
- # https://github.com/sitepress/sitepress/blob/738aae7eaef61b494ad90786bc9f796374088ee1/sitepress-server/rails/app/helpers/application_helper.rb#L18
4
- def render_layout(layout, **kwargs, &block)
5
- render(html: capture(&block), layout: "layouts/#{layout}", **kwargs)
6
- end
7
- end
@@ -1,26 +0,0 @@
1
- module SatanicPages
2
- class Engine < ::Rails::Engine
3
- initializer("satanic_pages.view_helpers") do
4
- ActiveSupport.on_load(:action_view) { include SatanicPages::LayoutHelper }
5
- end
6
-
7
- initializer("satanic_pages.register_markdown") do
8
- if has_markdown_rails?
9
- require "satanic_pages/markdown_template_handler"
10
-
11
- end
12
- end
13
-
14
- private
15
-
16
- def has_markdown_rails?
17
- return true if defined?(MarkdownRails)
18
-
19
- require "markdown-rails"
20
-
21
- true
22
- rescue LoadError
23
- false
24
- end
25
- end
26
- end