Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pquery
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pquery
Commits
41717226
Commit
41717226
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added object/associative array variable types to template.
parent
7bf29b24
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pquery.template.php
+15
-1
15 additions, 1 deletion
pquery.template.php
test/templates/expect_parse.html
+3
-0
3 additions, 0 deletions
test/templates/expect_parse.html
test/templates/test.tpl
+3
-0
3 additions, 0 deletions
test/templates/test.tpl
test/test_template.php
+8
-2
8 additions, 2 deletions
test/test_template.php
with
29 additions
and
3 deletions
pquery.template.php
+
15
−
1
View file @
41717226
...
...
@@ -148,6 +148,9 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
* Apply any of the following helper functions:
* - Translation: <code>{_:name[:count_var_name]}</code>
* - Default: <code>{var_name[:func1:func2:...]}</code>
* 'var_name' can be of the form 'foo.bar'. In this case, 'foo' is the
* name of an object ot associative array variable. 'bar' is a property
* name to get of the object, or the associative index to the array.
*
* @param string $variable The variable to replace.
* @param Block $data The data block to search in for the value.
...
...
@@ -164,7 +167,18 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
return
'--translation--'
;
break
;
default
:
$value
=
$data
->
get
(
$name
);
if
(
strpos
(
$name
,
'.'
)
!==
false
)
{
list
(
$object_name
,
$property
)
=
explode
(
'.'
,
$name
,
2
);
$object
=
$data
->
get
(
$object_name
);
if
(
is_object
(
$object
)
&&
property_exists
(
$object
,
$property
)
)
{
$value
=
$object
->
$property
;
}
elseif
(
is_array
(
$object
)
&&
isset
(
$object
[
$property
])
)
{
$value
=
$object
[
$property
];
}
}
else
{
$value
=
$data
->
get
(
$name
);
}
// Don't continue if the variable name is not foudn in the data block
if
(
$value
===
null
)
...
...
This diff is collapsed.
Click to expand it.
test/templates/expect_parse.
txt
→
test/templates/expect_parse.
html
+
3
−
0
View file @
41717226
...
...
@@ -28,7 +28,10 @@ block:test1
end:test1
-variable value-
amet
-object property-
-assoc index-
block:test3
...
...
This diff is collapsed.
Click to expand it.
test/templates/test.tpl
+
3
−
0
View file @
41717226
...
...
@@ -17,7 +17,10 @@ block:test1
end:test1
{
end
}
{
variable
}
amet
{
object
.
property
}
{
assoc
.
index
}
{
block
:
test3
}
block:test3
...
...
This diff is collapsed.
Click to expand it.
test/test_template.php
+
8
−
2
View file @
41717226
...
...
@@ -70,15 +70,21 @@ class pQueryTemplateTest extends UnitTestCase {
function
test_parse
()
{
// Add some blocks with test variables
$this
->
tpl
->
data
->
set
(
'variable'
,
'-variable value-'
);
$object
=
new
StdClass
;
$object
->
property
=
'-object property-'
;
$this
->
tpl
->
data
->
set
(
'object'
,
$object
);
$this
->
tpl
->
data
->
set
(
'assoc'
,
array
(
'index'
=>
'-assoc index-'
));
$test1
=
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-variable'
));
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-other-variable'
));
$test1
->
add
(
'test2'
);
$this
->
tpl
->
data
->
add
(
'test3'
);
// Expected content is defined in a text file
$expected_content
=
file_get_contents
(
$this
->
templates_folder
.
'expect_parse.
txt
'
);
$expected_content
=
file_get_contents
(
$this
->
templates_folder
.
'expect_parse.
html
'
);
$this
->
assertEqual
(
$this
->
tpl
->
parse
(),
$expected_content
,
'parsed templated does not match expected content'
);
$this
->
assertEqual
(
$this
->
tpl
->
parse
(),
$expected_content
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment