| 234 | } |
| 235 | |
| 236 | DocumentChangeSet TemplateRenderer::renderFileTemplate(const SourceFileTemplate& fileTemplate, |
| 237 | const QUrl& baseUrl, |
| 238 | const QHash<QString, QUrl>& fileUrls) |
| 239 | { |
| 240 | Q_ASSERT(fileTemplate.isValid()); |
| 241 | |
| 242 | DocumentChangeSet changes; |
| 243 | const QDir baseDir(baseUrl.path()); |
| 244 | |
| 245 | static const QRegularExpression nonAlphaNumeric(QStringLiteral("\\W")); |
| 246 | for (QHash<QString, QUrl>::const_iterator it = fileUrls.constBegin(); it != fileUrls.constEnd(); ++it) { |
| 247 | QString cleanName = it.key().toLower(); |
| 248 | cleanName.replace(nonAlphaNumeric, QStringLiteral("_")); |
| 249 | const QString path = it.value().toLocalFile(); |
| 250 | addVariable(QLatin1String("output_file_") + cleanName, baseDir.relativeFilePath(path)); |
| 251 | addVariable(QLatin1String("output_file_") + cleanName + QLatin1String("_absolute"), path); |
| 252 | } |
| 253 | |
| 254 | const KArchiveDirectory* directory = fileTemplate.directory(); |
| 255 | ArchiveTemplateLocation location(directory); |
| 256 | const auto outputFiles = fileTemplate.outputFiles(); |
| 257 | for (const SourceFileTemplate::OutputFile& outputFile : outputFiles) { |
| 258 | const KArchiveEntry* entry = directory->entry(outputFile.fileName); |
| 259 | if (!entry) { |
| 260 | qCWarning(LANGUAGE) << "Entry" << outputFile.fileName << "is mentioned in group" << outputFile.identifier << |
| 261 | "but is not present in the archive"; |
| 262 | continue; |
| 263 | } |
| 264 | |
| 265 | const auto* file = dynamic_cast<const KArchiveFile*>(entry); |
| 266 | if (!file) { |
| 267 | qCWarning(LANGUAGE) << "Entry" << entry->name() << "is not a file"; |
| 268 | continue; |
| 269 | } |
| 270 | |
| 271 | QUrl url = fileUrls[outputFile.identifier]; |
| 272 | IndexedString document(url); |
| 273 | KTextEditor::Range range(KTextEditor::Cursor(0, 0), 0); |
| 274 | |
| 275 | DocumentChange change(document, range, QString(), |
| 276 | render(QString::fromUtf8(file->data()), outputFile.identifier)); |
| 277 | changes.addChange(change); |
| 278 | qCDebug(LANGUAGE) << "Added change for file" << document.str(); |
| 279 | } |
| 280 | |
| 281 | return changes; |
| 282 | } |
| 283 | |
| 284 | QString TemplateRenderer::errorString() const |
| 285 | { |