Skip to content

Add better options building for props_template #56

@jho406

Description

@jho406

The syntax for options for props_template isn’t the most dev friendly. Here’s an example of what I mean:

json.note(
  partial: [
    "club_notes/note",
    fragment: "club_note_#{@club_note.id}",
    locals: {
      club_note: @club_note
    }
  ]
) do
# Empty block here
end

We’re using an empty block to distinguish between passing in options for additional props_template functionality or if we’re passing in object that we want to be part of a payload. I think we can make this better by introducing Props::Options

So the above, can now be

json.note Props::Options.new
  .partial(“club_notes/notes”, locals: {club_note: @club_note}
  .fragment(“club_note_#{@club_note.id}”)

Notice the fragment option no longer being nested (fragments must still exist with a partial).

We can also introduce a view helper like so:

json.note options
  .partial(“club_notes/notes”, locals: {club_note: @club_note}
  .fragment(“club_note_#{@club_note.id}”)

On the props_template side, we could just do a obj.is_a? Props::Options

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