Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
SPB_Exchange_Repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Amelin Konstantin
SPB_Exchange_Repo
Commits
e7f90532
Commit
e7f90532
authored
Oct 19, 2018
by
Amelin Konstantin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite render, delete tag with nested not found
parent
9872178a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
src/main/scala/templates/Template.scala
+22
-6
No files found.
src/main/scala/templates/Template.scala
View file @
e7f90532
...
...
@@ -64,19 +64,35 @@ abstract class Template(protected[this] val source: Node) {
def
template
:
Node
def
render
:
Node
=
{
val
rule
:
RewriteRule
=
new
RewriteRule
{
val
rule1
:
RewriteRule
=
new
RewriteRule
{
override
def
transform
(
n
:
Node
)
:
NodeSeq
=
{
val
children
=
n
.
child
.
filter
{
case
c
:
Elem
=>
true
case
_
=>
false
}
n
match
{
case
v
:
Elem
if
v.attributes.isEmpty
&&
children.nonEmpty
&&
children.forall
(
_
.text
==
msgNotFound
)
=>
NodeSeq
.
Empty
case
v
:
Elem
if
v.attributes.nonEmpty
&&
v.attributes.value.text.contains
(
msgNotFound
)
=>
v
.
copy
(
attributes
=
v
.
attributes
.
filter
(
_
.
value
.
text
!=
msgNotFound
))
case
_
=>
n
}
}
}
val
rule2
:
RewriteRule
=
new
RewriteRule
{
override
def
transform
(
n
:
Node
)
:
NodeSeq
=
n
match
{
case
v
if
v
.
text
==
msgNotFound
=>
case
v
:
Elem
if
v.text
=
=
msgNotFound
=>
NodeSeq
.
Empty
case
v
:
Elem
if
v.attributes.nonEmpty
&&
v.attributes.value.text.contains
(
msgNotFound
)
=>
v
.
copy
(
attributes
=
v
.
attributes
.
filter
(
_
.
value
.
text
!=
msgNotFound
))
case
_
=>
n
}
}
val
rt
=
new
RuleTransformer
(
rule
)
rt
.
transform
(
template
).
head
val
rt
1
=
new
RuleTransformer
(
rule1
)
val
rt2
=
new
RuleTransformer
(
rule2
)
rt2
.
transform
(
rt1
.
transform
(
template
)).
head
}
def
log
()
:
Unit
=
data
.
foreach
(
e
=>
println
(
e
.
_2
))
...
...
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