Skip to content

Commit

Permalink
Switching from jade to pug (#21047)
Browse files Browse the repository at this point in the history
* Upgrading pug

* Switching .jade to .pug and fixing templates

* Renaming the I18N usages of jade to pug

* No more jade in I18N
  • Loading branch information
kobelb authored Jul 27, 2018
1 parent bd03506 commit 15e3e59
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 165 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.1",
"inert": "4.0.2",
"jade": "1.11.0",
"jade-loader": "0.8.0",
"joi": "10.4.1",
"jquery": "^3.3.1",
"js-yaml": "3.4.1",
Expand Down Expand Up @@ -170,6 +168,7 @@
"postcss-loader": "2.0.6",
"prop-types": "15.5.8",
"proxy-from-env": "1.0.0",
"pug": "^2.0.3",
"querystring-browser": "1.0.4",
"raw-loader": "0.5.1",
"react": "^16.3.0",
Expand Down
12 changes: 6 additions & 6 deletions src/dev/i18n/extract_default_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import JSON5 from 'json5';

import { extractHtmlMessages } from './extract_html_messages';
import { extractCodeMessages } from './extract_code_messages';
import { extractJadeMessages } from './extract_jade_messages';
import { extractPugMessages } from './extract_pug_messages';
import { extractHandlebarsMessages } from './extract_handlebars_messages';
import { globAsync, makeDirAsync, accessAsync, readFileAsync, writeFileAsync } from './utils';

Expand All @@ -43,14 +43,14 @@ export async function extractDefaultTranslations(inputPath) {
matchBase: true,
});

const { htmlEntries, codeEntries, jadeEntries, hbsEntries } = entries.reduce(
const { htmlEntries, codeEntries, pugEntries, hbsEntries } = entries.reduce(
(paths, entry) => {
const resolvedPath = resolve(inputPath, entry);

if (resolvedPath.endsWith('.html')) {
paths.htmlEntries.push(resolvedPath);
} else if (resolvedPath.endsWith('.jade')) {
paths.jadeEntries.push(resolvedPath);
} else if (resolvedPath.endsWith('.pug')) {
paths.pugEntries.push(resolvedPath);
} else if (resolvedPath.endsWith('.hbs') || resolvedPath.endsWith('.handlebars')) {
paths.hbsFiles.push(resolvedPath);
} else {
Expand All @@ -59,7 +59,7 @@ export async function extractDefaultTranslations(inputPath) {

return paths;
},
{ htmlEntries: [], codeEntries: [], jadeEntries: [], hbsEntries: [] }
{ htmlEntries: [], codeEntries: [], pugEntries: [], hbsEntries: [] }
);

const defaultMessagesMap = new Map();
Expand All @@ -68,7 +68,7 @@ export async function extractDefaultTranslations(inputPath) {
[
[htmlEntries, extractHtmlMessages],
[codeEntries, extractCodeMessages],
[jadeEntries, extractJadeMessages],
[pugEntries, extractPugMessages],
[hbsEntries, extractHandlebarsMessages],
].map(async ([entries, extractFunction]) => {
const files = await Promise.all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import { isI18nTranslateFunction, traverseNodes } from './utils';
/**
* Matches `i18n(...)` in `#{i18n('id', { defaultMessage: 'Message text' })}`
*/
const JADE_I18N_REGEX = /(?<=\#\{)i18n\((([^)']|'([^'\\]|\\.)*')*\)(?=\}))/g;
const PUG_I18N_REGEX = /(?<=\#\{)i18n\((([^)']|'([^'\\]|\\.)*')*\)(?=\}))/g;

/**
* Example: `#{i18n('message-id', { defaultMessage: 'Message text' })}`
*/
export function* extractJadeMessages(buffer) {
const expressions = buffer.toString().match(JADE_I18N_REGEX) || [];
export function* extractPugMessages(buffer) {
const expressions = buffer.toString().match(PUG_I18N_REGEX) || [];

for (const expression of expressions) {
for (const node of traverseNodes(parse(expression).program.body)) {
Expand Down
5 changes: 0 additions & 5 deletions src/optimize/base_optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,6 @@ export default class BaseOptimizer {
test: /\.css$/,
use: getStyleLoaders(),
},
{
// TODO: this doesn't seem to be used, remove?
test: /\.jade$/,
loader: 'jade-loader'
},
{
test: /\.(html|tmpl)$/,
loader: 'raw-loader'
Expand Down
2 changes: 1 addition & 1 deletion src/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default async function (kbnServer, server, config) {
this.views({
path: path,
isCached: config.get('optimize.viewCaching'),
engines: _.assign({ jade: require('jade') }, engines || {})
engines: _.assign({ pug: require('pug') }, engines || {})
});
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ html(lang='en')

//- Favicons (generated from http://realfavicongenerator.net/)
link(
rel='apple-touch-icon' sizes='180x180' href='#{uiPublicUrl}/favicons/apple-touch-icon.png'
rel='apple-touch-icon' sizes='180x180' href=`${uiPublicUrl}/favicons/apple-touch-icon.png`
)
link(
rel='icon' type='image/png' href='#{uiPublicUrl}/favicons/favicon-32x32.png' sizes='32x32'
rel='icon' type='image/png' href=`${uiPublicUrl}/favicons/favicon-32x32.png` sizes='32x32'
)
link(
rel='icon' type='image/png' href='#{uiPublicUrl}/favicons/favicon-16x16.png' sizes='16x16'
rel='icon' type='image/png' href=`${uiPublicUrl}/favicons/favicon-16x16.png` sizes='16x16'
)
link(
rel='manifest' href='#{uiPublicUrl}/favicons/manifest.json'
rel='manifest' href=`${uiPublicUrl}/favicons/manifest.json`
)
link(
rel='mask-icon' href='#{uiPublicUrl}/favicons/safari-pinned-tab.svg' color='#e8488b'
rel='mask-icon' href=`${uiPublicUrl}/favicons/safari-pinned-tab.svg` color='#e8488b'
)
link(
rel='shortcut icon' href='#{uiPublicUrl}/favicons/favicon.ico'
rel='shortcut icon' href=`${uiPublicUrl}/favicons/favicon.ico`
)
meta(
name='msapplication-config' content='#{uiPublicUrl}/favicons/browserconfig.xml'
name='msapplication-config' content=`${uiPublicUrl}/favicons/browserconfig.xml`
)
meta(
name='theme-color' content='#ffffff'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends ./chrome.jade
extends ./chrome

block content
style.
Expand Down
4 changes: 2 additions & 2 deletions tasks/verify_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function verifyTranslations(uiExports) {
// Search files for used translation keys
const translationPatterns = [
{ regexp: 'i18n\\(\'(.*)\'\\)',
parsePaths: [fromRoot('src/ui/ui_render/views/*.jade')] }
parsePaths: [fromRoot('src/ui/ui_render/views/*.pug')] }
];
for (const { regexp, parsePaths } of translationPatterns) {
const keys = await i18nVerify.getTranslationKeys(regexp, parsePaths);
Expand All @@ -80,7 +80,7 @@ async function verifyTranslations(uiExports) {
throw new Error(
'\n' +
'\n' +
'The following keys are used in angular/jade views but are not translated:\n' +
'The following keys are used in angular/pug views but are not translated:\n' +
keysWithoutTranslations.map(([locale, keys]) => (
` - ${locale}: ${formatListAsProse(keys)}`
)).join('\n') +
Expand Down
Loading

0 comments on commit 15e3e59

Please sign in to comment.