Browse Source

Added support of abstract template

master
Artyom Beilis 8 years ago
parent
commit
9cc3c60bdd
3 changed files with 21 additions and 13 deletions
  1. +16
    -8
      bin/cppcms_tmpl_cc
  2. +4
    -4
      tests/tc_skin.tmpl
  3. +1
    -1
      tests/tc_test.cpp

+ 16
- 8
bin/cppcms_tmpl_cc View File

@@ -112,7 +112,7 @@ class html_type:


class view_block:
pattern=r'^<%\s*view\s+(\w+)\s+uses\s+(:?:?\w+(::\w+)*)(\s+extends\s+(:?:?\w+(::\w+)?))?\s*%>$'
pattern=r'^<%\s*view\s+(\w+)\s+uses\s+(:?:?\w+(::\w+)*)(\s+extends\s+(:?:?\w+(::\w+)?))?(?P<abs>\s+abstract)?\s*%>$'
basic_pattern='view'
basic_name='view'
type='view'
@@ -138,6 +138,7 @@ class view_block:
output_declaration("\t}")

def use(self,m):
self.abstract = m.group('abs')!=None
global view_name
global output_template
self.class_name=m.group(1)
@@ -152,20 +153,21 @@ class view_block:
if len(stack)!=1 or stack[-1].type!='skin':
error_exit("You must define view inside skin block only")
stack.append(self)
global class_list
global namespace_name
class information:
content_name=self.uses
name=self.class_name
namespace=namespace_name
class_list.append(information())
global class_list
if not self.abstract:
class_list.append(information())
def on_end(self):
output_declaration( "}; // end of class %s" % self.class_name)



class template_block:
pattern=r'^<%\s*template\s+([a-zA-Z]\w*)\s*\(([\w\s,:\&]*)\)\s*%>$'
pattern=r'^<%\s*template\s+([a-zA-Z]\w*)\s*\(([\w\s,:\&]*)\)\s*(?P<abs>=\s*0\s*)?%>$'
basic_pattern = 'template'
basic_name='template'
type='template'
@@ -199,16 +201,22 @@ class template_block:
global inline_templates
self.name=m.group(1)
params=""
abstract = m.group('abs') != None
if m.group(2) and not re.match('^\s*$',m.group(2)):
params=self.create_parameters(m.group(2))
if inline_templates:
output_declaration( "virtual void %s(%s) {" % (self.name,params) )
if abstract:
output_declaration( "virtual void %s(%s) = 0;" % (self.name,params) )
else:
output_declaration( "virtual void %s(%s);" % (self.name,params) )
output_definition( "void %s::%s(%s) {" % (view_name,self.name,params) )
if inline_templates:
output_declaration( "virtual void %s(%s) {" % (self.name,params) )
else:
output_declaration( "virtual void %s(%s);" % (self.name,params) )
output_definition( "void %s::%s(%s) {" % (view_name,self.name,params) )
global stack
if len(stack)==0 or stack[-1].type!='view':
error_exit("You must define template inside view block only")
if abstract:
return
stack.append(self)
global current_template
current_template=self.name


+ 4
- 4
tests/tc_skin.tmpl View File

@@ -219,12 +219,12 @@ TBD
<% end template %>
<% end view %>

<% view master_api uses data::master %>
<% template m1() %><% end %>
<% view master_api uses data::master abstract %>
<% template m1() = 0 %>
<% end view %>

<% view helper_api uses data::helper %>
<% template h1() %><% end %>
<% view helper_api uses data::helper abstract%>
<% template h1()=0%>
<% end view %>

<% view master_plugin uses data::master extends master_api %>


+ 1
- 1
tests/tc_test.cpp View File

@@ -535,7 +535,7 @@ int main(int argc,char **argv)
cfg["views"]["skins"][0]="tc_sep_skin_a";
cfg["views"]["skins"][1]="tc_sep_skin_b";
cfg["views"]["skins"][2]="tc_sep_skin";
cfg["views"]["skins"][2]="tc_plugin";
cfg["views"]["skins"][3]="tc_plugin";
}
else {
std::cout << "Using shared header/body" << std::endl;


Loading…
Cancel
Save