aboutsummaryrefslogtreecommitdiffstats
path: root/src/document_tree/elements.rs
diff options
context:
space:
mode:
authorPhil Schaf2015-11-14 20:13:45 +0100
committerPhil Schaf2015-11-14 20:13:45 +0100
commit5fdb21df228c78061cce9ee910fa87da0fd99d46 (patch)
tree707d234259202381be0c784e8f1efea8eb5081ec /src/document_tree/elements.rs
parent9c2f818b7e7139ed7a5da573d1cc104defa7579f (diff)
downloadrust-rst-5fdb21df228c78061cce9ee910fa87da0fd99d46.tar.bz2
redesign
Diffstat (limited to 'src/document_tree/elements.rs')
-rw-r--r--src/document_tree/elements.rs207
1 files changed, 207 insertions, 0 deletions
diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs
new file mode 100644
index 0000000..e6709b4
--- /dev/null
+++ b/src/document_tree/elements.rs
@@ -0,0 +1,207 @@
+use url::Url;
+
+use super::extra_attributes::{self,ExtraAttributes};
+use super::element_categories::*;
+
+
+//-----------------\\
+//Element hierarchy\\
+//-----------------\\
+
+pub trait Element {
+ fn ids(&self) -> &Vec<String>;
+ fn names(&self) -> &Vec<String>;
+ fn source(&self) -> &Option<Url>;
+ fn classes(&self) -> &Vec<String>;
+}
+
+#[derive(Default,Debug)]
+pub struct CommonAttributes {
+ ids: Vec<String>,
+ names: Vec<String>,
+ //left out dupnames
+ source: Option<Url>,
+ classes: Vec<String>,
+}
+
+//----\\
+//impl\\
+//----\\
+
+macro_rules! impl_element(($name:ident) => {
+ impl Element for $name {
+ fn ids(&self) -> &Vec<String> { &self.common.ids }
+ fn names(&self) -> &Vec<String> { &self.common.names }
+ fn source(&self) -> &Option<Url> { &self.common.source }
+ fn classes(&self) -> &Vec<String> { &self.common.classes }
+ }
+});
+
+macro_rules! impl_children(($name:ident, $childtype:ident) => {
+ impl HasChildren<$childtype> for $name {
+ fn add_child<R: Into<$childtype>>(&mut self, child: R) {
+ self.children.push(Box::new(child.into()));
+ }
+ }
+});
+
+macro_rules! impl_extra(($name:ident) => {
+ impl ExtraAttributes<extra_attributes::$name> for $name {
+ fn extra(&self) -> &extra_attributes::$name { &self.extra }
+ }
+});
+
+macro_rules! impl_elem(
+ ($name:ident) => {
+ #[derive(Default,Debug)]
+ pub struct $name { common: CommonAttributes }
+ impl_element!($name);
+ };
+ ($name:ident; +) => {
+ #[derive(Default,Debug)]
+ pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }
+ impl_element!($name); impl_extra!($name);
+ };
+ ($name:ident; *) => { //same as above with no default
+ #[derive(Debug)]
+ pub struct $name { common: CommonAttributes, extra: extra_attributes::$name }
+ impl_element!($name); impl_extra!($name);
+ };
+ ($name:ident, $childtype:ident) => {
+ #[derive(Default,Debug)]
+ pub struct $name { common: CommonAttributes, children: Vec<Box<$childtype>> }
+ impl_element!($name); impl_children!($name, $childtype);
+ };
+ ($name:ident, $childtype:ident; +) => {
+ #[derive(Default,Debug)]
+ pub struct $name { common: CommonAttributes, extra: extra_attributes::$name, children: Vec<Box<$childtype>> }
+ impl_element!($name); impl_extra!($name); impl_children!($name, $childtype);
+ };
+);
+
+macro_rules! impl_elems(( $( ($($args:tt)*) )* ) => {
+ $( impl_elem!($($args)*); )*
+});
+
+impl_elems!(
+ //structual elements
+ (Section, SubSection)
+ (Topic, SubTopic)
+ (Sidebar, SubSidebar)
+
+ //structural subelements
+ (Title, TextOrInlineElement)
+ (Subtitle, TextOrInlineElement)
+ (Decoration, DecorationElement)
+ (Docinfo, BibliographicElement)
+ (Transition)
+
+ //bibliographic elements
+ (Author, TextOrInlineElement)
+ (Authors, AuthorInfo)
+ (Organization, TextOrInlineElement)
+ (Address, TextOrInlineElement; +)
+ (Contact, TextOrInlineElement)
+ (Version, TextOrInlineElement)
+ (Revision, TextOrInlineElement)
+ (Status, TextOrInlineElement)
+ (Date, TextOrInlineElement)
+ (Copyright, TextOrInlineElement)
+ (Field, SubField)
+
+ //decoration elements
+ (Header, BodyElement)
+ (Footer, BodyElement)
+
+ //simple body elements
+ (Paragraph, TextOrInlineElement)
+ (LiteralBlock, TextOrInlineElement; +)
+ (DoctestBlock, TextOrInlineElement; +)
+ (MathBlock)
+ (Rubric, TextOrInlineElement)
+ (SubstitutionDefinition, TextOrInlineElement; +)
+ (Comment, TextOrInlineElement; +)
+ (Pending)
+ (Target; +)
+ (Raw; +)
+ (Image; *)
+
+ //compound body elements
+ (Compound, BodyElement)
+ (Container, BodyElement)
+
+ (BulletList, ListItem; +)
+ (EnumeratedList, ListItem; +)
+ (DefinitionList, DefinitionListItem)
+ (FieldList, Field)
+ (OptionList, OptionListItem)
+
+ (LineBlock, SubLineBlock)
+ (BlockQuote, SubBlockQuote)
+ (Admonition, SubTopic)
+ (Attention, BodyElement)
+ (Hint, BodyElement)
+ (Note, BodyElement)
+ (Caution, BodyElement)
+ (Danger, BodyElement)
+ (Error, BodyElement)
+ (Important, BodyElement)
+ (Tip, BodyElement)
+ (Warning, BodyElement)
+ (Footnote, SubFootnote; +)
+ (Citation, SubFootnote; +)
+ (SystemMessage, BodyElement; +)
+ (Figure, SubFigure; +)
+ (Table; +) //TODO
+
+ //body sub elements
+ (ListItem, BodyElement)
+
+ (DefinitionListItem, SubDLItem)
+ (Term, TextOrInlineElement)
+ (Classifier, TextOrInlineElement)
+ (Definition, BodyElement)
+
+ (FieldName, TextOrInlineElement)
+ (FieldBody, BodyElement)
+
+ (OptionListItem, SubOptionListItem)
+ (OptionGroup, Option_)
+ (Description, BodyElement)
+ (Option_, SubOption)
+ (OptionString, TextOrInlineElement)
+ (OptionArgument, TextOrInlineElement; +)
+
+ (Line, TextOrInlineElement)
+ (Attribution, TextOrInlineElement)
+ (Label_, TextOrInlineElement)
+
+ (Caption, TextOrInlineElement)
+ (Legend, BodyElement)
+
+ //inline elements
+ (Emphasis, TextOrInlineElement)
+ (Literal, TextOrInlineElement)
+ (Reference, TextOrInlineElement; +)
+ (Strong, TextOrInlineElement)
+ (FootnoteReference, TextOrInlineElement; +)
+ (CitationReference, TextOrInlineElement; +)
+ (SubstitutionReference, TextOrInlineElement; +)
+ (TitleReference, TextOrInlineElement)
+ (Abbreviation, TextOrInlineElement)
+ (Acronym, TextOrInlineElement)
+ (Superscript, TextOrInlineElement)
+ (Subscript, TextOrInlineElement)
+ (Inline, TextOrInlineElement)
+ (Problematic, TextOrInlineElement; +)
+ (Generated, TextOrInlineElement)
+ (Math)
+
+ //also have non-inline versions. Inline image is no figure child, inline target has content
+ (TargetInline, TextOrInlineElement; +)
+ (RawInline; +)
+ (ImageInline; *)
+
+ //text element
+ (TextElement)
+);