diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/document_title_processor.rb | 15 | ||||
| -rw-r--r-- | lib/extensions/lang_attribute_processor.rb | 9 | ||||
| -rw-r--r-- | lib/extensions/revision_history_processor.rb | 27 | ||||
| -rw-r--r-- | lib/extensions/section_id_validator.rb | 29 | ||||
| -rw-r--r-- | lib/extensions/source_id_processor.rb | 12 | ||||
| -rw-r--r-- | lib/extensions/source_id_validator.rb | 32 | ||||
| -rw-r--r-- | lib/extensions/tags_processor.rb | 20 |
7 files changed, 0 insertions, 144 deletions
diff --git a/lib/extensions/document_title_processor.rb b/lib/extensions/document_title_processor.rb deleted file mode 100644 index fd25844..0000000 --- a/lib/extensions/document_title_processor.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Nuldoc - module Extensions - class DocumentTitleProcessor < Asciidoctor::Extensions::TreeProcessor - def process(doc) - doc.title = substitute_document_title(doc.title) - end - - private - - def substitute_document_title(title) - title.sub(/\A\[(.+?)\] /, '【\1】') - end - end - end -end diff --git a/lib/extensions/lang_attribute_processor.rb b/lib/extensions/lang_attribute_processor.rb deleted file mode 100644 index 65511bc..0000000 --- a/lib/extensions/lang_attribute_processor.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Nuldoc - module Extensions - class LangAttributeProcessor < Asciidoctor::Extensions::TreeProcessor - def process(doc) - doc.attributes['lang'] ||= 'ja-JP' - end - end - end -end diff --git a/lib/extensions/revision_history_processor.rb b/lib/extensions/revision_history_processor.rb deleted file mode 100644 index f416de0..0000000 --- a/lib/extensions/revision_history_processor.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Nuldoc - module Extensions - class RevisionHistoryProcessor < Asciidoctor::Extensions::TreeProcessor - def process(doc) - revisions = [] - i = 1 - loop do - break unless (rev = doc.attributes["revision-#{i}"]) - revisions << parse_revision(rev) - i += 1 - end - doc.attributes['revision-history'] = revisions - end - - private - - def parse_revision(rev) - m = rev.match(/\A(\d\d\d\d-\d\d-\d\d) (.*)\z/) - raise unless m - Revision.new( - date: Date.parse(m[1], '%Y-%m-%d'), - remark: m[2], - ) - end - end - end -end diff --git a/lib/extensions/section_id_validator.rb b/lib/extensions/section_id_validator.rb deleted file mode 100644 index 2ad496c..0000000 --- a/lib/extensions/section_id_validator.rb +++ /dev/null @@ -1,29 +0,0 @@ -module Nuldoc - module Extensions - class SectionIdValidator < Asciidoctor::Extensions::TreeProcessor - def process(doc) - errors = [] - (doc.find_by(context: :section) {_1.level > 0}).each do |section| - errors << validate_section(section) - end - error_message = errors.compact.join("\n") - unless error_message.empty? - raise "SectionIdValidator (#{doc.attributes['source-file-path']}):\n#{error_message}" - end - end - - private - - def validate_section(section) - id = section.id - unless id - return "Section '#{section.title}': each section MUST have an id." - end - unless id.match?(/\A[-0-9a-z]+\z/) - return "Section '#{section.title}' (##{id}): section id MUST consist of either hyphen, digits or lowercases." - end - nil - end - end - end -end diff --git a/lib/extensions/source_id_processor.rb b/lib/extensions/source_id_processor.rb deleted file mode 100644 index 13813e0..0000000 --- a/lib/extensions/source_id_processor.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Nuldoc - module Extensions - class SourceIdProcessor < Asciidoctor::Extensions::TreeProcessor - def process(doc) - errors = [] - (doc.find_by(context: :listing) {_1.style == 'source'}).each do |source| - source.id = "source.#{source.id}" - end - end - end - end -end diff --git a/lib/extensions/source_id_validator.rb b/lib/extensions/source_id_validator.rb deleted file mode 100644 index 6e04deb..0000000 --- a/lib/extensions/source_id_validator.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Nuldoc - module Extensions - class SourceIdValidator < Asciidoctor::Extensions::TreeProcessor - def process(doc) - errors = [] - (doc.find_by(context: :listing) {_1.style == 'source'}).each do |source| - errors << validate_section(source) - end - error_message = errors.compact.join("\n") - unless error_message.empty? - raise "SourceIdValidator (#{doc.attributes['source-file-path']}):\n#{error_message}" - end - end - - private - - def validate_section(source) - id = source.id - unless id - return "Each source MUST have an id." - end - if id.start_with?('source.') - return "Source id (##{id}) MUST NOT start with 'source.', which is appended by `nul`." - end - unless id.match?(/\A[-0-9a-z]+\z/) - return "Source id (##{id}) MUST consist of either hypen, digits or lowercases." - end - nil - end - end - end -end diff --git a/lib/extensions/tags_processor.rb b/lib/extensions/tags_processor.rb deleted file mode 100644 index efbd2a8..0000000 --- a/lib/extensions/tags_processor.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Nuldoc - module Extensions - class TagsProcessor < Asciidoctor::Extensions::TreeProcessor - def process(doc) - doc.attributes['tags'] = convert_tags(doc.attributes['tags']) - end - - private - - def convert_tags(tags) - return [] unless tags - - tags - .split(',') - .map(&:strip) - .map { Tag.from_slug(_1) } - end - end - end -end |
