]> source.dussan.org Git - nextcloud-server.git/commitdiff
ability to add bower resources
authorMorris Jobke <hey@morrisjobke.de>
Mon, 3 Nov 2014 10:18:17 +0000 (11:18 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Mon, 3 Nov 2014 19:54:40 +0000 (20:54 +0100)
* add addVendorScript & addVendorStyle
* refactoring of addScript and addStyle
* add shortcuts vendorScript and vendorStyle

.bowerrc [new file with mode: 0644]
bower.json [new file with mode: 0644]
lib/private/template/functions.php
lib/private/util.php

diff --git a/.bowerrc b/.bowerrc
new file mode 100644 (file)
index 0000000..107785f
--- /dev/null
+++ b/.bowerrc
@@ -0,0 +1,3 @@
+{
+       "directory": "core/vendor"
+}
diff --git a/bower.json b/bower.json
new file mode 100644 (file)
index 0000000..3a6d8d7
--- /dev/null
@@ -0,0 +1,17 @@
+{
+       "name": "ownCloud",
+       "version": "8.0 pre alpha",
+       "homepage": "http://www.owncloud.org",
+       "license": "AGPL",
+       "private": true,
+       "ignore": [
+               "**/.*",
+               "node_modules",
+               "bower_components",
+               "core/vendor",
+               "test",
+               "tests"
+       ],
+       "dependencies": {
+       }
+}
index dede604c01de2da44e8fd02b2054714c2879b63d..0e2c5775c4695886145d96b2711a74d1f4499926 100644 (file)
@@ -39,6 +39,22 @@ function script($app, $file) {
        }
 }
 
+/**
+ * Shortcut for adding vendor scripts to a page
+ * @param string $app the appname
+ * @param string|string[] $file the filename,
+ * if an array is given it will add all scripts
+ */
+function vendorScript($app, $file) {
+       if(is_array($file)) {
+               foreach($file as $f) {
+                       OC_Util::addVendorScript($app, $f);
+               }
+       } else {
+               OC_Util::addVendorScript($app, $file);
+       }
+}
+
 /**
  * Shortcut for adding styles to a page
  * @param string $app the appname
@@ -55,6 +71,22 @@ function style($app, $file) {
        }
 }
 
+/**
+ * Shortcut for adding vendor styles to a page
+ * @param string $app the appname
+ * @param string|string[] $file the filename,
+ * if an array is given it will add all styles
+ */
+function vendorStyle($app, $file) {
+       if(is_array($file)) {
+               foreach($file as $f) {
+                       OC_Util::addVendorStyle($app, $f);
+               }
+       } else {
+               OC_Util::addVendorStyle($app, $file);
+       }
+}
+
 /**
  * Shortcut for adding translations to a page
  * @param string $app the appname
index de4bef4cb8a05a60a52a1113f120dbccbe6a4d1b..bee0a579192a625dc29d851f31a44767e228c4b1 100644 (file)
@@ -331,24 +331,47 @@ class OC_Util {
        }
 
        /**
-        * add a javascript file
+        * generates a path for JS/CSS files. If no application is provided it will create the path for core.
         *
-        * @param string $application application id
-        * @param string|null $file filename
-        * @return void
+        * @param $application application to get the files from
+        * @param $directory directory withing this application (css, js, vendor, etc)
+        * @param $file the file inside of the above folder
+        * @return string the path
         */
-       public static function addScript($application, $file = null) {
+       private static function generatePath($application, $directory, $file) {
                if (is_null($file)) {
                        $file = $application;
                        $application = "";
                }
                if (!empty($application)) {
-                       self::$scripts[] = "$application/js/$file";
+                       return "$application/$directory/$file";
                } else {
-                       self::$scripts[] = "js/$file";
+                       return "$directory/$file";
                }
        }
 
+       /**
+        * add a javascript file
+        *
+        * @param string $application application id
+        * @param string|null $file filename
+        * @return void
+        */
+       public static function addScript($application, $file = null) {
+               self::$scripts[] = OC_Util::generatePath($application, 'js', $file);
+       }
+
+       /**
+        * add a javascript file from the vendor sub folder
+        *
+        * @param string $application application id
+        * @param string|null $file filename
+        * @return void
+        */
+       public static function addVendorScript($application, $file = null) {
+               self::$scripts[] = OC_Util::generatePath($application, 'vendor', $file);
+       }
+
        /**
         * add a translation JS file
         *
@@ -375,15 +398,18 @@ class OC_Util {
         * @return void
         */
        public static function addStyle($application, $file = null) {
-               if (is_null($file)) {
-                       $file = $application;
-                       $application = "";
-               }
-               if (!empty($application)) {
-                       self::$styles[] = "$application/css/$file";
-               } else {
-                       self::$styles[] = "css/$file";
-               }
+               self::$styles[] = OC_Util::generatePath($application, 'css', $file);
+       }
+
+       /**
+        * add a css file from the vendor sub folder
+        *
+        * @param string $application application id
+        * @param string|null $file filename
+        * @return void
+        */
+       public static function addVendorStyle($application, $file = null) {
+               self::$styles[] = OC_Util::generatePath($application, 'vendor', $file);
        }
 
        /**