Class: RbbCode::SchemaTag

Inherits:
SchemaNode show all
Defined in:
lib/rbbcode/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema, name) ⇒ SchemaTag

Returns a new instance of SchemaTag.



38
39
40
41
# File 'lib/rbbcode/schema.rb', line 38

def initialize(schema, name)
  @schema = schema
  @name = name
end

Instance Method Details

#may_be_nestedObject



43
44
45
46
# File 'lib/rbbcode/schema.rb', line 43

def may_be_nested
  @schema.allow_descent(@name, @name)
  self
end

#may_contain_textObject



48
49
50
51
# File 'lib/rbbcode/schema.rb', line 48

def may_contain_text
  @schema.allow_text(@name)
  self
end

#may_descend_from(tag_name) ⇒ Object



58
59
60
61
# File 'lib/rbbcode/schema.rb', line 58

def may_descend_from(tag_name)
  @schema.allow_descent(tag_name, @name)
  self
end

#may_not_be_nestedObject



53
54
55
56
# File 'lib/rbbcode/schema.rb', line 53

def may_not_be_nested
  @schema.forbid_descent(@name, @name)
  self
end

#may_not_contain_textObject



68
69
70
71
# File 'lib/rbbcode/schema.rb', line 68

def may_not_contain_text
  @schema.forbid_text(@name)
  self
end

#may_not_descend_from(tag_name) ⇒ Object



73
74
75
76
# File 'lib/rbbcode/schema.rb', line 73

def may_not_descend_from(tag_name)
  @schema.forbid_descent(tag_name, @name)
  self
end

#may_only_be_parent_of(*tag_names) ⇒ Object



63
64
65
66
# File 'lib/rbbcode/schema.rb', line 63

def may_only_be_parent_of(*tag_names)
  @schema.forbid_children_except(@name, *tag_names)
  self
end

#must_be_child_of(*tag_names) ⇒ Object



78
79
80
81
# File 'lib/rbbcode/schema.rb', line 78

def must_be_child_of(*tag_names)
  @schema.require_parents(tag_names, @name)
  self
end

#must_be_emptyObject



83
84
85
86
87
# File 'lib/rbbcode/schema.rb', line 83

def must_be_empty
  @schema.forbid_children_except(@name, [])
  may_not_contain_text
  self
end

#need_not_be_child_of(tag_name) ⇒ Object



89
90
91
92
# File 'lib/rbbcode/schema.rb', line 89

def need_not_be_child_of(tag_name)
  @schema.unrequire_parent(tag_name, @name)
  self
end

#valid_in_context?(*ancestors) ⇒ Boolean

Returns true if tag_name is valid in the context defined by its list of ancestors. ancestors should be ordered from most recent ancestor to most distant.

Returns:

  • (Boolean)


96
97
98
# File 'lib/rbbcode/schema.rb', line 96

def valid_in_context?(*ancestors)
  @schema.tag_valid_in_context?(@name, normalize_ancestors(ancestors))
end