Comments: on this page. Click to read or post your own.

Class Requirements

Description

Requirements tracker, for javascript and css.

  • todo: Document the requirements tracker, and discuss it with the others.

Located in /sapphire/core/Requirements.php (line 8)


	
			
Variable Summary
static array $blocked
static array $combine_files
static boolean $combine_js_with_jsmin
static array $css
static array $customCSS
static mixed $customHeadTags
static array $customScript
static array $disabled
static array $javascript
static boolean $write_js_to_body
Method Summary
static void block (string $fileOrID)
static void clear ([$file $fileOrID = null])
static void clear_combined_files ()
static void combine_files (string $combinedFileName, array $files)
static void css ($file $file, [$media $media = null])
static void customCSS ( $script, [ $uniquenessID = null])
static void customScript (script $script, [uniquenessID $uniquenessID = null])
static void debug ()
static void delete_combined_files ([string $combinedFileName = null])
static array get_combine_files ()
static void get_custom_scripts ()
static string includeInHTML ( $templateFile, string $content, string $templateFilePath)
static void insertHeadTags (string $html, [string $uniquenessID = null])
static void javascript ( $file)
static void javascriptTemplate (file $file, vars $vars, [ $uniquenessID = null])
static string|boolean path_for_file (string $fileOrUrl)
static void process_combined_files ()
static void process_i18n_javascript ()
static void restore ()
static void themedCSS ($name $name, [$media $media = null])
static void unblock (string $fileOrID)
static void unblock_all ()
Variables
static array $blocked = array() (line 67)

The filepaths (relative to webroot) or uniquenessIDs of any included requirements which should be blocked when executing inlcudeInHTML().

This is useful to e.g. prevent core classes to modifying Requirements without subclassing the entire functionality. Use unblock() or unblock_all() to revert changes.

  • access: protected
static array $combine_files = array() (line 74)

See combine_files().

  • access: public
static boolean $combine_js_with_jsmin = true (line 82)

Using the JSMin library to minify any javascript file passed to combine_files().

  • access: public
static array $css = array() (line 22)

Paths to all required .css files relative to the webroot.

  • access: protected
static array $customCSS = array() (line 38)

All custom CSS rules which are inserted directly at the bottom of the HTML <head> tag.

  • access: protected
static mixed $customHeadTags = array() (line 45)

All custom HTML markup which is added before the closing <head> tag, e.g. additional metatags.

This is preferred to entering tags directly into

  • access: protected
static array $customScript = array() (line 30)

All custom javascript code that is inserted directly at the bottom of the HTML <head> tag.

  • access: protected
static array $disabled = array() (line 55)

Remembers the filepaths of all cleared Requirements through clear().

  • access: protected
static array $javascript = array() (line 15)

Paths to all required .js files relative to the webroot.

  • access: protected
static boolean $write_js_to_body = false (line 97)

Put all javascript includes at the bottom of the template before the closing <body> tag instead of the <head> tag.

This means script downloads won't block other HTTP-requests, which can be a performance improvement. Caution: Doesn't work when modifying the DOM from those external scripts without listening to window.onload/document.ready (e.g. toplevel document.write() calls).

  • see: js_bottom
  • access: public
Methods
static method block (line 237)

Needed to actively prevent the inclusion of a file, e.g. when using your own prototype.js.

Blocking should only be used as an exception, because it is hard to trace back. You can just block items with an ID, so make sure you add an unique identifier to customCSS() and customScript().

static void block (string $fileOrID)
  • string $fileOrID
static method clear (line 205)

Clear either a single or all requirements.

Caution: Clearing single rules works only with customCSS and customScript if you specified a {@uniquenessID}.

static void clear ([$file $fileOrID = null])
  • $file $fileOrID: String
static method clear_combined_files (line 498)

Re-sets the combined files definition

static void clear_combined_files ()
static method combine_files (line 460)

Concatenate several css or javascript files into a single dynamically generated file (stored in Director::baseFolder()). This increases performance by fewer HTTP requests.

The combined file is regenerated based on every file modification time. Optionally a rebuild can be triggered by appending ?flush=1 to the URL. If all files to be combined are javascript, we use the external JSMin library to minify the javascript. This can be controlled by $combine_js_with_jsmin.

All combined files will have a comment on the start of each concatenated file denoting their original position. For easier debugging, we recommend to only minify javascript if not in development mode (Director::isDev()).

CAUTION: You're responsible for ensuring that the load order for combined files is retained - otherwise combining javascript files can lead to functional errors in the javascript logic, and combining css can lead to wrong styling inheritance. Depending on the javascript logic, you also have to ensure that files are not included in more than one combine_files() call. Best practice is to include every javascript file in exactly *one* combine_files() directive to avoid the issues mentioned above - this is enforced by this function.

CAUTION: Combining CSS Files discards any "media" information.

Example for combined JavaScript:

  1.   'foobar.js',
  2.   array(
  3.          'mysite/javascript/foo.js',
  4.          'mysite/javascript/bar.js',
  5.      )
  6.  );

Example for combined CSS:

  1.   'foobar.css',
  2.      array(
  3.          'mysite/javascript/foo.css',
  4.          'mysite/javascript/bar.css',
  5.      )
  6.  );

static void combine_files (string $combinedFileName, array $files)
  • string $combinedFileName: Filename of the combined file (will be stored in Director::baseFolder() by default)
  • array $files: Array of filenames relative to the webroot
static method css (line 171)

Register the given stylesheet file as required.

static void css ($file $file, [$media $media = null])
  • $file $file: String Filenames should be relative to the base, eg, 'jsparty/tree/tree.css'
  • $media $media: String Comma-separated list of media-types (e.g. "screen,projector")
static method customCSS (line 126)

Add the CSS styling to the header of the page

  • todo: Make Requirements automatically put this into a separate file :-)
static void customCSS ( $script, [ $uniquenessID = null])
  • $script
  • $uniquenessID
static method customScript (line 113)

Add the javascript code to the header of the page

  • todo: Make Requirements automatically put this into a separate file :-)
static void customScript (script $script, [uniquenessID $uniquenessID = null])
  • script $script: The script content
  • uniquenessID $uniquenessID: Use this to ensure that pieces of code only get added once.
static method debug (line 599)
static void debug ()
static method delete_combined_files (line 485)

Deletes all dynamically generated combined files from the filesystem.

static void delete_combined_files ([string $combinedFileName = null])
  • string $combinedFileName: If left blank, all combined files are deleted.
static method get_combine_files (line 476)
static array get_combine_files ()
static method get_custom_scripts (line 587)
static void get_custom_scripts ()
static method includeInHTML (line 278)

Update the given HTML content with the appropriate include tags for the registered requirements. Needs to receive a valid HTML/XHTML template in the $content parameter, including a <head> tag. The requirements will insert before the closing <head> tag automatically.

  • return: HTML content thats augumented with the requirements before the closing <head> tag.
  • todo: Calculate $prefix properly
static string includeInHTML ( $templateFile, string $content, string $templateFilePath)
  • string $templateFilePath: Absolute path for the *.ss template file
  • string $content: HTML content that has already been parsed from the $templateFilePath through SSViewer.
  • $templateFile
static method insertHeadTags (line 140)

Add the following custom code to the <head> section of the page.

static void insertHeadTags (string $html, [string $uniquenessID = null])
  • string $html
  • string $uniquenessID
static method javascript (line 103)

Register the given javascript file as required.

Filenames should be relative to the base, eg, 'sapphire/javascript/loader.js'

static void javascript ( $file)
  • $file
static method javascriptTemplate (line 154)

Load the given javascript template with the page.

static void javascriptTemplate (file $file, vars $vars, [ $uniquenessID = null])
  • file $file: The template file to load.
  • vars $vars: The array of variables to load. These variables are loaded via string search & replace.
  • $uniquenessID
static method path_for_file (line 394)
  • access: protected
static string|boolean path_for_file (string $fileOrUrl)
  • string $fileOrUrl
static method process_combined_files (line 505)

See combine_files().

static void process_combined_files ()
static method process_i18n_javascript (line 359)

Automatically includes the necessary lang-files from the module according to the locale set in i18n::$current_locale.

Assumes that a subfolder /javascript exists relative to the included javascript file, with a file named after the locale - so usually <mymodule>/javascript/lang/en_US.js.

  • access: protected
static void process_i18n_javascript ()
static method restore (line 260)

Restore requirements cleared by call to Requirements::clear

static void restore ()
static method themedCSS (line 185)

Register the given "themeable stylesheet" as required.

Themeable stylesheets have globally unique names, just like templates and PHP files. Because of this, they can be replaced by similarly named CSS files in the theme directory.

static void themedCSS ($name $name, [$media $media = null])
  • $name $name: String The identifier of the file. For example, css/MyFile.css would have the identifier "MyFile"
  • $media $media: String Comma-separated list of media-types (e.g. "screen,projector")
static method unblock (line 246)

Removes an item from the blocking-list.

CAUTION: Does not "re-add" any previously blocked elements.

static void unblock (string $fileOrID)
  • string $fileOrID
static method unblock_all (line 253)

Removes all items from the blocking-list.

static void unblock_all ()
blog comments powered by Disqus

Documentation generated on Sun, 19 Oct 2008 06:45:01 +1300 by phpDocumentor 1.3.2