Class: Apress::Documentation::Dsl::Compilers::DocumentCompiler
- Inherits:
-
BaseCompiler
- Object
- BaseCompiler
- Apress::Documentation::Dsl::Compilers::DocumentCompiler
- Includes:
- Mixins::Dependable, Mixins::Publicity
- Defined in:
- lib/apress/documentation/dsl/compilers/document_compiler.rb
Overview
Private: “Компилирует” блок для объекта класса Document заполняя в нем нужные аттрибуты
Constant Summary
Constants included from Mixins::Publicity
Mixins::Publicity::ACCESS_MAPPING
Instance Attribute Summary
Attributes inherited from BaseCompiler
Instance Method Summary collapse
-
#document(slug, fields = {}, &block) ⇒ Object
Public: метод DSL, Создает документ, осуществляет вложеность документов.
-
#swagger_bind(html_id = nil, fields = {}, &block) ⇒ Object
Public: метод DSL, Создает swagger-описание внутри документа.
Methods included from Mixins::Publicity
Methods included from Mixins::Dependable
Methods inherited from BaseCompiler
#compile, #initialize, setters
Constructor Details
This class inherits a constructor from Apress::Documentation::Dsl::BaseCompiler
Instance Method Details
#document(slug, fields = {}, &block) ⇒ Object
Public: метод DSL, Создает документ, осуществляет вложеность документов
slug - (required), String or Symbol - слаг документа fields - Hash - позволяет задавать поля через хеш block - Proc - DSL для настройки полей документа
Examples
Apress::Documentation.build(:module) do
document(:html) do
description 'Описывает все HTMl старницы'
document(:page) do
description 'Тут описание только одной'
end
end
end
Можно вызывать без блока
Apress::Documentation.build(:module) do
document :name, title: :test, description: 'some description'
end
40 41 42 43 44 45 46 47 48 |
# File 'lib/apress/documentation/dsl/compilers/document_compiler.rb', line 40 def document(slug, fields = {}, &block) slug = slug.to_s doc = target.documents[slug] doc ||= Apress::Documentation::Storage::Document.new(target.slug + '/' + slug) Storage::DependencyGraph.instance.add_document(doc) target.documents[slug] = doc doc.compile(fields, &block) end |
#swagger_bind(html_id = nil, fields = {}, &block) ⇒ Object
Public: метод DSL, Создает swagger-описание внутри документа.
slug - (required), String or Symbol - слаг документа fields - Hash - позволяет задавать поля через хеш block - Proc - DSL для настройки полей документа
Examples
Apress::Documentation.build(:module) do
document(:http_api) do
description 'Описывает все API модуля'
swagger_bind('tag_operationId_content') do
description 'Тут описание только одной'
swagger_path('api/docs') do
# Тут вызовы методов Swagger::Blocks
end
end
end
end
Можно вызывать без указания html_id,
тогда он будет "распознан" из блока автоматически, если это возможно.
В случае если html_id не был передан и "распознать" html_id невозможно, будет кинуто исключение.
Детали "распознования" см. в Apress::Documentation::Dsl::Utils::SwaggerBindPointExtractor
Apress::Documentation.build(:module) do
document(:http_api) do
description 'Описывает все API модуля'
swagger_bind do # -> будет tag_operationId_content
description 'Тут описание только одной'
swagger_path('api/docs') do
operation :get do
key :operationId, 'operationId' # -> обязательный вызов для распознавания
key :tags, ['tag'] # -> обязательный вызов для распознавания
end
end
end
end
end
90 91 92 93 94 95 96 97 98 |
# File 'lib/apress/documentation/dsl/compilers/document_compiler.rb', line 90 def swagger_bind(html_id = nil, fields = {}, &block) html_id = recognize_html_id(html_id, &block) doc = target.swagger_documents[html_id] doc ||= Apress::Documentation::Storage::SwaggerDocument.new(target, html_id) Storage::DependencyGraph.instance.add_document(doc) target.swagger_documents[html_id] = doc doc.compile(fields, &block) end |