Class: Section
- Inherits:
-
ActiveComponent::Base
- Object
- ActiveComponent::Base
- Section
- Defined in:
- lib/active_component/components/section.rb
Constant Summary
Constants included from ActiveComponent
ActiveComponent::BLOCK_ELEMENTS, ActiveComponent::EMPTY_ELEMENTS, ActiveComponent::HEADING_ELEMENTS, ActiveComponent::HTML5_ELEMENTS, ActiveComponent::PHRASING_ELEMENTS, ActiveComponent::SECTION_ELEMENTS
Instance Attribute Summary collapse
-
#heading ⇒ Object
Returns the value of attribute heading.
-
#heading_attrs ⇒ Object
Returns the value of attribute heading_attrs.
-
#heading_level ⇒ Object
Returns the value of attribute heading_level.
-
#tag_type ⇒ Object
Returns the value of attribute tag_type.
Attributes inherited from ActiveComponent::Base
#attributes, #childrenHash, #node_content, #node_name, #parent, #title
Instance Method Summary collapse
-
#initialize(*args, &content_block) ⇒ Section
constructor
A new instance of Section.
- #to_html ⇒ Object
Methods inherited from ActiveComponent::Base
#<<, #<=>, #[], #add, #breadth, #breadth_each, #children, #class_name, #content, #content=, def_component_helper, def_html_sub_components, #depth, #detached_copy, #each, #each_leaf, #firstChild, #firstSibling, #freezeTree!, #hasChildren?, #hasnode_content?, #html_class, #in_degree, inherited, #init_component, #init_node, #isFirstSibling?, #isLastSibling?, #isLeaf?, #isOnlyChild?, #is_html_tag_wrapper?, #is_root?, json_create, #lastChild, #lastSibling, #length, #marshal_dump, #marshal_load, #nextSibling, #nodeDepth, #nodeHeight, #out_degree, #parentage, #preordered_each, #prepend, #previousSibling, #printTree, #remove!, #removeAll!, #removeFromParent!, #root, #siblings, #size, #to_json, #to_s
Methods included from Enumerable
#find_a, #includes_a?, #transmogrify
Methods included from ActiveComponent
#print_contents, #print_object, #print_tag, #wrap_contents
Constructor Details
#initialize(*args, &content_block) ⇒ Section
Returns a new instance of Section.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/active_component/components/section.rb', line 7 def initialize(*args, &content_block) init_component(args, [:content, :title, :tag_type, :heading, :heading_level, :heading_attrs, :attributes], &content_block) # Defaults @tag_type ||= :section # Validations raise ArgumentError, "attributes must be a hash (given #{@attributes.inspect} in section #{@title})" unless @attributes.is_a? Hash # TODO: Heading rank end |
Instance Attribute Details
#heading ⇒ Object
Returns the value of attribute heading.
5 6 7 |
# File 'lib/active_component/components/section.rb', line 5 def heading @heading end |
#heading_attrs ⇒ Object
Returns the value of attribute heading_attrs.
5 6 7 |
# File 'lib/active_component/components/section.rb', line 5 def heading_attrs @heading_attrs end |
#heading_level ⇒ Object
Returns the value of attribute heading_level.
5 6 7 |
# File 'lib/active_component/components/section.rb', line 5 def heading_level @heading_level end |
#tag_type ⇒ Object
Returns the value of attribute tag_type.
5 6 7 |
# File 'lib/active_component/components/section.rb', line 5 def tag_type @tag_type end |
Instance Method Details
#to_html ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/active_component/components/section.rb', line 18 def to_html if @heading.present? && !@heading.is_a?(ActiveComponent) @heading = Heading.new @heading, @heading_level, @heading_attrs children.nil? ? (self << @heading) : self.prepend(@heading) end # TODO: Is this clean? Is there a better way that hides buffer operations? # wrap_contents(@tag_type, :attributes => @attributes, :content => [@heading, content] print_buffer do tag_to_buffer @tag_type, @attributes do write_to_buffer print_object(@heading) content.transmogrify do |content| write_to_buffer print_object(content) end end end end |