Skip to content

Commit

Permalink
Merge pull request #93 from martonmiklos/master
Browse files Browse the repository at this point in the history
Fixed indentation in the generated view's.
  • Loading branch information
jadb committed Sep 14, 2015
2 parents 03a69bf + 5e29039 commit 2e91156
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 88 deletions.
37 changes: 22 additions & 15 deletions src/Template/Bake/Element/form.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ $this->extend('../Layout/TwitterBootstrap/dashboard');
$this->start('tb_actions');
?>
<% if (strpos($action, 'add') === false): %>
<li><?=
<li><?=
$this->Form->postLink(
__('Delete'),
['action' => 'delete', $<%= $singularVar
%>-><%= $primaryKey[0] %>],
['confirm' => __('Are you sure you want to delete # {0}?', $<%= $singularVar %>-><%= $primaryKey[0] %>)]
__('Delete'),
['action' => 'delete', $<%= $singularVar
%>-><%= $primaryKey[0] %>],
['confirm' => __('Are you sure you want to delete # {0}?', $<%= $singularVar %>-><%= $primaryKey[0] %>)]
)
?></li>
?>
</li>
<% endif; %>
<li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?></li>
<li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?></li>
<%
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
%>
<li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) %> </li>
<li><?= $this->Html->link(__('New <%= $this->_singularHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) %> </li>
<%
<li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) %> </li>
<li><?= $this->Html->link(__('New <%= $this->_singularHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) %> </li>
<%
$done[] = $details['controller'];
}
}
Expand All @@ -42,32 +43,38 @@ foreach ($associations as $type => $data) {
<fieldset>
<legend><?= __('<%= Inflector::humanize($action) %> {0}', ['<%= $singularHumanName %>']) ?></legend>
<?php
<%
<%
foreach ($fields as $field) {
if (in_array($field, $primaryKey)) {
continue;
}
if (isset($keyFields[$field])) {
%>
echo $this->Form->input('<%= $field %>', ['options' => $<%= $keyFields[$field] %>]);
<%
<%
continue;
}
if (!in_array($field, ['created', 'modified', 'updated'])) {
%>
echo $this->Form->input('<%= $field %>');
<%
<%
}
}
if (!empty($associations['BelongsToMany'])) {
foreach ($associations['BelongsToMany'] as $assocName => $assocData) {
%>
echo $this->Form->input('<%= $assocData['property'] %>._ids', ['options' => $<%= $assocData['variable'] %>]);
<%
<%
}
}
%>
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<%
if (strpos($action, 'add') === false)
$submitButtonTitle = '__("Save")';
else
$submitButtonTitle = '__("Add")';
%>
<?= $this->Form->button(<% echo $submitButtonTitle;%>); ?>
<?= $this->Form->end() ?>
25 changes: 12 additions & 13 deletions src/Template/Bake/Template/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use Cake\Utility\Inflector;
$this->extend('../Layout/TwitterBootstrap/dashboard');
$this->start('tb_actions');
?>
<li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']); ?></li>
<li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']); ?></li>
<%
$done = [];
foreach ($associations as $type => $data):
foreach ($data as $alias => $details):
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)):
%>
<li><?= $this->Html->link(__('List <%= Inflector::humanize($details["controller"]) %>'), ['controller' => '<%= $details["controller"] %>', 'action' => 'index']); ?></li>
<li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => ' <%= $details["controller"] %>', 'action' => 'add']); ?></li>
<%
<li><?= $this->Html->link(__('List <%= Inflector::humanize($details["controller"]) %>'), ['controller' => '<%= $details["controller"] %>', 'action' => 'index']); ?></li>
<li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => ' <%= $details["controller"] %>', 'action' => 'add']); ?></li>
<%
$done[] = $details['controller'];
endif;
endforeach;
Expand All @@ -34,16 +34,16 @@ $fields = collection($fields)
<table class="table table-striped" cellpadding="0" cellspacing="0">
<thead>
<tr>
<% foreach ($fields as $field): %>
<% foreach ($fields as $field): %>
<th><?= $this->Paginator->sort('<%= $field %>'); ?></th>
<% endforeach; %>
<% endforeach; %>
<th class="actions"><?= __('Actions'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($<%= $pluralVar %> as $<%= $singularVar %>): ?>
<tr>
<%
<%
foreach ($fields as $field) {
$isKey = false;
if (!empty($associations['BelongsTo'])) {
Expand All @@ -52,9 +52,9 @@ $fields = collection($fields)
$isKey = true;
%>
<td>
<?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?>
</td>
<%
<?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?>
</td>
<%
break;
}
}
Expand All @@ -63,11 +63,11 @@ $fields = collection($fields)
if (!in_array($schema->columnType($field), ['integer', 'biginteger', 'decimal', 'float'])) {
%>
<td><?= h($<%= $singularVar %>-><%= $field %>) ?></td>
<%
<%
} else {
%>
<td><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></td>
<%
<%
}
}
}
Expand All @@ -80,7 +80,6 @@ $fields = collection($fields)
<?= $this->Form->postLink('', ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $pk %>), 'title' => __('Delete'), 'class' => 'btn btn-default glyphicon glyphicon-trash']) ?>
</td>
</tr>

<?php endforeach; ?>
</tbody>
</table>
Expand Down
122 changes: 62 additions & 60 deletions src/Template/Bake/Template/view.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ $pk = "\$$singularVar->{$primaryKey[0]}";
$this->extend('../Layout/TwitterBootstrap/dashboard');
$this->start('tb_actions');
?>
<li><?= $this->Html->link(__('Edit <%= $singularHumanName %>'), ['action' => 'edit', <%= $pk %>]) ?> </li>
<li><?= $this->Form->postLink(__('Delete <%= $singularHumanName %>'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $pk %>)]) ?> </li>
<li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?> </li>
<li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']) ?> </li>
<li><?= $this->Html->link(__('Edit <%= $singularHumanName %>'), ['action' => 'edit', <%= $pk %>]) ?> </li>
<li><?= $this->Form->postLink(__('Delete <%= $singularHumanName %>'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $pk %>)]) ?> </li>
<li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?> </li>
<li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']) ?> </li>
<%
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
%>
<li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) ?> </li>
<li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) ?> </li>
<%
<li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) ?> </li>
<li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) ?> </li>
<%
$done[] = $details['controller'];
}
}
Expand All @@ -66,89 +66,91 @@ foreach ($associations as $type => $data) {

<h2><?= h($<%= $singularVar %>-><%= $displayField %>) ?></h2>
<div class="row">
<% if ($groupedFields['string']) : %>
<% if ($groupedFields['string']) : %>
<div class="col-lg-5">
<% foreach ($groupedFields['string'] as $field) : %>
<%
<% foreach ($groupedFields['string'] as $field) : %>
<%
if (isset($associationFields[$field])) :
$details = $associationFields[$field];
%>
<h6><?= __('<%= Inflector::humanize($details['property']) %>') ?></h6>
<p><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?></p>
<% else : %>
<p><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?></p>
<% else : %>
<h6><?= __('<%= Inflector::humanize($field) %>') ?></h6>
<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
<% endif; %>
<% endforeach; %>
<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
<% endif; %>
<% endforeach; %>
</div>
<% endif; %>
<% if ($groupedFields['number']) : %>
<% endif; %>
<% if ($groupedFields['number']) : %>
<div class="col-lg-2">
<% foreach ($groupedFields['number'] as $field) : %>
<% foreach ($groupedFields['number'] as $field) : %>
<h6><?= __('<%= Inflector::humanize($field) %>') ?></h6>
<p><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></p>
<% endforeach; %>
<p><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></p>
<% endforeach; %>
</div>
<% endif; %>
<% if ($groupedFields['date']) : %>
<% endif; %>
<% if ($groupedFields['date']) : %>
<div class="col-lg-2">
<% foreach ($groupedFields['date'] as $field) : %>
<% foreach ($groupedFields['date'] as $field) : %>
<h6><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></h6>
<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
<% endforeach; %>
<p><?= h($<%= $singularVar %>-><%= $field %>) ?></p>
<% endforeach; %>
</div>
<% endif; %>
<% if ($groupedFields['boolean']) : %>
<% endif; %>
<% if ($groupedFields['boolean']) : %>
<div class="col-lg-2">
<% foreach ($groupedFields['boolean'] as $field) : %>
<% foreach ($groupedFields['boolean'] as $field) : %>
<h6><?= __('<%= Inflector::humanize($field) %>') ?></h6>
<p><?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?></p>
<% endforeach; %>
<p><?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?></p>
<% endforeach; %>
</div>
<% endif; %>
<% endif; %>
</div>
<% if ($groupedFields['text']) : %>
<% foreach ($groupedFields['text'] as $field) : %>
<% foreach ($groupedFields['text'] as $field) : %>
<div class="row texts">
<div class="col-lg-9">
<h6><?= __('<%= Inflector::humanize($field) %>') ?></h6>
<?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?>
</div>
</div>
<% endforeach; %>
<% endif; %>
<div class="col-lg-9">
<h6><?= __('<%= Inflector::humanize($field) %>') ?></h6>
<?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?>
</div>
</div>
<%
endforeach;
endif;
%>
<%
$relations = $associations['HasMany'] + $associations['BelongsToMany'];
foreach ($relations as $alias => $details):
$otherSingularVar = Inflector::variable($alias);
$otherPluralHumanName = Inflector::humanize($details['controller']);
%>
<div class="related row">
<div class = "col-lg-12">
<h4><?= __('Related <%= $otherPluralHumanName %>') ?></h4>
<?php if (!empty($<%= $singularVar %>-><%= $details['property'] %>)): ?>
<table class="table table-striped">
<thead>
<tr>
<% foreach ($details['fields'] as $field): %>
<div class = "col-lg-12">
<h4><?= __('Related <%= $otherPluralHumanName %>') ?></h4>
<?php if (!empty($<%= $singularVar %>-><%= $details['property'] %>)): ?>
<table class="table table-striped">
<thead>
<tr>
<% foreach ($details['fields'] as $field): %>
<th><?= __('<%= Inflector::humanize($field) %>') ?></th>
<% endforeach; %>
<% endforeach; %>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($<%= $singularVar %>-><%= $details['property'] %> as $<%= $otherSingularVar %>): ?>
<tr>
<% foreach ($details['fields'] as $field): %>
</tr>
</thead>
<tbody>
<?php foreach ($<%= $singularVar %>-><%= $details['property'] %> as $<%= $otherSingularVar %>): ?>
<tr>
<% foreach ($details['fields'] as $field): %>
<td><?= h($<%= $otherSingularVar %>-><%= $field %>) ?></td>
<% endforeach; %>
<% $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; %>
<% endforeach; %>
<% $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; %>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $otherPk %>)]) ?>
</td>
</tr>
<?= $this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => '<%= $details['controller'] %>', 'action' => 'delete', <%= $otherPk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $otherPk %>)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Expand Down

0 comments on commit 2e91156

Please sign in to comment.