BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b356997a
Unverified
Commit
b356997a
authored
Oct 12, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove global export except in test environments
parent
9fd89990
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
45 deletions
+49
-45
copy_as_gfm.js
app/assets/javascripts/behaviors/copy_as_gfm.js
+9
-4
index.js
app/assets/javascripts/behaviors/index.js
+2
-1
copy_as_gfm_spec.rb
spec/features/copy_as_gfm_spec.rb
+2
-2
copy_as_gfm_spec.js
spec/javascripts/behaviors/copy_as_gfm_spec.js
+36
-38
No files found.
app/assets/javascripts/behaviors/copy_as_gfm.js
View file @
b356997a
...
...
@@ -285,7 +285,7 @@ const gfmRules = {
},
};
class
CopyAsGFM
{
export
class
CopyAsGFM
{
constructor
()
{
$
(
document
).
on
(
'copy'
,
'.md, .wiki'
,
(
e
)
=>
{
CopyAsGFM
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformGFMSelection
);
});
$
(
document
).
on
(
'copy'
,
'pre.code.highlight, .diff-content .line_content'
,
(
e
)
=>
{
CopyAsGFM
.
copyAsGFM
(
e
,
CopyAsGFM
.
transformCodeSelection
);
});
...
...
@@ -470,7 +470,12 @@ class CopyAsGFM {
}
}
window
.
gl
=
window
.
gl
||
{};
window
.
gl
.
CopyAsGFM
=
CopyAsGFM
;
// Export CopyAsGFM as a global for rspec to access
// see /spec/features/copy_as_gfm_spec.rb
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
window
.
CopyAsGFM
=
CopyAsGFM
;
}
new
CopyAsGFM
();
export
default
function
initCopyAsGFM
()
{
return
new
CopyAsGFM
();
}
app/assets/javascripts/behaviors/index.js
View file @
b356997a
import
'./autosize'
;
import
'./bind_in_out'
;
import
'./copy_as_gfm'
;
import
initCopyAsGFM
from
'./copy_as_gfm'
;
import
'./details_behavior'
;
import
installGlEmojiElement
from
'./gl_emoji'
;
import
'./quick_submit'
;
...
...
@@ -8,3 +8,4 @@ import './requires_input';
import
'./toggler_behavior'
;
installGlEmojiElement
();
initCopyAsGFM
();
spec/features/copy_as_gfm_spec.rb
View file @
b356997a
...
...
@@ -664,7 +664,7 @@ describe 'Copy as GFM', :js do
def
html_to_gfm
(
html
,
transformer
=
'transformGFMSelection'
,
target:
nil
)
js
=
<<-
JS
.
strip_heredoc
(function(html) {
var transformer = window.
gl.
CopyAsGFM[
#{
transformer
.
inspect
}
];
var transformer = window.CopyAsGFM[
#{
transformer
.
inspect
}
];
var node = document.createElement('div');
$(html).each(function() { node.appendChild(this) });
...
...
@@ -678,7 +678,7 @@ describe 'Copy as GFM', :js do
node = transformer(node, target);
if (!node) return null;
return window.
gl.
CopyAsGFM.nodeToGFM(node);
return window.CopyAsGFM.nodeToGFM(node);
})("
#{
escape_javascript
(
html
)
}
")
JS
page
.
evaluate_script
(
js
)
...
...
spec/javascripts/copy_as_gfm_spec.js
→
spec/javascripts/
behaviors/
copy_as_gfm_spec.js
View file @
b356997a
import
'~
/copy_as_gfm'
;
import
{
CopyAsGFM
}
from
'~/behaviors
/copy_as_gfm'
;
(()
=>
{
describe
(
'gl.CopyAsGFM'
,
()
=>
{
describe
(
'gl.CopyAsGFM.pasteGFM'
,
()
=>
{
function
callPasteGFM
()
{
const
e
=
{
originalEvent
:
{
clipboardData
:
{
getData
(
mimeType
)
{
// When GFM code is copied, we put the regular plain text
// on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
// This emulates the behavior of `getData` with that data.
if
(
mimeType
===
'text/plain'
)
{
return
'code'
;
}
if
(
mimeType
===
'text/x-gfm'
)
{
return
'`code`'
;
}
return
null
;
},
describe
(
'CopyAsGFM'
,
()
=>
{
describe
(
'CopyAsGFM.pasteGFM'
,
()
=>
{
function
callPasteGFM
()
{
const
e
=
{
originalEvent
:
{
clipboardData
:
{
getData
(
mimeType
)
{
// When GFM code is copied, we put the regular plain text
// on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
// This emulates the behavior of `getData` with that data.
if
(
mimeType
===
'text/plain'
)
{
return
'code'
;
}
if
(
mimeType
===
'text/x-gfm'
)
{
return
'`code`'
;
}
return
null
;
},
},
preventDefault
()
{},
};
},
preventDefault
()
{},
};
window
.
gl
.
CopyAsGFM
.
pasteGFM
(
e
);
}
CopyAsGFM
.
pasteGFM
(
e
);
}
it
(
'wraps pasted code when not already in code tags'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'insertText'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'This is code: '
,
''
);
expect
(
insertedText
).
toEqual
(
'`code`'
);
});
callPasteGFM
();
it
(
'wraps pasted code when not already in code tags'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'insertText'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'This is code: '
,
''
);
expect
(
insertedText
).
toEqual
(
'`code`'
);
});
it
(
'does not wrap pasted code when already in code tags'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'insertText'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'This is code: `'
,
'`'
);
expect
(
insertedText
).
toEqual
(
'code'
);
});
callPasteGFM
();
});
callPasteGFM
();
it
(
'does not wrap pasted code when already in code tags'
,
()
=>
{
spyOn
(
window
.
gl
.
utils
,
'insertText'
).
and
.
callFake
((
el
,
textFunc
)
=>
{
const
insertedText
=
textFunc
(
'This is code: `'
,
'`'
);
expect
(
insertedText
).
toEqual
(
'code'
);
});
callPasteGFM
();
});
});
})
()
;
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment