Page MenuHomeDevCentral

No OneTemporary

diff --git a/gadgets/generators/_documents.xml b/gadgets/generators/_documents.xml
new file mode 100644
index 0000000..79d69bd
--- /dev/null
+++ b/gadgets/generators/_documents.xml
@@ -0,0 +1,17 @@
+<documents topic="gadgets-generators">
+ <document>
+ <article>index</article>
+ <title>Generators</title>
+ <description>Craft sentences, expressions or generate names.</description>
+ <head><![CDATA[
+ <style type="text/css">
+ /* A nice font for our text */
+
+ #content .result { font-family: "OFL Sorts Mill Goudy TT"; font-size: 1.125em; }
+ </style>
+ <link href="//fonts.googleapis.com/css?family=OFL+Sorts+Mill+Goudy+TT:regular,italic" rel="stylesheet" type="text/css">
+ <link href="/stylesheets/react-select.css" rel="stylesheet" type="text/css">
+]]>
+ </head>
+ </document>
+</documents>
diff --git a/gadgets/generators/app.js b/gadgets/generators/app.js
new file mode 100644
index 0000000..aa20ad1
--- /dev/null
+++ b/gadgets/generators/app.js
@@ -0,0 +1,276 @@
+/** @jsx React.DOM */
+
+/* -------------------------------------------------------------
+ Generators - Craft sentences, expressions or generate names.
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ Author: Dereckson
+ Dependencies: React, JSX, classnames, react-select
+ Licence: BSD
+ ------------------------------------------------------------- */
+
+/* -------------------------------------------------------------
+ Dependencies
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+var React = require('react');
+var Select = require('react-select');
+
+/* -------------------------------------------------------------
+ Strings and Array prototype functions
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+String.prototype.capitalizeFirstLetter = function() {
+ // http://stackoverflow.com/a/1026087/1930997
+ return this.charAt(0).toUpperCase() + this.slice(1);
+}
+
+Array.prototype.randomElement = function () {
+ // http://stackoverflow.com/a/7120353/1930997
+ return this[Math.floor(Math.random() * this.length)]
+}
+
+/* -------------------------------------------------------------
+ Craft
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+var CraftBluePrint = {
+
+ bluePrint: null,
+
+ init: function (bluePrint) {
+ this.bluePrint = bluePrint;
+ },
+
+ getSource: function () {
+ return this.bluePrint.craft.source;
+ },
+
+ craftPickSeveralInOneGroup: function () {
+ /**
+ * In this mode, we have one group object array, and we select craft.amount items in this group.
+ * We return these picked items, concatenated, optionally taking craft.separator in consideration.
+ */
+ var separator = "", start = "", end = "";
+ if (this.bluePrint.craft.separator) {
+ separator = this.bluePrint.craft.separator;
+ }
+ if (this.bluePrint.craft.prepend) {
+ start = this.bluePrint.craft.prepend;
+ }
+ if (this.bluePrint.craft.append) {
+ end = this.bluePrint.craft.append;
+ }
+ var items = [];
+ for (var i = 0 ; i < this.bluePrint.craft.amount ; i++) {
+ do {
+ candidate = this.bluePrint.group.content.randomElement();
+ } while (items.indexOf(candidate) > -1)
+ items[i] = candidate;
+ };
+ return start + items.join(separator) + end;
+ },
+
+ craftPickOnePerGroup: function () {
+ /**
+ * In this mode, we have a groups array, and we select one item in each group.
+ * We return these picked items, concatenated, optionally taking craft.separator in consideration.
+ */
+ var separator = "";
+ if (this.bluePrint.craft.separator) {
+ separator = this.bluePrint.craft.separator;
+ }
+ var items = this.bluePrint.groups.map(function (group) {
+ return group.content.randomElement();
+ });
+ return items.join(separator);
+ },
+
+ craft: function () {
+ /* The blueprint should define a craft mode and other options:
+ craft: { mode: "Quux", ... };
+
+ We then call the mode method, for example here craftQuux().
+ */
+
+ var craftModeMethod = "craft" + this.bluePrint.craft.mode;
+ var itemsAmount = 1;
+ var itemsSeparator = "\n";
+
+ if (this.bluePrint.craft.populate) {
+ itemsAmount = this.bluePrint.craft.populate;
+ }
+ if (this.bluePrint.craft.populateSeparator) {
+ itemsSeparator = this.bluePrint.craft.populateSeparator;
+ }
+
+ if (this[craftModeMethod]) {
+ if (itemsAmount == 1) {
+ return this[craftModeMethod]();
+ }
+
+ var items = [];
+ for (i = 0 ; i < itemsAmount ; i++) {
+ items[i] = this[craftModeMethod]();
+ }
+ return items.join(itemsSeparator);
+ }
+ return "[Craft exception] Craft mode unknown: " + craftModeMethod;
+ },
+};
+
+/* -------------------------------------------------------------
+ Application UI
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+var App = React.createClass({
+ getDefaultProps: function () {
+ return {
+ searchable: true,
+ };
+ },
+
+ getInitialState: function () {
+ return {
+ generator: null,
+ generators: [],
+ generatorResult: "(running generator...)",
+ }
+ },
+
+ extractName: function (url) {
+ var re = /^.*\/(.*).json$/;
+ return re.exec(url)[1];
+ },
+
+ componentDidMount: function () {
+ var self = this;
+ var url = generators.datasource;
+ $.getJSON(url, function (result) {
+ if (!result || !result.length) {
+ return;
+ }
+ var generatorsList = result.map(function (item) {
+ return {
+ url: item,
+ name: self.extractName(item)
+ }
+ });
+ self.setState({
+ generators: generatorsList
+ });
+ });
+ },
+
+ updateGeneratorValue: function (newValue) {
+ var url = newValue || null;
+ this.setState({
+ generator: url
+ });
+ if (url) {
+ this.runGenerator(url);
+ }
+ },
+
+ getOptions: function () {
+ return this.state.generators.map(function (item) {
+ return { value: item.url, label: item.name };
+ });
+ },
+
+ renderSelector: function () {
+ return (
+ <div id="generator-selector">
+ <h2>Generator selection</h2>
+ <label htmlFor="generator">Generator to use:</label>
+ <Select
+ name="generator" id="generator"
+ options={this.getOptions()}
+ value={this.state.generator}
+ searchable={this.props.searchable}
+ onChange={this.updateGeneratorValue}
+ />
+ <span>Something else to craft? We'll be happy to add open datasources and provide the generator logic. <a href="https://devcentral.nasqueron.org/tag/tools/">Suggest it here.</a></span>
+ </div>);
+ },
+
+ canRenderGenerator: function () {
+ return this.state.generator != null;
+ },
+
+ getGeneratorTitle: function () {
+ return this.extractName(this.state.generator).replace("-", " — ").capitalizeFirstLetter();
+ },
+
+ recraft: function () {
+ this.setState({
+ generatorResult: CraftBluePrint.craft()
+ });
+ },
+
+ runGenerator: function (url) {
+ var self = this;
+ $.getJSON(url, function (result) {
+ if (!result) {
+ return;
+ }
+ CraftBluePrint.init(result);
+ self.setState({
+ generatorResult: CraftBluePrint.craft()
+ });
+ });
+ },
+
+ renderGenerator: function () {
+ if (!this.canRenderGenerator()) {
+ return "";
+ }
+
+ return <div id="generator-result">
+ <h2>{this.getGeneratorTitle()}</h2>
+ <textarea id="generator-result" className="result" value={this.state.generatorResult} readOnly rows="5" />
+ <button className="button" onClick={this.recraft}>Roll again</button>
+ <p id="generator-source"><strong>Source:</strong> {CraftBluePrint.getSource()}</p>
+ </div>;
+ },
+
+ render: function () {
+ return <div id="app">
+ {this.renderSelector()}
+ {this.renderGenerator()}
+ </div>;
+ }
+});
+
+/* -------------------------------------------------------------
+ Application entry point
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+var generators = {
+ datasource: null,
+ id: null,
+
+ init: function (datasource, id) {
+ this.datasource = datasource;
+ this.id = id;
+ },
+
+ getAppElement: function () {
+ return document.getElementById(this.id);
+ },
+
+ run: function () {
+ console.log('Rendering interface...');
+ React.render(
+ <App/>,
+ this.getAppElement()
+ );
+ console.log('... done.');
+ }
+}
+
+/* -------------------------------------------------------------
+ Runs application
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
+
+generators.init('list-generators.query', 'application');
+generators.run();
diff --git a/gadgets/generators/index.php b/gadgets/generators/index.php
new file mode 100644
index 0000000..f9734bb
--- /dev/null
+++ b/gadgets/generators/index.php
@@ -0,0 +1,2 @@
+ <div id="application"></div>
+ <script src="<?= get_url_for(get_directory(__DIR__), 'bundle.js') ?>"></script>
diff --git a/themes/RalfFallsIntoFoundation/footer.php b/themes/RalfFallsIntoFoundation/footer.php
index 2812a5d..2e2a7e2 100755
--- a/themes/RalfFallsIntoFoundation/footer.php
+++ b/themes/RalfFallsIntoFoundation/footer.php
@@ -1,92 +1,93 @@
</div></section>
<!-- Footer -->
<footer><div class="row">
<div class="twelve columns"><hr />
<div class="row">
<div class="three columns site-description">
<p><img src="/images/Nasqueron.png" width="80px" /></p>
<p><strong>Nasqueron</strong> is a community of developers <span class="ampersand">&</span> creative people.</p>
<hr />
<p><strong>Nasqueron Tools</strong> is a collection of small utilities, gadgets <span class="ampersand">&</span> scripts to perform daily tasks.</p>
</div>
<div class="three columns">
<dl>
<dt>Wikimedia dev</dt>
<dd><a href="/wikimedia/dev/feeds/">Gerrit activity feeds</a></dd>
<!--<dd>RSS generator</dd>-->
<dt>Wikimedia Writing Tools</dt>
<dd><a href="/wikimedia/write/sourcetemplatesgenerator/">Source templates generator</a></dd>
<dt>Finger</dt>
<dd><a href="/finger">Finger client</a></dd>
<dd><a href="/finger/thimbl">Thimbl client</a></dd>
<dt>µblogging</dt>
<dd><a href="/microblogging/twitterpoints">Twitter Points</a></dd>
+
+ <dt>Geocaching</dt>
+ <dd><a href="/geocaching/string2number">String to number</a></dd>
</dl>
</div>
<div class="three columns">
<dl>
<dt>Lists</dt>
<dd><a href="/lists/operations">Lists operations</a></dd>
<dd><a href="/lists/replace">Lists RegExp replace</a></dd>
<dt>CSS</dt>
<dd><a href="/css/media-queries-generator">Media queries generator</a></dd>
<dt>JSON</dt>
<dd><a href="/json/excel2json">Excel to JSON converter</a></dd>
<dt>Color</dt>
<dd><a href="/color/screen/">Random color screen</a></dd>
<dd><a href="/color/screen/879497">Gray-blue screen</a></dd>
</dl>
</div>
<div class="three columns">
<dl>
<dt>Generators</dt>
<dd><a href="/generators/GNOME/desktop-file">GNOME .desktop file generator</dd>
<dt>Gadgets</dt>
<dd><a href="/gadgets/motd-variations">MOTD in Jive <span class="ampersand">&</span> Valspeak</a></dd>
<dd><a href="/gadgets/text-variations">Letters variation</a></dd>
-
- <dt>Geocaching</dt>
- <dd><a href="/geocaching/string2number">String to number</a></dd>
+ <dd><a href="/gadgets/generators/">Sentences generator</a></dd>
<dt>Network</dt>
<dd><a href="/network/mx">MX</a></dd>
<dt>Start pages</dt>
<dd><a href="/lex">Lex</a></dd>
</dl>
</div>
</div>
</div>
<div class="twelve columns"><hr />
<div class="row extrainfos">
<div class="six columns">
<p><i class="general foundicon-settings"></i> <strong>Options:</strong> <a href="javascript:SetUITonality('dark');">dark mode</a> | <a href="javascript:SetUITonality('light');">light mode</a></p>
</div>
<div class="six columns">
<p class="right"><i class="general foundicon-flag"></i> <strong>Git revision:</strong> <?= substr(`git rev-parse HEAD`, 0, 7) ?> | <strong>Version:</strong> alpha preview</p>
</div>
</div>
<div class="row extrainfos">
<div class="six columns">
<p><i class="general foundicon-globe"></i> <strong>Crafted by</strong> <a href="http://www.dereckson.be/">Dereckson</a> | <strong>Powered by</strong> <a href="http://keruald.sf.net">Keruald/Pluton</a> <span class="ampersand">&</span> <a href="http://foundation.zurb.com/">Foundation</a>.</p>
</div>
<div class="six columns">
<p class="right">“For water, though supposedly incompressible, is not entirely so.”</p>
</div>
</div>
</div>
</div></footer>
<script src="/javascripts/jquery.cookie.js"></script>
<script src="/javascripts/app.js"></script>
<?= $document->footer ?>
</body>
</html>

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 14, 14:02 (1 d, 13 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4258345
Default Alt Text
(12 KB)

Event Timeline