Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
f6e33914
Commit
f6e33914
authored
Jan 03, 2018
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport of methods and components added in EBackport of methods and components added in EEE
parent
c6ab17f1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
0 deletions
+97
-0
app/assets/javascripts/lib/utils/text_utility.js
app/assets/javascripts/lib/utils/text_utility.js
+9
-0
app/assets/javascripts/vue_shared/components/expand_button.vue
...ssets/javascripts/vue_shared/components/expand_button.vue
+46
-0
spec/javascripts/lib/utils/text_utility_spec.js
spec/javascripts/lib/utils/text_utility_spec.js
+10
-0
spec/javascripts/vue_shared/components/expand_button_spec.js
spec/javascripts/vue_shared/components/expand_button_spec.js
+32
-0
No files found.
app/assets/javascripts/lib/utils/text_utility.js
View file @
f6e33914
...
...
@@ -64,3 +64,12 @@ export const truncate = (string, maxLength) => `${string.substr(0, (maxLength -
export
function
capitalizeFirstCharacter
(
text
)
{
return
`
${
text
[
0
].
toUpperCase
()}${
text
.
slice
(
1
)}
`
;
}
/**
* Replaces all html tags from a string with the given replacement.
*
* @param {String} string
* @param {*} replace
* @returns {String}
*/
export
const
stripeHtml
=
(
string
,
replace
=
''
)
=>
string
.
replace
(
/<
[^
>
]
*>/g
,
replace
);
app/assets/javascripts/vue_shared/components/expand_button.vue
0 → 100644
View file @
f6e33914
<
script
>
import
{
__
}
from
'
~/locale
'
;
/**
* Port of detail_behavior expand button.
*
* @example
* <expand-button>
* <template slot="expanded">
* Text goes here.
* </template>
* </expand-button>
*/
export
default
{
name
:
'
expandButton
'
,
data
()
{
return
{
isCollapsed
:
true
,
};
},
computed
:
{
ariaLabel
()
{
return
__
(
'
Click to expand text
'
);
},
},
methods
:
{
onClick
()
{
this
.
isCollapsed
=
!
this
.
isCollapsed
;
},
},
};
</
script
>
<
template
>
<span>
<button
type=
"button"
v-show=
"isCollapsed"
class=
"text-expander btn-blank"
aria-label=
"Click to Expand Text"
@
click=
"onClick"
>
...
</button>
<span
v-show=
"!isCollapsed"
>
<slot
name=
"expanded"
></slot>
</span>
</span>
</
template
>
spec/javascripts/lib/utils/text_utility_spec.js
View file @
f6e33914
...
...
@@ -62,4 +62,14 @@ describe('text_utility', () => {
expect
(
textUtils
.
slugify
(
'
João
'
)).
toEqual
(
'
joão
'
);
});
});
describe
(
'
stripeHtml
'
,
()
=>
{
it
(
'
replaces html tag with the default replacement
'
,
()
=>
{
expect
(
textUtils
.
stripeHtml
(
'
This is a text with <p>html</p>.
'
)).
toEqual
(
'
This is a text with html.
'
);
});
it
(
'
replaces html tags with the provided replacement
'
,
()
=>
{
expect
(
textUtils
.
stripeHtml
(
'
This is a text with <p>html</p>.
'
,
'
'
)).
toEqual
(
'
This is a text with html .
'
);
});
});
});
spec/javascripts/vue_shared/components/expand_button_spec.js
0 → 100644
View file @
f6e33914
import
Vue
from
'
vue
'
;
import
expandButton
from
'
~/vue_shared/components/expand_button.vue
'
;
import
mountComponent
from
'
../../helpers/vue_mount_component_helper
'
;
describe
(
'
expand button
'
,
()
=>
{
let
vm
;
beforeEach
(()
=>
{
const
Component
=
Vue
.
extend
(
expandButton
);
vm
=
mountComponent
(
Component
,
{
slots
:
{
expanded
:
'
<p>Expanded!</p>
'
,
},
});
});
afterEach
(()
=>
{
vm
.
$destroy
();
});
it
(
'
renders a collpased button
'
,
()
=>
{
expect
(
vm
.
$el
.
textContent
.
trim
()).
toEqual
(
'
...
'
);
});
it
(
'
hides expander on click
'
,
(
done
)
=>
{
vm
.
$el
.
querySelector
(
'
button
'
).
click
();
vm
.
$nextTick
(()
=>
{
expect
(
vm
.
$el
.
querySelector
(
'
button
'
).
getAttribute
(
'
style
'
)).
toEqual
(
'
display: none;
'
);
done
();
});
});
});
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