ADD outil de minification du javascript (pour la mise en prod)
authorGreg Burri <greg.burri@gmail.com>
Wed, 16 Apr 2008 07:35:58 +0000 (07:35 +0000)
committerGreg Burri <greg.burri@gmail.com>
Wed, 16 Apr 2008 07:35:58 +0000 (07:35 +0000)
README
mise_en_prod.rb
tool/minjs.rb [new file with mode: 0644]

diff --git a/README b/README
index 7f0a5e1..04e1564 100644 (file)
--- a/README
+++ b/README
@@ -1,70 +1,72 @@
-README - EUPHORIK\r
------------------\r
+== README - EUPHORIK ==\r
 \r
 Ce document a pour but d'introduire le projet Euphorik, de décrire\r
 sa strucure et son utilisation au niveau du développement et de son\r
 utilisation.\r
 \r
 \r
 \r
 Ce document a pour but d'introduire le projet Euphorik, de décrire\r
 sa strucure et son utilisation au niveau du développement et de son\r
 utilisation.\r
 \r
 \r
--- Description --\r
+== Description ==\r
 Euphorik est un site web communautaire développer en Erlang pour le serveur Yaws et utilisant la base de données Mnesia.\r
 \r
 \r
 Euphorik est un site web communautaire développer en Erlang pour le serveur Yaws et utilisant la base de données Mnesia.\r
 \r
 \r
--- Installation\r
+== Installation ==\r
 L'installation de Yaws et sa configuration ainsi que l'initialisation de la base de données\r
 est décrit dans le fichier /doc/installation.txt.\r
 \r
 \r
 L'installation de Yaws et sa configuration ainsi que l'initialisation de la base de données\r
 est décrit dans le fichier /doc/installation.txt.\r
 \r
 \r
--- Dossiers / Fichiers --\r
-/index.html\r
+== Dossiers / Fichiers ==\r
+ /index.html\r
    La page principale du site. Elle est statique.\r
 \r
    La page principale du site. Elle est statique.\r
 \r
-/mise_en_prod.rb\r
+ /mise_en_prod.rb\r
    Script permettant la mise en production du site.\r
    \r
    Script permettant la mise en production du site.\r
    \r
-/BD\r
+ /BD\r
    Contient les fichiers lié à la base de données, initialement vide.\r
    \r
    Contient les fichiers lié à la base de données, initialement vide.\r
    \r
-/css\r
+ /css\r
    Contient les feuilles de style de chaque skin contenu dans un dossier représentant le numéro du skin.\r
    \r
    Contient les feuilles de style de chaque skin contenu dans un dossier représentant le numéro du skin.\r
    \r
-/css/common.css\r
+ /css/common.css\r
    La feuille de style\r
    \r
    La feuille de style\r
    \r
-/doc\r
+ /doc\r
    Contient tous les documents de conception (fonctionnel, technique, etc.).\r
    \r
    Contient tous les documents de conception (fonctionnel, technique, etc.).\r
    \r
-/img\r
+ /img\r
    Contient les images du site avec un séparation des images propres à chaque skin.\r
    Certaines images sont issues de document de conception se trouvant dans /doc/graphiques\r
    \r
    Contient les images du site avec un séparation des images propres à chaque skin.\r
    Certaines images sont issues de document de conception se trouvant dans /doc/graphiques\r
    \r
-/js\r
+ /js\r
    Contient tous les scripts JavaScript. Il existe un script général à Euphorik : euphorik.js ainsi qu'un script par page : page*.js\r
    \r
    Contient tous les scripts JavaScript. Il existe un script général à Euphorik : euphorik.js ainsi qu'un script par page : page*.js\r
    \r
-/lightbox\r
+ /lightbox\r
    Lib JavaScript permettant d'afficher des images sous la forme de pop-up div.\r
    \r
    Lib JavaScript permettant d'afficher des images sous la forme de pop-up div.\r
    \r
-/modules\r
+ /modules\r
    Contient la partie serveur.\r
    \r
    Contient la partie serveur.\r
    \r
-/modules/Makefile\r
+ /modules/Makefile\r
    Règle de compilation des modules du serveur.\r
    \r
    Règle de compilation des modules du serveur.\r
    \r
-/modules/ebin\r
+ /modules/ebin\r
    Contient les modules compilées, initialement vide.\r
    \r
    Contient les modules compilées, initialement vide.\r
    \r
-/module/erl\r
+ /module/erl\r
    Contient le code sources des différents modules.\r
    \r
    Contient le code sources des différents modules.\r
    \r
-/modules/include\r
+ /modules/include\r
    Contient certaines définitions (headers).\r
    \r
    Contient certaines définitions (headers).\r
    \r
-/pages\r
+ /pages\r
    Contient certaines pages XHTML qui seront chargée via AJAX.\r
    \r
    Contient certaines pages XHTML qui seront chargée via AJAX.\r
    \r
-/sessions\r
+ /sessions\r
    Contient différentes sessions de travail pour le développement avec Scite.\r
    \r
    Contient différentes sessions de travail pour le développement avec Scite.\r
    \r
-\r
+ /tool\r
+   Contient des outils diverses permettant l'aide au développement ou la mise en production.\r
+ /tool/minjs.rb\r
+   Permet la minification du javascript utilisé lors de la mise en production\r
    \r
    
\ No newline at end of file
    \r
    
\ No newline at end of file
index 5c5a8f7..d540cd2 100755 (executable)
@@ -1,15 +1,17 @@
 #!/usr/bin/ruby
 
 def copy_files(dest, opt)    
 #!/usr/bin/ruby
 
 def copy_files(dest, opt)    
-   p    "rsync #{opt} index.html #{dest}"
    `rsync #{opt} index.html #{dest}`
    `rsync #{opt} -r css #{dest}`
    `rsync #{opt} -r img #{dest}`
    `rsync #{opt} index.html #{dest}`
    `rsync #{opt} -r css #{dest}`
    `rsync #{opt} -r img #{dest}`
-   `rsync #{opt} -r js #{dest}`
+   #`rsync #{opt} -r js #{dest}`
    `rsync #{opt} -r lightbox #{dest}`
    `rsync #{opt} -r modules/include #{dest}/modules`
    `rsync #{opt} -r modules/ebin #{dest}/modules`
    `rsync #{opt} -r lightbox #{dest}`
    `rsync #{opt} -r modules/include #{dest}/modules`
    `rsync #{opt} -r modules/ebin #{dest}/modules`
-   `rsync #{opt} -r pages #{dest}`
+   `rsync #{opt} -r pages #{dest}`\r
+   \r
+   # copie des js avec minification\r
+   
 end
 
 if __FILE__ == $0   
 end
 
 if __FILE__ == $0   
diff --git a/tool/minjs.rb b/tool/minjs.rb
new file mode 100644 (file)
index 0000000..00fd804
--- /dev/null
@@ -0,0 +1,205 @@
+#!/usr/bin/ruby
+# jsmin.rb 2007-07-20
+# Author: Uladzislau Latynski
+# This work is a translation from C to Ruby of jsmin.c published by
+# Douglas Crockford.  Permission is hereby granted to use the Ruby
+# version under the same conditions as the jsmin.c on which it is
+# based.
+#
+# /* jsmin.c
+#    2003-04-21
+#
+# Copyright (c) 2002 Douglas Crockford  (www.crockford.com)
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of
+# this software and associated documentation files (the "Software"), to deal in
+# the Software without restriction, including without limitation the rights to
+# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+# of the Software, and to permit persons to whom the Software is furnished to do
+# so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# The Software shall be used for Good, not Evil.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+EOF = -1
+$theA = ""
+$theB = ""
+
+# isAlphanum -- return true if the character is a letter, digit, underscore,
+# dollar sign, or non-ASCII character
+def isAlphanum(c)
+   return false if !c || c == EOF
+   return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
+           (c >= 'A' && c <= 'Z') || c == '_' || c == '$' ||
+           c == '\\' || c[0] > 126)
+end
+
+# get -- return the next character from stdin. Watch out for lookahead. If
+# the character is a control character, translate it to a space or linefeed.
+def get()
+  c = $stdin.getc
+  return EOF if(!c)
+  c = c.chr
+  return c if (c >= " " || c == "\n" || c.unpack("c") == EOF)
+  return "\n" if (c == "\r")
+  return " "
+end
+
+# Get the next character without getting it.
+def peek()
+    lookaheadChar = $stdin.getc
+    $stdin.ungetc(lookaheadChar)
+    return lookaheadChar.chr
+end
+
+# mynext -- get the next character, excluding comments.
+# peek() is used to see if a '/' is followed by a '/' or '*'.
+def mynext()
+    c = get
+    if (c == "/")
+        if(peek == "/")
+            while(true)
+                c = get
+                if (c <= "\n")
+                return c
+                end
+            end
+        end
+        if(peek == "*")
+            get
+            while(true)
+                case get
+                when "*"
+                   if (peek == "/")
+                        get
+                        return " "
+                    end
+                when EOF
+                    raise "Unterminated comment"
+                end
+            end
+        end
+    end
+    return c
+end
+
+
+# action -- do something! What you do is determined by the argument: 1
+# Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B.
+# (Delete A). 3 Get the next B. (Delete B). action treats a string as a
+# single character. Wow! action recognizes a regular expression if it is
+# preceded by ( or , or =.
+def action(a)
+    if(a==1)
+        $stdout.write $theA
+    end
+    if(a==1 || a==2)
+        $theA = $theB
+        if ($theA == "\'" || $theA == "\"")
+            while (true)
+                $stdout.write $theA
+                $theA = get
+                break if ($theA == $theB)
+                raise "Unterminated string literal" if ($theA <= "\n")
+                if ($theA == "\\")
+                    $stdout.write $theA
+                    $theA = get
+                end
+            end
+        end
+    end
+    if(a==1 || a==2 || a==3)
+        $theB = mynext
+        if ($theB == "/" && ($theA == "(" || $theA == "," || $theA == "=" ||
+                             $theA == ":" || $theA == "[" || $theA == "!" ||
+                             $theA == "&" || $theA == "|" || $theA == "?" ||
+                             $theA == "{" || $theA == "}" || $theA == ";" ||
+                             $theA == "\n"))
+            $stdout.write $theA
+            $stdout.write $theB
+            while (true)
+                $theA = get
+                if ($theA == "/")
+                    break
+                elsif ($theA == "\\")
+                    $stdout.write $theA
+                    $theA = get
+                elsif ($theA <= "\n")
+                    raise "Unterminated RegExp Literal"
+                end
+                $stdout.write $theA
+            end
+            $theB = mynext
+        end
+    end
+end
+
+# jsmin -- Copy the input to the output, deleting the characters which are
+# insignificant to JavaScript. Comments will be removed. Tabs will be
+# replaced with spaces. Carriage returns will be replaced with linefeeds.
+# Most spaces and linefeeds will be removed.
+def jsmin
+    $theA = "\n"
+    action(3)
+    while ($theA != EOF)
+        case $theA
+        when " "
+            if (isAlphanum($theB))
+                action(1)
+            else
+                action(2)
+            end
+        when "\n"
+            case ($theB)
+            when "{","[","(","+","-"
+                action(1)
+            when " "
+                action(3)
+            else
+                if (isAlphanum($theB))
+                    action(1)
+                else
+                    action(2)
+                end
+            end
+        else
+            case ($theB)
+            when " "
+                if (isAlphanum($theA))
+                    action(1)
+                else
+                    action(3)
+                end
+            when "\n"
+                case ($theA)
+                when "}","]",")","+","-","\"","\\", "'", '"'
+                    action(1)
+                else
+                    if (isAlphanum($theA))
+                        action(1)
+                    else
+                        action(3)
+                    end
+                end
+            else
+                action(1)
+            end
+        end
+    end
+end
+
+ARGV.each do |anArg|
+    $stdout.write "// #{anArg}\n"
+end
+
+jsmin
\ No newline at end of file