Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including hoshi from a outside class #2

Open
madhermit opened this issue Jun 8, 2020 · 3 comments
Open

Including hoshi from a outside class #2

madhermit opened this issue Jun 8, 2020 · 3 comments

Comments

@madhermit
Copy link

madhermit commented Jun 8, 2020

Hi @pete

I have an outside class that has a to_hoshi method. How can I have that method interpolated into the Hoshi output of my view class in Watts. Here is an example:

require "hoshi"

class Foo < Hoshi::View :html5
  def show
    h1 "inside Foo#show"
    Bar.new.inclusion
    inclusion
  end

  def inclusion
    h2 "inside Foo#inclusion"
  end
end

class Bar
  def inclusion
    h2 "inside Bar#inclusion"
  end
end

puts Foo.new.show

Desired output:

<h1>inside Foo#show</h1>
<h2>inside Bar#inclusion</h2>
<h2>inside Foo#inclusion</h2>

Current output:
inclusion': undefined method 'h2' for #<Bar:0x0055dafd73e988> (NoMethodError)

Thanks!

@pete
Copy link
Owner

pete commented Jun 9, 2020

Bar would have to subclass Foo or Hoshi::View for that to work.

1 similar comment
@pete
Copy link
Owner

pete commented Jun 9, 2020

Bar would have to subclass Foo or Hoshi::View for that to work.

@madhermit
Copy link
Author

Thanks for the response!

Subclassing Bar with Foo or Hoshi::View :html5 results in:

<h1>inside Foo#show</h1>
<h2>inside Foo#inclusion</h2>

Missing the interpolation of <h2>inside Bar#inclusion</h2>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants