serbea 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72bb8c66c7a574ed69bbec8995cd8a5e28fa72caf82768264b95b602ce1db815
4
- data.tar.gz: 3cece4d891ef8100bf0a5eb51570f89bdc58566914fe6f0b514d21a3a76e2f7e
3
+ metadata.gz: 439fb102e78e2208de075b03b058b77d1cc909a6fe9414c341a48370fd3988e2
4
+ data.tar.gz: d0ff78ac67f00a59fa1047f7f05795cee88051ff0fdb9c179601984601fecae4
5
5
  SHA512:
6
- metadata.gz: 3b8d9d2677748d88ec34dbea4abbf65fb05253c0ccd8d1f4bcde2f9781ef9056194a6c25bfe8027dc20f906055fd7db023587aedbb944025109cc443ad9e720a
7
- data.tar.gz: a9622d5f4a502291fd8472eb24f2f6e479f434897eec51095eb2ba668b95fd1dd438eb400274d9811eaddfbd485e523d76ce7230245f9e8d11a284170afe3725
6
+ metadata.gz: 6ca9922186315539c54e3a44fad5da81b3075425bb991dd8521e4777f5d46e515d4a65f9fd7fd54c52b870df21c8155b32beb3a24c84080c95367b1143526ff5
7
+ data.tar.gz: ccb34f9d8129fe5c4e34f96d7cbce118f5dbf8538151ae554cca9c35f63e223a0d14b4456e1463c8a79661de6109831ca3058aaee184f2925af974acfbc5f6b1
@@ -32,9 +32,7 @@ if defined?(Rails::Railtie)
32
32
  ActiveSupport.on_load(:action_view) do
33
33
  require "serbea/rails_support"
34
34
 
35
- app.config.after_initialize do
36
- Serbea::Plugin.initialize_frontmatter
37
- end
35
+ ActionController::Base.include Serbea::Rails::FrontmatterControllerActions
38
36
  end
39
37
  end
40
38
  end
@@ -1,34 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # inspired by https://github.com/haml/haml/blob/main/lib/haml/plugin.rb
4
3
  module Serbea
5
- # This module makes Serbea work with Rails using the template handler API.
6
- class Plugin
7
- def handles_encoding?; true; end
8
-
9
- def compile(template, source)
10
- "self.class.include(Serbea::Helpers);" + Tilt::SerbeaTemplate.new { source }.precompiled_template([])
4
+ module Rails
5
+ module FrontmatterHelpers
6
+ def set_page_frontmatter=(data)
7
+ @frontmatter ||= HashWithDotAccess::Hash.new
8
+ @frontmatter.update(data)
9
+ end
11
10
  end
12
11
 
13
- def self.call(template, source = nil)
14
- source ||= template.source
12
+ module FrontmatterControllerActions
13
+ extend ActiveSupport::Concern
15
14
 
16
- new.compile(template, source)
15
+ included do
16
+ Serbea::TemplateEngine.front_matter_preamble = "self.set_page_frontmatter = local_frontmatter = YAML.load"
17
+
18
+ before_action { @frontmatter ||= HashWithDotAccess::Hash.new }
19
+
20
+ helper Serbea::Rails::FrontmatterHelpers
21
+ end
17
22
  end
18
23
 
19
- def self.initialize_frontmatter
20
- if defined?(ApplicationHelper)
21
- Serbea::TemplateEngine.front_matter_preamble = "self.set_page_frontmatter = local_frontmatter = YAML.load"
22
-
23
- ApplicationHelper.define_method(:set_page_frontmatter=) do |data|
24
- @frontmatter ||= HashWithDotAccess::Hash.new
25
- @frontmatter.update(data)
26
- end
27
-
28
- ApplicationController.before_action { @frontmatter ||= HashWithDotAccess::Hash.new }
24
+ class TemplateHandler
25
+ def handles_encoding?; true; end
26
+
27
+ def compile(template, source)
28
+ "self.class.include(Serbea::Helpers);" + Tilt::SerbeaTemplate.new { source }.precompiled_template([])
29
+ end
30
+
31
+ def self.call(template, source = nil)
32
+ source ||= template.source
33
+
34
+ new.compile(template, source)
29
35
  end
30
36
  end
31
37
  end
32
38
  end
33
39
 
34
- ActionView::Template.register_template_handler(:serb, Serbea::Plugin)
40
+ ActionView::Template.register_template_handler(:serb, Serbea::Rails::TemplateHandler)
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serbea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team