3 namespace DrupalCodeGenerator;
5 use DrupalCodeGenerator\Helper\Renderer;
8 * Simple data structure to represent an asset being generated.
27 * Twig template to render header.
31 protected $headerTemplate;
34 * Twig template to render main content.
50 * This defines an action to take if specified file already exists.
54 protected $action = 'replace';
61 protected $headerSize = 0;
71 * Asset type (file or directory).
75 protected $type = 'file';
78 * Getter for asset path.
83 public function getPath() {
84 return Utils::tokenReplace($this->path, $this->getVars());
88 * Getter for asset content.
93 public function getContent() {
94 return $this->content;
98 * Getter for header template.
101 * Asset header template.
103 public function getHeaderTemplate() {
104 return $this->headerTemplate;
108 * Getter for template.
113 public function getTemplate() {
114 return $this->template;
118 * Getter for asset vars.
121 * Asset template variables.
123 public function getVars() {
128 * Getter for asset action.
133 public function getAction() {
134 return $this->action;
138 * Getter for asset header size.
143 public function getHeaderSize() {
144 return $this->headerSize;
148 * Getter for asset mode.
153 public function getMode() {
154 return $this->mode ?: ($this->isDirectory() ? 0755 : 0644);
158 * Getter for asset type.
163 public function getType() {
168 * Setter for asset path.
170 * @param string $path
173 * @return \DrupalCodeGenerator\Asset
176 public function path($path) {
182 * Setter for asset content.
184 * @param string $content
187 * @return \DrupalCodeGenerator\Asset
190 public function content($content) {
191 $this->content = $content;
196 * Setter for asset header template.
198 * @param string $header_template
201 * @return \DrupalCodeGenerator\Asset
204 public function headerTemplate($header_template) {
205 $this->headerTemplate = $header_template;
210 * Setter for asset template.
212 * @param string $template
215 * @return \DrupalCodeGenerator\Asset
218 public function template($template) {
219 $this->template = $template;
224 * Setter for asset vars.
227 * Asset template variables.
229 * @return \DrupalCodeGenerator\Asset
232 public function vars(array $vars) {
238 * Setter for asset action.
240 * @param string $action
243 * @return \DrupalCodeGenerator\Asset
246 public function action($action) {
247 $this->action = $action;
252 * Setter for asset header size.
254 * @param int $header_size
257 * @return \DrupalCodeGenerator\Asset
260 public function headerSize($header_size) {
261 $this->headerSize = $header_size;
266 * Setter for asset mode.
268 * @param string $mode
271 * @return \DrupalCodeGenerator\Asset
274 public function mode($mode) {
280 * Setter for asset type.
282 * @param string $type
285 * @return \DrupalCodeGenerator\Asset
288 public function type($type) {
294 * Determines if the asset is a directory.
297 * True if the asset is a directory, false otherwise.
299 public function isDirectory() {
300 return $this->getType() == 'directory';
304 * Renders the asset template.
306 * @param \DrupalCodeGenerator\Helper\Renderer $renderer
309 public function render(Renderer $renderer) {
310 if (!$this->isDirectory() && is_null($this->getContent())) {
312 if ($header_template = $this->getHeaderTemplate()) {
313 $content .= $renderer->render($header_template, $this->getVars()) . "\n";
315 $content .= $renderer->render($this->getTemplate(), $this->getVars());
316 $this->content($content);