Added an extras template to generate snippets for Victory Points.

master
Pacman Ghost 5 years ago
parent e8c710f00b
commit 187faa112b
  1. 7
      vasl_templates/webapp/data/default-template-pack/extras/victory-points.j2
  2. 48
      vasl_templates/webapp/static/extras.js
  3. 3
      vasl_templates/webapp/tests/fixtures/data/default-template-pack/extras/droplist.j2
  4. 37
      vasl_templates/webapp/tests/test_extras_templates.py

@ -0,0 +1,7 @@
<html> <!-- vasl-templates:id {{SNIPPET_ID}} -->
<!-- vasl-templates:name Victory Points -->
<!-- vasl-templates:description Add a label to keep track of your victory points, and press <i>Ctrl-L</i> when you need to update them. -->
<!-- vasl-templates:comment The HTML is deliberately malformed, so that the number remaining is the last thing in snippet, which makes it easier to change during the course of a game. -->
<div style="font-size:12px;"> <b>{{TYPE:Victory Points::Casualty VP::Exit VP|Type}}:</b> 0

@ -76,20 +76,29 @@ function _show_extra_template( template_id )
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( "<td class='value'>" ) ;
if ( template_info.params[i].type === "input" ) {
buf.push( "<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( ">" ) ;
} else if ( template_info.params[i].type === "select" ) {
buf.push( "<select class='param' name='" + escapeHTML(template_info.params[i].name) + "'>" ) ;
for ( var j=0 ; j < template_info.params[i].options.length ; ++j )
buf.push( "<option>", template_info.params[i].options[j], "</option>" ) ;
buf.push( "</select>" ) ;
}
}
buf.push( "</table>" ) ;
}
buf.push( "<button class='generate' data-id='" + template_info.template_id + "'>Snippet</button>" ) ;
buf.push( "</div>" ) ;
var $form = $( buf.join("") ) ;
$form.find( "select" ).select2( { minimumResultsForSearch: -1 } ) ;
fixup_external_links( $form ) ;
// initialize the "generate" button
@ -124,13 +133,24 @@ function _parse_extra_template( template_id, template )
var pos = param.name.indexOf( ":" ) ;
if ( pos === -1 )
continue ;
param.default = param.name.substr( pos+1 ) ;
var val = 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 ) ;
// figure out what type of parameter we have
if ( val.indexOf( "::" ) !== -1 ) {
// we have a <select>
param.type = "select" ;
param.options = val.split( "::" ) ;
} else {
// we have an <input>
param.type = "input" ;
// extract the default value and field width
pos = val.indexOf( "/" ) ;
if ( pos === -1 )
param.default = val ;
else {
param.default = val.substr( 0, pos ) ;
param.width = val.substr( pos+1 ) ;
}
}
// extract the caption and description
if ( words.length >= 2 )

@ -0,0 +1,3 @@
<!-- vasl-templates:name select -->
Selected: {{DROPLIST:item 1::item 2::item 3|Value}}

@ -1,9 +1,10 @@
""" Test the extras templates. """
from selenium.webdriver.support.ui import Select
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.utils import init_webapp, select_tab, get_droplist_vals, select_droplist_val, \
find_child, find_children, wait_for, wait_for_clipboard
from vasl_templates.webapp.tests.test_template_packs import make_zip_from_files, upload_template_pack_zip
# ---------------------------------------------------------------------
@ -18,7 +19,8 @@ def test_extras_templates( webapp, webdriver ):
# check that the extras templates were loaded correctly
assert _get_extras_template_index() == [
( "extras/minimal", None ),
( "Full template", "This is the caption." )
( "Full template", "This is the caption." ),
( "select", None ),
]
# check that the "full" template was loaded correctly
@ -60,6 +62,31 @@ def test_extras_templates( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_droplists( webapp, webdriver ):
"""Test droplist's in extras templates."""
# initialize
init_webapp( webapp, webdriver )
select_tab( "extras" )
# load the "droplist" template
_select_extras_template( webdriver, "extras/droplist" )
content = find_child( "#tabs-extras .right-panel" )
params = find_children( "tr", content )
assert len(params) == 1
sel = Select( find_child( "td.value select", params[0] ) )
vals = get_droplist_vals( sel )
assert vals == [ ("item 1","item 1"), ("item 2","item 2"), ("item 3","item 3") ]
# generate the snippet for each droplist choice
for i in range(1,3+1):
select_droplist_val( sel, "item {}".format(i) )
snippet_btn = find_child( "button.generate", content )
snippet_btn.click()
wait_for_clipboard( 2, "Selected: item {}".format(i) )
# ---------------------------------------------------------------------
def test_template_pack( webapp, webdriver ):
"""Test uploading a template pack that contains extras templates."""
@ -70,7 +97,8 @@ def test_template_pack( webapp, webdriver ):
# check that the extras templates were loaded correctly
assert _get_extras_template_index() == [
( "extras/minimal", None ),
( "Full template", "This is the caption." )
( "Full template", "This is the caption." ),
( "select", None ),
]
# upload the template pack
@ -82,6 +110,7 @@ def test_template_pack( webapp, webdriver ):
( "extras/minimal", None ),
( "Full template (modified)", "This is the caption (modified)." ),
( "New template", None ),
( "select", None ),
]
# check that the modified "full" template is being used

Loading…
Cancel
Save