Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/Console/Commands/LarouteGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ protected function getTemplatePath()
protected function getTemplateData()
{
$namespace = $this->getOptionOrConfig('namespace');
$routes = $this->routes->toJSON();
$absolute = $this->config->get('laroute.absolute', false);
$rootUrl = $this->config->get('app.url', '');
$prefix = $this->config->get('laroute.prefix', '');
$routes = $this->option('empty') ? json_encode([]) : $this->routes->toJSON();
$absolute = $this->option('empty') ? false : $this->config->get('laroute.absolute', false);
$rootUrl = $this->option('empty') ? '' : $this->config->get('app.url', '');
$prefix = $this->option('empty') ? '' : $this->config->get('laroute.prefix', '');

return compact('namespace', 'routes', 'absolute', 'rootUrl', 'prefix');
}
Expand Down Expand Up @@ -162,13 +162,24 @@ protected function getOptions()
[
'namespace',
null,
InputOption::VALUE_OPTIONAL, sprintf('Javascript namespace for the functions (think _.js) (default: "%s")', $this->config->get('laroute.namespace'))
InputOption::VALUE_OPTIONAL,
sprintf(
'Javascript namespace for the functions (think _.js) (default: "%s")',
$this->config->get('laroute.namespace')
)
],
[
'prefix',
'pr',
InputOption::VALUE_OPTIONAL, sprintf('Prefix for the generated URLs (default: "%s")', $this->config->get('laroute.prefix'))
InputOption::VALUE_OPTIONAL,
sprintf('Prefix for the generated URLs (default: "%s")', $this->config->get('laroute.prefix'))
],
[
'empty',
null,
InputOption::VALUE_NONE,
'Whether to hard-code configuration values in the generated JavaScript file.'
]
];
}
}
24 changes: 24 additions & 0 deletions src/templates/laroute.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@
var url = this.action(action, parameters);

return getHtmlLink(url, title, attributes);
},

// Whether we're using absolute URLs or not.
// $NAMESPACE$.set_absolute(true)
set_absolute : function (absolute) {
routes.absolute = absolute;
},

// Set a base url for all routes.
// $NAMESPACE$.set_root_url('http://localhost')
set_root_url : function (url) {
routes.rootUrl = url;
},

// JSON encoded route collection.
// $NAMESPACE$.set_routes([])
set_routes : function (json) {
routes.routes = json;
},

// Add a prefix to all URLs.
// $NAMEPSACE$.set_prefix('my-prefix')
set_prefix : function (prefix) {
routes.prefix = prefix;
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/templates/laroute.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.