Add erb support
This commit is contained in:
parent
8d4b9d172d
commit
e9c26ce2d0
11 changed files with 77 additions and 6 deletions
|
@ -3,4 +3,8 @@ class WidgetController < ApplicationController
|
||||||
expires_in 10.minutes
|
expires_in 10.minutes
|
||||||
head :found, location: helpers.asset_pack_url("donate-button-v2.js"), content_type: "application/javascript"
|
head :found, location: helpers.asset_pack_url("donate-button-v2.js"), content_type: "application/javascript"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def i18n
|
||||||
|
head :found, location: helpers.asset_pack_url("i18n.js"), content_type: "application/javascript"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
7
app/javascript/i18n.js.erb
Normal file
7
app/javascript/i18n.js.erb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import I18n from 'i18n-js';
|
||||||
|
|
||||||
|
I18n.translations || (I18n.translations = {});
|
||||||
|
<% I18n::JS::translations.each do |k,v| %>
|
||||||
|
<% byebug %>
|
||||||
|
I18n.translations[<%= k %>] = I18n.extend((I18n.translations[<%= k %>] || {}),<%= JSON.generate(v) %>);
|
||||||
|
<% end %>
|
3
app/javascript/packs/i18n.js
Normal file
3
app/javascript/packs/i18n.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
const i18n = require('../i18n.js.erb')
|
||||||
|
|
||||||
|
window.I18n = i18n;
|
31
config/i18n-js.yml
Normal file
31
config/i18n-js.yml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Split context in several files.
|
||||||
|
#
|
||||||
|
# By default only one file with all translations is exported and
|
||||||
|
# no configuration is required. Your settings for asset pipeline
|
||||||
|
# are automatically recognized.
|
||||||
|
#
|
||||||
|
# If you want to split translations into several files or specify
|
||||||
|
# locale contexts that will be exported, just use this file to do
|
||||||
|
# so.
|
||||||
|
#
|
||||||
|
# For more informations about the export options with this file, please
|
||||||
|
# refer to the README
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# If you're going to use the Rails 3.1 asset pipeline, change
|
||||||
|
# the following configuration to something like this:
|
||||||
|
#
|
||||||
|
# translations:
|
||||||
|
# - file: "app/assets/javascripts/i18n/translations.js"
|
||||||
|
#
|
||||||
|
# If you're running an old version, you can use something
|
||||||
|
# like this:
|
||||||
|
#
|
||||||
|
# translations:
|
||||||
|
# - file: "app/assets/javascripts/i18n/translations.js"
|
||||||
|
# only: "*"
|
||||||
|
#
|
||||||
|
translations:
|
||||||
|
- file: 'public/javascripts/translations.js'
|
||||||
|
only: '*'
|
||||||
|
prefix: "import I18n from 'i18n-js';\n"
|
|
@ -258,5 +258,6 @@ Rails.application.routes.draw do
|
||||||
get '/static/ccs' => 'static#ccs'
|
get '/static/ccs' => 'static#ccs'
|
||||||
|
|
||||||
get '/js/donate-button.v2.js' => 'widget#v2'
|
get '/js/donate-button.v2.js' => 'widget#v2'
|
||||||
|
get '/js/i18n.js' => 'widget#i18n'
|
||||||
root to: 'front#index'
|
root to: 'front#index'
|
||||||
end
|
end
|
|
@ -1,6 +1,8 @@
|
||||||
const { environment } = require('@rails/webpacker')
|
const { environment } = require('@rails/webpacker')
|
||||||
|
const erb = require('./loaders/erb')
|
||||||
const typescript = require('./loaders/typescript')
|
const typescript = require('./loaders/typescript')
|
||||||
|
|
||||||
environment.loaders.prepend('typescript', typescript)
|
environment.loaders.prepend('typescript', typescript)
|
||||||
|
|
||||||
|
environment.loaders.prepend('erb', erb)
|
||||||
module.exports = environment
|
module.exports = environment
|
||||||
|
|
11
config/webpack/loaders/erb.js
Normal file
11
config/webpack/loaders/erb.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module.exports = {
|
||||||
|
test: /\.erb$/,
|
||||||
|
enforce: 'pre',
|
||||||
|
exclude: /node_modules/,
|
||||||
|
use: [{
|
||||||
|
loader: 'rails-erb-loader',
|
||||||
|
options: {
|
||||||
|
runner: (/^win/.test(process.platform) ? 'ruby ' : '') + 'bin/rails runner'
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -34,6 +34,7 @@ default: &default
|
||||||
- .woff2
|
- .woff2
|
||||||
|
|
||||||
extensions:
|
extensions:
|
||||||
|
- .erb
|
||||||
- .tsx
|
- .tsx
|
||||||
- .ts
|
- .ts
|
||||||
- .mjs
|
- .mjs
|
||||||
|
|
|
@ -10,10 +10,13 @@ import {CSRFInterceptor} from "../../lib/csrf_interceptor";
|
||||||
import * as CustomAPIS from "../../lib/apis"
|
import * as CustomAPIS from "../../lib/apis"
|
||||||
|
|
||||||
const enLocaleData = require('react-intl/locale-data/en');
|
const enLocaleData = require('react-intl/locale-data/en');
|
||||||
const deLocaleData = require('react-intl/locale-data/de');
|
const I18n = require('../../../../app/javascript/i18n.js.erb')
|
||||||
const I18n = require('i18n')
|
const localeData = [...enLocaleData]
|
||||||
|
I18n.translations.keys().filter((i:string) => i !== 'en').each((i:string) => {
|
||||||
addLocaleData([...enLocaleData, ...deLocaleData])
|
const data = [...require(`react-intl/locale-data/${i}`)]
|
||||||
|
localeData.concat(data)
|
||||||
|
})
|
||||||
|
addLocaleData(localeData)
|
||||||
|
|
||||||
interface RootProps
|
interface RootProps
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
"ci-build-all": "script/compile-assets.sh && yarn build",
|
"ci-build-all": "script/compile-assets.sh && yarn build",
|
||||||
"test": "rake -v spec && yarn build && yarn jest",
|
"test": "rake -v spec && yarn build && yarn jest",
|
||||||
"export-button-config": "bundle exec rake settings:generate_json",
|
"export-button-config": "bundle exec rake settings:generate_json",
|
||||||
"export-i18n": "bundle exec rake settings:combine_translations",
|
|
||||||
"generate-openapi": "rake oapi:gen",
|
"generate-openapi": "rake oapi:gen",
|
||||||
"get-codegen-cli": "script/download_codegen_cli.sh",
|
"get-codegen-cli": "script/download_codegen_cli.sh",
|
||||||
"generate-api-js": "rm -rf javascripts/api && yarn get-codegen-cli && yarn generate-openapi && java -jar .bin/swagger-codegen-cli.jar generate -l 'typescript-jquery' -i tmp/openapi.json -o javascripts/api --config 'swagger.json' -t lib/swagger-typescript-jquery",
|
"generate-api-js": "rm -rf javascripts/api && yarn get-codegen-cli && yarn generate-openapi && java -jar .bin/swagger-codegen-cli.jar generate -l 'typescript-jquery' -i tmp/openapi.json -o javascripts/api --config 'swagger.json' -t lib/swagger-typescript-jquery",
|
||||||
|
@ -132,6 +131,7 @@
|
||||||
"pikaday-time": "1.5.1",
|
"pikaday-time": "1.5.1",
|
||||||
"query-string": "4.2.2",
|
"query-string": "4.2.2",
|
||||||
"quill": "^1.3.6",
|
"quill": "^1.3.6",
|
||||||
|
"rails-erb-loader": "^5.5.2",
|
||||||
"ramda": "^0.21.0",
|
"ramda": "^0.21.0",
|
||||||
"react": "^16.2.0",
|
"react": "^16.2.0",
|
||||||
"react-aria-modal": "^3.0.1",
|
"react-aria-modal": "^3.0.1",
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -7309,7 +7309,7 @@ lodash.defaults@^3.1.2:
|
||||||
lodash.assign "^3.0.0"
|
lodash.assign "^3.0.0"
|
||||||
lodash.restparam "^3.0.0"
|
lodash.restparam "^3.0.0"
|
||||||
|
|
||||||
lodash.defaults@^4.0.0:
|
lodash.defaults@^4.0.0, lodash.defaults@^4.2.0:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
|
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
|
||||||
integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=
|
integrity sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=
|
||||||
|
@ -10045,6 +10045,14 @@ railroad-diagrams@^1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e"
|
resolved "https://registry.yarnpkg.com/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz#eb7e6267548ddedfb899c1b90e57374559cddb7e"
|
||||||
integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=
|
integrity sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=
|
||||||
|
|
||||||
|
rails-erb-loader@^5.5.2:
|
||||||
|
version "5.5.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/rails-erb-loader/-/rails-erb-loader-5.5.2.tgz#db3fa8ac89600f09d179a1a70a2ca18c592576ea"
|
||||||
|
integrity sha512-cjQH9SuSvRPhnWkvjmmAW/S4AFVDfAtYnQO4XpKJ8xpRdZayT73iXoE+IPc3VzN03noZXhVmyvsCvKvHj4LY6w==
|
||||||
|
dependencies:
|
||||||
|
loader-utils "^1.1.0"
|
||||||
|
lodash.defaults "^4.2.0"
|
||||||
|
|
||||||
ramda@0.19.1, ramda@^0.19.1:
|
ramda@0.19.1, ramda@^0.19.1:
|
||||||
version "0.19.1"
|
version "0.19.1"
|
||||||
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.19.1.tgz#89c4ad697265ff6b1face9f286439e2520d6679c"
|
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.19.1.tgz#89c4ad697265ff6b1face9f286439e2520d6679c"
|
||||||
|
|
Loading…
Reference in a new issue