[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add utility binary adapt

2017-10-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/381945 )

Change subject: Add utility binary adapt
..


Add utility binary adapt

Adapts given HTML content using cxserver adaptation system.
Useful for debugging and development

Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307
---
A bin/adapt
1 file changed, 45 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Nikerabbit: Looks good to me, approved



diff --git a/bin/adapt b/bin/adapt
new file mode 100755
index 000..7e90699
--- /dev/null
+++ b/bin/adapt
@@ -0,0 +1,45 @@
+#!/usr/bin/env node
+const fs = require( 'fs' ),
+   yaml = require( 'js-yaml' ),
+   Adapter = require( __dirname + '/../lib/Adapter' ),
+   Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer;
+
+let config = yaml.load( fs.readFileSync( 'config.yaml' ) );
+if ( !config ) {
+   process.stdout.write( 'Failed to load config' );
+   process.exit( 1 );
+}
+
+let cxConfig = config.services && Array.isArray( config.services ) &&
+   config.services.filter( function ( item ) {
+   return item && item.name === 'cxserver';
+   } )[ 0 ];
+if ( !cxConfig ) {
+   process.stdout.write( 'Cannot find cxserver config' );
+   process.exit( 1 );
+}
+
+function normalize( html ) {
+   var normalizer = new Normalizer();
+   normalizer.init();
+   normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) );
+   return normalizer.getHtml();
+}
+
+let xhtml = fs.readFileSync( '/dev/stdin', 'utf8' );
+if ( xhtml.trim() === '' || process.argv.length !== 4 ) {
+   let script = process.argv[ 1 ];
+   process.stderr.write(
+   'Usage: node ' + script + ' fromLang toLang < file\n'
+   );
+   process.exit( 1 );
+
+}
+
+let from = process.argv[ 2 ];
+let to = process.argv[ 3 ];
+let adapter = new Adapter( from, to, cxConfig );
+adapter.adapt( xhtml ).then( function ( result ) {
+   result = normalize( result.getHtml() );
+   process.stdout.write( result + '\n' );
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/381945
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] mediawiki...cxserver[master]: Add utility binary adapt

2017-10-03 Thread Santhosh (Code Review)
Santhosh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/381945 )

Change subject: Add utility binary adapt
..

Add utility binary adapt

Adapts given HTML content using cxserver adaptation system.
Useful for debugging and development

Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307
---
A bin/adapt
1 file changed, 45 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver 
refs/changes/45/381945/1

diff --git a/bin/adapt b/bin/adapt
new file mode 100755
index 000..7e90699
--- /dev/null
+++ b/bin/adapt
@@ -0,0 +1,45 @@
+#!/usr/bin/env node
+const fs = require( 'fs' ),
+   yaml = require( 'js-yaml' ),
+   Adapter = require( __dirname + '/../lib/Adapter' ),
+   Normalizer = require( __dirname + '/../lib/lineardoc' ).Normalizer;
+
+let config = yaml.load( fs.readFileSync( 'config.yaml' ) );
+if ( !config ) {
+   process.stdout.write( 'Failed to load config' );
+   process.exit( 1 );
+}
+
+let cxConfig = config.services && Array.isArray( config.services ) &&
+   config.services.filter( function ( item ) {
+   return item && item.name === 'cxserver';
+   } )[ 0 ];
+if ( !cxConfig ) {
+   process.stdout.write( 'Cannot find cxserver config' );
+   process.exit( 1 );
+}
+
+function normalize( html ) {
+   var normalizer = new Normalizer();
+   normalizer.init();
+   normalizer.write( html.replace( /(\r\n|\n|\t|\r)/gm, '' ) );
+   return normalizer.getHtml();
+}
+
+let xhtml = fs.readFileSync( '/dev/stdin', 'utf8' );
+if ( xhtml.trim() === '' || process.argv.length !== 4 ) {
+   let script = process.argv[ 1 ];
+   process.stderr.write(
+   'Usage: node ' + script + ' fromLang toLang < file\n'
+   );
+   process.exit( 1 );
+
+}
+
+let from = process.argv[ 2 ];
+let to = process.argv[ 3 ];
+let adapter = new Adapter( from, to, cxConfig );
+adapter.adapt( xhtml ).then( function ( result ) {
+   result = normalize( result.getHtml() );
+   process.stdout.write( result + '\n' );
+} );

-- 
To view, visit https://gerrit.wikimedia.org/r/381945
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a303689ab0dd1c98ac8106fb1621ac78e39d307
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Santhosh 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits