Skip to content

Commit

Permalink
Update tests to use view_template
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Jan 30, 2024
1 parent a9e9a57 commit f8332e7
Show file tree
Hide file tree
Showing 30 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion fixtures/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(title: "Example")
@title = title
end

def template(&block)
def view_template(&block)
html do
head do
title { @title }
Expand Down
2 changes: 1 addition & 1 deletion fixtures/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Example
class Page < Phlex::HTML
def template
def view_template
render LayoutComponent.new do
h1 { "Hi" }

Expand Down
2 changes: 1 addition & 1 deletion lib/phlex/deferred_render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# @tabs = []
# end
#
# def template
# def view_template
# @tabs.each { |t| a { t.name } }
# @tabs.each { |t| article(&t.content) }
# end
Expand Down
2 changes: 1 addition & 1 deletion lib/phlex/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# class MyComponent < Phlex::HTML
# include MyCustomElements
#
# def template
# def view_template
# trix_editor
# end
# end
Expand Down
6 changes: 3 additions & 3 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def element_method?(method_name)

# @abstract Override to define a template for your component.
# @example
# def template
# def view_template
# h1 { "👋 Hello World!" }
# end
# @example Your template may yield a content block.
# def template
# def view_template
# main {
# h1 { "Hello World" }
# yield
# }
# end
# @example Alternatively, you can delegate the content block to an element.
# def template(&block)
# def view_template(&block)
# article(class: "card", &block)
# end
def template
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def before_template
h1 { "Hello" }
end

def template
def view_template
h2 { "World" }
end

Expand Down
6 changes: 3 additions & 3 deletions test/phlex/render_enumerable.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Card < Phlex::HTML
def template(&block)
def view_template(&block)
article(&block)
end
end
Expand All @@ -14,13 +14,13 @@ def initialize
]
end

def template
def view_template
render @cards
end
end

class WithBlock < WithoutBlock
def template
def view_template
render @cards do
h1 { "Hi" }
end
Expand Down
4 changes: 2 additions & 2 deletions test/phlex/svg.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

class Example < Phlex::SVG
def template
def view_template
svg do
path(d: "123")
end
end
end

class ExampleFromHTML < Phlex::HTML
def template
def view_template
svg do |s|
s.path(d: "321")
end
Expand Down
4 changes: 2 additions & 2 deletions test/phlex/testing/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
require "phlex/testing/view_helper"

class ExampleHTML < Phlex::HTML
def template
def view_template
h1 { "👋" }
end
end

class ExampleSVG < Phlex::SVG
def template
def view_template
svg do
path(d: "123")
end
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/unbuffered.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Example < Phlex::HTML
def template
def view_template
yield
end

Expand Down
2 changes: 1 addition & 1 deletion test/phlex/view/around_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def around_template
h3 { "After" }
end

def template
def view_template
h2 { "Hello" }
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/phlex/view/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extend ViewHelper

view do
def template
def view_template
plain "Hi"
end
end
Expand All @@ -17,7 +17,7 @@ def template

with "`render?` method returning false when the view context is true" do
view do
def template
def view_template
plain "Hi"
end

Expand All @@ -29,7 +29,7 @@ def render?

with "a view that yields an object" do
view do
def template
def view_template
yield(1, 2)
end
end
Expand All @@ -47,7 +47,7 @@ def template

with "a view that yields nothing" do
view do
def template
def view_template
yield
end

Expand Down
12 changes: 6 additions & 6 deletions test/phlex/view/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
view do
attr_accessor :captured

def template
def view_template
h1 { "Before" }
@captured = capture { "Hello" }
h1 { "After" }
Expand All @@ -24,7 +24,7 @@ def template
view do
attr_accessor :captured

def template
def view_template
h1 { "Before" }
@captured = capture do
h1 { "Hello" }
Expand All @@ -43,7 +43,7 @@ def template
view do
attr_accessor :captured

def template
def view_template
h1 { "Before" }
@captured = capture do
h1 { "Hello" }
Expand All @@ -63,7 +63,7 @@ def template
with "a call to flush inside a component rendered in the block" do
let(:component) do
Class.new(Phlex::HTML) do
def template
def view_template
h1 { "Hello" }
flush
h1 { "World" }
Expand All @@ -73,7 +73,7 @@ def template

let(:previewer) do
Class.new(Phlex::HTML) do
def template
def view_template
srcdoc = capture { yield } if block_given?

iframe srcdoc: srcdoc
Expand All @@ -82,7 +82,7 @@ def template
end

view do
def template
def view_template
h1 { "Before" }
render @_view_context.previewer do
render @_view_context.component
Expand Down
8 changes: 4 additions & 4 deletions test/phlex/view/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

with "simple comment" do
view do
def template
def view_template
comment { "This is an HTML comment" }
end
end
Expand All @@ -17,7 +17,7 @@ def template

with "empty comment" do
view do
def template
def view_template
comment
end
end
Expand All @@ -29,7 +29,7 @@ def template

with "number comment" do
view do
def template
def view_template
comment { 1 }
end
end
Expand All @@ -41,7 +41,7 @@ def template

with "escaped comment" do
view do
def template
def view_template
comment { "<b>Important</b>" }
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/view/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

with "content" do
view do
def template
def view_template
h1 { "Before" }
yield
h2 { "After" }
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/view/custom_elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
register_element :trix_editor
register_element :trix_toolbar

def template
def view_template
div do
trix_toolbar
trix_editor { "Hello" }
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/view/doctype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

with "a doctype" do
view do
def template
def view_template
html do
head { doctype }
end
Expand Down
2 changes: 1 addition & 1 deletion test/phlex/view/format_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "date"

class Example < Phlex::HTML
def template
def view_template
h1 { Date.new(2022, 11, 28) }
end

Expand Down
12 changes: 6 additions & 6 deletions test/phlex/view/naughty_business.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

with "naughty text" do
view do
def template
def view_template
plain %("><script type="text/javascript" src="bad_script.js"></script>)
end
end
Expand All @@ -17,7 +17,7 @@ def template

with "naughty tag attribute values" do
view do
def template
def view_template
article id: %("><script type="text/javascript" src="bad_script.js"></script>)
end
end
Expand All @@ -29,7 +29,7 @@ def template

with "naughty javascript link protocol in href" do
view do
def template
def view_template
a href: "javascript:javascript:alert(1)" do
"naughty link"
end
Expand All @@ -43,7 +43,7 @@ def template

with "naughty javascript link protocol in href" do
view do
def template
def view_template
a "href" => "javascript:javascript:alert(1)" do
"naughty link"
end
Expand All @@ -60,7 +60,7 @@ def template
naughty_attributes = { event_attribute => "alert(1);" }

view do
define_method :template do
define_method :view_template do
send(:div, **naughty_attributes)
end
end
Expand All @@ -78,7 +78,7 @@ def template
naughty_attributes = { naughty_attribute => "alert(1);" }

view do
define_method :template do
define_method :view_template do
send(:div, **naughty_attributes)
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/phlex/view/new.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Example < Phlex::HTML
def template(&block)
def view_template(&block)
h1(&block)
end
end
Expand All @@ -16,7 +16,7 @@ def render?
@should_render
end

def template
def view_template
h1 {
yield
plain(", #{@name}")
Expand All @@ -29,7 +29,7 @@ def template

with "a block passed to new" do
view do
def template
def view_template
render Example.new { "Hello" }
end
end
Expand All @@ -41,7 +41,7 @@ def template

with "a block and arguments passed to new" do
view do
def template
def view_template
render ExampleWithArgs.new("World", should_render: true) { "Hello" }
end
end
Expand Down
Loading

0 comments on commit f8332e7

Please sign in to comment.