Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from i3thuan5/包成套件
Browse files Browse the repository at this point in the history
包成套件
  • Loading branch information
Wenli Tsai authored Jun 7, 2017
2 parents 35f923d + 895d14a commit e89f336
Show file tree
Hide file tree
Showing 33 changed files with 879 additions and 276 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"development": {
"presets": ["react-hmre"]
},
"production": {
"presets": ["es2015"]
},
"test": {
"presets": ["es2015"]
}
Expand Down
20 changes: 20 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node_modules/
.npmignore
.gitignore
.babelrc
.eslintrc.json

# demo
webpack.config.dev.js
webpack.config.prod.js
devServer.js
taupahji.config.js
index.html
demo/
favicons/
build/

# unittest
app-css-dnt-compiler.js
test/
.travis.yml
13 changes: 13 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import { render } from "react-dom";
import MyProvider from "../src";

const root = document.getElementById("app");

// tau_pah_ji or sia_siann_mih
// min, hakka, or uan

render(
<MyProvider/>
, root,
);
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"name": "tau3_phah4-ji7",
"name": "ten1su4",
"version": "0.0.1",
"description": "鬥拍字",
"description": "ten1su4",
"scripts": {
"start": "node devServer.js",
"test": "NODE_ENV=test mocha --compilers js:babel-register,css:app-css-dnt-compiler --recursive",
"check": "eslint --ext .js --ext .jsx src/ test/",
"reformat": "eslint --fix --ext .js --ext .jsx src/ test/",
"build": "mkdir -p build;rm -f build/* && NODE_ENV=production webpack --config webpack.config.prod.js --bail && (echo 'xn--kpu3003h.xn--v0qr21b.xn--kpry57d' > build/CNAME) && cp index.html favicons/* build/ && cp index.html build/404.html",
"deploy": "npm run build && gh-pages -d build/"
"clear": "mkdir -p build;rm -f build/*",
"build": "NODE_ENV=production webpack --config webpack.config.prod.js --bail && (echo 'xn--kpu3003h.xn--v0qr21b.xn--kpry57d' > build/CNAME) && cp index.html favicons/* build/ && cp index.html build/404.html",
"deploy": "npm run clear && npm run build && gh-pages -d build/",
"clear-lib": "rm -rf lib;mkdir -p lib",
"compile-lib": "NODE_ENV=production babel src --out-dir lib --copy-files",
"publish-lib": "npm run clear-lib && npm run compile-lib && npm publish"
},
"repository": {
"type": "git",
"url": "https://github.com/sih4sing5hong5/tau3_phah4-ji7.git"
"url": "https://github.com/i3thuan5/ten1su4.git"
},
"keywords": [
"臺語",
Expand All @@ -21,13 +25,13 @@
"author": "薛丞宏",
"license": "MIT",
"bugs": {
"url": "https://github.com/sih4sing5hong5/tau3_phah4-ji7/issues"
"url": "https://github.com/i3thuan5/ten1su4/issues"
},
"homepage": "http://xn--jny.xn--v0qr21b.xn--kpry57d/",
"homepage": "https://xn--kpu3003h.xn--v0qr21b.xn--kpry57d/",
"dependencies": {
"bluebird": "^3.4.1",
"debug": "^2.2.0",
"demo-ui": "^1.11.5",
"demo-ui": "^1.13.6",
"prop-types": "^15.5.8",
"react": "^15.5.4",
"react-dom": "^15.5.4",
Expand All @@ -41,6 +45,7 @@
"superagent-bluebird-promise": "^3.0.2"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.4.0",
"babel-eslint": "^7.2.3",
"babel-loader": "^6.2.1",
Expand All @@ -63,6 +68,8 @@
"file-loader": "^0.9.0",
"gh-pages": "^0.11.0",
"html-loader": "^0.4.3",
"jsdom": "^11.0.0",
"jsdom-global": "^3.0.2",
"json-loader": "^0.5.4",
"mocha": "^3.2.0",
"nock": "^9.0.11",
Expand Down
6 changes: 4 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
RECIEVE_HANLO,
RECIEVE_ERROR_HANLO,
} from "./action.type";
import { 後端網址, 標漢字音標 } from "../後端網址";
import API from "../api";

export const 請求遠端查詢 = (語句, 腔口) => ({
type: REQUEST_HANLO,
Expand All @@ -28,8 +28,10 @@ export const 遠端查詢發生錯誤 = (語句, 腔口, error) => ({

export const 遠端查詢 = (語句, 腔口) => (dispatch) => {
dispatch(請求遠端查詢(語句, 腔口));
const apiFunc = API.取得查詢函式();

return superagent
.get(後端網址 + 標漢字音標)
.get(apiFunc())
.query({
查詢腔口: 腔口,
查詢語句: 語句.trim(),
Expand Down
30 changes: 30 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import config from "../config";

const api = {};
const self = api;

api.網域 = () => ("https://服務.意傳.台灣/");

api.標漢字音標 = () => `${self.網域()}標漢字音標`;

api.正規化翻譯 = () => `${self.網域()}正規化翻譯`;

api.語音合成 = ({ 腔口 = "", 分詞 = "" } = {}) =>
encodeURI(`${self.網域()}語音合成?` +
`查詢腔口=${腔口}&查詢語句=${分詞}`);

api.取得查詢函式名稱 = (專案 = config.專案()) => {
switch (專案) {
case "寫啥物":
return "正規化翻譯";
case "鬥拍字":
return "標漢字音標";
default:
return null;
}
};

api.取得查詢函式 = (專案 = config.專案()) =>
api[self.取得查詢函式名稱(專案)];

export default api;
11 changes: 11 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import config from "../../taupahji.config";

const configGenerator = {
專案: () => (config.專案),
全部腔口: () => (config.腔口),
預設腔口: () => (config.腔口[0]),
範例查詢: () => (config.範例查詢),
頁尾連結: () => (config.頁尾連結),
};

export default configGenerator;
40 changes: 1 addition & 39 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
import React from "react";
import { render } from "react-dom";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
import thunk from "redux-thunk";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import createLogger from "redux-logger";
import Debug from "debug";
import 網站 from "./網站/網站";
import from "./頁/查/查.container";
import reducer from "./reducers";

Debug.enable("tau3:*");

const root = document.getElementById("app");
const middlewares = [thunk];
if (process.env.NODE_ENV !== "production") {
middlewares.push(createLogger);
}

const store = createStore(
reducer,
applyMiddleware(...middlewares),
);

render(
<Provider store={store}>
<Router history={browserHistory}>
<Route path='/' component={網站 }>
<IndexRoute component={}/>
<Route path='%E8%AC%9B/:khiunn/:ku' component={}/>
<Route path='%E8%AC%9B(/:ku)' component={}/>
<Route path='%E8%AC%9B' component={}/>
<Route path='**/:ku' component={}/>
</Route>
</Router>
</Provider>,
root,
);
export default from "./providers";
40 changes: 40 additions & 0 deletions src/providers/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
import thunk from "redux-thunk";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import createLogger from "redux-logger";
import 網站 from "../網站/網站";
import from "../頁/查/查";
import reducer from "../reducers";

const getAppStore = () => {
const middlewares = [thunk];
if (process.env.NODE_ENV !== "production") {
middlewares.push(createLogger);
}
const store = createStore(
reducer,
applyMiddleware(...middlewares),
);
return store;
};

const MyProvider = () => {
const store = getAppStore();
return (
<Provider store={store}>
<Router history={browserHistory}>
<Route path='/' component={網站}>
<IndexRoute component={}/>
<Route path='%E8%AC%9B/:khiunn/:ku' component={}/>
<Route path='%E8%AC%9B(/:ku)' component={}/>
<Route path='%E8%AC%9B' component={}/>
<Route path='**/:ku' component={}/>
</Route>
</Router>
</Provider>
);
};

export default MyProvider;
10 changes: 4 additions & 6 deletions src/reducers/查詢.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import {
RECIEVE_ERROR_HANLO,
} from "../actions/action.type";

const 初始state = {
const 初始state = () => ({
語句: "",
腔口: "四縣腔",
腔口: "",
正在查詢: false,
發生錯誤: false,
};
});

const 查詢 = (state = 初始state, action) => {
const 查詢 = (state = 初始state(), action) => {
switch (action.type) {
case REQUEST_HANLO:

// 保留上一次的查詢結果
return {
...state,
語句: action.語句,
Expand Down
27 changes: 22 additions & 5 deletions src/reducers/查詢結果.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,38 @@ import {
RECIEVE_ERROR_HANLO,
} from "../actions/action.type";

const 初始state = {
export const 正規化綜合標音 = (綜合標音 = []) => {
if (!綜合標音 || 綜合標音.length === 0) {
return [];
}
const first = 綜合標音[0];
const keys = Object.keys(first);
const newKeys = keys.filter(x => (
x !== "臺羅閏號調" && x !== "臺灣客話"
));
return 綜合標音.map((t) => {
const result = {};
result.羅馬字 = t.臺羅閏號調 || t.臺灣客話;
newKeys.forEach((k) => { result[k] = t[k]; });
return result;
});
};

const 初始state = () => ({
結果語句: "",
結果腔口: "四縣腔",
結果腔口: "",
分詞: "",
綜合標音: [],
};
});

const 查詢結果 = (state = 初始state, action) => {
const 查詢結果 = (state = 初始state(), action) => {
switch (action.type) {
case RECIEVE_HANLO:
return {
結果語句: action.語句,
結果腔口: action.腔口,
分詞: action.查詢結果.分詞,
綜合標音: action.查詢結果.綜合標音,
綜合標音: 正規化綜合標音(action.查詢結果.綜合標音),
};
case RECIEVE_ERROR_HANLO:
return {
Expand Down
22 changes: 22 additions & 0 deletions src/utils/複製.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const 計算複製內容 = (綜合標音 = []) => {
if (!綜合標音 || 綜合標音.length < 1) {
return 綜合標音;
}

return 綜合標音
.map((item) => {
const 漢字 = item.漢字.replace(/ /g, "");
return {
漢字羅馬: [漢字, item.羅馬字].join("\n"),
羅馬字: item.羅馬字,
漢字,
};
})
.reduce((acc, item) => ({
漢字羅馬: [acc.漢字羅馬, item.漢字羅馬].join("\n"),
漢字: [acc.漢字, item.漢字].join("\n"),
羅馬字: [acc.羅馬字, item.羅馬字].join("\n"),
}));
};

export default 計算複製內容;
Loading

0 comments on commit e89f336

Please sign in to comment.