Skip to content

never gonna give you up - #826

Closed
Closed

Description

@wdiechmann

I know what it sounds like - but no, I'm not rick-rolling you 🤣

Anticipating 2.0 I've decided to try lining up early to the party gettin' a feel for the amount of work awaiting me in order to rewrite my app for 2.0 - but I don't know, it's like this @buffer never sinks in with me (remember the form_with and friends issue of "Christmas Past") so what do you say - got one more for the old Man?

Say I'd like to "write some text and part of it will be strong and some even STRONGER" (it's a lot more complex and ambitious than that but I reckon this will suffice to get me 'cross)

Reading the new https://beta.phlex.fun/ from doctype to </html> I figured I could do something like

<%= render Components::Text.new do |t|
    span { "write some text and part of it will be" }
    strong { "strong" }
    span { "and some even" }
    Components:TextStrong.new() { "STRONGER" } 
end %>

using

class Components::Text < Components::Base
  attr_accessor :css

  def initialize(css: nil)
    @css = css || "text-base/6 text-zinc-500 sm:text-sm/6 dark:text-zinc-400"
  end

  def view_template(&)
    p(class: css) { yield }
  end
end

# frozen_string_literal: true

class Components::TextStrong < Components::Base
  attr_accessor :css

  def initialize(css: nil)
    @css = css || "font-medium text-zinc-950 dark:text-white"
  end

  def view_template(&)
    strong(class: css) { yield }
  end
end


- but ah-no!

If I do

<%= render Components::Text.new do |c|
      c.span {"write some text and part of it will be"}
      c.strong {"strong"}
    end %>

I can have 'strong' (as a small token of appreciation for all my elephantizing-the-glass-store

So - there's the lay of the land - but you gotta' give me some credit for sticking with Phlex for all this time
😅 not knowing what the f* I'm doing 😎

Activity

  1. joeldrapper commented on Feb 3, 2025

    @joeldrapper
    Collaborator

    When rendering Phlex from ERB, you should use it more like this.

    <%= render Components::Text.new do %>
      <span>write some text and part of it will be</span>
      <strong>strong</strong>
      <span>and some even</span>
      <%= render Components:TextStrong.new do %>
        STRONGER
      <% end %>
    <% end %>

    The block passed in will be treated by Phlex as if it was an ERB block, not a Phlex block.

  2. pinned this issue on Feb 3, 2025
  3. unpinned this issue on Feb 3, 2025
  4. locked and limited conversation to collaborators on Feb 3, 2025
  5. converted this issue into a discussion #837 on Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions