From a5084cfa844f6e27a5a2befd0dbcc0c753cc37e8 Mon Sep 17 00:00:00 2001 From: echarp Date: Sun, 7 May 2017 22:09:04 +0200 Subject: [PATCH] French typography, spacing at least, when applicable --- app/assets/javascripts/application.js.coffee | 1 + app/assets/javascripts/frTypo.coffee | 47 ++++++++++++++++++++ app/assets/stylesheets/application.sass | 1 + app/assets/stylesheets/frTypo.sass | 5 +++ 4 files changed, 54 insertions(+) create mode 100644 app/assets/javascripts/frTypo.coffee create mode 100644 app/assets/stylesheets/frTypo.sass diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 7dabcb6e..d3f0d2aa 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -22,6 +22,7 @@ #= require leaflet #= require leaflet.markercluster #= require leaflet.awesome-markers +#= require frTypo #= require_tree . $(document).on 'turbolinks:load', -> diff --git a/app/assets/javascripts/frTypo.coffee b/app/assets/javascripts/frTypo.coffee new file mode 100644 index 00000000..de926612 --- /dev/null +++ b/app/assets/javascripts/frTypo.coffee @@ -0,0 +1,47 @@ +### + @licstart The following is the entire license notice for the JavaScript code in this page. + + frTypo, la typographie française simplifiée + + Copyright (C) 2013 acoeuro + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + @licend The above is the entire license notice for the JavaScript code in this page. +### + +$(document).on 'turbolinks:load', -> + if $('html').attr('lang') == 'fr' + # Ne devrait s'appliquer qu'à une page en français + $('body *').contents().filter -> + this.nodeType == Node.TEXT_NODE + + .filter -> + # Supprime les éléments pouvant utiliser des ponctuations sans nécessiter + # un espacement + 0 > ['CODE', 'PRE', 'STYLE'].indexOf this.parentNode.tagName + + .filter -> + this.nodeValue.match(regexp)? || this.nodeValue.match(regexpPost)? + + .each -> + console.log 'huuu' + $(this).replaceWith -> + this.nodeValue + .replace(regexp, '$1$2$3') + .replace(regexpPost, '$1$2') + +regexp = /([\w])([!?:;»%])([\s]|[^\w\/]|$)/g + +regexpPost = /([«])([\w])/g diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass index d8af1c69..d248b105 100644 --- a/app/assets/stylesheets/application.sass +++ b/app/assets/stylesheets/application.sass @@ -12,6 +12,7 @@ * *= require jquery-ui *= require jquery.tagsinput + *= require frTypo *= require_tree . */ diff --git a/app/assets/stylesheets/frTypo.sass b/app/assets/stylesheets/frTypo.sass new file mode 100644 index 00000000..7dd0b07a --- /dev/null +++ b/app/assets/stylesheets/frTypo.sass @@ -0,0 +1,5 @@ +.finePre, .city:after, span.label:after + margin-left: 0.25em +.finePost + margin-right: 0.25em +