lib/asciidoctor/section.rb in asciidoctor-0.0.5 vs lib/asciidoctor/section.rb in asciidoctor-0.0.6
- old
+ new
@@ -22,27 +22,29 @@
attr_accessor :level
# Public: Set the String section name.
attr_writer :name
- # Public: Get/Set the String section title.
- attr_accessor :title
-
# Public: Get/Set the String section caption.
attr_accessor :caption
# Public: Get/Set the String section anchor name.
attr_accessor :anchor
+ alias :id :anchor
+ # Public: Get the Hash of attributes for this block
+ attr_accessor :attributes
+
# Public: Get the Array of section blocks.
attr_reader :blocks
# Public: Initialize an Asciidoctor::Section object.
#
# parent - The parent Asciidoc Object.
def initialize(parent)
@parent = parent
+ @attributes = {}
@blocks = []
end
# Public: Get the String section name with intrinsics converted
#
@@ -57,27 +59,46 @@
@name &&
@name.gsub(/(^|[^\\])\{(\w[\w\-]+\w)\}/) { $1 + Asciidoctor::INTRINSICS[$2] }.
gsub( /`([^`]+)`/, '<tt>\1</tt>' )
end
- # Public: Get the String section id
+ # Public: Get the String section id prefixed with value of idprefix attribute, otherwise an underscore
#
+ # Section ID synthesis can be disabled by undefining the sectids attribute.
+ #
# Examples
#
- # section = Section.new
+ # section = Section.new(parent)
# section.name = "Foo"
# section.section_id
# => "_foo"
def section_id
- "_#{name && name.downcase.gsub(/\W+/,'_').gsub(/_+$/, '')}".tr_s('_', '_')
+ if self.document.attributes.has_key? 'sectids'
+ self.document.attributes.fetch('idprefix', '_') + "#{name && name.downcase.gsub(/\W+/,'_').gsub(/_+$/, '')}".tr_s('_', '_')
+ else
+ nil
+ end
end
# Public: Get the Asciidoctor::Document instance to which this Block belongs
def document
@parent.is_a?(Asciidoctor::Document) ? @parent : @parent.document
end
+ def attr(name, default = nil)
+ default.nil? ? @attributes.fetch(name.to_s, self.document.attr(name)) :
+ @attributes.fetch(name.to_s, self.document.attr(name, default))
+ end
+
+ def attr?(name)
+ @attributes.has_key?(name.to_s) || self.document.attr?(name)
+ end
+
+ def update_attributes(attributes)
+ @attributes.update(attributes)
+ end
+
# Public: Get the Asciidoctor::Renderer instance being used for the ancestor
# Asciidoctor::Document instance.
def renderer
Asciidoctor.debug "Section#renderer: Looking for my renderer up in #{@parent}"
@parent.renderer
@@ -105,9 +126,14 @@
Asciidoctor.debug "Begin rendering block #{block.is_a?(Asciidoctor::Section) ? block.name : 'n/a'} #{block} (context: #{block.is_a?(Asciidoctor::Block) ? block.context : 'n/a' })"
poo = block.render
Asciidoctor.debug "===> Done rendering block #{block.is_a?(Asciidoctor::Section) ? block.name : 'n/a'} #{block} (context: #{block.is_a?(Asciidoctor::Block) ? block.context : 'n/a' })"
poo
end.join
+ end
+
+ # Public: The title of this section, an alias of the section name
+ def title
+ @name
end
# Public: Get the Integer number of blocks in the section.
#
# Examples