serbea 0.11.4 → 1.0.1

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.
@@ -1,68 +0,0 @@
1
- require "serbea/rouge_lexer"
2
- require "bridgetown-core"
3
-
4
- module Bridgetown
5
- class SerbeaView < ERBView
6
- include Serbea::Helpers
7
-
8
- def partial(partial_name, options = {}, &block)
9
- options.merge!(options[:locals]) if options[:locals]
10
- options[:content] = capture(&block) if block
11
-
12
- partial_segments = partial_name.split("/")
13
- partial_segments.last.sub!(%r!^!, "_")
14
- partial_name = partial_segments.join("/")
15
-
16
- Tilt::SerbeaTemplate.new(
17
- site.in_source_dir(site.config[:partials_dir], "#{partial_name}.serb")
18
- ).render(self, options)
19
- end
20
- end
21
-
22
- module Converters
23
- class SerbeaTemplates < Converter
24
- priority :highest
25
- input :serb
26
-
27
- # Logic to do the Serbea content conversion.
28
- #
29
- # @param content [String] Content of the file (without front matter).
30
- # @param convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
31
- # The instantiated object which is processing the file.
32
- #
33
- # @return [String] The converted content.
34
- def convert(content, convertible)
35
- return content if convertible.data[:template_engine] != "serbea"
36
-
37
- serb_view = Bridgetown::SerbeaView.new(convertible)
38
-
39
- serb_renderer = Tilt::SerbeaTemplate.new(convertible.relative_path) { content }
40
-
41
- if convertible.is_a?(Bridgetown::Layout)
42
- serb_renderer.render(serb_view) do
43
- convertible.current_document_output
44
- end
45
- else
46
- serb_renderer.render(serb_view)
47
- end
48
- end
49
-
50
- def matches(ext, convertible)
51
- if convertible.data[:template_engine] == "serbea" ||
52
- (convertible.data[:template_engine].nil? &&
53
- @config[:template_engine] == "serbea")
54
- convertible.data[:template_engine] = "serbea"
55
- return true
56
- end
57
-
58
- super(ext).tap do |ext_matches|
59
- convertible.data[:template_engine] = "serbea" if ext_matches
60
- end
61
- end
62
-
63
- def output_ext(ext)
64
- ext == ".serb" ? ".html" : ext
65
- end
66
- end
67
- end
68
- end
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hash_with_dot_access"
4
-
5
- module Serbea
6
- module Rails
7
- module FrontmatterHelpers
8
- def set_page_frontmatter=(data)
9
- @frontmatter ||= HashWithDotAccess::Hash.new
10
- @frontmatter.update(data)
11
- end
12
- end
13
-
14
- module FrontmatterControllerActions
15
- extend ActiveSupport::Concern
16
-
17
- included do
18
- Serbea::TemplateEngine.front_matter_preamble = "self.set_page_frontmatter = local_frontmatter = YAML.load"
19
-
20
- before_action { @frontmatter ||= HashWithDotAccess::Hash.new }
21
-
22
- helper Serbea::Rails::FrontmatterHelpers
23
- end
24
- end
25
-
26
- class TemplateHandler
27
- def handles_encoding?; true; end
28
-
29
- def compile(template, source)
30
- "self.class.include(Serbea::Helpers);" + Tilt::SerbeaTemplate.new { source }.precompiled_template([])
31
- end
32
-
33
- def self.call(template, source = nil)
34
- source ||= template.source
35
-
36
- new.compile(template, source)
37
- end
38
- end
39
- end
40
- end
41
-
42
- Serbea::TemplateEngine.directive :form, ->(code, buffer) do
43
- model_name, space, params = code.lstrip.partition(%r(\s)m)
44
- model_name.chomp!(",")
45
- model_name = "#{model_name}," unless params.lstrip.start_with?("do", "{")
46
-
47
- buffer << "{%= form_with model: "
48
- buffer << model_name << " #{params}"
49
- buffer << " %}"
50
- end
51
-
52
- Serbea::TemplateEngine.directive :frame, ->(code, buffer) do
53
- buffer << "{%= turbo_frame_tag "
54
- buffer << code
55
- buffer << " %}"
56
- end
57
-
58
- %i(append prepend update replace remove).each do |action|
59
- Serbea::TemplateEngine.directive action, ->(code, buffer) do
60
- buffer << "{%= turbo_stream.#{action} "
61
- buffer << code
62
- buffer << " %}"
63
- end
64
- end
65
-
66
- Serbea::TemplateEngine.directive :_, ->(code, buffer) do
67
- tag_name, space, params = code.lstrip.partition(%r(\s)m)
68
-
69
- if tag_name.end_with?(":")
70
- tag_name.chomp!(":")
71
- tag_name = ":#{tag_name}" unless tag_name.start_with?(":")
72
- end
73
-
74
- buffer << "{%= tag.tag_string "
75
- buffer << tag_name << ", " << params
76
- buffer << " %}"
77
- end
78
-
79
- ActionView::Template.register_template_handler(:serb, Serbea::Rails::TemplateHandler)