From 51e63603d84ec19e61395a04e5d37ca1d3f1399e Mon Sep 17 00:00:00 2001 From: Jeremy Jackson Date: Mon, 17 Nov 2025 15:38:32 -0700 Subject: [PATCH 1/2] Attempts to avoid namespace issues with handlebars.rb --- lib/ruby-handlebars.rb | 4 ++-- lib/ruby-handlebars/context.rb | 2 +- lib/ruby-handlebars/template.rb | 4 ++-- spec/ruby-handlebars/context_spec.rb | 5 ++--- spec/ruby-handlebars/helpers/each_helper_spec.rb | 2 +- .../helpers/helper_missing_helper_spec.rb | 9 ++------- spec/ruby-handlebars/helpers/if_helper_spec.rb | 2 +- spec/ruby-handlebars/helpers/unless_helper_spec.rb | 2 +- 8 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/ruby-handlebars.rb b/lib/ruby-handlebars.rb index a554942..d883f53 100644 --- a/lib/ruby-handlebars.rb +++ b/lib/ruby-handlebars.rb @@ -19,7 +19,7 @@ def initialize() end def compile(template) - Template.new(self, template_to_ast(template)) + TemplateHandler.new(self, template_to_ast(template)) end def register_helper(name, &fn) @@ -45,7 +45,7 @@ def register_partial(name, content) def get_partial(name) raise(::Handlebars::MissingPartial, "Partial \"#{name}\" not registered.") unless @partials[name.to_s] - @partials[name.to_s][:compiled] ||= Template.new(self, template_to_ast(@partials[name.to_s][:content])) + @partials[name.to_s][:compiled] ||= TemplateHandler.new(self, template_to_ast(@partials[name.to_s][:content])) end def set_escaper(escaper = nil) diff --git a/lib/ruby-handlebars/context.rb b/lib/ruby-handlebars/context.rb index 6dedd1f..40a867a 100644 --- a/lib/ruby-handlebars/context.rb +++ b/lib/ruby-handlebars/context.rb @@ -1,7 +1,7 @@ require "forwardable" module Handlebars - class Context + class ContextHandler PATH_REGEX = /\.\.\/|[^.\/]+/ class Data diff --git a/lib/ruby-handlebars/template.rb b/lib/ruby-handlebars/template.rb index 25020b7..0005da1 100644 --- a/lib/ruby-handlebars/template.rb +++ b/lib/ruby-handlebars/template.rb @@ -1,14 +1,14 @@ require_relative 'context' module Handlebars - class Template + class TemplateHandler def initialize(hbs, ast) @hbs = hbs @ast = ast end def call(args = nil) - ctx = Context.new(@hbs, args) + ctx = ContextHandler.new(@hbs, args) @ast.eval(ctx) end diff --git a/spec/ruby-handlebars/context_spec.rb b/spec/ruby-handlebars/context_spec.rb index 68eacee..bdf0694 100644 --- a/spec/ruby-handlebars/context_spec.rb +++ b/spec/ruby-handlebars/context_spec.rb @@ -1,7 +1,6 @@ -require_relative '../spec_helper' -require_relative '../../lib/ruby-handlebars/context' +require 'spec_helper' -describe Handlebars::Context do +describe Handlebars::ContextHandler do let(:ctx) { described_class.new(nil, data) } context 'get' do diff --git a/spec/ruby-handlebars/helpers/each_helper_spec.rb b/spec/ruby-handlebars/helpers/each_helper_spec.rb index 9b3f86a..2b78393 100644 --- a/spec/ruby-handlebars/helpers/each_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/each_helper_spec.rb @@ -4,7 +4,7 @@ describe Handlebars::Helpers::EachHelper do let(:subject) { Handlebars::Helpers::EachHelper } let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::Context.new(hbs, {})} + let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} it_behaves_like "a registerable helper", "each" diff --git a/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb b/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb index 598b80d..4cf1c50 100644 --- a/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb @@ -1,15 +1,10 @@ -require_relative '../../spec_helper' +require 'spec_helper' require_relative './shared' -require_relative '../../../lib/ruby-handlebars' -require_relative '../../../lib/ruby-handlebars/tree' -require_relative '../../../lib/ruby-handlebars/helpers/helper_missing_helper' - - describe Handlebars::Helpers::HelperMissingHelper do let(:subject) { Handlebars::Helpers::HelperMissingHelper } let(:hbs) { Handlebars::Handlebars.new } - let(:ctx) {Handlebars::Context.new(hbs, {})} + let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} it_behaves_like "a registerable helper", "helperMissing" diff --git a/spec/ruby-handlebars/helpers/if_helper_spec.rb b/spec/ruby-handlebars/helpers/if_helper_spec.rb index d8cf594..5a32c09 100644 --- a/spec/ruby-handlebars/helpers/if_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/if_helper_spec.rb @@ -4,7 +4,7 @@ describe Handlebars::Helpers::IfHelper do let(:subject) { Handlebars::Helpers::IfHelper } let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::Context.new(hbs, {})} + let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} it_behaves_like "a registerable helper", "if" diff --git a/spec/ruby-handlebars/helpers/unless_helper_spec.rb b/spec/ruby-handlebars/helpers/unless_helper_spec.rb index ca77c51..e19e3cf 100644 --- a/spec/ruby-handlebars/helpers/unless_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/unless_helper_spec.rb @@ -4,7 +4,7 @@ describe Handlebars::Helpers::UnlessHelper do let(:subject) { Handlebars::Helpers::UnlessHelper } let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::Context.new(hbs, {})} + let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} it_behaves_like "a registerable helper", "unless" From a43a97ef0b5298e9e3f51198c366cc8ff6946871 Mon Sep 17 00:00:00 2001 From: Jeremy Jackson Date: Tue, 2 Dec 2025 15:39:20 +0100 Subject: [PATCH 2/2] Restores namespaces. --- lib/ruby-handlebars.rb | 4 ++-- lib/ruby-handlebars/context.rb | 2 +- lib/ruby-handlebars/template.rb | 4 ++-- spec/ruby-handlebars/context_spec.rb | 2 +- spec/ruby-handlebars/helpers/each_helper_spec.rb | 4 ++-- spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb | 2 +- spec/ruby-handlebars/helpers/if_helper_spec.rb | 4 ++-- spec/ruby-handlebars/helpers/unless_helper_spec.rb | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/ruby-handlebars.rb b/lib/ruby-handlebars.rb index d883f53..a554942 100644 --- a/lib/ruby-handlebars.rb +++ b/lib/ruby-handlebars.rb @@ -19,7 +19,7 @@ def initialize() end def compile(template) - TemplateHandler.new(self, template_to_ast(template)) + Template.new(self, template_to_ast(template)) end def register_helper(name, &fn) @@ -45,7 +45,7 @@ def register_partial(name, content) def get_partial(name) raise(::Handlebars::MissingPartial, "Partial \"#{name}\" not registered.") unless @partials[name.to_s] - @partials[name.to_s][:compiled] ||= TemplateHandler.new(self, template_to_ast(@partials[name.to_s][:content])) + @partials[name.to_s][:compiled] ||= Template.new(self, template_to_ast(@partials[name.to_s][:content])) end def set_escaper(escaper = nil) diff --git a/lib/ruby-handlebars/context.rb b/lib/ruby-handlebars/context.rb index 40a867a..6dedd1f 100644 --- a/lib/ruby-handlebars/context.rb +++ b/lib/ruby-handlebars/context.rb @@ -1,7 +1,7 @@ require "forwardable" module Handlebars - class ContextHandler + class Context PATH_REGEX = /\.\.\/|[^.\/]+/ class Data diff --git a/lib/ruby-handlebars/template.rb b/lib/ruby-handlebars/template.rb index 0005da1..25020b7 100644 --- a/lib/ruby-handlebars/template.rb +++ b/lib/ruby-handlebars/template.rb @@ -1,14 +1,14 @@ require_relative 'context' module Handlebars - class TemplateHandler + class Template def initialize(hbs, ast) @hbs = hbs @ast = ast end def call(args = nil) - ctx = ContextHandler.new(@hbs, args) + ctx = Context.new(@hbs, args) @ast.eval(ctx) end diff --git a/spec/ruby-handlebars/context_spec.rb b/spec/ruby-handlebars/context_spec.rb index bdf0694..cb6f2c4 100644 --- a/spec/ruby-handlebars/context_spec.rb +++ b/spec/ruby-handlebars/context_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Handlebars::ContextHandler do +describe Handlebars::Context do let(:ctx) { described_class.new(nil, data) } context 'get' do diff --git a/spec/ruby-handlebars/helpers/each_helper_spec.rb b/spec/ruby-handlebars/helpers/each_helper_spec.rb index 2b78393..b9322c8 100644 --- a/spec/ruby-handlebars/helpers/each_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/each_helper_spec.rb @@ -3,8 +3,8 @@ describe Handlebars::Helpers::EachHelper do let(:subject) { Handlebars::Helpers::EachHelper } - let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} + let(:hbs) { Handlebars::Handlebars.new } + let(:ctx) { Handlebars::Context.new(hbs, {}) } it_behaves_like "a registerable helper", "each" diff --git a/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb b/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb index 4cf1c50..2bc2fe8 100644 --- a/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/helper_missing_helper_spec.rb @@ -4,7 +4,7 @@ describe Handlebars::Helpers::HelperMissingHelper do let(:subject) { Handlebars::Helpers::HelperMissingHelper } let(:hbs) { Handlebars::Handlebars.new } - let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} + let(:ctx) { Handlebars::Context.new(hbs, {}) } it_behaves_like "a registerable helper", "helperMissing" diff --git a/spec/ruby-handlebars/helpers/if_helper_spec.rb b/spec/ruby-handlebars/helpers/if_helper_spec.rb index 5a32c09..ef8f959 100644 --- a/spec/ruby-handlebars/helpers/if_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/if_helper_spec.rb @@ -3,8 +3,8 @@ describe Handlebars::Helpers::IfHelper do let(:subject) { Handlebars::Helpers::IfHelper } - let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} + let(:hbs) { Handlebars::Handlebars.new} + let(:ctx) { Handlebars::Context.new(hbs, {}) } it_behaves_like "a registerable helper", "if" diff --git a/spec/ruby-handlebars/helpers/unless_helper_spec.rb b/spec/ruby-handlebars/helpers/unless_helper_spec.rb index e19e3cf..7a5dfa5 100644 --- a/spec/ruby-handlebars/helpers/unless_helper_spec.rb +++ b/spec/ruby-handlebars/helpers/unless_helper_spec.rb @@ -3,8 +3,8 @@ describe Handlebars::Helpers::UnlessHelper do let(:subject) { Handlebars::Helpers::UnlessHelper } - let(:hbs) {Handlebars::Handlebars.new} - let(:ctx) {Handlebars::ContextHandler.new(hbs, {})} + let(:hbs) { Handlebars::Handlebars.new } + let(:ctx) { Handlebars::Context.new(hbs, {}) } it_behaves_like "a registerable helper", "unless"