Repository: yippee-fun/phlex (ruby)

Issue:
Rename `raw` to indicate just how unsafe it is



Discussion:

Patch:
diff --git a/docs/components/code_block.rb b/docs/components/code_block.rb
--- a/docs/components/code_block.rb
+++ b/docs/components/code_block.rb
@@ -11,7 +11,7 @@ def initialize(code, syntax:)
 
 		def template
 			pre(class: "highlight p-5 whitespace-pre-wrap bg-stone-50") {
-				raw FORMATTER.format(
+				unsafe_raw FORMATTER.format(
 					lexer.lex(@code)
 				)
 			}
diff --git a/docs/components/heading.rb b/docs/components/heading.rb
--- a/docs/components/heading.rb
+++ b/docs/components/heading.rb
@@ -3,7 +3,7 @@
 module Components
 	class Heading < Phlex::View
 		def template(&block)
-			h2(class: "text-2xl font-semibold mt-10 mb-5") { raw(&block) }
+			h2(class: "text-2xl font-semibold mt-10 mb-5") { unsafe_raw(&block) }
 		end
 	end
 end
diff --git a/docs/components/layout.rb b/docs/components/layout.rb
--- a/docs/components/layout.rb
+++ b/docs/components/layout.rb
@@ -17,7 +17,7 @@ def template(&block)
 					meta name: "viewport", content: "width=device-width, initial-scale=1"
 					title { @title }
 					link href: "/application.css", rel: "stylesheet"
-					style { raw Rouge::Theme.find("github").render(scope: ".highlight") }
+					style { unsafe_raw Rouge::Theme.find("github").render(scope: ".highlight") }
 				end
 
 				body class: "text-stone-700" do
@@ -25,7 +25,7 @@ def template(&block)
 						header class: "border-b py-4 px-4 lg:px-10 flex justify-between items-center sticky top-0 left-0 bg-white z-50" do
 							div class: "flex flex-row items-center gap-2" do
 								label for: "nav-toggle", class: "cursor-pointer lg:hidden" do
-									raw '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-8 h-8"> <path fill-rule="evenodd" d="M3 6.75A.75.75 0 013.75 6h16.5a.75.75 0 010 1.5H3.75A.75.75 0 013 6.75zM3 12a.75.75 0 01.75-.75h16.5a.75.75 0 010 1.5H3.75A.75.75 0 013 12zm0 5.25a.75.75 0 01.75-.75h16.5a.75.75 0 010 1.5H3.75a.75.75 0 01-.75-.75z" clip-rule="evenodd" /> </svg>'
+									unsafe_raw '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-8 h-8"> <path fill-rule="evenodd" d="M3 6.75A.75.75 0 013.75 6h16.5a.75.75 0 010 1.5H3.75A.75.75 0 013 6.75zM3 12a.75.75 0 01.75-.75h16.5a.75.75 0 010 1.5H3.75A.75.75 0 013 12zm0 5.25a.75.75 0 01.75-.75h16.5a.75.75 0 010 1.5H3.75a.75.75 0 01-.75-.75z" clip-rule="evenodd" /> </svg>'
 								end
 
 								a(href: "/", class: "block") { img src: "/assets/logo.png", width: "100" }
diff --git a/docs/components/markdown.rb b/docs/components/markdown.rb
--- a/docs/components/markdown.rb
+++ b/docs/components/markdown.rb
@@ -34,7 +34,7 @@ def initialize(content)
 		end
 
 		def template
-			raw MARKDOWN.render(@content)
+			unsafe_raw MARKDOWN.render(@content)
 		end
 	end
 end
diff --git a/docs/components/title.rb b/docs/components/title.rb
--- a/docs/components/title.rb
+++ b/docs/components/title.rb
@@ -3,7 +3,7 @@
 module Components
 	class Title < Phlex::View
 		def template(&block)
-			h1(class: "text-3xl font-semibold my-5") { raw(&block) }
+			h1(class: "text-3xl font-semibold my-5") { unsafe_raw(&block) }
 		end
 	end
 end
diff --git a/docs/pages/rails/helpers.rb b/docs/pages/rails/helpers.rb
--- a/docs/pages/rails/helpers.rb
+++ b/docs/pages/rails/helpers.rb
@@ -35,7 +35,7 @@ def template
 						Using these is equvalent to passing the output of the original Rails helpers to `raw`, e.g:
 
 						```ruby
-						raw helpers.javascript_include_tag
+						unsafe_raw helpers.javascript_include_tag
 						```
 
 						## Including proxies
diff --git a/lib/phlex/rails/helpers.rb b/lib/phlex/rails/helpers.rb
--- a/lib/phlex/rails/helpers.rb
+++ b/lib/phlex/rails/helpers.rb
@@ -29,7 +29,7 @@ def action_cable_meta_tag
 
 			module FormWith
 				def form_with(*args, **kwargs, &block)
-					raw @_view_context.form_with(*args, **kwargs) { |form|
+					@_target << @_view_context.form_with(*args, **kwargs) { |form|
 						capture do
 							yield(
 								Phlex::Buffered.new(form, buffer: @_target)
diff --git a/lib/phlex/renderable.rb b/lib/phlex/renderable.rb
--- a/lib/phlex/renderable.rb
+++ b/lib/phlex/renderable.rb
@@ -28,7 +28,7 @@ def render_in(view_context, &block)
 
 						if unchanged
 							if defined?(ActiveSupport::SafeBuffer) && output.is_a?(ActiveSupport::SafeBuffer)
-								raw(output)
+								unsafe_raw(output)
 							else
 								text(output)
 							end
diff --git a/lib/phlex/view.rb b/lib/phlex/view.rb
--- a/lib/phlex/view.rb
+++ b/lib/phlex/view.rb
@@ -101,7 +101,7 @@ def doctype
 			nil
 		end
 
-		def raw(content = nil, &block)
+		def unsafe_raw(content = nil, &block)
 			@_target << (content || instance_exec(&block))
 			nil
 		end


Test patch:
diff --git a/test/phlex/view/raw.rb b/test/phlex/view/unsafe_raw.rb
similarity index 85%
rename from test/phlex/view/raw.rb
rename to test/phlex/view/unsafe_raw.rb
--- a/test/phlex/view/raw.rb
+++ b/test/phlex/view/unsafe_raw.rb
@@ -8,7 +8,7 @@
 	with "raw content" do
 		view do
 			def template
-				raw %(<h1 class="test">Hello</h1>)
+				unsafe_raw %(<h1 class="test">Hello</h1>)
 			end
 		end