Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pquery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pquery
Commits
41717226
Commit
41717226
authored
Dec 06, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added object/associative array variable types to template.
parent
7bf29b24
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
3 deletions
+29
-3
pquery.template.php
pquery.template.php
+15
-1
test/templates/expect_parse.html
test/templates/expect_parse.html
+3
-0
test/templates/test.tpl
test/templates/test.tpl
+3
-0
test/test_template.php
test/test_template.php
+8
-2
No files found.
pquery.template.php
View file @
41717226
...
@@ -148,6 +148,9 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
...
@@ -148,6 +148,9 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
* Apply any of the following helper functions:
* Apply any of the following helper functions:
* - Translation: <code>{_:name[:count_var_name]}</code>
* - Translation: <code>{_:name[:count_var_name]}</code>
* - Default: <code>{var_name[:func1:func2:...]}</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 string $variable The variable to replace.
* @param Block $data The data block to search in for the value.
* @param Block $data The data block to search in for the value.
...
@@ -164,7 +167,18 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
...
@@ -164,7 +167,18 @@ class pQueryTemplate extends pQuery implements pQueryExtension {
return
'--translation--'
;
return
'--translation--'
;
break
;
break
;
default
:
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
// Don't continue if the variable name is not foudn in the data block
if
(
$value
===
null
)
if
(
$value
===
null
)
...
...
test/templates/expect_parse.
txt
→
test/templates/expect_parse.
html
View file @
41717226
...
@@ -28,7 +28,10 @@ block:test1
...
@@ -28,7 +28,10 @@ block:test1
end:test1
end:test1
-variable value-
amet
amet
-object property-
-assoc index-
block:test3
block:test3
...
...
test/templates/test.tpl
View file @
41717226
...
@@ -17,7 +17,10 @@ block:test1
...
@@ -17,7 +17,10 @@ block:test1
end:test1
end:test1
{
end
}
{
end
}
{
variable
}
amet
amet
{
object
.
property
}
{
assoc
.
index
}
{
block
:
test3
}
{
block
:
test3
}
block:test3
block:test3
...
...
test/test_template.php
View file @
41717226
...
@@ -70,15 +70,21 @@ class pQueryTemplateTest extends UnitTestCase {
...
@@ -70,15 +70,21 @@ class pQueryTemplateTest extends UnitTestCase {
function
test_parse
()
{
function
test_parse
()
{
// Add some blocks with test variables
// 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'
));
$test1
=
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-variable'
));
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-other-variable'
));
$this
->
tpl
->
data
->
add
(
'test1'
,
array
(
'var'
=>
'some-other-variable'
));
$test1
->
add
(
'test2'
);
$test1
->
add
(
'test2'
);
$this
->
tpl
->
data
->
add
(
'test3'
);
$this
->
tpl
->
data
->
add
(
'test3'
);
// Expected content is defined in a text file
// 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
);
}
}
}
}
...
...
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