Skip to content

Commit

Permalink
Updated generator to parse out attachment and PDF capable models
Browse files Browse the repository at this point in the history
  • Loading branch information
calcinai committed Jun 20, 2015
1 parent 7735070 commit 99046d4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions generator/generate
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ foreach($scrape_apis as $scrape_api) {
//Debug
$model->printPropertyTable();
}

if(strpos($primary_model->rawHTML, 'returned as PDF') !== false){
//Assume that it does support it.
$primary_model->setSupportsPDF(true);
}
}

});
Expand Down
38 changes: 37 additions & 1 deletion generator/objects/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Model {
private $api;

/**
* @var The parent model of the object. This is if it's defined as a secondary model on a doc page
* The parent model of the object. This is if it's defined as a secondary model on a doc page
*
* @var Model $parent_model
*/
private $parent_model;

Expand All @@ -23,6 +25,14 @@ class Model {
*/
private $guid_property;

/**
* @var bool $supports_pdf
*/
private $supports_pdf;


public $rawHTML;

/**
* No args in constructor. Most things are not known when it's built
*/
Expand All @@ -31,6 +41,7 @@ public function __construct(){
$this->properties = array();
$this->methods = array();
$this->sub_models = array();
$this->supports_pdf = false;
}

/**
Expand Down Expand Up @@ -250,6 +261,31 @@ public function setUrl($url) {
$this->url = $url;
}


/**
* This should be enough to tell if it supports them
*
* @return boolean
*/
public function getSupportsAttachments() {
return $this->hasProperty('HasAttachments');
}

/**
* @return boolean
*/
public function getSupportsPDF() {
return $this->supports_pdf;
}

/**
* @param boolean $supports_pdf
*/
public function setSupportsPDF($supports_pdf) {
$this->supports_pdf = $supports_pdf;
}


/**
* Shortcut for getting them from $api where the group is the same as this name
*
Expand Down
14 changes: 14 additions & 0 deletions generator/templates/model.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@ namespace XeroPHP\Models\{{ model.Namespace }};

use XeroPHP\Remote;

{% if model.SupportsPDF %}
use XeroPHP\Traits\PDFTrait;
{% endif %}
{% if model.SupportsAttachments %}
use XeroPHP\Traits\AttachmentTrait;

{% endif %}
{% for class in model.UsedClasses %}
use XeroPHP\Models\{{ class }};
{% endfor %}

class {{ model.ClassName }} extends Remote\Object {

{% if model.SupportsPDF %}
use PDFTrait;
{% endif %}
{% if model.SupportsAttachments %}
use AttachmentTrait;

{% endif %}
{% for property in model.Properties %}
/**
* {{ property.Description|wordwrap(100, "\n * ")|raw }}
Expand Down

0 comments on commit 99046d4

Please sign in to comment.