parent
675629dc14
commit
b524af57c2
@ -0,0 +1,11 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name Blank space --> |
||||
<!-- vasl-templates:description Generates a white label that can be used to cover up and hide things in your scenario. --> |
||||
|
||||
<table> |
||||
<tr> |
||||
<td style="width:{{WIDTH:60px/5|Width}};height:{{HEIGHT:60px/5|Height}};background:white;"> |
||||
</table> |
||||
|
||||
</html> |
@ -0,0 +1,60 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name Hidden Guns --> |
||||
<!-- vasl-templates:description HIP Guns for Solo Play, taken from <a href="http://vftt.co.uk/vfttpdfs.asp" target="_blank"><i>View From The Trenches</i></a>, Issue 34/35. --> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<style> |
||||
td { margin: 0 ; padding: 0 5px ; text-align: center ; } |
||||
td.header { font-weight: bold ; } |
||||
td.header2 { background: #f8f8f8 ; padding: 2px 5px ; font-weight: bold ; } |
||||
td.status { font-weight: bold ; text-align: left ; } |
||||
</style> |
||||
</head> |
||||
|
||||
<table> |
||||
|
||||
<tr> |
||||
<td colspan="5" style="background: #f0f0f0 ; border-bottom: 1px solid #c0c0c0 ; padding: 2px 5px ; font-weight: bold ;"> |
||||
<center> Hidden Guns </center> |
||||
|
||||
<tr> |
||||
<td> |
||||
<td class="header2" colspan=2> Hidden |
||||
<td class="header2" colspan=2> Possible |
||||
<tr> |
||||
<td> |
||||
<td class="header"> Fires |
||||
<td class="header"> Flip |
||||
<td class="header"> Fires |
||||
<td class="header"> Remove |
||||
|
||||
<tr> |
||||
<td class="status"> H H H |
||||
<td> 2-5 <td> 6+ <td> <td> |
||||
<tr> |
||||
<td class="status"> H H P |
||||
<td> 2-6 <td> 7+ <td> 2-3 <td> 4-11 |
||||
<tr> |
||||
<td class="status"> H P P |
||||
<td> 2-7 <td> 8+ <td> 2-4 <td> 5-11 |
||||
<tr> |
||||
<td class="status"> H H |
||||
<td> 2-6 <td> 7+ <td> <td> |
||||
<tr> |
||||
<td class="status"> H P |
||||
<td> 2-8 <td> 9+ <td> 2-4 <td> 5-11 |
||||
<tr> |
||||
<td class="status"> P P P |
||||
<td> <td> <td> 2-5 <td> 6-10 |
||||
<tr> |
||||
<td class="status"> P P |
||||
<td> <td> <td> 2-6 <td> 7-10 |
||||
|
||||
</table> |
||||
|
||||
Leadership DRM's apply. |
||||
|
||||
</html> |
||||
|
@ -0,0 +1,42 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name KGS Grenade Bundles --> |
||||
<!-- vasl-templates:description Data chart for Grenade Bundles in <i>Kampfgruppe Scherer</i>. --> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<style> |
||||
td { margin: 0 ; padding: 0 ; } |
||||
</style> |
||||
</head> |
||||
|
||||
<table> |
||||
|
||||
<tr> |
||||
<td colspan="2" style="background: {{PLAYER_COLORS["german"][0]}} ; border-bottom: 1px solid {{PLAYER_COLORS["german"][2]}} ; padding: 2px 5px ; font-weight: bold ;"> |
||||
{%if PLAYER_FLAGS["german"]%}<img src="{{PLAYER_FLAGS["german"]}}" height=15 width=15> {%endif%}Grenade Bundles |
||||
|
||||
<tr> |
||||
<td style="padding:2px 5px;"> |
||||
-2 CC Attack DRM <br> |
||||
ATMM check: dr ≤ 3 (△) <br> |
||||
<table style="margin-left:10px;"> |
||||
<tr> |
||||
<td style="width:20px;"> +1 |
||||
<td> HS/crew |
||||
<tr> |
||||
<td> +2 |
||||
<td> SMC |
||||
<tr> |
||||
<td> +1 |
||||
<td> CX |
||||
<tr> |
||||
<td> +1 |
||||
<td> vs. non-armored vehicle |
||||
</table> |
||||
original 6 = pinned (CCV reduced by 1) |
||||
|
||||
</table> |
||||
|
||||
</html> |
||||
|
@ -0,0 +1,45 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name KGS Molotov Cocktails --> |
||||
<!-- vasl-templates:description Data chart for Molotov Cocktails in <i>Kampfgruppe Scherer</i>. --> |
||||
|
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<style> |
||||
td { margin: 0 ; padding: 0 ; } |
||||
ul { margin: 0 0 0 10px ; padding: 0 ; } |
||||
</style> |
||||
</head> |
||||
|
||||
<table> |
||||
|
||||
<tr> |
||||
<td colspan="2" style="background: {{PLAYER_COLORS["german"][0]}} ; border-bottom: 1px solid {{PLAYER_COLORS["german"][2]}} ; padding: 2px 5px ; font-weight: bold ;"> |
||||
{%if PLAYER_FLAGS["german"]%}<img src="{{PLAYER_FLAGS["german"]}}" height=15 width=15> {%endif%}Molotov Cocktails |
||||
|
||||
<tr> |
||||
<td style="padding:0 5px;"> |
||||
vs. AFV only <br> |
||||
MOL check: dr ≤ 3 (△) <br> |
||||
<table style="margin-left:10px;"> |
||||
<tr> |
||||
<td style="width:20px;"> +1 |
||||
<td> HS/crew |
||||
<tr> |
||||
<td> +2 |
||||
<td> SMC |
||||
<tr> |
||||
<td> +1 |
||||
<td> CX |
||||
</table> |
||||
IFT DR original colored dr: |
||||
<ul> |
||||
<li> 1 = Flame in target Location |
||||
<li> 6 = thrower breaks, Flame in their Location |
||||
</ul> |
||||
Kindling Attempt: +2 DRM |
||||
|
||||
</table> |
||||
|
||||
</html> |
||||
|
@ -0,0 +1,7 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name PF count --> |
||||
<!-- vasl-templates:description Add the snippet as the label of a Panzerfaust counter, then press <i>Ctrl-L</i> when you need to update the number of remaining shots. --> |
||||
<!-- vasl-templates:comment The HTML is deliberately malformed, so that the number of remaining shots is the last thing in snippet, which makes it easier to change during the course of a game. --> |
||||
|
||||
<div style="font-size:12px;font-weight:bold;"> {{PF_COUNT:/3|Number of PF shots}} |
@ -0,0 +1,11 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name Turn Track shading --> |
||||
<!-- vasl-templates:description Generates a shaded square that you can place behind the Turn Track to indicate an LV Hindrance e.g. because of dusk/dawn. --> |
||||
|
||||
<table> |
||||
<tr> |
||||
<td style="width:{{WIDTH:45px/5|Width}};height:{{HEIGHT:45px/5|Height}};background:#f0f0f0;"> |
||||
</table> |
||||
|
||||
</html> |
@ -0,0 +1,22 @@ |
||||
/* -------------------------------------------------------------------- */ |
||||
|
||||
#tabs-extras { height: 100% ; display: flex ; flex-direction: row ; overflow: hidden ; } |
||||
#tabs-extras .left-panel { flex: 0 0 auto ; overflow: hidden auto ; min-width: 13em ; border-right: 2px dotted #aaa; margin-right: 5px ; padding-right: 5px ; } |
||||
#tabs-extras .right-panel { flex: 1 1 auto ; width: 100%; bottom: 0 ; } |
||||
|
||||
#tabs-extras .left-panel ul { list-style-type: none ; margin: 0 ; } |
||||
#tabs-extras .left-panel li { margin-bottom: 0.25em ; padding: 5px 8px ; border: 1px solid #ccc ; background: #eee ; cursor: pointer ; } |
||||
#tabs-extras .left-panel .ui-selected { background: #fff ; border: 1px solid #888 ; text-color: #666 ; } |
||||
|
||||
#tabs-extras .left-panel .name { font-weight: bold ; color: #666 ; } |
||||
#tabs-extras .left-panel .caption { margin-top: 0.25em ; font-size: 80% ; font-style: italic ; color: #888 ; } |
||||
|
||||
#tabs-extras .right-panel { overflow-y: hidden ; padding: 5px ; border: 1px solid #888 ; border-radius: 0 10px 0 0 ; background: #fff ; } |
||||
|
||||
#tabs-extras .right-panel div.name { font-size: 150% ; font-weight: bold ; } |
||||
#tabs-extras .right-panel div.caption { font-style: italic ; } |
||||
#tabs-extras .right-panel div.description { margin-top: 0.5em ; } |
||||
|
||||
#tabs-extras .right-panel table { margin-top: 1em ; } |
||||
#tabs-extras .right-panel td.caption { font-weight: bold ; padding-right: 0.25em ; } |
||||
#tabs-extras .right-panel .snippet-control { margin-top: 0.5em ; } |
@ -0,0 +1,166 @@ |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function init_extras() |
||||
{ |
||||
// initialize the layout
|
||||
$( "#tabs-extras .left-panel" ).resizable( { |
||||
resizeHeight: false, |
||||
handles: "e", |
||||
create: function( event, ui ) { |
||||
$( ".ui-resizable-e" ).css( "cursor", "ew-resize" ) ; |
||||
}, |
||||
} ) ; |
||||
|
||||
// identify the extras templates
|
||||
var extra_templates = [] ; |
||||
for ( var template_id in gTemplatePack.templates ) { |
||||
if ( template_id.substr( 0, 7 ) === "extras/" ) { |
||||
extra_templates.push( |
||||
_parse_extra_template( template_id, gTemplatePack.templates[template_id] ) |
||||
) ; |
||||
} |
||||
} |
||||
|
||||
// sort the extras templates by name
|
||||
extra_templates.sort( function( lhs, rhs ) { |
||||
return lhs.name.localeCompare( rhs.name, "en", { sensitivity: "base" } ) ; |
||||
} ) ; |
||||
|
||||
// build the side-panel showing the available templates
|
||||
var $index = $( "<ul></ul>" ) ; |
||||
for ( var i=0 ; i < extra_templates.length ; ++i ) { |
||||
var buf = [] ; |
||||
buf.push( "<li class='ui-widget-content'>", |
||||
"<div class='name'>", extra_templates[i].name, "</div>" |
||||
) ; |
||||
if ( extra_templates[i].caption ) |
||||
buf.push( "<div class='caption'>", extra_templates[i].caption, "</div>" ) ; |
||||
buf.push( "</div>", "</li>" ) ; |
||||
var $entry = $( buf.join("") ) ; |
||||
if ( i === 0 ) |
||||
$entry.addClass( "ui-selecting" ) ; |
||||
$entry.data( "template_id", extra_templates[i].template_id ) ; |
||||
$index.append( $entry ) ; |
||||
} |
||||
$index.selectable( { |
||||
selected: function( evt, ui ) { |
||||
_show_extra_template( $(ui.selected).data( "template_id" ) ) ; |
||||
}, |
||||
selecting: function( evt, ui ) { // nb: prevent multiple selections
|
||||
if ( $index.find( ".ui-selected, .ui-selecting" ).length > 1 ) |
||||
$(ui.selecting).removeClass( "ui-selecting" ) ; |
||||
}, |
||||
} ) ; |
||||
$index.data( "ui-selectable" )._mouseStop( null ) ; // nb: trigger the selection
|
||||
$( "#tabs-extras .left-panel .content" ).empty().append( $index ) ; |
||||
} |
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
function _show_extra_template( template_id ) |
||||
{ |
||||
// parse the template (nb: we do this every time since the user may have changed it in the UI)
|
||||
var template_info = _parse_extra_template( template_id, gTemplatePack.templates[template_id] ) ; |
||||
|
||||
// generate the form for entering the template parameters
|
||||
var buf = [ "<div>" ] ; |
||||
buf.push( "<div class='name'>", template_info.name, "</div>" ) ; |
||||
if ( template_info.caption ) |
||||
buf.push( "<div class='caption'>", template_info.caption, "</div>" ) ; |
||||
if ( template_info.description ) |
||||
buf.push( "<div class='description'>", template_info.description, "</div>" ) ; |
||||
if ( template_info.params.length > 0 ) { |
||||
buf.push( "<table>" ) ; |
||||
for ( var i=0 ; i < template_info.params.length ; ++i ) { |
||||
buf.push( "<tr>" ) ; |
||||
var display_name = template_info.params[i].caption || template_info.params[i].name ; |
||||
buf.push( "<td class='caption'>", escapeHTML(display_name)+":" ) ; |
||||
buf.push( "<td class='value'>", "<input class='param' name='" + escapeHTML(template_info.params[i].name) + "' type='text'" ) ; |
||||
if ( template_info.params[i].width ) |
||||
buf.push( " size='" + escapeHTML(template_info.params[i].width) + "'" ) ; |
||||
if ( template_info.params[i].default ) |
||||
buf.push( " value='" + escapeHTML(template_info.params[i].default) + "'" ) ; |
||||
if ( template_info.params[i].description ) |
||||
buf.push( " title='" + escapeHTML(template_info.params[i].description) + "'" ) ; |
||||
buf.push( ">" ) ; |
||||
} |
||||
buf.push( "</table>" ) ; |
||||
} |
||||
buf.push( "<button class='generate' data-id='" + template_info.template_id + "'>Snippet</button>" ) ; |
||||
buf.push( "</div>" ) ; |
||||
var $form = $( buf.join("") ) ; |
||||
|
||||
// initialize the "generate" button
|
||||
init_snippet_button( $form.find( "button.generate" ) ) ; |
||||
|
||||
// install the form
|
||||
$( "#tabs-extras .right-panel" ).empty().append( $form ) ; |
||||
} |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function _parse_extra_template( template_id, template ) |
||||
{ |
||||
// extract the main details
|
||||
var result = { template_id: template_id, name: template_id } ; |
||||
function extract_val( key ) { |
||||
var match = template.match( new RegExp( "<!-- vasl-templates:" + key + " (.*?) -->" ) ) ; |
||||
if ( match ) |
||||
result[key] = match[1] ; |
||||
} |
||||
extract_val( "name" ) ; |
||||
extract_val( "caption" ) ; |
||||
extract_val( "description" ) ; |
||||
|
||||
// extract the template parameters
|
||||
result.params = [] ; |
||||
var params_regex = new RegExp( /\{\{(.*?)\}\}/g ) ; |
||||
while( (match = params_regex.exec( template )) !== null ) { |
||||
// extract the parameter name and default value
|
||||
var words = match[1].split( "|" ) ; |
||||
var param = { name: words[0] } ; |
||||
var pos = param.name.indexOf( ":" ) ; |
||||
if ( pos === -1 ) |
||||
continue ; |
||||
param.default = param.name.substr( pos+1 ) ; |
||||
param.name = param.name.substr( 0, pos ) ; |
||||
// extract the field width
|
||||
pos = param.default.indexOf( "/" ) ; |
||||
if ( pos !== -1 ) { |
||||
param.width = param.default.substr( pos+1 ) ; |
||||
param.default = param.default.substr( 0, pos ) ; |
||||
} |
||||
// extract the caption and description
|
||||
if ( words.length >= 2 ) |
||||
param.caption = words[1] ; |
||||
if ( words.length >= 3 ) |
||||
param.description = words[2] ; |
||||
result.params.push( param ) ; |
||||
} |
||||
|
||||
return result ; |
||||
} |
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
function fixup_template_parameters( template ) |
||||
{ |
||||
// identify any non-standard template parameters
|
||||
var matches = [] ; |
||||
var regex = /\{\{([A-Z0-9_]+?):.*?\}\}/g ; |
||||
var match ; |
||||
while( (match = regex.exec( template )) !== null ) |
||||
matches.push( [ regex.lastIndex-match[0].length, match[0].length, match[1] ] ) ; |
||||
|
||||
// fix them up
|
||||
if ( matches.length > 0 ) { |
||||
for ( var i=matches.length-1 ; i >= 0 ; --i ) |
||||
template = template.substr(0,matches[i][0]) + "{{"+matches[i][2]+"}}" + template.substr(matches[i][0]+matches[i][1]) ; |
||||
} |
||||
|
||||
// remove comments
|
||||
template = template.replace( /<!-- vasl-templates:.*? -->\n*/g, "" ) ; |
||||
|
||||
return template ; |
||||
} |
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 437 B After Width: | Height: | Size: 871 B |
@ -0,0 +1,9 @@ |
||||
<div id="tabs-extras"> |
||||
|
||||
<div class="left-panel"> |
||||
<div class='content'></div> |
||||
</div> |
||||
|
||||
<div class="right-panel"></div> |
||||
|
||||
</div> |
@ -1,18 +1,22 @@ |
||||
<div id="tabs"> |
||||
|
||||
<img src="{{url_for('static',filename='images/flags/scenario.png')}}" style="display:none;"> |
||||
<img src="{{url_for('static',filename='images/flags/german.png')}}" style="display:none;"> |
||||
<img src="{{url_for('static',filename='images/flags/russian.png')}}" style="display:none;"> |
||||
<img src="{{url_for('static',filename='images/extras.png')}}" style="display:none;"> |
||||
|
||||
<ul> |
||||
<li> <a href="#tabs-scenario"><img src="{{url_for('static',filename='images/scenario.png')}}"> Scenario</a> |
||||
<li> <a href="#tabs-ob1"><div style="width:7em;"> </div></a> |
||||
<li> <a href="#tabs-ob2"><div style="width:7em;"> </div></a> |
||||
<li> <a href="#tabs-extras"><div style="width:4em;"> </div></a> |
||||
<li style="display:none;"> <a href="#tabs-help"><img src="{{url_for('static',filename='images/help.png')}}"> Help</a> |
||||
</ul> |
||||
|
||||
{%include "tabs-scenario.html"%} |
||||
{%include "tabs-ob1.html"%} |
||||
{%include "tabs-ob2.html"%} |
||||
{%include "tabs-extras.html"%} |
||||
{%include "tabs-help.html"%} |
||||
|
||||
</div> <!-- #tabs --> |
||||
|
@ -0,0 +1,14 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name Full template --> |
||||
<!-- vasl-templates:caption This is the caption. --> |
||||
<!-- vasl-templates:description This is the description. --> |
||||
<!-- vasl-templates:comment This is the comment (shouldn't appear anywhere, including the snippet). --> |
||||
|
||||
{{FOO}} <!-- nb: this is a normal parameter, not one of ours (no embedded colon) --> |
||||
|
||||
<div> |
||||
param = {{PARAM:default-val/10|The parameter|This is the parameter description.}} |
||||
</div> |
||||
|
||||
</html> |
@ -0,0 +1,7 @@ |
||||
<html> |
||||
|
||||
<div> |
||||
param = {{PARAM:}} |
||||
</div> |
||||
|
||||
</html> |
@ -0,0 +1,15 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name Full template (modified) --> |
||||
<!-- vasl-templates:caption This is the caption (modified). --> |
||||
<!-- vasl-templates:description This is the description. --> |
||||
<!-- vasl-templates:comment This is the comment (shouldn't appear anywhere, including the snippet). --> |
||||
|
||||
{{FOO}} <!-- nb: this is a normal parameter, not one of ours (no embedded colon) --> |
||||
|
||||
<div> |
||||
modified-param = {{MODIFIED-PARAM:modified-default-val/10|The modified parameter|This is the modified parameter description.}} |
||||
new-param = {{NEW-PARAM:}} |
||||
</div> |
||||
|
||||
</html> |
@ -0,0 +1,9 @@ |
||||
<html> |
||||
|
||||
<!-- vasl-templates:name New template --> |
||||
|
||||
<div> |
||||
new-param = {{NEW-PARAM:}} |
||||
</div> |
||||
|
||||
</html> |
@ -0,0 +1,182 @@ |
||||
""" Test the extras templates. """ |
||||
|
||||
from selenium.webdriver.common.keys import Keys |
||||
|
||||
from vasl_templates.webapp.tests.utils import \ |
||||
init_webapp, find_child, find_children, wait_for, wait_for_clipboard, select_tab |
||||
from vasl_templates.webapp.tests.test_template_packs import make_zip_from_files, upload_template_pack_zip |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
def test_extras_templates( webapp, webdriver ): |
||||
"""Test the extras templates.""" |
||||
|
||||
# initialize |
||||
init_webapp( webapp, webdriver ) |
||||
select_tab( "extras" ) |
||||
|
||||
# check that the extras templates were loaded correctly |
||||
assert _get_extras_template_index() == [ |
||||
( "extras/minimal", None ), |
||||
( "Full template", "This is the caption." ) |
||||
] |
||||
|
||||
# check that the "full" template was loaded correctly |
||||
_select_extras_template( webdriver, "extras/full" ) |
||||
content = find_child( "#tabs-extras .right-panel" ) |
||||
assert find_child( "div.name", content ).text == "Full template" |
||||
assert find_child( "div.caption", content ).text == "This is the caption." |
||||
assert find_child( "div.description", content ).text == "This is the description." |
||||
params = find_children( "tr", content ) |
||||
assert len(params) == 1 |
||||
assert find_child( "td.caption", params[0] ).text == "The parameter:" |
||||
textbox = find_child( "td.value input", params[0] ) |
||||
assert textbox.get_attribute( "value" ) == "default-val" |
||||
assert textbox.get_attribute( "size" ) == "10" |
||||
assert textbox.get_attribute( "title" ) == "This is the parameter description." |
||||
|
||||
# generate the snippet |
||||
snippet_btn = find_child( "button.generate", content ) |
||||
snippet_btn.click() |
||||
clipboard = wait_for_clipboard( 2, "param = default-val", contains=True ) |
||||
assert "vasl-templates:comment" not in clipboard # nb: check that the comment was removed |
||||
|
||||
# check that the "minimal" template was loaded correctly |
||||
_select_extras_template( webdriver, "extras/minimal" ) |
||||
assert find_child( "div.name", content ).text == "extras/minimal" |
||||
assert find_child( "div.caption", content ) is None |
||||
assert find_child( "div.description", content ) is None |
||||
params = find_children( "tr", content ) |
||||
assert len(params) == 1 |
||||
assert find_child( "td.caption", params[0] ).text == "PARAM:" |
||||
textbox = find_child( "td.value input", params[0] ) |
||||
assert textbox.get_attribute( "value" ) == "" |
||||
|
||||
# generate the snippet |
||||
textbox.send_keys( "boo!" ) |
||||
snippet_btn = find_child( "button.generate", content ) |
||||
snippet_btn.click() |
||||
clipboard = wait_for_clipboard( 2, "param = boo!", contains=True ) |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
def test_template_pack( webapp, webdriver ): |
||||
"""Test uploading a template pack that contains extras templates.""" |
||||
|
||||
# initialize |
||||
init_webapp( webapp, webdriver, template_pack_persistence=1 ) |
||||
select_tab( "extras" ) |
||||
|
||||
# check that the extras templates were loaded correctly |
||||
assert _get_extras_template_index() == [ |
||||
( "extras/minimal", None ), |
||||
( "Full template", "This is the caption." ) |
||||
] |
||||
|
||||
# upload the template pack |
||||
zip_data = make_zip_from_files( "extras" ) |
||||
upload_template_pack_zip( zip_data, False ) |
||||
|
||||
# check that the templates were updated correctly |
||||
assert _get_extras_template_index() == [ |
||||
( "extras/minimal", None ), |
||||
( "Full template (modified)", "This is the caption (modified)." ), |
||||
( "New template", None ), |
||||
] |
||||
|
||||
# check that the modified "full" template is being used |
||||
_select_extras_template( webdriver, "extras/full" ) |
||||
content = find_child( "#tabs-extras .right-panel" ) |
||||
assert find_child( "div.name", content ).text == "Full template (modified)" |
||||
assert find_child( "div.caption", content ).text == "This is the caption (modified)." |
||||
params = find_children( "tr", content ) |
||||
assert len(params) == 2 |
||||
assert find_child( "td.caption", params[0] ).text == "The modified parameter:" |
||||
textbox = find_child( "td.value input", params[0] ) |
||||
assert textbox.get_attribute( "value" ) == "modified-default-val" |
||||
assert textbox.get_attribute( "size" ) == "10" |
||||
assert textbox.get_attribute( "title" ) == "This is the modified parameter description." |
||||
assert find_child( "td.caption", params[1] ).text == "NEW-PARAM:" |
||||
textbox = find_child( "td.value input", params[1] ) |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
def test_edit_extras_template( webapp, webdriver ): |
||||
"""Test editing an extras templates.""" |
||||
|
||||
# initialize |
||||
init_webapp( webapp, webdriver ) |
||||
select_tab( "extras" ) |
||||
|
||||
# edit the "minimal" template |
||||
_select_extras_template( webdriver, "extras/minimal" ) |
||||
content = find_child( "#tabs-extras .right-panel" ) |
||||
assert find_child( "div.caption", content ) is None |
||||
webdriver.execute_script( "edit_template('extras/minimal')", content ) |
||||
textarea = find_child( "#edit-template textarea" ) |
||||
template = textarea.get_attribute( "value" ) \ |
||||
.replace( "<html>", "<html>\n<!-- vasl-templates:caption Modified minimal. -->" ) \ |
||||
.replace( "<div>", "<div>\nadded = {{ADDED:added-val}}" ) |
||||
textarea.clear() |
||||
textarea.send_keys( template ) |
||||
textarea.send_keys( Keys.ESCAPE ) |
||||
|
||||
# generate the template (we should still be using the old template) |
||||
snippet_btn = find_child( "button.generate", content ) |
||||
snippet_btn.click() |
||||
wait_for_clipboard( 2, "param = ", contains=True ) |
||||
|
||||
# switch to another template, then back again |
||||
_select_extras_template( webdriver, "extras/full" ) |
||||
_select_extras_template( webdriver, "extras/minimal" ) |
||||
|
||||
# make sure the new template was loaded |
||||
assert find_child( "div.caption", content ).text == "Modified minimal." |
||||
params = find_children( "tr", content ) |
||||
assert len(params) == 2 |
||||
assert find_child( "td.caption", params[0] ).text == "ADDED:" |
||||
textbox = find_child( "td.value input", params[0] ) |
||||
assert textbox.get_attribute( "value" ) == "added-val" |
||||
|
||||
# generate the template (we should be using the new template) |
||||
snippet_btn = find_child( "button.generate", content ) |
||||
snippet_btn.click() |
||||
wait_for_clipboard( 2, "added = added-val\nparam = ", contains=True ) |
||||
|
||||
# --------------------------------------------------------------------- |
||||
|
||||
def _get_extras_template_index(): |
||||
"""Get the list of extras templates from the sidebar.""" |
||||
def get_child_text( child_class, elem ): #pylint: disable=missing-docstring |
||||
elem = find_child( child_class, elem ) |
||||
return elem.text if elem else None |
||||
return [ |
||||
( get_child_text(".name",elem), get_child_text(".caption",elem) ) |
||||
for elem in _get_extras_templates() |
||||
] |
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
||||
|
||||
def _get_extras_templates(): |
||||
"""Get the available extras templates.""" |
||||
return find_children( "#tabs-extras .left-panel li" ) |
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
||||
|
||||
def _select_extras_template( webdriver, template_id ): |
||||
"""Select the specified extras template.""" |
||||
|
||||
# find the specified template in the index |
||||
elems = [ |
||||
e for e in _get_extras_templates() |
||||
if webdriver.execute_script( "return $(arguments[0]).data('template_id')", e ) == template_id |
||||
] |
||||
assert len(elems) == 1 |
||||
template_name = find_child( ".name", elems[0] ).text |
||||
|
||||
# select the template and wait for it to load |
||||
elems[0].click() |
||||
def is_template_loaded(): #pylint: disable=missing-docstring |
||||
elem = find_child( "#tabs-extras .right-panel .name" ) |
||||
return elem and elem.text == template_name |
||||
wait_for( 2, is_template_loaded ) |
Loading…
Reference in new issue