Class: Asciidoctor::Diagram::PlantUMLPreprocessedSource

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/asciidoctor-diagram/plantuml/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, converter) ⇒ PlantUMLPreprocessedSource

Returns a new instance of PlantUMLPreprocessedSource.



147
148
149
150
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 147

def initialize(source, converter)
  super(source)
  @converter = converter
end

Instance Method Details

#codeObject



152
153
154
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 152

def code
  @code ||= load_code
end

#load_codeObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/asciidoctor-diagram/plantuml/converter.rb', line 156

def load_code
  Java.load

  code = __getobj__.code

  tag = @converter.class.tag
  code = "@start#{tag}\n#{code}\n@end#{tag}" unless code.index("@start") && code.index("@end")

  if @converter.should_preprocess(self)
    headers = {}
    @converter.add_common_headers(headers, self)
    @converter.add_theme_header(headers, @converter.collect_options(self)[:theme])

    response = Java.send_request(
      :url => '/plantumlpreprocessor',
      :body => code,
      :headers => headers
    )

    unless response[:code] == 200
      raise Java.create_error("PlantUML preprocessing failed", response)
    end

    code = response[:body]
    code.force_encoding(Encoding::UTF_8)
  end

  code
end