@@ -731,51 +731,50 @@ describe('Emoji Unit test', function () {
731731} ) ;
732732
733733var Base = function ( ) {
734- function Base ( input , output , options , embeds ) {
735- babelHelpers_classCallCheck ( this , Base ) ;
734+ function Base ( input , output , options , embeds ) {
735+ babelHelpers_classCallCheck ( this , Base ) ;
736736
737- this . input = input ;
738- this . output = output ;
739- this . options = options ;
740- this . embeds = embeds ;
741- }
737+ this . input = input ;
738+ this . output = output ;
739+ this . options = options ;
740+ this . embeds = embeds ;
741+ }
742742
743- babelHelpers_createClass ( Base , [ {
744- key : 'process' ,
745- value : function process ( ) {
746- var _this = this ;
743+ babelHelpers_createClass ( Base , [ {
744+ key : 'process' ,
745+ value : function process ( ) {
746+ var _this = this ;
747747
748- if ( ! ifInline ( this . options , this . service ) ) {
749- var regexInline = this . options . link ? new RegExp ( '([^>]*' + this . regex . source + ')</a>' , 'gm' ) : new RegExp ( '([^\\s]*' + this . regex . source + ')' , 'gm' ) ;
750- this . output = this . output . replace ( regexInline , function ( match ) {
751- var url = _this . options . link ? match . slice ( 0 , - 4 ) : match ;
752- if ( _this . options . served . indexOf ( url ) === - 1 ) {
753- _this . options . served . push ( url ) ;
754- if ( _this . options . link ) {
755- return ! _this . options . inlineText ? _this . template ( match . slice ( 0 , - 4 ) ) + '</a>' : match + _this . template ( match . slice ( 0 , - 4 ) ) ;
756- } else {
757- return ! _this . options . inlineText ? _this . template ( match ) : match + _this . template ( match ) ;
758- }
759- } else {
760- return url ;
761- }
762- } ) ;
763- } else {
764- var match = undefined ;
765- while ( ( match = matches ( this . regex , this . input ) ) !== null ) {
766- if ( this . options . served . indexOf ( match [ 0 ] ) === - 1 ) {
767- var text = this . template ( match [ 0 ] ) ;
768- this . embeds . push ( {
769- text : text ,
770- index : match . index
771- } ) ;
772- }
773- }
774- }
775- return [ this . output , this . embeds ] ;
776- }
777- } ] ) ;
778- return Base ;
748+ if ( ! ifInline ( this . options , this . service ) ) {
749+ var regexInline = this . options . link ? new RegExp ( '([^>]*' + this . regex . source + ')</a>' , 'gm' ) : new RegExp ( '([^\\s]*' + this . regex . source + ')' , 'gm' ) ;
750+ this . output = this . output . replace ( regexInline , function ( match ) {
751+ var url = _this . options . link ? match . slice ( 0 , - 4 ) : match ;
752+ if ( _this . options . served . indexOf ( url ) === - 1 ) {
753+ _this . options . served . push ( url ) ;
754+ if ( _this . options . link ) {
755+ return ! _this . options . inlineText ? _this . template ( match . slice ( 0 , - 4 ) ) + '</a>' : match + _this . template ( match . slice ( 0 , - 4 ) ) ;
756+ } else {
757+ return ! _this . options . inlineText ? _this . template ( match ) : match + _this . template ( match ) ;
758+ }
759+ } else {
760+ return url ;
761+ }
762+ } ) ;
763+ } else {
764+ var match = undefined ;
765+ while ( ( match = matches ( this . regex , this . input ) ) !== null ) {
766+ if ( ! ( this . options . served . indexOf ( match [ 0 ] ) === - 1 ) ) continue ;
767+ var text = this . template ( match [ 0 ] ) ;
768+ this . embeds . push ( {
769+ text : text ,
770+ index : match . index
771+ } ) ;
772+ }
773+ }
774+ return [ this . output , this . embeds ] ;
775+ }
776+ } ] ) ;
777+ return Base ;
779778} ( ) ;
780779
781780var Plunker = function ( _Base ) {
@@ -819,11 +818,60 @@ describe('Class Plunker => unit test', function () {
819818 output = _plunker$process2 [ 0 ] ;
820819 embeds = _plunker$process2 [ 1 ] ;
821820
821+ console . log ( embeds ) ;
822+
822823 expect$4 ( output ) . to . be . a ( 'string' ) ;
823824 expect$4 ( embeds ) . to . be . a ( 'array' ) ;
824825
825826 expect$4 ( embeds [ 0 ] . index ) . to . equal ( 33 ) ;
826827
827828 expect$4 ( embeds [ 0 ] . text . replace ( / \t | \n / gi, '' ) ) . to . equal ( '<div class="ejs-embed ejs-plunker"><iframe class="ne-plunker" src="http://embed.plnkr.co/nVCmukG5abpi1Y4ZHkrq" height="500"></iframe></div>' ) ;
828829 } ) ;
830+ } ) ;
831+
832+ var CodePen = function ( _Base ) {
833+ babelHelpers_inherits ( CodePen , _Base ) ;
834+
835+ function CodePen ( input , output , options , embeds ) {
836+ babelHelpers_classCallCheck ( this , CodePen ) ;
837+
838+ var _this = babelHelpers_possibleConstructorReturn ( this , Object . getPrototypeOf ( CodePen ) . call ( this , input , output , options , embeds ) ) ;
839+
840+ _this . regex = / h t t p : \/ \/ c o d e p e n .i o \/ ( [ A - Z a - z 0 - 9 _ ] + ) \/ p e n \/ ( [ A - Z a - z 0 - 9 _ ] + ) / gi;
841+ _this . service = 'codepen' ;
842+ return _this ;
843+ }
844+
845+ babelHelpers_createClass ( CodePen , [ {
846+ key : 'template' ,
847+ value : function template ( id ) {
848+ return ejs . template . codePen ( id , this . options ) || '<div class="ejs-embed ejs-codepen">\n\t\t\t<iframe scrolling="no" height="' + this . options . codeEmbedHeight + '" src="' + id . replace ( / \/ p e n \/ / , '/embed/' ) + '/?height=' + this . options . codeEmbedHeight + '"></iframe>\n\t\t</div>' ;
849+ }
850+ } ] ) ;
851+ return CodePen ;
852+ } ( Base ) ;
853+
854+ var expect$5 = chai . expect ;
855+
856+ describe ( 'Class Codepen => unit test' , function ( ) {
857+ it ( 'should return a valid plunked embedding url' , function ( ) {
858+
859+ var output = undefined ;
860+ var embeds = [ ] ;
861+ var input = output = 'Sunt castores desiderium http://codepen.io/enxaneta/pen/meYEzO#0 grandis, pius zetaes.Cur luna persuadere?' ;
862+ var codepen = new CodePen ( input , output , options , embeds ) ;
863+
864+ var _codepen$process = codepen . process ( ) ;
865+
866+ var _codepen$process2 = babelHelpers_slicedToArray ( _codepen$process , 2 ) ;
867+
868+ output = _codepen$process2 [ 0 ] ;
869+ embeds = _codepen$process2 [ 1 ] ;
870+
871+ console . log ( embeds ) ;
872+ expect$5 ( output ) . to . be . a ( 'string' ) ;
873+ expect$5 ( embeds ) . to . be . a ( 'array' ) ;
874+
875+ expect$5 ( embeds [ 0 ] . text . replace ( / ( \r \n | \n | \r | \t ) / gm, '' ) ) . to . equal ( '<div class="ejs-embed ejs-codepen"><iframe scrolling="no" height="500" src="http://codepen.io/enxaneta/embed/meYEzO/?height=500"></iframe></div>' ) ;
876+ } ) ;
829877} ) ;
0 commit comments