-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example: Development & Production + CJS & AMD environments #9
Open
rxaviers
wants to merge
3
commits into
globalizejs:master
Choose a base branch
from
rxaviers:dev-prod-builds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var React = require("react"); | ||
var Globalize = require("globalize"); | ||
var GlobalizeCompiler = require("globalize/tool/compiler"); | ||
|
||
function compiler() { | ||
var components = [].slice.call(arguments, 0); | ||
|
||
// Have react to render all passed components, therefore any formatters in use will be created. | ||
components.forEach(function(component) { | ||
React.renderToString(component); | ||
}); | ||
|
||
// Compile all generated formatters. | ||
return GlobalizeCompiler(Globalize.cache); | ||
} | ||
|
||
module.exports = compiler; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"scripts": { | ||
"preinstall": "npm install [email protected]", | ||
"postinstall": "node ./node_modules/cldr-data-downloader/bin/download.js -i bower_components/cldr-data/index.json -o bower_components/cldr-data/" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Example | ||
======= | ||
|
||
Development mode | ||
------- | ||
These instructions assume you have node and npm installed. For help, see the [npm docs](https://docs.npmjs.com/getting-started/installing-node) | ||
|
||
1. Run `npm install` once. | ||
3. Open browser and navigate to `react-globalize/examples/development.html`. | ||
|
||
Production mode | ||
------- | ||
|
||
1. Run `npm install` once. | ||
2. Run `npm run-script build` to generate the built JS file. | ||
3. Open browser and navigate to `react-globalize/examples/production.html`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "react-globalize-example", | ||
"devDependencies": { | ||
"almond": "~0.3.1", | ||
"cldr-data": "27.x", | ||
"globalize": "jquery/globalize#fix-398-runtime", | ||
"react": "0.13.1", | ||
"react-globalize": "rxaviers/react-globalize#addons", | ||
"requirejs": "2.1.x", | ||
"requirejs-plugins": "1.0.2", | ||
"requirejs-react-jsx": "0.13.1", | ||
"requirejs-text": "2.0.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#! /usr/bin/env node | ||
|
||
var requirejs = require("requirejs"); | ||
var util = require("util"); | ||
|
||
var config = require("./src/config"); | ||
config.paths.almond = "../bower_components/almond/almond"; | ||
config.paths["globalize-precompiled-formatters"] = "../tmp/globalize-precompiled-formatters"; | ||
config.paths["globalize-runtime"] = "../bower_components/globalize/dist/globalize-runtime"; | ||
config.map = { | ||
"*": { | ||
"globalize": "globalize-runtime" | ||
} | ||
}; | ||
delete config.paths["cldr-data"]; | ||
|
||
util._extend(config, { | ||
dir: "tmp/.build", | ||
appDir: "src", | ||
baseUrl: ".", | ||
optimize: "none", | ||
skipDirOptimize: true, | ||
skipSemiColonInsertion: true, | ||
skipModuleInsertion: true, | ||
findNestedDependencies: true, | ||
stubModules : ["text"], | ||
onBuildWrite: function (id, path, contents) { | ||
return contents | ||
.replace(/"globalize"/g, "\"globalize-runtime\"") | ||
.replace(/"globalize\//g, "\"globalize-runtime\/") | ||
.replace(/jsx!/g, ""); | ||
}, | ||
modules: [{ | ||
name: "app", | ||
include: ["almond", "jsx!production"], | ||
exclude: ["jsx"], | ||
create: true | ||
}] | ||
}); | ||
|
||
requirejs.optimize(config, function(){}, console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv='Content-type' content='text/html; charset=utf-8'> | ||
<title>Examples</title> | ||
</head> | ||
<body> | ||
<script src="src/config.js"></script> | ||
<script src="bower_components/requirejs/require.js"></script> | ||
<script> | ||
require(["jsx!./src/development"]); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#! /usr/bin/env node | ||
|
||
var GlobalizeCompiler = require("globalize/tool/compiler"); | ||
var React = require("react"); | ||
var requirejs = require("requirejs"); | ||
var config = require("./src/config"); | ||
|
||
config.nodeRequire = require; | ||
config.baseUrl = __dirname + "/src"; | ||
requirejs.config(config); | ||
|
||
Globalize = requirejs("globalize"); | ||
requirejs("load-globalize-i18n-data"); | ||
var App = requirejs("jsx!app"); | ||
|
||
// Have react to render all passed components, therefore any formatters in use will be created. | ||
React.renderToString(React.createElement(App, {locale: "en"})); | ||
React.renderToString(React.createElement(App, {locale: "pt"})); | ||
|
||
// Compile all generated formatters. | ||
console.log(GlobalizeCompiler(Globalize.cache)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "react-globalize-example", | ||
"description": "Examples demonstrating use of the components", | ||
"main": "app.js", | ||
"devDependencies": { | ||
"react": "~0.13.0", | ||
"react-tools": "^0.13.2", | ||
"requirejs": "^2.1.17", | ||
"uglify-js": "^2.4.20" | ||
}, | ||
"scripts": { | ||
"clean": "for DIR in tmp dist; do ( test -d $DIR && rm -rf $DIR ); mkdir $DIR; done", | ||
"build": "npm run-script clean && ./globalize-compiler > tmp/globalize-precompiled-formatters.js && ./build && cp tmp/.build/app.js dist/production.js && uglifyjs dist/production.js > dist/production.min.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv='Content-type' content='text/html; charset=utf-8'> | ||
<title>Examples</title> | ||
</head> | ||
<body> | ||
<script src="dist/production.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
define([ | ||
"globalize", | ||
"react", | ||
"jsx!./components/currency", | ||
"jsx!./components/dates", | ||
"jsx!./components/messages", | ||
"jsx!./components/numbers" | ||
], function(Globalize, React, LocalizedCurrencies, LocalizedDates, LocalizedMessages, LocalizedNumbers) { | ||
|
||
var App = React.createClass({ | ||
getInitialState: function() { | ||
return { | ||
locale: this.props.locale | ||
}; | ||
}, | ||
changeLocale: function( event ) { | ||
this.setState({ | ||
locale: event.target.value | ||
}); | ||
}, | ||
render: function() { | ||
Globalize.locale(this.state.locale); | ||
return ( | ||
<div> | ||
<h1>Select a locale:</h1> | ||
<select onChange={this.changeLocale}> | ||
<option value="en">en-US</option> | ||
<option value="pt">pt-BR</option> | ||
</select> | ||
|
||
<h1>Currency</h1> | ||
<LocalizedCurrencies /> | ||
|
||
<h1>Dates</h1> | ||
<LocalizedDates /> | ||
|
||
<h1>Messages</h1> | ||
<LocalizedMessages /> | ||
|
||
<h1>Numbers</h1> | ||
<LocalizedNumbers /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
return App; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
define([ | ||
"react", | ||
"react-globalize" | ||
], function(React, ReactGlobalize) { | ||
|
||
var FormatCurrency = ReactGlobalize.FormatCurrency; | ||
|
||
var LocalizedCurrencies = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
USD, 150, default - <FormatCurrency currency="USD" value={150} /> | ||
<br/> | ||
USD, -150, style: "accounting" - <FormatCurrency currency="USD" value={-150} options={{ style: "accounting" }} /> | ||
<br/> | ||
USD, 150, style: "name" - <FormatCurrency currency="USD" value={150} options={{ style: "name" }} /> | ||
<br/> | ||
USD, 150, style: "code" - <FormatCurrency currency="USD" value={150} options={{ style: "code" }} /> | ||
<br/> | ||
USD, 1.491, round: "ceil" - <FormatCurrency currency="USD" value={1.491} options={{ round: "ceil" }} /> | ||
<br/> | ||
EUR, 150, default - <FormatCurrency currency="EUR" value={150} /> | ||
<br/> | ||
EUR, -150, style: "accounting" - <FormatCurrency currency="EUR" value={-150} options={{ style: "accounting" }} /> | ||
<br/> | ||
EUR, 150, style: "name" - <FormatCurrency currency="EUR" value={150} options={{ style: "name" }} /> | ||
<br/> | ||
EUR, 150, style: "code" - <FormatCurrency currency="EUR" value={150} options={{ style: "code" }} /> | ||
<br/> | ||
EUR, 1.491, round: "ceil" - <FormatCurrency currency="EUR" value={1.491} options={{ round: "ceil" }} /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
return LocalizedCurrencies; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
define([ | ||
"react", | ||
"react-globalize" | ||
], function(React, ReactGlobalize) { | ||
|
||
var FormatDate = ReactGlobalize.FormatDate; | ||
|
||
var LocalizedDates = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
default - <FormatDate value={new Date()} /> | ||
<br /> | ||
skeleton: "GyMMMd" - <FormatDate value={new Date()} options={{ skeleton: "GyMMMd" }} /> | ||
<br/> | ||
date: "medium" - <FormatDate value={new Date()} options={{ date: "medium" }} /> | ||
<br/> | ||
time: "medium" - <FormatDate value={new Date()} options={{ time: "medium" }} /> | ||
<br/> | ||
datetime: "medium" - <FormatDate value={new Date()} options={{ datetime: "medium" }} /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
return LocalizedDates; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
define([ | ||
"react", | ||
"react-globalize" | ||
], function(React, ReactGlobalize) { | ||
|
||
var FormatMessage = ReactGlobalize.FormatMessage; | ||
var FormatNumber = ReactGlobalize.FormatNumber; | ||
|
||
var LocalizedMessages = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
<h3>Simple Salutation</h3> | ||
hi - <FormatMessage path="salutations/hi" /> | ||
<br/> | ||
bye - <FormatMessage path="salutations/bye" /> | ||
<h3>Variable Replacement</h3> | ||
["Wolfgang", "Amadeus", "Mozart"] - <FormatMessage path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} /> | ||
<br/> | ||
{JSON.stringify({first:"Wolfgang", middle:"Amadeus", last:"Mozart"})} - <FormatMessage path="variables/hey" variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}} /> | ||
<h3>Gender Inflection</h3> | ||
{JSON.stringify({guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"male"})} - <FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"male"}} /> | ||
<br/> | ||
{JSON.stringify({guest:"Mozart", guestGender:"male", host:"Mendelssohn", hostGender:"female"})} - <FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Mendelssohn", hostGender:"female"}} /> | ||
<br/> | ||
{JSON.stringify({guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"other"})} - <FormatMessage path="party" variables={{guest:"Mozart", guestGender:"male", host:"Beethoven", hostGender:"other"}} /> | ||
<br/> | ||
{JSON.stringify({guest:"Mozart", guestGender:"other", host:"Beethoven", hostGender:"male"})} - <FormatMessage path="party" variables={{guest:"Mozart", guestGender:"other", host:"Mendelssohn", hostGender:"female"}} /> | ||
<br/> | ||
{JSON.stringify({guest:"Mozart", guestGender:"other", host:"Beethoven", hostGender:"other"})} - <FormatMessage path="party" variables={{guest:"Mozart", guestGender:"other", host:"Beethoven", hostGender:"other"}} /> | ||
<h3>Plural Inflection</h3> | ||
task count 1 - <FormatMessage path="task" variables={{count: 1}} /> | ||
<br/> | ||
task count 0 - <FormatMessage path="task" variables={{count: 0}} /> | ||
<br/> | ||
task count 1000 formatted - <FormatMessage ref="formattedTask" path="task" variables={{ | ||
count: 1000, | ||
formattedCount: <FormatNumber value={1000} /> | ||
}} /> | ||
<br/> | ||
like count 0 with offset:1 - <FormatMessage path="likeIncludingMe" variables={{count: 0}} /> | ||
<br/> | ||
like count 1 with offset:1 - <FormatMessage path="likeIncludingMe" variables={{count: 1}} /> | ||
<br/> | ||
like count 2 with offset:1 - <FormatMessage path="likeIncludingMe" variables={{count: 2}} /> | ||
<br/> | ||
like count 3 with offset:1 - <FormatMessage path="likeIncludingMe" variables={{count: 3}} /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
return LocalizedMessages; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
define([ | ||
"react", | ||
"react-globalize" | ||
], function(React, ReactGlobalize) { | ||
|
||
var FormatNumber = ReactGlobalize.FormatNumber; | ||
|
||
var LocalizedNumbers = React.createClass({ | ||
render: function() { | ||
return ( | ||
<div> | ||
pi, no options - <FormatNumber value={Math.PI} /> | ||
<br/> | ||
pi, maximumFractionDigits: 5 - <FormatNumber value={Math.PI} options={{ maximumFractionDigits: 5 }} /> | ||
<br/> | ||
pi, round: "floor" - <FormatNumber value={Math.PI} options={{ round: "floor" }} /> | ||
<br/> | ||
10000, minimumFractionDigits: 2 - <FormatNumber value={10000} options={{ minimumFractionDigits: 2 }} /> | ||
<br/> | ||
0.5, style: "percent" - <FormatNumber value={0.5} options={{ style: "percent" }} /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
return LocalizedNumbers; | ||
|
||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary. Needs to be fixed before landing.