-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
647 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
defmodule Sassone.Builder.Description do | ||
@moduledoc """ | ||
A struct representing the description of an XML resource element or attribute. | ||
""" | ||
|
||
@type type :: :element | :attribute | ||
|
||
@type field_name :: atom() | ||
|
||
@type t :: %__MODULE__{ | ||
field_name: field_name(), | ||
deserialize: boolean(), | ||
many: boolean(), | ||
resource: module(), | ||
serialize: boolean(), | ||
type: type(), | ||
recased_name: String.t() | ||
} | ||
|
||
@enforce_keys [:field_name, :deserialize, :serialize, :type, :recased_name] | ||
defstruct field_name: nil, | ||
deserialize: true, | ||
many: false, | ||
resource: nil, | ||
serialize: true, | ||
type: nil, | ||
recased_name: nil | ||
|
||
schema = [ | ||
case: [ | ||
doc: "Recase the resource field names automatically with the given strategy.", | ||
type: {:in, [:pascal, :camel, :snake, :kebab]}, | ||
default: :pascal | ||
], | ||
debug: [doc: "Enable debug for parser generation.", type: :boolean, default: false], | ||
fields: [ | ||
doc: | ||
"Resource fields to map to XML. The order of elements will be preserved in the generated XML.", | ||
type: :keyword_list, | ||
keys: [ | ||
*: [ | ||
type: :keyword_list, | ||
keys: [ | ||
deserialize: [ | ||
doc: "If false, the resource field won't be deserialized from XML.", | ||
type: :boolean, | ||
default: true | ||
], | ||
serialize: [ | ||
doc: "If false, the resource field won't be serialized to XML.", | ||
type: :boolean, | ||
default: true | ||
], | ||
many: [ | ||
doc: | ||
"Specifies if the element can be repeated and should be serialized and deserialized as a list.", | ||
type: :boolean, | ||
default: false | ||
], | ||
name: [ | ||
doc: | ||
"Custom resource field name for serialization and deserialization. If defined, it will be used as-is instead of recasing.", | ||
type: :string | ||
], | ||
resource: [ | ||
doc: | ||
"If the element is represented by another resource, it needs to be specified here.", | ||
type: :atom | ||
], | ||
type: [ | ||
doc: "The XML shape that the resource field has in XML.", | ||
type: {:in, [:element, :attribute]}, | ||
default: :element | ||
] | ||
] | ||
] | ||
], | ||
required: true | ||
], | ||
namespace: [ | ||
doc: "XML namespace to apply to the resource when serializing.", | ||
type: {:or, [:string, nil]}, | ||
default: nil | ||
], | ||
root_element: [ | ||
doc: "XML root element. This applies only to the toplevel Resource when (de)serializing.", | ||
type: :string, | ||
default: "Root" | ||
] | ||
] | ||
|
||
def __schema__, do: unquote(schema) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
defmodule Sassone.Builder.Parser do | ||
@moduledoc false | ||
defstruct parsers: [], elements: [], keys: [], state: %{} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...assone/parser/builder/buffering_helper.ex → ...sone/parser/generator/buffering_helper.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/sassone/parser/builder/guards.ex → lib/sassone/parser/generator/guards.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/sassone/parser/builder/lookahead.ex → lib/sassone/parser/generator/lookahead.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters