serbea 0.12 → 1.0.0

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: a06fc22c4a790174a7d774b39eb7332bef7c78c328ed4582a77dc1fd2d79a968
4
- data.tar.gz: e94abb8855965947238b8c3c32ce953d2ad13208425fba92c02ac97f76f70b81
3
+ metadata.gz: 2014debe9382e252988c8d41ebec4102153508a856dca4dd7b72d2e347fb4023
4
+ data.tar.gz: aa729c3b2212ff33e5399544bc798593864248d6aacaeb0764c92fa43dc0cf8e
5
5
  SHA512:
6
- metadata.gz: fb47116dbb72fd826be07dd8e6294b0f32536434b7012d4541c14929788cbc4ac635567a7579b254002645e8db9dc492b806ba6d040ff76043faa4e851833ea9
7
- data.tar.gz: 436c2f51d6da3d047016de80dce01496fa4648d10a427512ddc4a5652bce63bc126e03d4902298f1b2f5b500910d04e80387cad213611d00fb46c4ddc0de0de3
6
+ metadata.gz: c7d3037ee50671772fad0ab5e8cbce90a9ae402769d5ffd49163df182a8c011da83d66809602d01d3186b2cc513d30116922fab461f03d3d0746b2d3f17a977e
7
+ data.tar.gz: 63f25bbbc2edd056c6c5cb461c356b52301f4590cc8733ca2be621f430b39d20df30f8ee881344e3c4088e19fb34d5630f4b9ac045db2fb5a3908830ae6bef18
data/docs/src/index.md CHANGED
@@ -82,7 +82,7 @@ layout: home
82
82
  {{ wow | prepend: "OMG! " }}
83
83
  ```
84
84
 
85
- Serbea lets us define helpers inside templates directly:
85
+ Use `helper` (alias `macro`) to create ad-hoc filters:
86
86
 
87
87
  ```serb
88
88
  <p>
@@ -50,4 +50,4 @@ module Rouge
50
50
  end
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -30,7 +30,7 @@ module Serbea
30
30
  def import(*args, **kwargs, &block)
31
31
  helper_names = %i(partial render)
32
32
  available_helper = helper_names.find { |meth| respond_to?(meth) }
33
- raise "Serbea error: no `render' helper is available in #{self.class}" unless available_helper
33
+ raise "Serbea Error: no `render' or `partial' helper available in #{self.class}" unless available_helper
34
34
  available_helper == :partial ? partial(*args, **kwargs, &block) : render(*args, **kwargs, &block)
35
35
  nil
36
36
  end
@@ -1,3 +1,4 @@
1
+ require "set"
1
2
  require "active_support/core_ext/string/output_safety"
2
3
  require "active_support/core_ext/object/blank"
3
4
 
@@ -68,38 +69,21 @@ module Serbea
68
69
  @value = value
69
70
  end
70
71
 
71
- # TODO: clean this up somehow and still support Ruby 2.5..3.0!
72
72
  def filter(name, *args, **kwargs)
73
73
  if @value.respond_to?(name) && !self.class.value_methods_denylist.include?(name)
74
74
  if args.last.is_a?(Proc)
75
75
  real_args = args.take(args.length - 1)
76
76
  block = args.last
77
- unless kwargs.empty?
78
- @value = @value.send(name, *real_args, **kwargs, &block)
79
- else
80
- @value = @value.send(name, *real_args, &block)
81
- end
77
+ @value = @value.send(name, *real_args, **kwargs, &block)
82
78
  else
83
- unless kwargs.empty?
84
- @value = @value.send(name, *args, **kwargs)
85
- else
86
- @value = @value.send(name, *args)
87
- end
79
+ @value = @value.send(name, *args, **kwargs)
88
80
  end
89
81
  elsif @context.respond_to?(name)
90
- unless kwargs.empty?
91
- @value = @context.send(name, @value, *args, **kwargs)
92
- else
93
- @value = @context.send(name, @value, *args)
94
- end
82
+ @value = @context.send(name, @value, *args, **kwargs)
95
83
  elsif @binding.local_variables.include?(name)
96
84
  var = @binding.local_variable_get(name)
97
85
  if var.respond_to?(:call)
98
- unless kwargs.empty?
99
- @value = var.call(@value, *args, **kwargs)
100
- else
101
- @value = var.call(@value, *args)
102
- end
86
+ @value = var.call(@value, *args, **kwargs)
103
87
  else
104
88
  "Serbea warning: Filter #{name} does not respond to call".tap do |warning|
105
89
  self.class.raise_on_missing_filters ? raise(warning) : STDERR.puts(warning)
data/lib/serbea.rb CHANGED
@@ -25,19 +25,3 @@ module Tilt
25
25
  end
26
26
 
27
27
  Tilt.register Tilt::SerbeaTemplate, "serb"
28
-
29
- if defined?(Rails::Railtie)
30
- class Railtie < ::Rails::Railtie
31
- initializer :serbea do |app|
32
- ActiveSupport.on_load(:action_view) do
33
- require "serbea/rails_support"
34
-
35
- ActionController::Base.include Serbea::Rails::FrontmatterControllerActions
36
- end
37
- end
38
- end
39
- end
40
-
41
- if defined?(Bridgetown)
42
- require "serbea/bridgetown_support"
43
- end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.12"
2
+ VERSION = "1.0.0"
3
3
  end
data/serbea.gemspec CHANGED
@@ -11,12 +11,12 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://github.com/bridgetownrb/serbea"
12
12
  spec.license = "MIT"
13
13
 
14
- spec.required_ruby_version = ">= 2.5"
14
+ spec.required_ruby_version = ">= 2.7"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features)/!) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_runtime_dependency("activesupport", "~> 6.0")
19
+ spec.add_runtime_dependency("activesupport", ">= 6.0")
20
20
  spec.add_runtime_dependency("erubi", ">= 1.10")
21
21
  spec.add_runtime_dependency("hash_with_dot_access", "~> 1.1")
22
22
  spec.add_runtime_dependency("tilt", "~> 2.0")
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serbea
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.12'
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-04 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '13.0'
83
- description:
83
+ description:
84
84
  email: maintainers@bridgetownrb.com
85
85
  executables: []
86
86
  extensions: []
@@ -117,12 +117,10 @@ files:
117
117
  - docs/sync.js
118
118
  - docs/webpack.config.js
119
119
  - docs/yarn.lock
120
+ - lib/rouge/lexers/serbea.rb
120
121
  - lib/serbea.rb
121
- - lib/serbea/bridgetown_support.rb
122
122
  - lib/serbea/helpers.rb
123
123
  - lib/serbea/pipeline.rb
124
- - lib/serbea/rails_support.rb
125
- - lib/serbea/rouge_lexer.rb
126
124
  - lib/serbea/template_engine.rb
127
125
  - lib/version.rb
128
126
  - serbea.gemspec
@@ -130,7 +128,7 @@ homepage: https://github.com/bridgetownrb/serbea
130
128
  licenses:
131
129
  - MIT
132
130
  metadata: {}
133
- post_install_message:
131
+ post_install_message:
134
132
  rdoc_options: []
135
133
  require_paths:
136
134
  - lib
@@ -138,15 +136,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
136
  requirements:
139
137
  - - ">="
140
138
  - !ruby/object:Gem::Version
141
- version: '2.5'
139
+ version: '2.7'
142
140
  required_rubygems_version: !ruby/object:Gem::Requirement
143
141
  requirements:
144
142
  - - ">="
145
143
  - !ruby/object:Gem::Version
146
144
  version: '0'
147
145
  requirements: []
148
- rubygems_version: 3.2.3
149
- signing_key:
146
+ rubygems_version: 3.1.4
147
+ signing_key:
150
148
  specification_version: 4
151
149
  summary: Similar to ERB, Except Awesomer
152
150
  test_files: []
@@ -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)