serbea 0.5.0 → 0.6.4

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: ce17e2b60c2abf63a033d8d358686d4df115e87a4c149ba3c625a403863e129c
4
- data.tar.gz: a3901a5286afc92e84b2ecc29b2622e80a592f0d0d9de46a7aa58d836e150c65
3
+ metadata.gz: 1d16e1fa13dfcc4f2b10dc287e5d4c150130c0760a8be00cf323287849132f49
4
+ data.tar.gz: 60ab217fb343de0d7af90cf4dc18592dc867f6bbad8ce31349901dc64e677390
5
5
  SHA512:
6
- metadata.gz: 52aadba5419583064f26be67a99805ea66af5798b3bd3a34604967c91fdee3f2e6010ba692b6f70a2de798fa5d899bb7760fd3a76975e415932e5922c7f21c6a
7
- data.tar.gz: 4bc3fcfa08bb021ceb68ae675f4f47d4fd72a2e1cdd71fe68d8b4e435493238c49f205f10ccc52e0980d160a226433af19b70d39d18bc3d73b30c9afb8be0698
6
+ metadata.gz: ed744553b4a670b1de4a617a8d34d2ecd4fac83135795994f601b4873f9ef46763e2ec09d814881c4005a5f070ed530f35e4334998e0e3445a62d5025030a665
7
+ data.tar.gz: 3d875dc56647f48098b1ba129a05c5fa56a7be4294de207199fb5e7ca5ab41d19ce511585e4b0533a74b000e6671fb6e3a0dd54d7779e9e5ee27ae0003df0d0d
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in serbea.gemspec
6
6
  gemspec
7
+
8
+ gem "erubi", github: "jaredcwhite/erubi", branch: "config-literal-prefix"
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
+ require "bundler"
4
+
5
+ Bundler.setup
3
6
 
4
7
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/test_*.rb"]
8
+ t.test_files = FileList["test/test.rb"]
9
+ t.warning = false
8
10
  end
9
11
 
10
12
  task :default => :test
@@ -1,6 +1,5 @@
1
1
  require "tilt"
2
2
  require "tilt/erubi"
3
- require "erubi/capture_end"
4
3
 
5
4
  require "serbea/helpers"
6
5
  require "serbea/pipeline"
@@ -10,7 +9,13 @@ require "serbea/component_renderer"
10
9
  module Tilt
11
10
  class SerbeaTemplate < ErubiTemplate
12
11
  def prepare
13
- @options.merge!(outvar: "@_erbout", bufval: "Serbea::Buffer.new", engine_class: Serbea::TemplateEngine)
12
+ @options.merge!(
13
+ outvar: "@_erbout",
14
+ bufval: "Serbea::Buffer.new",
15
+ literal_prefix: "{%",
16
+ literal_postfix: "%}",
17
+ engine_class: Serbea::TemplateEngine
18
+ )
14
19
  super
15
20
  end
16
21
 
@@ -1,4 +1,5 @@
1
1
  require "serbea/rouge_lexer"
2
+ require "bridgetown-core"
2
3
 
3
4
  module Bridgetown
4
5
  class SerbeaView < RubyTemplateView
@@ -70,3 +71,13 @@ module Bridgetown
70
71
  end
71
72
  end
72
73
  end
74
+
75
+ Bridgetown::Hooks.register :site, :pre_render, reloadable: false do |site|
76
+ # make sure Liquid doesn't find {% %} and decide to process Serbea code!
77
+ site.contents.each do |convertible|
78
+ convertible.data.render_with_liquid = false if convertible.extname == ".serb"
79
+ end
80
+ site.layouts.values.each do |convertible|
81
+ convertible.data.render_with_liquid = false if convertible.ext == ".serb"
82
+ end
83
+ end
@@ -1,3 +1,5 @@
1
+ require "active_support/core_ext/string/output_safety"
2
+
1
3
  module Serbea
2
4
  module Helpers
3
5
  def self.included(mod)
@@ -20,23 +22,45 @@ module Serbea
20
22
  @_erbout = previous_buffer_state
21
23
  @output_buffer = previous_ob_state
22
24
 
23
- result.respond_to?(:html_safe) ? result.html_safe : result
25
+ result.html_safe
24
26
  end
25
27
 
26
28
  def pipeline(context, value)
27
29
  Pipeline.new(context, value)
28
30
  end
29
31
 
30
- def helper(name, &block)
31
- self.class.send(:define_method, name, &block)
32
+ def helper(name, &helper_block)
33
+ self.class.define_method(name) do |*args, &block|
34
+ previous_buffer_state = @_erbout
35
+ @_erbout = Serbea::Buffer.new
36
+
37
+ # For compatibility with ActionView, not used by Bridgetown normally
38
+ previous_ob_state = @output_buffer
39
+ @output_buffer = Serbea::Buffer.new
40
+
41
+ result = helper_block.call(*args, &block)
42
+ if @output_buffer != ""
43
+ # use Rails' ActionView buffer if present
44
+ result = @output_buffer
45
+ end
46
+ @_erbout = previous_buffer_state
47
+ @output_buffer = previous_ob_state
48
+
49
+ result.is_a?(String) ? result.html_safe : result
50
+ end
32
51
  end
52
+ alias_method :macro, :helper
33
53
 
34
54
  def h(input)
35
- result = Erubi.h(input)
36
- result.respond_to?(:html_safe) ? result.html_safe : result
55
+ ERB::Util.h(input.to_s)
37
56
  end
38
57
  alias_method :escape, :h
39
58
 
59
+ def safe(input)
60
+ input.to_s.html_safe
61
+ end
62
+ alias_method :raw, :safe
63
+
40
64
  def prepend(old_string, new_string)
41
65
  "#{new_string}#{old_string}"
42
66
  end
@@ -1,3 +1,5 @@
1
+ require "active_support/core_ext/string/output_safety"
2
+
1
3
  module Serbea
2
4
  class Pipeline
3
5
  def self.exec(template, input: (no_input_passed = true; nil), include_helpers: nil)
@@ -27,11 +29,17 @@ module Serbea
27
29
  end
28
30
  def self.output_processor
29
31
  @output_processor ||= lambda do |input|
30
- # no-op
31
- input
32
+ (!input.html_safe? && self.autoescape) ? ERB::Util.h(input) : input.html_safe
32
33
  end
33
34
  end
34
35
 
36
+ def self.autoescape=(config_boolean)
37
+ @autoescape = config_boolean
38
+ end
39
+ def self.autoescape
40
+ @autoescape.nil? ? true : @autoescape
41
+ end
42
+
35
43
  def self.raise_on_missing_filters=(config_boolean)
36
44
  @raise_on_missing_filters = config_boolean
37
45
  end
@@ -85,7 +93,7 @@ module Serbea
85
93
  end
86
94
 
87
95
  def to_s
88
- self.class.output_processor.call @value.to_s
96
+ self.class.output_processor.call(@value.is_a?(String) ? @value : @value.to_s)
89
97
  end
90
98
  end
91
99
  end
@@ -16,19 +16,7 @@ module Serbea
16
16
 
17
17
  new.compile(template, source)
18
18
  end
19
-
20
- # def cache_fragment(block, name = {}, options = nil)
21
- # @view.fragment_for(block, name, options) do
22
- # eval("_hamlout.buffer", block.binding)
23
- # end
24
- # end
25
19
  end
26
20
  end
27
21
 
28
22
  ActionView::Template.register_template_handler(:serb, Serbea::Plugin)
29
-
30
- if defined?(ActionController::Base)
31
- Serbea::Pipeline.output_processor = lambda do |input|
32
- input.html_safe? ? input : ActionController::Base.helpers.strip_tags(input)
33
- end
34
- end
@@ -38,7 +38,7 @@ module Serbea
38
38
 
39
39
  def add_postamble(postamble)
40
40
  src << postamble
41
- src << "#{@bufvar}.html_safe" if postamble.respond_to?(:html_safe)
41
+ src << "#{@bufvar}.html_safe"
42
42
 
43
43
  src.gsub!("__RAW_START_PRINT__", "{{")
44
44
  src.gsub!("__RAW_END_PRINT__", "}}")
@@ -127,8 +127,8 @@ module Serbea
127
127
 
128
128
  buff << text
129
129
  if code.length > 0
130
- code.sub! /^\{%@/, ""
131
- code.sub! /%}$/, ""
130
+ code.sub!(/^\{%@/, "")
131
+ code.sub!(/%}$/, "")
132
132
  unless ["end", ""].include? code.strip
133
133
  original_line_length = code.lines.size
134
134
 
@@ -1,3 +1,3 @@
1
1
  module Serbea
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
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("rake", "~> 13.0")
19
20
  spec.add_runtime_dependency("erubi", "~> 1.9")
21
+ spec.add_runtime_dependency("activesupport", "~> 6.0")
20
22
  spec.add_runtime_dependency("tilt", "~> 2.0")
21
23
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serbea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.4
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-10-27 00:00:00.000000000 Z
11
+ date: 2020-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: erubi
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: tilt
29
57
  requirement: !ruby/object:Gem::Requirement