From aab80b10bc481fad48c1f6e15f2c1277f66e343e Mon Sep 17 00:00:00 2001 From: Josh LeBlanc Date: Sun, 14 Jan 2024 11:44:49 -0400 Subject: [PATCH 1/4] introduce props mimetype --- lib/props_template/railtie.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/props_template/railtie.rb b/lib/props_template/railtie.rb index b8ce520..ec79217 100644 --- a/lib/props_template/railtie.rb +++ b/lib/props_template/railtie.rb @@ -5,6 +5,7 @@ module Props class Railtie < ::Rails::Railtie initializer :props_template do ActiveSupport.on_load :action_view do + Mime::Type.register "application/vnd.thoughtbot.props+json", :props ActionView::Template.register_template_handler :props, Props::Handler require "props_template/dependency_tracker" require "props_template/layout_patch" From 0fd040c27f8b52c70ebab10a71a44b50bebedb9f Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Sun, 14 Jan 2024 12:09:05 -0400 Subject: [PATCH 2/4] change formats to props --- lib/props_template/extensions/partial_renderer.rb | 2 +- lib/props_template/handler.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/props_template/extensions/partial_renderer.rb b/lib/props_template/extensions/partial_renderer.rb index 823dd20..e27e638 100644 --- a/lib/props_template/extensions/partial_renderer.rb +++ b/lib/props_template/extensions/partial_renderer.rb @@ -81,7 +81,7 @@ def block_opts_to_render_opts(builder, options) pass_opts ||= {} pass_opts[:locals] ||= {} pass_opts[:partial] = partial - pass_opts[:formats] = [:json] + pass_opts[:formats] = [:props] pass_opts.delete(:handlers) if !(String === partial) diff --git a/lib/props_template/handler.rb b/lib/props_template/handler.rb index 79d71b2..7d845b2 100644 --- a/lib/props_template/handler.rb +++ b/lib/props_template/handler.rb @@ -3,7 +3,7 @@ module Props class Handler cattr_accessor :default_format - self.default_format = :json + self.default_format = :props def self.call(template, source = nil) source ||= template.source From 8f812ea136399f08edd46082b78ce0535a96e69a Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Sun, 14 Jan 2024 12:38:39 -0400 Subject: [PATCH 3/4] rename props to pbuilder --- lib/props_template/railtie.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/props_template/railtie.rb b/lib/props_template/railtie.rb index ec79217..bb0574a 100644 --- a/lib/props_template/railtie.rb +++ b/lib/props_template/railtie.rb @@ -6,7 +6,7 @@ class Railtie < ::Rails::Railtie initializer :props_template do ActiveSupport.on_load :action_view do Mime::Type.register "application/vnd.thoughtbot.props+json", :props - ActionView::Template.register_template_handler :props, Props::Handler + ActionView::Template.register_template_handler :pbuilder, Props::Handler require "props_template/dependency_tracker" require "props_template/layout_patch" end From ccf79ce416e87863929eb9c448d7912e097224db Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Thu, 25 Jan 2024 14:36:26 -0400 Subject: [PATCH 4/4] Allow customizing default format --- lib/props_template/extensions/partial_renderer.rb | 2 +- lib/props_template/handler.rb | 2 +- lib/props_template/railtie.rb | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/props_template/extensions/partial_renderer.rb b/lib/props_template/extensions/partial_renderer.rb index e27e638..7aa2892 100644 --- a/lib/props_template/extensions/partial_renderer.rb +++ b/lib/props_template/extensions/partial_renderer.rb @@ -81,7 +81,7 @@ def block_opts_to_render_opts(builder, options) pass_opts ||= {} pass_opts[:locals] ||= {} pass_opts[:partial] = partial - pass_opts[:formats] = [:props] + pass_opts[:formats] = [Handler.default_format] pass_opts.delete(:handlers) if !(String === partial) diff --git a/lib/props_template/handler.rb b/lib/props_template/handler.rb index 7d845b2..79d71b2 100644 --- a/lib/props_template/handler.rb +++ b/lib/props_template/handler.rb @@ -3,7 +3,7 @@ module Props class Handler cattr_accessor :default_format - self.default_format = :props + self.default_format = :json def self.call(template, source = nil) source ||= template.source diff --git a/lib/props_template/railtie.rb b/lib/props_template/railtie.rb index bb0574a..b8ce520 100644 --- a/lib/props_template/railtie.rb +++ b/lib/props_template/railtie.rb @@ -5,8 +5,7 @@ module Props class Railtie < ::Rails::Railtie initializer :props_template do ActiveSupport.on_load :action_view do - Mime::Type.register "application/vnd.thoughtbot.props+json", :props - ActionView::Template.register_template_handler :pbuilder, Props::Handler + ActionView::Template.register_template_handler :props, Props::Handler require "props_template/dependency_tracker" require "props_template/layout_patch" end