Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Dec 16, 2024
1 parent 1e31e90 commit 19e630d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3 2024-12-16

- Update dependencies

## 1.2 2023-08-21

- Update dependencies
Expand Down
16 changes: 8 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ PATH
specs:
papercraft (1.2)
escape_utils (~> 1.3.0)
kramdown (~> 2.4.0)
kramdown (~> 2.5.1)
kramdown-parser-gfm (~> 1.1.0)
rouge (~> 4.2.0)
rouge (~> 4.5.1)
sirop (~> 0.4)

GEM
Expand All @@ -14,14 +14,14 @@ GEM
benchmark-ips (2.7.2)
erubis (2.7.0)
escape_utils (1.3.0)
kramdown (2.4.0)
rexml
kramdown (2.5.1)
rexml (>= 3.3.9)
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
minitest (5.22.3)
minitest (5.25.4)
prism (0.27.0)
rexml (3.2.6)
rouge (4.2.1)
rexml (3.4.0)
rouge (4.5.1)
sirop (0.4)
prism (~> 0.27.0)
tilt (2.2.0)
Expand All @@ -34,7 +34,7 @@ PLATFORMS
DEPENDENCIES
benchmark-ips (~> 2.7.2)
erubis (~> 2.7.0)
minitest (~> 5.22.0)
minitest (~> 5.25.4)
papercraft!
tilt (~> 2.2.0)

Expand Down
46 changes: 45 additions & 1 deletion lib/papercraft/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def initialize
end

def compile(node)
@root_node = node
inject_buffer_parameter(node)

@buffer.clear
Expand Down Expand Up @@ -96,7 +97,13 @@ def flush_html_buffer
if @last_loc_start
adjust_whitespace(@html_location_start) if @html_location_start
end
@buffer << "__buffer__ << \"#{@html_buffer}\""
if @defer_proc_mode
@buffer << "__b__ << \"#{@html_buffer}\""
elsif @defer_mode
@buffer << "__parts__ << \"#{@html_buffer}\""
else
@buffer << "__buffer__ << \"#{@html_buffer}\""
end
@html_buffer.clear
@last_loc_end = loc_end(@html_location_end) if @html_location_end

Expand All @@ -114,6 +121,10 @@ def visit_call_node(node)
emit_html_text(node)
when :emit
emit_html_emit(node)
when :emit_yield
raise NotImplementedError, "emit_yield is not yet supported in compiled templates"
when :defer
emit_html_deferred(node)
else
emit_html_tag(node)
end
Expand Down Expand Up @@ -216,4 +227,37 @@ def emit_html_emit(node)

embed_visit(node.arguments, '#{Papercraft.render_emit_call(', ')}')
end

def emit_html_deferred(node)
raise NotImplementedError, "#defer in embed mode is not supported in compiled templates" if @embed_mode

block = node.block
return if not block

setup_defer_mode if !@defer_mode

flush_html_buffer
@buffer << ';__parts__ << ->(__b__) '
@defer_proc_mode = true
visit(node.block)
@defer_proc_mode = nil
end

DEFER_PREFIX_EMPTY = "; __parts__ = []"
DEFER_PREFIX_NOT_EMPTY = "; __parts__ = [__buffer__.dup]; __buffer__.clear"
DEFER_POSTFIX = ";__parts__.each { |p| p.is_a?(Proc) ? p.(__buffer__) : (__buffer__ << p) }"

def setup_defer_mode
@defer_mode = true
if @html_buffer && !@html_buffer.empty?
@buffer << DEFER_PREFIX_NOT_EMPTY
else
@buffer << DEFER_PREFIX_EMPTY
end

@root_node.after_body do
flush_html_buffer
@buffer << DEFER_POSTFIX
end
end
end
2 changes: 1 addition & 1 deletion lib/papercraft/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Papercraft
VERSION = '1.2'
VERSION = '1.3'
end
6 changes: 3 additions & 3 deletions papercraft.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'sirop', '~>0.4'
s.add_runtime_dependency 'escape_utils', '~>1.3.0'
s.add_runtime_dependency 'kramdown', '~>2.4.0'
s.add_runtime_dependency 'rouge', '~>4.2.0'
s.add_runtime_dependency 'kramdown', '~>2.5.1'
s.add_runtime_dependency 'rouge', '~>4.5.1'
s.add_runtime_dependency 'kramdown-parser-gfm', '~>1.1.0'

s.add_development_dependency 'minitest', '~>5.22.0'
s.add_development_dependency 'minitest', '~>5.25.4'
s.add_development_dependency 'benchmark-ips', '~>2.7.2'
s.add_development_dependency 'erubis', '~>2.7.0'
s.add_development_dependency 'tilt', '~>2.2.0'
Expand Down

0 comments on commit 19e630d

Please sign in to comment.