add: draft
This commit is contained in:
45
etpgrf_site/typograph/templates/typograph/base.html
Normal file
45
etpgrf_site/typograph/templates/typograph/base.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{% block title %}ETPGRF - Типограф{% endblock %}</title>
|
||||
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
|
||||
<!-- HTMX -->
|
||||
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
||||
|
||||
<style>
|
||||
/* Небольшие стили для красоты */
|
||||
body { background-color: #f8f9fa; }
|
||||
.result-box {
|
||||
background: white;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 0.375rem;
|
||||
padding: 1rem;
|
||||
min-height: 300px;
|
||||
}
|
||||
/* Стили для висячей пунктуации (из спецификации) */
|
||||
.etp-laquo { margin-left: -0.44em; }
|
||||
.etp-bdquo { margin-left: -0.44em; }
|
||||
/* Добавь остальные классы по мере необходимости */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-4">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">ETPGRF — единая типографика для веба</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<!-- Bootstrap JS -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
23
etpgrf_site/typograph/templates/typograph/index.html
Normal file
23
etpgrf_site/typograph/templates/typograph/index.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% extends 'typograph/base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<h3>Исходный текст</h3>
|
||||
<form hx-post="{% url 'process_text' %}" hx-target="#result-area" hx-swap="innerHTML">
|
||||
{% csrf_token %}
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control" name="text" rows="15" placeholder="Вставьте текст сюда..."></textarea>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Типографировать</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<h3>Результат</h3>
|
||||
<div id="result-area" class="result-box">
|
||||
<p class="text-muted">Здесь появится результат...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1 @@
|
||||
{{ processed_text }}
|
||||
8
etpgrf_site/typograph/urls.py
Normal file
8
etpgrf_site/typograph/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('process/', views.process_text, name='process_text'),
|
||||
]
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from etpgrf import Typographer
|
||||
|
||||
# Create your views here.
|
||||
# Инициализируем типограф один раз (как рекомендовано в спеке)
|
||||
# Можно вынести настройки в settings.py, но пока так
|
||||
typo = Typographer(langs='ru', process_html=True, hanging_punctuation='both')
|
||||
|
||||
def index(request):
|
||||
return render(request, template_name='typograph/index.html')
|
||||
|
||||
|
||||
def process_text(request):
|
||||
if request.method == 'POST':
|
||||
text = request.POST.get(key='text', default='')
|
||||
# Обрабатываем текст
|
||||
processed = typo.process(text)
|
||||
|
||||
# Возвращаем только фрагмент для HTMX
|
||||
return render(request, template_name='typograph/result_fragment.html', context={'processed_text': processed})
|
||||
|
||||
return HttpResponse(status=405)
|
||||
|
||||
Reference in New Issue
Block a user