serbea 0.10.1 → 0.11
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/lib/serbea/bridgetown_support.rb +3 -9
 - data/lib/serbea/rails_support.rb +26 -2
 - data/lib/serbea/template_engine.rb +27 -21
 - data/lib/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b350bfc24a2bccc41291ffec1e28d213271685fd2ca27413fd5eb07d7d120a46
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: bae64f05c4a70a7b53656b6ec8aa88b0693c755e1c51e5fffff2c619b72d7fa9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f4dd4fa55bbb9031a55e19da029a73e0f5bbb6b67735aef4cf24be5e009f9f2b186edcd6724b43151de6ccdd6547425befd146b22734d7dda39bf3836ebe035a
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f1acbc71a92e58d1c229cbf7de524e7ac933f2547b48b551c81a44e552ae0298de8cffba6a6c77ff7c0c6507d3fc99b3999df80631832aaed9c224ccb0d2c495
         
     | 
| 
         @@ -2,8 +2,10 @@ require "serbea/rouge_lexer" 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require "bridgetown-core"
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Bridgetown
         
     | 
| 
       5 
     | 
    
         
            -
              class SerbeaView <  
     | 
| 
      
 5 
     | 
    
         
            +
              class SerbeaView < ERBView
         
     | 
| 
      
 6 
     | 
    
         
            +
                alias_method :_erb_capture, :capture
         
     | 
| 
       6 
7 
     | 
    
         
             
                include Serbea::Helpers
         
     | 
| 
      
 8 
     | 
    
         
            +
                alias_method :capture, :_erb_capture
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
10 
     | 
    
         
             
                def partial(partial_name, options = {}, &block)
         
     | 
| 
       9 
11 
     | 
    
         
             
                  options.merge!(options[:locals]) if options[:locals]
         
     | 
| 
         @@ -17,14 +19,6 @@ module Bridgetown 
     | 
|
| 
       17 
19 
     | 
    
         
             
                    site.in_source_dir(site.config[:partials_dir], "#{partial_name}.serb")
         
     | 
| 
       18 
20 
     | 
    
         
             
                  ).render(self, options)
         
     | 
| 
       19 
21 
     | 
    
         
             
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                def markdownify(input = nil, &block)
         
     | 
| 
       22 
     | 
    
         
            -
                  content = Bridgetown::Utils.reindent_for_markdown(
         
     | 
| 
       23 
     | 
    
         
            -
                    block.nil? ? input.to_s : capture(&block)
         
     | 
| 
       24 
     | 
    
         
            -
                  )
         
     | 
| 
       25 
     | 
    
         
            -
                  converter = site.find_converter_instance(Bridgetown::Converters::Markdown)
         
     | 
| 
       26 
     | 
    
         
            -
                  converter.convert(content).strip
         
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
22 
     | 
    
         
             
              end
         
     | 
| 
       29 
23 
     | 
    
         | 
| 
       30 
24 
     | 
    
         
             
              module Converters
         
     | 
    
        data/lib/serbea/rails_support.rb
    CHANGED
    
    | 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            require "hash_with_dot_access"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
       3 
5 
     | 
    
         
             
            module Serbea
         
     | 
| 
       4 
6 
     | 
    
         
             
              module Rails
         
     | 
| 
       5 
7 
     | 
    
         
             
                module FrontmatterHelpers
         
     | 
| 
         @@ -42,10 +44,32 @@ Serbea::TemplateEngine.directive :form, ->(code, buffer) do 
     | 
|
| 
       42 
44 
     | 
    
         
             
              buffer << code
         
     | 
| 
       43 
45 
     | 
    
         
             
              buffer << " %}"
         
     | 
| 
       44 
46 
     | 
    
         
             
            end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            Serbea::TemplateEngine.directive :frame, ->(code, buffer) do
         
     | 
| 
      
 49 
     | 
    
         
            +
              buffer << "{%= turbo_frame_tag "
         
     | 
| 
       47 
50 
     | 
    
         
             
              buffer << code
         
     | 
| 
       48 
51 
     | 
    
         
             
              buffer << " %}"
         
     | 
| 
       49 
52 
     | 
    
         
             
            end
         
     | 
| 
       50 
53 
     | 
    
         | 
| 
      
 54 
     | 
    
         
            +
            %i(append prepend update replace remove).each do |action|
         
     | 
| 
      
 55 
     | 
    
         
            +
              Serbea::TemplateEngine.directive action, ->(code, buffer) do
         
     | 
| 
      
 56 
     | 
    
         
            +
                buffer << "{%= turbo_stream.#{action} "
         
     | 
| 
      
 57 
     | 
    
         
            +
                buffer << code
         
     | 
| 
      
 58 
     | 
    
         
            +
                buffer << " %}"
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
            end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            Serbea::TemplateEngine.directive :_, ->(code, buffer) do
         
     | 
| 
      
 63 
     | 
    
         
            +
              tag_name, space, params = code.lstrip.partition(%r(\s)m)
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              if tag_name.end_with?(":")
         
     | 
| 
      
 66 
     | 
    
         
            +
                tag_name.chomp!(":")
         
     | 
| 
      
 67 
     | 
    
         
            +
                tag_name = ":#{tag_name}" unless tag_name.start_with?(":")
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              buffer << "{%= tag.tag_string "
         
     | 
| 
      
 71 
     | 
    
         
            +
              buffer << tag_name << ", " << params
         
     | 
| 
      
 72 
     | 
    
         
            +
              buffer << " %}"
         
     | 
| 
      
 73 
     | 
    
         
            +
            end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
       51 
75 
     | 
    
         
             
            ActionView::Template.register_template_handler(:serb, Serbea::Rails::TemplateHandler)
         
     | 
| 
         @@ -17,11 +17,10 @@ module Serbea 
     | 
|
| 
       17 
17 
     | 
    
         
             
                def self.directive(new_directive, directive_resolution)
         
     | 
| 
       18 
18 
     | 
    
         
             
                  directives[new_directive.to_s] = directive_resolution
         
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       20 
21 
     | 
    
         
             
                def self.directives
         
     | 
| 
       21 
22 
     | 
    
         
             
                  @directives ||= {
         
     | 
| 
       22 
23 
     | 
    
         
             
                    "@" => ->(code, buffer) do
         
     | 
| 
       23 
     | 
    
         
            -
                      original_line_length = code.lines.size
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
24 
     | 
    
         
             
                      pieces = code.split(" ")
         
     | 
| 
       26 
25 
     | 
    
         
             
                      if pieces[0].start_with?(/[A-Z]/) # Ruby class name
         
     | 
| 
       27 
26 
     | 
    
         
             
                        pieces[0].prepend " "
         
     | 
| 
         @@ -45,9 +44,11 @@ module Serbea 
     | 
|
| 
       45 
44 
     | 
    
         
             
                        pieces.last << ")"
         
     | 
| 
       46 
45 
     | 
    
         
             
                        buffer << "{%= render#{pieces.join(" ")} %}"
         
     | 
| 
       47 
46 
     | 
    
         
             
                      end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                       
     | 
| 
      
 47 
     | 
    
         
            +
                    end,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    "`" => ->(code, buffer) do
         
     | 
| 
      
 49 
     | 
    
         
            +
                      buffer << "{%= %`"
         
     | 
| 
      
 50 
     | 
    
         
            +
                      buffer << code.gsub(%r("([^\\]?)\#{(.*?)}"), "\"\\1\#{h(\\2)}\"")
         
     | 
| 
      
 51 
     | 
    
         
            +
                      buffer << ".strip %}"
         
     | 
| 
       51 
52 
     | 
    
         
             
                    end
         
     | 
| 
       52 
53 
     | 
    
         
             
                  }
         
     | 
| 
       53 
54 
     | 
    
         
             
                end
         
     | 
| 
         @@ -55,30 +56,21 @@ module Serbea 
     | 
|
| 
       55 
56 
     | 
    
         
             
                def self.front_matter_preamble=(varname)
         
     | 
| 
       56 
57 
     | 
    
         
             
                  @front_matter_preamble = varname
         
     | 
| 
       57 
58 
     | 
    
         
             
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       58 
60 
     | 
    
         
             
                def self.front_matter_preamble
         
     | 
| 
       59 
61 
     | 
    
         
             
                  @front_matter_preamble ||= "frontmatter = YAML.load"
         
     | 
| 
       60 
62 
     | 
    
         
             
                end
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       62 
64 
     | 
    
         
             
                def self.has_yaml_header?(template)
         
     | 
| 
       63 
65 
     | 
    
         
             
                  template.lines.first&.match? %r!\A---\s*\r?\n!
         
     | 
| 
       64 
66 
     | 
    
         
             
                end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
       66 
68 
     | 
    
         
             
                def initialize(input, properties={})
         
     | 
| 
       67 
69 
     | 
    
         
             
                  properties[:regexp] = /{%(={1,2}|-|\#|%)?(.*?)([-=])?%}([ \t]*\r?\n)?/m
         
     | 
| 
       68 
70 
     | 
    
         
             
                  properties[:strip_front_matter] = true unless properties.key?(:strip_front_matter)
         
     | 
| 
       69 
71 
     | 
    
         
             
                  super process_serbea_input(input, properties), properties
         
     | 
| 
       70 
72 
     | 
    
         
             
                end
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                def add_postamble(postamble)
         
     | 
| 
       73 
     | 
    
         
            -
                  src << postamble
         
     | 
| 
       74 
     | 
    
         
            -
                  src << "#{@bufvar}.html_safe"
         
     | 
| 
       75 
     | 
    
         
            -
              
         
     | 
| 
       76 
     | 
    
         
            -
                  src.gsub!("__RAW_START_PRINT__", "{{")
         
     | 
| 
       77 
     | 
    
         
            -
                  src.gsub!("__RAW_END_PRINT__", "}}")
         
     | 
| 
       78 
     | 
    
         
            -
                  src.gsub!("__RAW_START_EVAL__", "{%")
         
     | 
| 
       79 
     | 
    
         
            -
                  src.gsub!("__RAW_END_EVAL__", "%}")
         
     | 
| 
       80 
     | 
    
         
            -
                end
         
     | 
| 
       81 
     | 
    
         
            -
              
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
       82 
74 
     | 
    
         
             
                def process_serbea_input(template, properties)
         
     | 
| 
       83 
75 
     | 
    
         
             
                  buff = ""
         
     | 
| 
       84 
76 
     | 
    
         | 
| 
         @@ -180,7 +172,7 @@ module Serbea 
     | 
|
| 
       180 
172 
     | 
    
         
             
                  string = buff
         
     | 
| 
       181 
173 
     | 
    
         
             
                  buff = ""
         
     | 
| 
       182 
174 
     | 
    
         
             
                  until string.empty?
         
     | 
| 
       183 
     | 
    
         
            -
                    text, code, string = string.partition(/{%@([a-z_]+)?(.*?)%}/m)
         
     | 
| 
      
 175 
     | 
    
         
            +
                    text, code, string = string.partition(/{%@([a-z_`]+)?(.*?)%}/m)
         
     | 
| 
       184 
176 
     | 
    
         | 
| 
       185 
177 
     | 
    
         
             
                    buff << text
         
     | 
| 
       186 
178 
     | 
    
         
             
                    if code.length > 0
         
     | 
| 
         @@ -190,7 +182,11 @@ module Serbea 
     | 
|
| 
       190 
182 
     | 
    
         
             
                        directive = $1 ? self.class.directives[$1] : self.class.directives["@"]
         
     | 
| 
       191 
183 
     | 
    
         | 
| 
       192 
184 
     | 
    
         
             
                        if directive
         
     | 
| 
      
 185 
     | 
    
         
            +
                          additional_length = "#{buff}#{code}".lines.size
         
     | 
| 
       193 
186 
     | 
    
         
             
                          directive.(code, buff)
         
     | 
| 
      
 187 
     | 
    
         
            +
                          (additional_length - buff.lines.size).times do
         
     | 
| 
      
 188 
     | 
    
         
            +
                            buff << "{% %}\n" # preserve original directive line length
         
     | 
| 
      
 189 
     | 
    
         
            +
                          end
         
     | 
| 
       194 
190 
     | 
    
         
             
                        else
         
     | 
| 
       195 
191 
     | 
    
         
             
                          raise "Handler for Serbea template directive `#{$1}' not found"
         
     | 
| 
       196 
192 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -202,7 +198,7 @@ module Serbea 
     | 
|
| 
       202 
198 
     | 
    
         | 
| 
       203 
199 
     | 
    
         
             
                  buff
         
     | 
| 
       204 
200 
     | 
    
         
             
                end
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
       206 
202 
     | 
    
         
             
                private
         
     | 
| 
       207 
203 
     | 
    
         | 
| 
       208 
204 
     | 
    
         
             
                def add_code(code)
         
     | 
| 
         @@ -226,5 +222,15 @@ module Serbea 
     | 
|
| 
       226 
222 
     | 
    
         
             
                def add_expression_result_escaped(code)
         
     | 
| 
       227 
223 
     | 
    
         
             
                  add_expression_result(code)
         
     | 
| 
       228 
224 
     | 
    
         
             
                end
         
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                def add_postamble(postamble)
         
     | 
| 
      
 227 
     | 
    
         
            +
                  src << postamble
         
     | 
| 
      
 228 
     | 
    
         
            +
                  src << "#{@bufvar}.html_safe"
         
     | 
| 
      
 229 
     | 
    
         
            +
              
         
     | 
| 
      
 230 
     | 
    
         
            +
                  src.gsub!("__RAW_START_PRINT__", "{{")
         
     | 
| 
      
 231 
     | 
    
         
            +
                  src.gsub!("__RAW_END_PRINT__", "}}")
         
     | 
| 
      
 232 
     | 
    
         
            +
                  src.gsub!("__RAW_START_EVAL__", "{%")
         
     | 
| 
      
 233 
     | 
    
         
            +
                  src.gsub!("__RAW_END_EVAL__", "%}")
         
     | 
| 
      
 234 
     | 
    
         
            +
                end
         
     | 
| 
      
 235 
     | 
    
         
            +
              end
         
     | 
| 
       230 
236 
     | 
    
         
             
            end
         
     | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: serbea
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: '0.11'
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Bridgetown Team
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2020-12- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2020-12-29 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     |