Spark - reading child options

Hi All I have defined the following DSL
crud do
attributes([:name, :email, :joined])
root_url("/crud")

read do
layout(&AshCrudWeb.Layouts.app/1)
end
end
crud do
attributes([:name, :email, :joined])
root_url("/crud")

read do
layout(&AshCrudWeb.Layouts.app/1)
end
end
I can use the following to get the value of root_url...
root_url =
Spark.Dsl.Extension.get_opt(resource, [:crud], :root_url, nil, true)
root_url =
Spark.Dsl.Extension.get_opt(resource, [:crud], :root_url, nil, true)
Reading the docs I thought I could get the value of layout with....
layout = Spark.Dsl.Extension.get_opt(resource, [:crud, :read], :layout, nil, true)
layout = Spark.Dsl.Extension.get_opt(resource, [:crud, :read], :layout, nil, true)
but this always returns nil despite the fact the value is configured. I've read the Spark docs and I'm getting myself confused (easily done). Any pointers as to what I'm doing wrong? Many thanks in advance.
4 Replies
ZachDaniel
ZachDaniel3w ago
Can I see the DSL? is read an entity or a section?
D B Simmons
D B SimmonsOP3w ago
The DSL is....
defmodule AshCrud.Dsl do
defmodule Read do
defstruct [:layout]
end



@read %Spark.Dsl.Entity{
name: :read,
target: Read,
describe: "Define attribute for a CRUD read",
schema: [
layout: [
type: {:fun, 1}
]
]
}
@crud %Spark.Dsl.Section{
name: :crud,
schema: [
attributes: [
type: {:list, :atom},
required: true,
doc: "A list of atoms representing the attributes to use in the CRUD pages"
],
root_url: [
type: :string,
required: true,
doc: "The base of the url used for routing to CRUD pages"
]
],
entities: [
@create,
@read,
@update,
@delete
]
}


use Spark.Dsl.Extension,
sections: [@crud],
verifiers: [
AshCrud.Verifiers.VerifyAttributes
]
end
defmodule AshCrud.Dsl do
defmodule Read do
defstruct [:layout]
end



@read %Spark.Dsl.Entity{
name: :read,
target: Read,
describe: "Define attribute for a CRUD read",
schema: [
layout: [
type: {:fun, 1}
]
]
}
@crud %Spark.Dsl.Section{
name: :crud,
schema: [
attributes: [
type: {:list, :atom},
required: true,
doc: "A list of atoms representing the attributes to use in the CRUD pages"
],
root_url: [
type: :string,
required: true,
doc: "The base of the url used for routing to CRUD pages"
]
],
entities: [
@create,
@read,
@update,
@delete
]
}


use Spark.Dsl.Extension,
sections: [@crud],
verifiers: [
AshCrud.Verifiers.VerifyAttributes
]
end
ZachDaniel
ZachDaniel3w ago
Entities are stored and retrieved differently You'd ask for the entities inside of the crud section You can derive that all with Spark.InfoGenerator, which defines functions you can look at in iex etc.
D B Simmons
D B SimmonsOP3w ago
Thanks @ZachDaniel - I'll give it a go - appreciate the pointer.

Did you find this page helpful?