Commit bf44ce81 authored by Taylor Otwell's avatar Taylor Otwell

added asset links and improved html class.

parent 868a33fb
...@@ -21,7 +21,7 @@ class HTML { ...@@ -21,7 +21,7 @@ class HTML {
*/ */
public static function script($url) public static function script($url)
{ {
return '<script type="text/javascript" src="'.trim(static::entities(URL::to($url)), '.js').'.js"></script>'.PHP_EOL; return '<script type="text/javascript" src="'.trim(static::entities(URL::to_asset($url)), '.js').'.js"></script>'.PHP_EOL;
} }
/** /**
...@@ -32,7 +32,7 @@ class HTML { ...@@ -32,7 +32,7 @@ class HTML {
*/ */
public static function style($url, $media = 'all') public static function style($url, $media = 'all')
{ {
return '<link href="'.trim(static::entities(URL::to($url)), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL; return '<link href="'.trim(static::entities(URL::to_asset($url)), '.css').'.css" rel="stylesheet" type="text/css" media="'.$media.'" />'.PHP_EOL;
} }
/** /**
...@@ -42,11 +42,12 @@ class HTML { ...@@ -42,11 +42,12 @@ class HTML {
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
* @param bool $https * @param bool $https
* @param bool $asset
* @return string * @return string
*/ */
public static function link($url, $title, $attributes = array(), $https = false) public static function link($url, $title, $attributes = array(), $https = false, $asset = false)
{ {
return '<a href="'.static::entities(URL::to($url, $https)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>'; return '<a href="'.static::entities(URL::to($url, $https, $asset)).'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
} }
/** /**
...@@ -57,11 +58,24 @@ class HTML { ...@@ -57,11 +58,24 @@ class HTML {
* @param array $attributes * @param array $attributes
* @return string * @return string
*/ */
public static function secure_link($url, $title, $attributes) public static function link_to_secure($url, $title, $attributes)
{ {
return static::link($url, $title, $attributes, true); return static::link($url, $title, $attributes, true);
} }
/**
* Generate an HTML link to an asset.
*
* @param string $url
* @param string $title
* @param array $attributes
* @return string
*/
public static function link_to_asset($url, $title, $attributes)
{
return static::link($url, $title, $attributes, false, true);
}
/** /**
* Generate an HTML mailto link. * Generate an HTML mailto link.
* *
...@@ -72,9 +86,6 @@ class HTML { ...@@ -72,9 +86,6 @@ class HTML {
*/ */
public static function mailto($email, $title = null, $attributes = array()) public static function mailto($email, $title = null, $attributes = array())
{ {
// -------------------------------------------------------
// Obfuscate the e-mail address.
// -------------------------------------------------------
$email = static::email($email); $email = static::email($email);
if (is_null($title)) if (is_null($title))
...@@ -107,7 +118,7 @@ class HTML { ...@@ -107,7 +118,7 @@ class HTML {
public static function image($url, $alt = '', $attributes = array()) public static function image($url, $alt = '', $attributes = array())
{ {
$attributes['alt'] = static::entities($alt); $attributes['alt'] = static::entities($alt);
return '<img src="'.static::entities(URL::to($url)).'"'.static::attributes($attributes).' />'; return '<img src="'.static::entities(URL::to_asset($url)).'"'.static::attributes($attributes).' />';
} }
/** /**
...@@ -166,11 +177,6 @@ class HTML { ...@@ -166,11 +177,6 @@ class HTML {
*/ */
private static function list_elements($type, $list, $attributes) private static function list_elements($type, $list, $attributes)
{ {
if ( ! is_array($list))
{
return '';
}
$html = ''; $html = '';
foreach ($list as $key => $value) foreach ($list as $key => $value)
...@@ -199,14 +205,7 @@ class HTML { ...@@ -199,14 +205,7 @@ class HTML {
} }
} }
if (count($html) > 0) return (count($html) > 0) ? ' '.implode(' ', $html) : '';
{
return ' '.implode(' ', $html);
}
else
{
return '';
}
} }
/** /**
......
...@@ -6,9 +6,11 @@ class URL { ...@@ -6,9 +6,11 @@ class URL {
* Generate an application URL. * Generate an application URL.
* *
* @param string $url * @param string $url
* @param bool $https
* @param bool $asset
* @return string * @return string
*/ */
public static function to($url = '', $https = false) public static function to($url = '', $https = false, $asset = false)
{ {
// ---------------------------------------------------- // ----------------------------------------------------
// Return the URL unchanged if it is already formed. // Return the URL unchanged if it is already formed.
...@@ -21,7 +23,17 @@ class URL { ...@@ -21,7 +23,17 @@ class URL {
// ---------------------------------------------------- // ----------------------------------------------------
// Get the base URL and index page. // Get the base URL and index page.
// ---------------------------------------------------- // ----------------------------------------------------
$base = Config::get('application.url').'/'.Config::get('application.index'); $base = Config::get('application.url');
// ----------------------------------------------------
// Assets live in the public directory, so we don't
// want to append the index file to the URL if the
// URL is to an asset.
// ----------------------------------------------------
if ( ! $asset)
{
$base .= '/'.Config::get('application.index');
}
// ---------------------------------------------------- // ----------------------------------------------------
// Does the URL need an HTTPS protocol? // Does the URL need an HTTPS protocol?
...@@ -45,6 +57,18 @@ class URL { ...@@ -45,6 +57,18 @@ class URL {
return static::to($url, true); return static::to($url, true);
} }
/**
* Generate an application URL to an asset. The index file
* will not be added to the URL.
*
* @param string $url
* @return string
*/
public static function to_asset($url)
{
return static::to($url, false, true);
}
/** /**
* Generate a URL from a route name. * Generate a URL from a route name.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment