Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

[WIP] removal of duplicate about attribute in collections rendering #46

Merged
merged 10 commits into from
Feb 14, 2013
Merged

[WIP] removal of duplicate about attribute in collections rendering #46

merged 10 commits into from
Feb 14, 2013

Conversation

adou600
Copy link
Contributor

@adou600 adou600 commented Jan 11, 2013

This PR try to address #29 and #44.

The idea is to add a noautotag tag in twig to allow the user not to render the enclosing html element automatically. By default, this tag is not set and the enclosing div is rendered with the rdf attributes. To avoid the about attribute duplication, Collection::renderAttributeschecks if the parent is currently rendering and if yes removes the about attribute.

Do not merge this PR yet, some changes are still to come:

  • new test without noautotag in the twig template
  • new test to detect the case where an about property is removed
  • README update with noautotag information

@adou600
Copy link
Contributor Author

adou600 commented Jan 11, 2013

CC @dbu

@@ -291,11 +287,14 @@ public function render($tag_name = false)
*
* @api
*/
public function renderAttributes()
public function renderAttributes($attributesToRemove = array())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please call this $attributesToSkip (they are not removed, just not printed) and add a doc comment about it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the doc comment should go to the NodeInterface method.

@adou600
Copy link
Contributor Author

adou600 commented Jan 16, 2013

@dbu @flack I think this PR is ready for the review.

The README is updated and the tests have been refactored to allow to test the twig extensions with and without noautotag (CreatephpExtensionTest::testBasicTemplates). A complete example for collections rendering in twig is also available (CreatephpExtensionTest::testCollectionsTemplate).

@@ -224,14 +224,15 @@ name is generated by appending "_rdf" to your model name.
Inside the createphp tag, you can render the entity with the default structure
(see above), or render single fields as in the example below:

{% createphp mymodel %}
<div {{ createphp_attributes(mymodel_rdf) }}>
{% createphp mymodel noautotag %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the first example should be using the autotag feature, and then we add a section how to have more control over the html from the template where we explain the noautotag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if you look at https://github.com/symfony-cmf/createphp/blob/d146e4d71dd0797ffc0c4ccc859c4cf9a8e2ab1a/README.md#twig-extension, the first example is using the autotag:
{% createphp mymodel %}{{ mymodel_rdf|raw }}{% endcreatephp %}
Is it ok like this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, just saw that this replaced something existing and thought there is no more example without noautotag. all fine then.

@dbu
Copy link
Collaborator

dbu commented Jan 17, 2013

@flack: i put some explanatory comments into the code for you. the bigger number of changes is in that adrien uses the real metadata loader in the tests now instead of mocking, which makes the tests more reliable.

@adou600 maybe you could move some of the comments i made in the PR as comments into the code so that people reading the code later see the reasoning too.

@@ -37,12 +37,12 @@ public function prepareObject(TypeInterface $type, $parent = null)
/** @var $meta \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
$meta = $this->om->getClassMetaData(get_class($object));

if (!property_exists($object, $meta->parentMapping['fieldName'])) {
if (!property_exists($object, $meta->parentMapping)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a conflict with #47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it just makes #47 superfluous .. so if this PR gets merged that PR can get closed. i think its ok to include it here too.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw just FYI for the future you could also just cherry pick my commit and then the other PR would be automatically closed and no conflict could occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint! I had to change it after the dependencies update on the sandbox. As we don't know how easily #46 will be merged, may be we should keep #47 ?


public function __construct($title = 'the model title',
$content = 'the model content',
$subject = '/the/subject/model') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the { should be on the next line

* @return string the rendered attributes
*/
public function renderAttributes();
public function renderAttributes($attributesToSkip = array());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about using a typehint here? i.e.

public function renderAttributes(array $attributesToSkip = array());

just to make it a bit more robust

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

willdo

@dbu
Copy link
Collaborator

dbu commented Feb 14, 2013

i just pushed changes according to your comments above. good to merge?

@flack
Copy link
Collaborator

flack commented Feb 14, 2013

Well, right now the tests fail accoring to Travis: https://travis-ci.org/flack/createphp/builds/4791902

Other than that, I think we're good :)

@dbu
Copy link
Collaborator

dbu commented Feb 14, 2013

good thing we have the tests. i did not think very far in my last commit. now it should be good, at least it was locally.

flack added a commit that referenced this pull request Feb 14, 2013
[WIP] removal of duplicate about attribute in collections rendering
@flack flack merged commit 4166d01 into openpsa:master Feb 14, 2013
@lsmith77 lsmith77 deleted the about-fix branch February 22, 2013 00:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants