-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser/renderer): support for document attributes reset and subs…
…titutions (#23) Also: introduce a custom `Context` type that includes the document being processed, giving access to document attributes when declaration, reset and subsitutions elements are processed/rendered. Also, rename type `DocumentAttribute` -> `DocumentAttributeDeclaration` while introducing `DocumentAttributeSubstitution` and `DocumentAttributeReset` types. Signed-off-by: Xavier Coulon <[email protected]>
- Loading branch information
Showing
20 changed files
with
454 additions
and
146 deletions.
There are no files selected for viewing
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,43 @@ | ||
package context | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/bytesparadise/libasciidoc/types" | ||
) | ||
|
||
// Context is a custom implementation of the standard golang context.Context interface, | ||
// which carries the types.Document which is being processed | ||
type Context struct { | ||
context context.Context | ||
Document types.Document | ||
} | ||
|
||
// Wrap wraps the given `ctx` context into a new context which will contain the given `document` document. | ||
func Wrap(ctx context.Context, document types.Document) Context { | ||
return Context{ | ||
context: ctx, | ||
Document: document, | ||
} | ||
} | ||
|
||
// Deadline wrapper implementation of context.Context.Deadline() | ||
func (ctx *Context) Deadline() (deadline time.Time, ok bool) { | ||
return ctx.context.Deadline() | ||
} | ||
|
||
// Done wrapper implementation of context.Context.Done() | ||
func (ctx *Context) Done() <-chan struct{} { | ||
return ctx.Done() | ||
} | ||
|
||
// Err wrapper implementation of context.Context.Err() | ||
func (ctx *Context) Err() error { | ||
return ctx.Err() | ||
} | ||
|
||
// Value wrapper implementation of context.Context.Value(interface{}) | ||
func (ctx *Context) Value(key interface{}) interface{} { | ||
return ctx.Value(key) | ||
} |
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
Oops, something went wrong.