diff --git a/Gemfile.lock b/Gemfile.lock index b7001d5..b1a747b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,12 @@ PATH remote: . specs: - papercraft (1.2) + papercraft (1.3) escape_utils (~> 1.3.0) kramdown (~> 2.5.1) kramdown-parser-gfm (~> 1.1.0) rouge (~> 4.5.1) - sirop (~> 0.4) + sirop (~> 0.5) GEM remote: https://rubygems.org/ @@ -22,7 +22,7 @@ GEM prism (0.27.0) rexml (3.4.0) rouge (4.5.1) - sirop (0.4) + sirop (0.5) prism (~> 0.27.0) tilt (2.2.0) diff --git a/lib/papercraft.rb b/lib/papercraft.rb index 55ebef4..7363fea 100644 --- a/lib/papercraft.rb +++ b/lib/papercraft.rb @@ -1,13 +1,8 @@ # frozen_string_literal: true -require 'kramdown' -require 'rouge' -require 'kramdown-parser-gfm' - require_relative 'papercraft/template' require_relative 'papercraft/renderer' -require_relative 'papercraft/compiler' - +# require_relative 'papercraft/compiler' # Papercraft is a composable templating library module Papercraft @@ -82,6 +77,11 @@ def json(o = nil, mime_type: nil, &template) # @param opts [Hash] Kramdown option overrides # @return [String] HTML def markdown(markdown, **opts) + # require relevant deps on use + require 'kramdown' + require 'rouge' + require 'kramdown-parser-gfm' + opts = default_kramdown_options.merge(opts) Kramdown::Document.new(markdown, **opts).to_html end diff --git a/papercraft.gemspec b/papercraft.gemspec index 1eddc7a..a0c6dff 100644 --- a/papercraft.gemspec +++ b/papercraft.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.required_ruby_version = '>= 3.2' - s.add_runtime_dependency 'sirop', '~>0.4' + s.add_runtime_dependency 'sirop', '~>0.5' s.add_runtime_dependency 'escape_utils', '~>1.3.0' s.add_runtime_dependency 'kramdown', '~>2.5.1' s.add_runtime_dependency 'rouge', '~>4.5.1' diff --git a/test/fixtures/compiler/defer.html b/test/fixtures/compiler/defer.html new file mode 100644 index 0000000..6e8c77a --- /dev/null +++ b/test/fixtures/compiler/defer.html @@ -0,0 +1 @@ +

bar

\ No newline at end of file diff --git a/test/fixtures/compiler/defer_compiled.rb b/test/fixtures/compiler/defer_compiled.rb new file mode 100644 index 0000000..3b4d9d5 --- /dev/null +++ b/test/fixtures/compiler/defer_compiled.rb @@ -0,0 +1,7 @@ +->(__buffer__) {; __parts__ = [__buffer__.dup]; __buffer__.clear + __parts__ << "
";__parts__ << ->(__b__) { + __b__ << "

#{CGI.escapeHTML((@foo).to_s)}

" + } + @foo = 'bar' + __parts__ << "
";__parts__.each { |p| p.is_a?(Proc) ? p.(__buffer__) : (__buffer__ << p) } +} diff --git a/test/fixtures/compiler/defer_source.rb b/test/fixtures/compiler/defer_source.rb new file mode 100644 index 0000000..8c538aa --- /dev/null +++ b/test/fixtures/compiler/defer_source.rb @@ -0,0 +1,8 @@ +->() { + div { + defer { + h1 @foo + } + @foo = 'bar' + } +} diff --git a/test/test_compiler.rb b/test/test_compiler.rb index 6d0234e..fd4301e 100644 --- a/test/test_compiler.rb +++ b/test/test_compiler.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative './helper' +require_relative '../lib/papercraft/compiler' class CompilerTest < Minitest::Test Dir["#{FIXTURES_PATH}/compiler/*_source.rb"].each do |fn|