summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-core/src/components')
-rw-r--r--packages/gitbook-core/src/components/ContextProvider.js8
-rw-r--r--packages/gitbook-core/src/components/I18nProvider.js6
-rw-r--r--packages/gitbook-core/src/components/Link.js30
3 files changed, 29 insertions, 15 deletions
diff --git a/packages/gitbook-core/src/components/ContextProvider.js b/packages/gitbook-core/src/components/ContextProvider.js
index 9b81e9b..86c8d41 100644
--- a/packages/gitbook-core/src/components/ContextProvider.js
+++ b/packages/gitbook-core/src/components/ContextProvider.js
@@ -1,25 +1,27 @@
const React = require('react');
const { Provider } = require('react-redux');
+const ContextShape = require('../shapes/Context');
+
/**
* React component to provide a GitBook context to children components.
*/
const ContextProvider = React.createClass({
propTypes: {
- context: React.PropTypes.object.isRequired,
+ context: ContextShape.isRequired,
children: React.PropTypes.node
},
childContextTypes: {
- gitbookContext: React.PropTypes.object.isRequired
+ gitbook: ContextShape
},
getChildContext() {
const { context } = this.props;
return {
- gitbookContext: context
+ gitbook: context
};
},
diff --git a/packages/gitbook-core/src/components/I18nProvider.js b/packages/gitbook-core/src/components/I18nProvider.js
index 8e169c4..32fa4a0 100644
--- a/packages/gitbook-core/src/components/I18nProvider.js
+++ b/packages/gitbook-core/src/components/I18nProvider.js
@@ -19,4 +19,8 @@ const I18nProvider = React.createClass({
}
});
-module.exports = ReactRedux.connect()(I18nProvider);
+const mapStateToProps = state => {
+ return { messages: state.i18n.messages };
+};
+
+module.exports = ReactRedux.connect(mapStateToProps)(I18nProvider);
diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js
index 83ecdd5..8c142ea 100644
--- a/packages/gitbook-core/src/components/Link.js
+++ b/packages/gitbook-core/src/components/Link.js
@@ -1,8 +1,10 @@
const React = require('react');
const ReactRedux = require('react-redux');
-const path = require('path');
-const url = require('url');
+
+const File = require('../models/File');
+const SummaryArticle = require('../models/SummaryArticle');
const SummaryArticleShape = require('../shapes/SummaryArticle');
+const ContextShape = require('../shapes/Context');
const Link = React.createClass({
propTypes: {
@@ -14,25 +16,31 @@ const Link = React.createClass({
])
},
+ contextTypes: {
+ gitbook: ContextShape.isRequired
+ },
+
getHref() {
- const { to, href } = this.props;
+ const { gitbook } = this.context;
+ let { to, href } = this.props;
if (href) {
return href;
}
- if (typeof to === 'string') {
- return to;
+ if (SummaryArticle.is(to)) {
+ return to.toURL(gitbook);
}
- // Article
- if (typeof to.ref === 'string') {
- const parts = url.parse(to.ref);
- const ext = path.extname(parts.pathname);
- const pathname = path.basename(parts.pathname, ext) + '.html';
+ if (typeof to === 'string') {
+ to = new File(to);
+ }
- return pathname + (parts.hash || '');
+ if (File.is(to)) {
+ return to.toURL(gitbook);
}
+
+ throw new Error('Invalid format for prop "to"');
},
render() {